75e5adf00d34a50951f84fb03c615bcd0aa05b26
[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
5513 #endif /* DEBUG_REPEAT_TEST_CASE */
5514
5515                 bool case_result = true;
5516
5517                 /* Execute case */
5518                 if (false == testCase(test_case))
5519                 {
5520                         case_result = false;
5521                 }
5522
5523                 /* Log failure */
5524                 if (false == case_result)
5525                 {
5526                         const std::string& test_case_name = getTestCaseName(test_case);
5527
5528                         if (false == test_case_name.empty())
5529                         {
5530                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case_name
5531                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5532                         }
5533                         else
5534                         {
5535                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case
5536                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5537                         }
5538
5539                         result = false;
5540                 }
5541         }
5542
5543         /* Done */
5544         return result;
5545 }
5546
5547 /* Constants used by BufferTestBase */
5548 const GLuint BufferTestBase::bufferDescriptor::m_non_indexed = -1;
5549
5550 /** Constructor
5551  *
5552  * @param context          Test context
5553  * @param test_name        Name of test
5554  * @param test_description Description of test
5555  **/
5556 BufferTestBase::BufferTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5557         : TestBase(context, test_name, test_description)
5558 {
5559 }
5560
5561 /** Execute drawArrays for single vertex
5562  *
5563  * @param ignored
5564  *
5565  * @return true
5566  **/
5567 bool BufferTestBase::executeDrawCall(bool tesEnabled, GLuint /* test_case_index */)
5568 {
5569         const Functions& gl = m_context.getRenderContext().getFunctions();
5570
5571         gl.disable(GL_RASTERIZER_DISCARD);
5572         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
5573
5574         gl.beginTransformFeedback(GL_POINTS);
5575         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
5576
5577         // Only TES is existed, glDrawArray can use the parameter GL_PATCHES
5578         if (tesEnabled == false)
5579         {
5580                 gl.drawArrays(GL_POINTS, 0 /* first */, 1 /* count */);
5581         }
5582         else
5583         {
5584                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
5585         }
5586
5587         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
5588
5589         gl.endTransformFeedback();
5590         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
5591
5592         return true;
5593 }
5594
5595 /** Get descriptors of buffers necessary for test
5596  *
5597  * @param ignored
5598  * @param ignored
5599  **/
5600 void BufferTestBase::getBufferDescriptors(glw::GLuint /* test_case_index */,
5601                                                                                   bufferDescriptor::Vector& /* out_descriptors */)
5602 {
5603         /* Nothhing to be done */
5604 }
5605
5606 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
5607  *
5608  * @param ignored
5609  * @param ignored
5610  **/
5611 void BufferTestBase::getCapturedVaryings(glw::GLuint /* test_case_index */,
5612                                                                                  Utils::Program::NameVector& /* captured_varyings */)
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                 getCapturedVaryings(test_case_index, captured_varyings);
5705
5706                 /* Get shader sources */
5707                 const std::string& fragment_shader  = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
5708                 const std::string& geometry_shader  = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
5709                 const std::string& tess_ctrl_shader = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
5710                 const std::string& tess_eval_shader = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
5711                 const std::string& vertex_shader        = getShaderSource(test_case_index, Utils::Shader::VERTEX);
5712
5713                 /* Set up program */
5714                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
5715                                          vertex_shader, captured_varyings, true, false /* is_separable */);
5716
5717                 /* Inspection */
5718                 {
5719                         std::stringstream stream;
5720                         if (false == inspectProgram(test_case_index, program, stream))
5721                         {
5722                                 m_context.getTestContext().getLog()
5723                                         << tcu::TestLog::Message
5724                                         << "Program inspection failed. Test case: " << getTestCaseName(test_case_index)
5725                                         << ". Reason: " << stream.str() << tcu::TestLog::EndMessage
5726                                         << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5727                                         << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5728                                         << tcu::TestLog::KernelSource(fragment_shader);
5729
5730                                 return false;
5731                         }
5732                 }
5733
5734                 program.Use();
5735
5736                 /* Set up buffers */
5737                 getBufferDescriptors(test_case_index, descriptors);
5738                 cleanBuffers();
5739                 prepareBuffers(descriptors, buffers);
5740
5741                 /* Set up vao */
5742                 vao.Init();
5743                 vao.Bind();
5744
5745                 /* Draw */
5746                 bool result = executeDrawCall((program.m_tess_eval.m_id != 0), test_case_index);
5747
5748 #if USE_NSIGHT
5749                 m_context.getRenderContext().postIterate();
5750 #endif
5751
5752                 if (false == result)
5753                 {
5754                         m_context.getTestContext().getLog()
5755                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5756                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5757                                 << tcu::TestLog::KernelSource(fragment_shader);
5758
5759                         return false;
5760                 }
5761
5762                 /* Verify result */
5763                 if (false == verifyBuffers(buffers))
5764                 {
5765                         m_context.getTestContext().getLog()
5766                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5767                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5768                                 << tcu::TestLog::KernelSource(fragment_shader);
5769
5770                         return false;
5771                 }
5772         }
5773         catch (Utils::Shader::InvalidSourceException& exc)
5774         {
5775                 exc.log(m_context);
5776                 TCU_FAIL(exc.what());
5777         }
5778         catch (Utils::Program::BuildException& exc)
5779         {
5780                 exc.log(m_context);
5781                 TCU_FAIL(exc.what());
5782         }
5783
5784         /* Done */
5785         return true;
5786 }
5787
5788 /** Verify contents of buffers
5789  *
5790  * @param buffers Collection of buffers to be verified
5791  *
5792  * @return true if everything is as expected, false otherwise
5793  **/
5794 bool BufferTestBase::verifyBuffers(bufferCollection& buffers)
5795 {
5796         bool result = true;
5797
5798         for (bufferCollection::Vector::iterator it = buffers.m_vector.begin(), end = buffers.m_vector.end(); end != it;
5799                  ++it)
5800         {
5801                 bufferCollection::pair& pair       = *it;
5802                 Utils::Buffer*                  buffer   = pair.m_buffer;
5803                 bufferDescriptor*               descriptor = pair.m_descriptor;
5804                 size_t                                  size       = descriptor->m_expected_data.size();
5805
5806                 /* Skip buffers that have no expected data */
5807                 if (0 == size)
5808                 {
5809                         continue;
5810                 }
5811
5812                 /* Get pointer to contents of buffer */
5813                 buffer->Bind();
5814                 GLvoid* buffer_data = buffer->Map(Utils::Buffer::ReadOnly);
5815
5816                 /* Get pointer to expected data */
5817                 GLvoid* expected_data = &descriptor->m_expected_data[0];
5818
5819                 /* Compare */
5820                 int res = memcmp(buffer_data, expected_data, size);
5821
5822                 if (0 != res)
5823                 {
5824                         m_context.getTestContext().getLog()
5825                                 << tcu::TestLog::Message
5826                                 << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
5827                                 << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
5828
5829                         result = false;
5830                 }
5831
5832                 /* Release buffer mapping */
5833                 buffer->UnMap();
5834         }
5835
5836         return result;
5837 }
5838
5839 /** Unbinds all uniforms and xfb
5840  *
5841  **/
5842 void BufferTestBase::cleanBuffers()
5843 {
5844         const Functions& gl = m_context.getRenderContext().getFunctions();
5845
5846         GLint max_uni = 0;
5847         GLint max_xfb = 0;
5848
5849         gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uni);
5850         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
5851         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5852
5853         for (GLint i = 0; i < max_uni; ++i)
5854         {
5855                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Uniform, i);
5856         }
5857
5858         for (GLint i = 0; i < max_xfb; ++i)
5859         {
5860                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Transform_feedback, i);
5861         }
5862 }
5863
5864 /** Get template of shader for given stage
5865  *
5866  * @param stage Stage
5867  *
5868  * @return Template of shader source
5869  **/
5870 std::string BufferTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
5871 {
5872         static const GLchar* compute_shader_template = "#version 430 core\n"
5873                                                                                                    "#extension GL_ARB_enhanced_layouts : require\n"
5874                                                                                                    "\n"
5875                                                                                                    "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5876                                                                                                    "\n"
5877                                                                                                    "writeonly uniform uimage2D uni_image;\n"
5878                                                                                                    "\n"
5879                                                                                                    "INTERFACE"
5880                                                                                                    "\n"
5881                                                                                                    "void main()\n"
5882                                                                                                    "{\n"
5883                                                                                                    "CALCULATIONS"
5884                                                                                                    "\n"
5885                                                                                                    "ASSIGNMENTS"
5886                                                                                                    "}\n"
5887                                                                                                    "\n";
5888
5889         static const GLchar* fragment_shader_template = "#version 430 core\n"
5890                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5891                                                                                                         "\n"
5892                                                                                                         "INTERFACE"
5893                                                                                                         "\n"
5894                                                                                                         "void main()\n"
5895                                                                                                         "{\n"
5896                                                                                                         "CALCULATIONS"
5897                                                                                                         "\n"
5898                                                                                                         "ASSIGNMENTS"
5899                                                                                                         "}\n"
5900                                                                                                         "\n";
5901
5902         // max_vertices is set to 3 for the test case "xfb_vertex_streams" declares 3 streams in geometry shader,
5903         // according to spec, max_vertices should be no less than 3 if there are 3 streams in GS.
5904         static const GLchar* geometry_shader_template = "#version 430 core\n"
5905                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5906                                                                                                         "\n"
5907                                                                                                         "layout(points)                   in;\n"
5908                                                                                                         "layout(points, max_vertices = 3) out;\n"
5909                                                                                                         "\n"
5910                                                                                                         "INTERFACE"
5911                                                                                                         "\n"
5912                                                                                                         "void main()\n"
5913                                                                                                         "{\n"
5914                                                                                                         "CALCULATIONS"
5915                                                                                                         "\n"
5916                                                                                                         "\n"
5917                                                                                                         "ASSIGNMENTS"
5918                                                                                                         "    gl_Position  = vec4(0, 0, 0, 1);\n"
5919                                                                                                         "    EmitVertex();\n"
5920                                                                                                         "}\n"
5921                                                                                                         "\n";
5922
5923         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
5924                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5925                                                                                                          "\n"
5926                                                                                                          "layout(vertices = 1) out;\n"
5927                                                                                                          "\n"
5928                                                                                                          "INTERFACE"
5929                                                                                                          "\n"
5930                                                                                                          "void main()\n"
5931                                                                                                          "{\n"
5932                                                                                                          "CALCULATIONS"
5933                                                                                                          "\n"
5934                                                                                                          "ASSIGNMENTS"
5935                                                                                                          "\n"
5936                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
5937                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
5938                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
5939                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
5940                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
5941                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
5942                                                                                                          "}\n"
5943                                                                                                          "\n";
5944
5945         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
5946                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5947                                                                                                          "\n"
5948                                                                                                          "layout(isolines, point_mode) in;\n"
5949                                                                                                          "\n"
5950                                                                                                          "INTERFACE"
5951                                                                                                          "\n"
5952                                                                                                          "void main()\n"
5953                                                                                                          "{\n"
5954                                                                                                          "CALCULATIONS"
5955                                                                                                          "\n"
5956                                                                                                          "ASSIGNMENTS"
5957                                                                                                          "}\n"
5958                                                                                                          "\n";
5959
5960         static const GLchar* vertex_shader_template = "#version 430 core\n"
5961                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
5962                                                                                                   "\n"
5963                                                                                                   "INTERFACE"
5964                                                                                                   "\n"
5965                                                                                                   "void main()\n"
5966                                                                                                   "{\n"
5967                                                                                                   "CALCULATIONS"
5968                                                                                                   "\n"
5969                                                                                                   "ASSIGNMENTS"
5970                                                                                                   "}\n"
5971                                                                                                   "\n";
5972
5973         const GLchar* result = 0;
5974
5975         switch (stage)
5976         {
5977         case Utils::Shader::COMPUTE:
5978                 result = compute_shader_template;
5979                 break;
5980         case Utils::Shader::FRAGMENT:
5981                 result = fragment_shader_template;
5982                 break;
5983         case Utils::Shader::GEOMETRY:
5984                 result = geometry_shader_template;
5985                 break;
5986         case Utils::Shader::TESS_CTRL:
5987                 result = tess_ctrl_shader_template;
5988                 break;
5989         case Utils::Shader::TESS_EVAL:
5990                 result = tess_eval_shader_template;
5991                 break;
5992         case Utils::Shader::VERTEX:
5993                 result = vertex_shader_template;
5994                 break;
5995         default:
5996                 TCU_FAIL("Invalid enum");
5997         }
5998
5999         return result;
6000 }
6001
6002 /** Prepare buffer according to descriptor
6003  *
6004  * @param buffer Buffer to prepare
6005  * @param desc   Descriptor
6006  **/
6007 void BufferTestBase::prepareBuffer(Utils::Buffer& buffer, bufferDescriptor& desc)
6008 {
6009         GLsizeiptr size = 0;
6010         GLvoid* data = 0;
6011
6012         if (false == desc.m_initial_data.empty())
6013         {
6014                 size = desc.m_initial_data.size();
6015                 data = &desc.m_initial_data[0];
6016         }
6017         else if (false == desc.m_expected_data.empty())
6018         {
6019                 size = desc.m_expected_data.size();
6020         }
6021
6022         buffer.Init(desc.m_target, Utils::Buffer::StaticDraw, size, data);
6023
6024         if (bufferDescriptor::m_non_indexed != desc.m_index)
6025         {
6026                 buffer.BindBase(desc.m_index);
6027         }
6028         else
6029         {
6030                 buffer.Bind();
6031         }
6032 }
6033
6034 /** Prepare collection of buffer
6035  *
6036  * @param descriptors Collection of descriptors
6037  * @param out_buffers Collection of buffers
6038  **/
6039 void BufferTestBase::prepareBuffers(bufferDescriptor::Vector& descriptors, bufferCollection& out_buffers)
6040 {
6041         for (bufferDescriptor::Vector::iterator it = descriptors.begin(), end = descriptors.end(); end != it; ++it)
6042         {
6043                 bufferCollection::pair pair;
6044
6045                 pair.m_buffer = new Utils::Buffer(m_context);
6046                 if (0 == pair.m_buffer)
6047                 {
6048                         TCU_FAIL("Memory allocation failed");
6049                 }
6050
6051                 pair.m_descriptor = &(*it);
6052
6053                 prepareBuffer(*pair.m_buffer, *pair.m_descriptor);
6054
6055                 out_buffers.m_vector.push_back(pair);
6056         }
6057 }
6058
6059 /** Destructor
6060  *
6061  **/
6062 BufferTestBase::bufferCollection::~bufferCollection()
6063 {
6064         for (Vector::iterator it = m_vector.begin(), end = m_vector.end(); end != it; ++it)
6065         {
6066                 if (0 != it->m_buffer)
6067                 {
6068                         delete it->m_buffer;
6069                         it->m_buffer = 0;
6070                 }
6071         }
6072 }
6073
6074 /** Constructor
6075  *
6076  * @param context          Test context
6077  * @param test_name        Name of test
6078  * @param test_description Description of test
6079  **/
6080 NegativeTestBase::NegativeTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6081         : TestBase(context, test_name, test_description)
6082 {
6083 }
6084
6085 /** Selects if "compute" stage is relevant for test
6086  *
6087  * @param ignored
6088  *
6089  * @return true
6090  **/
6091 bool NegativeTestBase::isComputeRelevant(GLuint /* test_case_index */)
6092 {
6093         return true;
6094 }
6095
6096 /** Selects if compilation failure is expected result
6097  *
6098  * @param ignored
6099  *
6100  * @return true
6101  **/
6102 bool NegativeTestBase::isFailureExpected(GLuint /* test_case_index */)
6103 {
6104         return true;
6105 }
6106
6107 /** Runs test case
6108  *
6109  * @param test_case_index Id of test case
6110  *
6111  * @return true if test case pass, false otherwise
6112  **/
6113 bool NegativeTestBase::testCase(GLuint test_case_index)
6114 {
6115         bool test_case_result = true;
6116
6117         /* Compute */
6118         if (true == isComputeRelevant(test_case_index))
6119         {
6120                 const std::string& cs_source               = getShaderSource(test_case_index, Utils::Shader::COMPUTE);
6121                 bool                       is_build_error         = false;
6122                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6123                 Utils::Program   program(m_context);
6124
6125                 try
6126                 {
6127                         program.Init(cs_source, "" /* fs */, "" /* gs */, "" /* tcs */, "" /* tes */, "" /* vs */,
6128                                                  false /* separable */);
6129                 }
6130                 catch (Utils::Shader::InvalidSourceException& exc)
6131                 {
6132                         if (false == is_failure_expected)
6133                         {
6134                                 m_context.getTestContext().getLog()
6135                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6136                                 exc.log(m_context);
6137                         }
6138
6139 #if DEBUG_NEG_LOG_ERROR
6140
6141                         else
6142                         {
6143                                 m_context.getTestContext().getLog()
6144                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6145                                         << tcu::TestLog::EndMessage;
6146                                 exc.log(m_context);
6147                         }
6148
6149 #endif /* DEBUG_NEG_LOG_ERROR */
6150
6151                         is_build_error = true;
6152                 }
6153                 catch (Utils::Program::BuildException& exc)
6154                 {
6155                         if (false == is_failure_expected)
6156                         {
6157                                 m_context.getTestContext().getLog()
6158                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6159                                 exc.log(m_context);
6160                         }
6161
6162 #if DEBUG_NEG_LOG_ERROR
6163
6164                         else
6165                         {
6166                                 m_context.getTestContext().getLog()
6167                                         << tcu::TestLog::Message
6168                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6169                                 exc.log(m_context);
6170                         }
6171
6172 #endif /* DEBUG_NEG_LOG_ERROR */
6173
6174                         is_build_error = true;
6175                 }
6176
6177                 if (is_build_error != is_failure_expected)
6178                 {
6179                         if (!is_build_error)
6180                         {
6181                                 m_context.getTestContext().getLog()
6182                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6183                                 Utils::Shader::LogSource(m_context, cs_source, Utils::Shader::COMPUTE);
6184                         }
6185                         test_case_result = false;
6186                 }
6187         }
6188         else /* Draw */
6189         {
6190                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6191                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6192                 bool                       is_build_error         = false;
6193                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6194                 Utils::Program   program(m_context);
6195                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6196                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6197                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6198
6199                 try
6200                 {
6201                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6202                 }
6203                 catch (Utils::Shader::InvalidSourceException& exc)
6204                 {
6205                         if (false == is_failure_expected)
6206                         {
6207                                 m_context.getTestContext().getLog()
6208                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6209                                 exc.log(m_context);
6210                         }
6211
6212 #if DEBUG_NEG_LOG_ERROR
6213
6214                         else
6215                         {
6216                                 m_context.getTestContext().getLog()
6217                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6218                                         << tcu::TestLog::EndMessage;
6219                                 exc.log(m_context);
6220                         }
6221
6222 #endif /* DEBUG_NEG_LOG_ERROR */
6223
6224                         is_build_error = true;
6225                 }
6226                 catch (Utils::Program::BuildException& exc)
6227                 {
6228                         if (false == is_failure_expected)
6229                         {
6230                                 m_context.getTestContext().getLog()
6231                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6232                                 exc.log(m_context);
6233                         }
6234
6235 #if DEBUG_NEG_LOG_ERROR
6236
6237                         else
6238                         {
6239                                 m_context.getTestContext().getLog()
6240                                         << tcu::TestLog::Message
6241                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6242                                 exc.log(m_context);
6243                         }
6244
6245 #endif /* DEBUG_NEG_LOG_ERROR */
6246
6247                         is_build_error = true;
6248                 }
6249
6250                 if (is_build_error != is_failure_expected)
6251                 {
6252                         if (!is_build_error)
6253                         {
6254                                 m_context.getTestContext().getLog()
6255                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6256                                 Utils::Shader::LogSource(m_context, vs_source, Utils::Shader::VERTEX);
6257                                 Utils::Shader::LogSource(m_context, tcs_source, Utils::Shader::TESS_CTRL);
6258                                 Utils::Shader::LogSource(m_context, tes_source, Utils::Shader::TESS_EVAL);
6259                                 Utils::Shader::LogSource(m_context, gs_source, Utils::Shader::GEOMETRY);
6260                                 Utils::Shader::LogSource(m_context, fs_source, Utils::Shader::FRAGMENT);
6261                         }
6262                         test_case_result = false;
6263                 }
6264         }
6265
6266         return test_case_result;
6267 }
6268
6269 /* Constants used by TextureTestBase */
6270 const glw::GLuint TextureTestBase::m_width  = 16;
6271 const glw::GLuint TextureTestBase::m_height = 16;
6272
6273 /** Constructor
6274  *
6275  * @param context          Test context
6276  * @param test_name        Name of test
6277  * @param test_description Description of test
6278  **/
6279 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6280         : TestBase(context, test_name, test_description)
6281 {
6282 }
6283
6284 /** Get locations for all inputs with automatic_location
6285  *
6286  * @param program           Program object
6287  * @param program_interface Interface of program
6288  **/
6289 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6290 {
6291         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6292
6293         Utils::Variable::PtrVector& inputs = si.m_inputs;
6294
6295         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6296         {
6297                 /* Test does not specify location, query value and set */
6298                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6299                 {
6300                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6301                         GLint  location = 0;
6302
6303                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6304
6305                         (*it)->m_descriptor.m_expected_location = location;
6306                 }
6307         }
6308 }
6309
6310 /** Verifies contents of drawn image
6311  *
6312  * @param ignored
6313  * @param color_0 Verified image
6314  *
6315  * @return true if image is filled with 1, false otherwise
6316  **/
6317 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6318 {
6319         static const GLuint size                   = m_width * m_height;
6320         static const GLuint expected_color = 1;
6321
6322         std::vector<GLuint> data;
6323         data.resize(size);
6324
6325         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6326
6327         for (GLuint i = 0; i < size; ++i)
6328         {
6329                 const GLuint color = data[i];
6330
6331                 if (expected_color != color)
6332                 {
6333                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6334                                                                                                 << tcu::TestLog::EndMessage;
6335                         return false;
6336                 }
6337         }
6338
6339         return true;
6340 }
6341
6342 /** Execute dispatch compute for 16x16x1
6343  *
6344  * @param ignored
6345  **/
6346 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6347 {
6348         const Functions& gl = m_context.getRenderContext().getFunctions();
6349
6350         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6351         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6352 }
6353
6354 /** Execute drawArrays for single vertex
6355  *
6356  * @param ignored
6357  **/
6358 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6359 {
6360         const Functions& gl = m_context.getRenderContext().getFunctions();
6361
6362         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6363         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6364 }
6365
6366 /** Prepare code snippet that will pass in variables to out variables
6367  *
6368  * @param ignored
6369  * @param varying_passthrough Collection of connections between in and out variables
6370  * @param stage               Shader stage
6371  *
6372  * @return Code that pass in variables to next stage
6373  **/
6374 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6375                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6376 {
6377         static const GLchar* separator = "\n    ";
6378
6379         /* Skip for compute shader */
6380         if (Utils::Shader::COMPUTE == stage)
6381         {
6382                 return "";
6383         }
6384
6385         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6386
6387         std::string result   = Utils::g_list;
6388         size_t          position = 0;
6389
6390         for (GLuint i = 0; i < vector.size(); ++i)
6391         {
6392
6393                 Utils::VaryingConnection& connection = vector[i];
6394
6395                 Utils::Variable* in  = connection.m_in;
6396                 Utils::Variable* out = connection.m_out;
6397
6398                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6399                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6400
6401                 const std::string passthrough =
6402                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6403
6404                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6405         }
6406
6407         Utils::endList("", position, result);
6408
6409         return result;
6410 }
6411
6412 /** Basic implementation of method getProgramInterface
6413  *
6414  * @param ignored
6415  * @param ignored
6416  * @param ignored
6417  **/
6418 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6419                                                                                   Utils::ProgramInterface& /* program_interface */,
6420                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6421 {
6422 }
6423
6424 /** Prepare code snippet that will verify in and uniform variables
6425  *
6426  * @param ignored
6427  * @param program_interface Interface of program
6428  * @param stage             Shader stage
6429  *
6430  * @return Code that verify variables
6431  **/
6432 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6433                                                                                                         Utils::ProgramInterface& program_interface,
6434                                                                                                         Utils::Shader::STAGES   stage)
6435 {
6436         static const GLchar* separator = " ||\n        ";
6437
6438         std::string verification = "if (LIST)\n"
6439                                                            "    {\n"
6440                                                            "        result = 0u;\n"
6441                                                            "    }\n";
6442
6443         /* Get flavour of in and out variables */
6444         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6445
6446         /* Get interface for shader stage */
6447         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6448
6449         /* There are no varialbes to verify */
6450         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6451         {
6452                 return "";
6453         }
6454
6455         /* For each in variable insert verification code */
6456         size_t position = 0;
6457
6458         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6459         {
6460                 const Utils::Variable& var                              = *si.m_inputs[i];
6461                 const std::string&       var_verification = getVariableVerification("", var.m_data, var.m_descriptor, in_flavour);
6462
6463                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6464         }
6465
6466         /* For each unifrom variable insert verification code */
6467         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6468         {
6469                 const Utils::Variable& var = *si.m_uniforms[i];
6470                 const std::string&       var_verification =
6471                         getVariableVerification("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6472
6473                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6474         }
6475
6476         /* For each ssb variable insert verification code */
6477         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6478         {
6479                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6480                 const std::string&       var_verification =
6481                         getVariableVerification("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6482
6483                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6484         }
6485
6486         Utils::endList("", position, verification);
6487
6488 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6489
6490         {
6491                 GLchar buffer[16];
6492                 sprintf(buffer, "%d", stage + 10);
6493                 Utils::replaceToken("0u", position, buffer, verification);
6494         }
6495
6496 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6497
6498         if (Utils::Shader::VERTEX == stage)
6499         {
6500                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6501         }
6502         else
6503         {
6504                 Utils::replaceToken("0u", position, "31u", verification);
6505         }
6506
6507 #endif
6508
6509         /* Done */
6510         return verification;
6511 }
6512
6513 /** Selects if "compute" stage is relevant for test
6514  *
6515  * @param ignored
6516  *
6517  * @return true
6518  **/
6519 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6520 {
6521         return true;
6522 }
6523
6524 /** Selects if "draw" stages are relevant for test
6525  *
6526  * @param ignored
6527  *
6528  * @return true
6529  **/
6530 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6531 {
6532         return true;
6533 }
6534
6535 /** Prepare code that will do assignment of single in to single out
6536  *
6537  * @param in_parent_name  Name of parent in variable
6538  * @param in_variable     Descriptor of in variable
6539  * @param in_flavour      Flavoud of in variable
6540  * @param out_parent_name Name of parent out variable
6541  * @param out_variable    Descriptor of out variable
6542  * @param out_flavour     Flavoud of out variable
6543  *
6544  * @return Code that does OUT = IN
6545  **/
6546 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6547                                                                                                         const Utils::Variable::Descriptor& in_variable,
6548                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6549                                                                                                         const std::string&                                 out_parent_name,
6550                                                                                                         const Utils::Variable::Descriptor& out_variable,
6551                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6552 {
6553         bool                             done             = false;
6554         GLuint                           index            = 0;
6555         GLuint                           member_index = 0;
6556         size_t                           position        = 0;
6557         std::string                      result           = Utils::g_list;
6558         static const GLchar* separator  = ";\n    ";
6559
6560         /* For each member of each array element */
6561         do
6562         {
6563                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6564                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6565                 std::string               passthrough;
6566
6567                 /* Prepare verification */
6568                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6569                 {
6570                         size_t pass_position = 0;
6571
6572                         passthrough = "OUT = IN;";
6573
6574                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6575                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6576
6577                         /* Increment index */
6578                         ++index;
6579                 }
6580                 else
6581                 {
6582                         const Utils::Interface* in_interface  = in_variable.m_interface;
6583                         const Utils::Interface* out_interface = out_variable.m_interface;
6584
6585                         if ((0 == in_interface) || (0 == out_interface))
6586                         {
6587                                 TCU_FAIL("Nullptr");
6588                         }
6589
6590                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6591                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6592
6593                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6594                                                                                                  Utils::Variable::BASIC);
6595
6596                         /* Increment member_index */
6597                         ++member_index;
6598
6599                         /* Increment index and reset member_index if all members were processed */
6600                         if (in_interface->m_members.size() == member_index)
6601                         {
6602                                 ++index;
6603                                 member_index = 0;
6604                         }
6605                 }
6606
6607                 /* Check if loop should end */
6608                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6609                 {
6610                         done = true;
6611                 }
6612
6613                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6614
6615         } while (true != done);
6616
6617         Utils::endList("", position, result);
6618
6619         /* Done */
6620         return result;
6621 }
6622
6623 /** Get verification of single variable
6624  *
6625  * @param parent_name Name of parent variable
6626  * @param data        Data that should be used as EXPECTED
6627  * @param variable    Descriptor of variable
6628  * @param flavour     Flavour of variable
6629  *
6630  * @return Code that does (EXPECTED != VALUE) ||
6631  **/
6632 std::string TextureTestBase::getVariableVerification(const std::string& parent_name, const GLvoid* data,
6633                                                                                                          const Utils::Variable::Descriptor& variable,
6634                                                                                                          Utils::Variable::FLAVOUR                       flavour)
6635 {
6636         static const GLchar* logic_op   = " ||\n        ";
6637         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6638         size_t                           position   = 0;
6639         std::string                      result         = Utils::g_list;
6640         GLint                            stride         = variable.m_expected_stride_of_element;
6641
6642         /* For each each array element */
6643         for (GLuint element = 0; element < n_elements; ++element)
6644         {
6645                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6646
6647                 /* Calculate data pointer */
6648                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6649
6650                 /* Prepare verification */
6651                 if (Utils::Variable::BUILTIN == variable.m_type)
6652                 {
6653                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6654                         std::string                verification;
6655                         size_t                     verification_position = 0;
6656
6657                         verification = "(EXPECTED != NAME)";
6658
6659                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6660                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6661
6662                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6663                 }
6664                 else
6665                 {
6666                         const Utils::Interface* interface = variable.m_interface;
6667
6668                         if (0 == interface)
6669                         {
6670                                 TCU_FAIL("Nullptr");
6671                         }
6672
6673                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6674
6675                         /* for each member */
6676                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6677                         {
6678                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6679
6680                                 /* Get verification of member */
6681                                 const std::string& verification =
6682                                         getVariableVerification(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6683
6684                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6685                         }
6686                 }
6687         }
6688
6689         Utils::endList("", position, result);
6690
6691         return result;
6692 }
6693
6694 /** Prepare attributes, vertex array object and array buffer
6695  *
6696  * @param test_case_index   Index of test case
6697  * @param program_interface Interface of program
6698  * @param buffer            Array buffer
6699  * @param vao               Vertex array object
6700  **/
6701 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6702                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6703 {
6704         bool use_component_qualifier = useComponentQualifier(test_case_index);
6705
6706         /* Get shader interface */
6707         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6708
6709         /* Bind vao and buffer */
6710         vao.Bind();
6711         buffer.Bind();
6712
6713         /* Skip if there are no input variables in vertex shader */
6714         if (0 == si.m_inputs.size())
6715         {
6716                 return;
6717         }
6718
6719         /* Calculate vertex stride and check */
6720         GLint vertex_stride = 0;
6721
6722         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6723         {
6724                 Utils::Variable& variable = *si.m_inputs[i];
6725
6726                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6727
6728                 GLint ends_at = variable_size + variable.m_descriptor.m_offset;
6729
6730                 vertex_stride = std::max(vertex_stride, ends_at);
6731         }
6732
6733         /* Prepare buffer data and set up vao */
6734         std::vector<GLubyte> buffer_data;
6735         buffer_data.resize(vertex_stride);
6736
6737         GLubyte* ptr = &buffer_data[0];
6738
6739         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6740         {
6741                 Utils::Variable& variable = *si.m_inputs[i];
6742
6743                 memcpy(ptr + variable.m_descriptor.m_offset, variable.m_data, variable.m_data_size);
6744
6745                 if (false == use_component_qualifier)
6746                 {
6747                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6748                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6749                                                   variable.GetStride(), (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6750                 }
6751                 else if (0 == variable.m_descriptor.m_expected_component)
6752                 {
6753                         /* Components can only be applied to vectors.
6754                          Assumption that test use all 4 components */
6755                         const Utils::Type& type =
6756                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6757
6758                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6759                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6760                                                   (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6761                 }
6762         }
6763
6764         /* Update buffer */
6765         buffer.Data(Utils::Buffer::StaticDraw, vertex_stride, ptr);
6766 }
6767
6768 /** Get locations for all outputs with automatic_location
6769  *
6770  * @param program           Program object
6771  * @param program_interface Interface of program
6772  **/
6773 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6774 {
6775         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6776         Utils::Variable::PtrVector& outputs = si.m_outputs;
6777
6778         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6779         {
6780                 /* Test does not specify location, query value and set */
6781                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6782                 {
6783                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6784                         GLint  location = 0;
6785
6786                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6787
6788                         (*it)->m_descriptor.m_expected_location = location;
6789                 }
6790         }
6791 }
6792
6793 /** Prepare framebuffer with single texture as color attachment
6794  *
6795  * @param framebuffer     Framebuffer
6796  * @param color_0_texture Texture that will used as color attachment
6797  **/
6798 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6799 {
6800         /* Prepare data */
6801         std::vector<GLuint> texture_data;
6802         texture_data.resize(m_width * m_height);
6803
6804         for (GLuint i = 0; i < texture_data.size(); ++i)
6805         {
6806                 texture_data[i] = 0x20406080;
6807         }
6808
6809         /* Prepare texture */
6810         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6811                                                  &texture_data[0]);
6812
6813         /* Prepare framebuffer */
6814         framebuffer.Init();
6815         framebuffer.Bind();
6816         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6817
6818         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6819         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6820 }
6821
6822 /** Prepare iamge unit for compute shader
6823  *
6824  * @param location      Uniform location
6825  * @param image_texture Texture that will used as color attachment
6826  **/
6827 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6828 {
6829         static const GLuint image_unit = 0;
6830
6831         std::vector<GLuint> texture_data;
6832         texture_data.resize(m_width * m_height);
6833
6834         for (GLuint i = 0; i < texture_data.size(); ++i)
6835         {
6836                 texture_data[i] = 0x20406080;
6837         }
6838
6839         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6840                                            &texture_data[0]);
6841
6842         const Functions& gl = m_context.getRenderContext().getFunctions();
6843
6844         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6845                                                 GL_WRITE_ONLY, GL_R32UI);
6846         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6847
6848         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6849 }
6850
6851 /** Basic implementation
6852  *
6853  * @param ignored
6854  * @param si        Shader interface
6855  * @param program   Program
6856  * @param cs_buffer Buffer for ssb blocks
6857  **/
6858 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6859                                                                   Utils::Buffer& buffer)
6860 {
6861         /* Skip if there are no input variables in vertex shader */
6862         if (0 == si.m_ssb_blocks.size())
6863         {
6864                 return;
6865         }
6866
6867         /* Calculate vertex stride */
6868         GLint ssbs_stride = 0;
6869
6870         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6871         {
6872                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6873
6874                 if (false == variable.IsBlock())
6875                 {
6876                         continue;
6877                 }
6878
6879                 GLint variable_stride = variable.GetStride();
6880
6881                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6882
6883                 ssbs_stride = std::max(ssbs_stride, ends_at);
6884         }
6885
6886         /* Set active program */
6887         program.Use();
6888
6889         /* Allocate */
6890         buffer.Bind();
6891         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6892
6893         /* Set up uniforms */
6894         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6895         {
6896                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6897
6898                 /* prepareUnifor should work fine for ssb blocks */
6899                 prepareUniform(program, variable, buffer);
6900         }
6901 }
6902
6903 /** Basic implementation
6904  *
6905  * @param test_case_index   Test case index
6906  * @param program_interface Program interface
6907  * @param program           Program
6908  * @param cs_buffer         Buffer for compute shader stage
6909  **/
6910 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6911                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6912 {
6913         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6914
6915         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6916
6917         prepareSSBs(test_case_index, cs, program, cs_buffer);
6918
6919         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6920 }
6921
6922 /** Basic implementation
6923  *
6924  * @param test_case_index   Test case index
6925  * @param program_interface Program interface
6926  * @param program           Program
6927  * @param fs_buffer         Buffer for fragment shader stage
6928  * @param gs_buffer         Buffer for geometry shader stage
6929  * @param tcs_buffer        Buffer for tessellation control shader stage
6930  * @param tes_buffer        Buffer for tessellation evaluation shader stage
6931  * @param vs_buffer         Buffer for vertex shader stage
6932  **/
6933 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6934                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6935                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6936 {
6937         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6938         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6939         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6940         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6941         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6942
6943         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6944         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6945         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6946         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6947         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6948
6949         prepareSSBs(test_case_index, fs, program, fs_buffer);
6950         prepareSSBs(test_case_index, gs, program, gs_buffer);
6951         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
6952         prepareSSBs(test_case_index, tes, program, tes_buffer);
6953         prepareSSBs(test_case_index, vs, program, vs_buffer);
6954
6955         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
6956         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
6957         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
6958         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
6959         vs_buffer.BindBase(Utils::Shader::VERTEX);
6960 }
6961
6962 /** Updates buffer data with variable
6963  *
6964  * @param program  Program object
6965  * @param variable Variable
6966  * @param buffer   Buffer
6967  **/
6968 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
6969 {
6970         const Functions& gl = m_context.getRenderContext().getFunctions();
6971
6972         GLsizei count = variable.m_descriptor.m_n_array_elements;
6973         if (0 == count)
6974         {
6975                 count = 1;
6976         }
6977
6978         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
6979         {
6980                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
6981                                                 variable.m_data);
6982         }
6983         else
6984         {
6985                 const bool is_block = variable.IsBlock();
6986
6987                 if (false == is_block)
6988                 {
6989                         TCU_FAIL("Not implemented");
6990                 }
6991                 else
6992                 {
6993                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
6994                                                    variable.m_data);
6995                 }
6996         }
6997 }
6998
6999 /** Basic implementation
7000  *
7001  * @param ignored
7002  * @param si        Shader interface
7003  * @param program   Program
7004  * @param cs_buffer Buffer for uniform blocks
7005  **/
7006 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
7007                                                                           Utils::Buffer& buffer)
7008 {
7009         /* Skip if there are no input variables in vertex shader */
7010         if (0 == si.m_uniforms.size())
7011         {
7012                 return;
7013         }
7014
7015         /* Calculate vertex stride */
7016         GLint uniforms_stride = 0;
7017
7018         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7019         {
7020                 Utils::Variable& variable = *si.m_uniforms[i];
7021
7022                 if (false == variable.IsBlock())
7023                 {
7024                         continue;
7025                 }
7026
7027                 GLint variable_stride = variable.GetStride();
7028
7029                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
7030
7031                 uniforms_stride = std::max(uniforms_stride, ends_at);
7032         }
7033
7034         /* Set active program */
7035         program.Use();
7036
7037         /* Allocate */
7038         buffer.Bind();
7039         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
7040
7041         /* Set up uniforms */
7042         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7043         {
7044                 Utils::Variable& variable = *si.m_uniforms[i];
7045
7046                 prepareUniform(program, variable, buffer);
7047         }
7048 }
7049
7050 /** Basic implementation
7051  *
7052  * @param test_case_index   Test case index
7053  * @param program_interface Program interface
7054  * @param program           Program
7055  * @param cs_buffer         Buffer for compute shader stage
7056  **/
7057 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7058                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7059 {
7060         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7061
7062         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7063
7064         prepareUniforms(test_case_index, cs, program, cs_buffer);
7065
7066         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7067 }
7068
7069 /** Basic implementation
7070  *
7071  * @param test_case_index   Test case index
7072  * @param program_interface Program interface
7073  * @param program           Program
7074  * @param fs_buffer         Buffer for fragment shader stage
7075  * @param gs_buffer         Buffer for geometry shader stage
7076  * @param tcs_buffer        Buffer for tessellation control shader stage
7077  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7078  * @param vs_buffer         Buffer for vertex shader stage
7079  **/
7080 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7081                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7082                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7083 {
7084         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7085         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7086         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7087         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7088         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7089
7090         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7091         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7092         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7093         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7094         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7095
7096         prepareUniforms(test_case_index, fs, program, fs_buffer);
7097         prepareUniforms(test_case_index, gs, program, gs_buffer);
7098         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7099         prepareUniforms(test_case_index, tes, program, tes_buffer);
7100         prepareUniforms(test_case_index, vs, program, vs_buffer);
7101
7102         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7103         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7104         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7105         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7106         vs_buffer.BindBase(Utils::Shader::VERTEX);
7107 }
7108
7109 /** Basic implementation
7110  *
7111  * @param test_case_index   Test case index
7112  * @param program_interface Program interface
7113  * @param program           Program
7114  * @param fs_buffer         Buffer for fragment shader stage
7115  * @param gs_buffer         Buffer for geometry shader stage
7116  * @param tcs_buffer        Buffer for tessellation control shader stage
7117  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7118  * @param vs_buffer         Buffer for vertex shader stage
7119  **/
7120 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7121                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7122                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7123                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7124                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7125 {
7126         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7127         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7128         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7129         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7130         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7131
7132         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7133         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7134         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7135         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7136         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7137
7138         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7139         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7140
7141         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7142         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7143
7144         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7145         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7146
7147         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7148         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7149
7150         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7151         vs_buffer.BindBase(Utils::Shader::VERTEX);
7152 }
7153
7154 /** Prepare source for shader
7155  *
7156  * @param test_case_index     Index of test case
7157  * @param program_interface   Interface of program
7158  * @param varying_passthrough Collection of connection between in and out variables
7159  * @param stage               Shader stage
7160  *
7161  * @return Source of shader
7162  **/
7163 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7164                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7165                                                                                          Utils::Shader::STAGES          stage)
7166 {
7167         /* Get strings */
7168         const GLchar*     shader_template  = getShaderTemplate(stage);
7169         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7170
7171         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7172
7173         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7174
7175         const GLchar* per_vertex = "";
7176
7177         std::string source   = shader_template;
7178         size_t          position = 0;
7179
7180         /* Replace tokens in template */
7181         if (Utils::Shader::GEOMETRY == stage)
7182         {
7183                 if (false == useMonolithicProgram(test_case_index))
7184                 {
7185                         per_vertex = "out gl_PerVertex {\n"
7186                                                  "vec4 gl_Position;\n"
7187                                                  "};\n"
7188                                                  "\n";
7189                 }
7190
7191                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7192         }
7193
7194         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7195         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7196
7197         if (false == verification.empty())
7198         {
7199                 Utils::replaceAllTokens("ELSE", "    else ", source);
7200         }
7201         else
7202         {
7203                 Utils::replaceAllTokens("ELSE", "", source);
7204         }
7205
7206         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7207
7208         /* Done */
7209         return source;
7210 }
7211
7212 /** Returns template of shader for given stage
7213  *
7214  * @param stage Shade stage
7215  *
7216  * @return Proper template
7217  **/
7218 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7219 {
7220
7221         static const GLchar* compute_shader_template =
7222                 "#version 430 core\n"
7223                 "#extension GL_ARB_enhanced_layouts : require\n"
7224                 "\n"
7225                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7226                 "\n"
7227                 "writeonly uniform uimage2D uni_image;\n"
7228                 "\n"
7229                 "INTERFACE"
7230                 "\n"
7231                 "void main()\n"
7232                 "{\n"
7233                 "    uint result = 1u;\n"
7234                 "\n"
7235                 "    VERIFICATION"
7236                 "\n"
7237                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7238                 "}\n"
7239                 "\n";
7240
7241         static const GLchar* fragment_shader_template = "#version 430 core\n"
7242                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7243                                                                                                         "\n"
7244                                                                                                         "flat in  uint gs_fs_result;\n"
7245                                                                                                         "     out uint fs_out_result;\n"
7246                                                                                                         "\n"
7247                                                                                                         "INTERFACE"
7248                                                                                                         "\n"
7249                                                                                                         "void main()\n"
7250                                                                                                         "{\n"
7251                                                                                                         "    uint result = 1u;\n"
7252                                                                                                         "\n"
7253                                                                                                         "    if (1u != gs_fs_result)\n"
7254                                                                                                         "    {\n"
7255                                                                                                         "         result = gs_fs_result;\n"
7256                                                                                                         "    }\n"
7257                                                                                                         "ELSEVERIFICATION"
7258                                                                                                         "\n"
7259                                                                                                         "    fs_out_result = result;\n"
7260                                                                                                         "    PASSTHROUGH\n"
7261                                                                                                         "}\n"
7262                                                                                                         "\n";
7263
7264         static const GLchar* geometry_shader_template =
7265                 "#version 430 core\n"
7266                 "#extension GL_ARB_enhanced_layouts : require\n"
7267                 "\n"
7268                 "layout(points)                           in;\n"
7269                 "layout(triangle_strip, max_vertices = 4) out;\n"
7270                 "\n"
7271                 "     in  uint tes_gs_result[];\n"
7272                 "flat out uint gs_fs_result;\n"
7273                 "\n"
7274                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7275                 "INTERFACE"
7276                 "\n"
7277                 "void main()\n"
7278                 "{\n"
7279                 "    uint result = 1u;\n"
7280                 "\n"
7281                 "    if (1u != tes_gs_result[0])\n"
7282                 "    {\n"
7283                 "         result = tes_gs_result[0];\n"
7284                 "    }\n"
7285                 "ELSEVERIFICATION"
7286                 "\n"
7287                 "    gs_fs_result = result;\n"
7288                 "    PASSTHROUGH\n"
7289                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7290                 "    EmitVertex();\n"
7291                 "    gs_fs_result = result;\n"
7292                 "    PASSTHROUGH\n"
7293                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7294                 "    EmitVertex();\n"
7295                 "    gs_fs_result = result;\n"
7296                 "    PASSTHROUGH\n"
7297                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7298                 "    EmitVertex();\n"
7299                 "    gs_fs_result = result;\n"
7300                 "    PASSTHROUGH\n"
7301                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7302                 "    EmitVertex();\n"
7303                 "}\n"
7304                 "\n";
7305
7306         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7307                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7308                                                                                                          "\n"
7309                                                                                                          "layout(vertices = 1) out;\n"
7310                                                                                                          "\n"
7311                                                                                                          "in  uint vs_tcs_result[];\n"
7312                                                                                                          "out uint tcs_tes_result[];\n"
7313                                                                                                          "\n"
7314                                                                                                          "INTERFACE"
7315                                                                                                          "\n"
7316                                                                                                          "void main()\n"
7317                                                                                                          "{\n"
7318                                                                                                          "    uint result = 1u;\n"
7319                                                                                                          "\n"
7320                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7321                                                                                                          "    {\n"
7322                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7323                                                                                                          "    }\n"
7324                                                                                                          "ELSEVERIFICATION"
7325                                                                                                          "\n"
7326                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7327                                                                                                          "\n"
7328                                                                                                          "    PASSTHROUGH\n"
7329                                                                                                          "\n"
7330                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7331                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7332                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7333                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7334                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7335                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7336                                                                                                          "}\n"
7337                                                                                                          "\n";
7338
7339         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7340                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7341                                                                                                          "\n"
7342                                                                                                          "layout(isolines, point_mode) in;\n"
7343                                                                                                          "\n"
7344                                                                                                          "in  uint tcs_tes_result[];\n"
7345                                                                                                          "out uint tes_gs_result;\n"
7346                                                                                                          "\n"
7347                                                                                                          "INTERFACE"
7348                                                                                                          "\n"
7349                                                                                                          "void main()\n"
7350                                                                                                          "{\n"
7351                                                                                                          "    uint result = 1u;\n"
7352                                                                                                          "\n"
7353                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7354                                                                                                          "    {\n"
7355                                                                                                          "         result = tcs_tes_result[0];\n"
7356                                                                                                          "    }\n"
7357                                                                                                          "ELSEVERIFICATION"
7358                                                                                                          "\n"
7359                                                                                                          "    tes_gs_result = result;\n"
7360                                                                                                          "\n"
7361                                                                                                          "    PASSTHROUGH\n"
7362                                                                                                          "}\n"
7363                                                                                                          "\n";
7364
7365         static const GLchar* vertex_shader_template = "#version 430 core\n"
7366                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7367                                                                                                   "\n"
7368                                                                                                   "out uint vs_tcs_result;\n"
7369                                                                                                   "\n"
7370                                                                                                   "INTERFACE"
7371                                                                                                   "\n"
7372                                                                                                   "void main()\n"
7373                                                                                                   "{\n"
7374                                                                                                   "    uint result = 1u;\n"
7375                                                                                                   "\n"
7376                                                                                                   "    VERIFICATION\n"
7377                                                                                                   "\n"
7378                                                                                                   "    vs_tcs_result = result;\n"
7379                                                                                                   "\n"
7380                                                                                                   "    PASSTHROUGH\n"
7381                                                                                                   "}\n"
7382                                                                                                   "\n";
7383
7384         const GLchar* result = 0;
7385
7386         switch (stage)
7387         {
7388         case Utils::Shader::COMPUTE:
7389                 result = compute_shader_template;
7390                 break;
7391         case Utils::Shader::FRAGMENT:
7392                 result = fragment_shader_template;
7393                 break;
7394         case Utils::Shader::GEOMETRY:
7395                 result = geometry_shader_template;
7396                 break;
7397         case Utils::Shader::TESS_CTRL:
7398                 result = tess_ctrl_shader_template;
7399                 break;
7400         case Utils::Shader::TESS_EVAL:
7401                 result = tess_eval_shader_template;
7402                 break;
7403         case Utils::Shader::VERTEX:
7404                 result = vertex_shader_template;
7405                 break;
7406         default:
7407                 TCU_FAIL("Invalid enum");
7408         }
7409
7410         return result;
7411 }
7412
7413 /** Runs test case
7414  *
7415  * @param test_case_index Id of test case
7416  *
7417  * @return true if test case pass, false otherwise
7418  **/
7419 bool TextureTestBase::testCase(GLuint test_case_index)
7420 {
7421         try
7422         {
7423                 if (true == useMonolithicProgram(test_case_index))
7424                 {
7425                         return testMonolithic(test_case_index);
7426                 }
7427                 else
7428                 {
7429                         return testSeparable(test_case_index);
7430                 }
7431         }
7432         catch (Utils::Shader::InvalidSourceException& exc)
7433         {
7434                 exc.log(m_context);
7435                 TCU_FAIL(exc.what());
7436         }
7437         catch (Utils::Program::BuildException& exc)
7438         {
7439                 TCU_FAIL(exc.what());
7440         }
7441 }
7442
7443 /** Runs "draw" test with monolithic program
7444  *
7445  * @param test_case_index Id of test case
7446  **/
7447 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7448 {
7449         Utils::ProgramInterface   program_interface;
7450         Utils::VaryingPassthrough varying_passthrough;
7451
7452         /* */
7453         const std::string& test_name = getTestCaseName(test_case_index);
7454
7455         /* */
7456         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7457
7458         bool result = true;
7459         /* Draw */
7460         if (true == isDrawRelevant(test_case_index))
7461         {
7462                 Utils::Buffer     buffer_attr(m_context);
7463                 Utils::Buffer     buffer_ssb_fs(m_context);
7464                 Utils::Buffer     buffer_ssb_gs(m_context);
7465                 Utils::Buffer     buffer_ssb_tcs(m_context);
7466                 Utils::Buffer     buffer_ssb_tes(m_context);
7467                 Utils::Buffer     buffer_ssb_vs(m_context);
7468                 Utils::Buffer     buffer_u_fs(m_context);
7469                 Utils::Buffer     buffer_u_gs(m_context);
7470                 Utils::Buffer     buffer_u_tcs(m_context);
7471                 Utils::Buffer     buffer_u_tes(m_context);
7472                 Utils::Buffer     buffer_u_vs(m_context);
7473                 Utils::Framebuffer framebuffer(m_context);
7474                 Utils::Program   program(m_context);
7475                 Utils::Texture   texture_fb(m_context);
7476                 Utils::VertexArray vao(m_context);
7477
7478                 /* */
7479                 const std::string& fragment_shader =
7480                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7481                 const std::string& geometry_shader =
7482                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7483                 const std::string& tess_ctrl_shader =
7484                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7485                 const std::string& tess_eval_shader =
7486                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7487                 const std::string& vertex_shader =
7488                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7489
7490                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7491                                          vertex_shader, false /* is_separable */);
7492
7493                 /* */
7494                 prepareAttribLocation(program, program_interface);
7495                 prepareFragmentDataLoc(program, program_interface);
7496
7497                 /* */
7498                 std::stringstream stream;
7499                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7500                 {
7501                         m_context.getTestContext().getLog()
7502                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7503                                 << ". Inspection of draw program interface failed:\n"
7504                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7505                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7506                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7507
7508                         return false;
7509                 }
7510
7511                 /* */
7512                 program.Use();
7513
7514                 /* */
7515                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7516                 vao.Init();
7517                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7518
7519                 /* */
7520                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7521                                                 buffer_u_tes, buffer_u_vs);
7522
7523                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7524                                         buffer_ssb_tes, buffer_ssb_vs);
7525
7526                 /* */
7527                 prepareFramebuffer(framebuffer, texture_fb);
7528
7529                 /* Draw */
7530                 executeDrawCall(test_case_index);
7531
7532 #if USE_NSIGHT
7533                 m_context.getRenderContext().postIterate();
7534 #endif
7535
7536                 /* Check results */
7537                 if (false == checkResults(test_case_index, texture_fb))
7538                 {
7539                         m_context.getTestContext().getLog()
7540                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7541                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7542                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7543                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7544
7545                         result = false;
7546                 }
7547         }
7548
7549         /* Compute */
7550         if (true == isComputeRelevant(test_case_index))
7551         {
7552                 Utils::Buffer     buffer_ssb_cs(m_context);
7553                 Utils::Buffer     buffer_u_cs(m_context);
7554                 Utils::Program   program(m_context);
7555                 Utils::Texture   texture_im(m_context);
7556                 Utils::VertexArray vao(m_context);
7557
7558                 /* */
7559                 const std::string& compute_shader =
7560                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7561
7562                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7563                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7564
7565                 /* */
7566                 {
7567                         std::stringstream stream;
7568
7569                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7570                         {
7571                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7572                                                                                                         << ". Inspection of compute program interface failed:\n"
7573                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7574
7575                                 return false;
7576                         }
7577                 }
7578
7579                 /* */
7580                 program.Use();
7581
7582                 /* */
7583                 vao.Init();
7584                 vao.Bind();
7585
7586                 /* */
7587                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7588
7589                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7590
7591                 /* */
7592                 GLint image_location = program.GetUniformLocation("uni_image");
7593                 prepareImage(image_location, texture_im);
7594
7595                 /* Draw */
7596                 executeDispatchCall(test_case_index);
7597
7598 #if USE_NSIGHT
7599                 m_context.getRenderContext().postIterate();
7600 #endif
7601
7602                 /* Check results */
7603                 if (false == checkResults(test_case_index, texture_im))
7604                 {
7605                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7606                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7607                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7608
7609                         result = false;
7610                 }
7611         }
7612
7613         return result;
7614 }
7615
7616 /** Runs "draw" test with separable program
7617  *
7618  * @param test_case_index Id of test case
7619  **/
7620 bool TextureTestBase::testSeparable(GLuint test_case_index)
7621 {
7622         Utils::ProgramInterface   program_interface;
7623         Utils::VaryingPassthrough varying_passthrough;
7624
7625         /* */
7626         const std::string& test_name = getTestCaseName(test_case_index);
7627
7628         /* */
7629         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7630
7631         bool result = true;
7632         /* Draw */
7633         if (true == isDrawRelevant(test_case_index))
7634         {
7635                 Utils::Buffer     buffer_attr(m_context);
7636                 Utils::Buffer     buffer_u_fs(m_context);
7637                 Utils::Buffer     buffer_u_gs(m_context);
7638                 Utils::Buffer     buffer_u_tcs(m_context);
7639                 Utils::Buffer     buffer_u_tes(m_context);
7640                 Utils::Buffer     buffer_u_vs(m_context);
7641                 Utils::Framebuffer framebuffer(m_context);
7642                 Utils::Pipeline pipeline(m_context);
7643                 Utils::Program   program_fs(m_context);
7644                 Utils::Program   program_gs(m_context);
7645                 Utils::Program   program_tcs(m_context);
7646                 Utils::Program   program_tes(m_context);
7647                 Utils::Program   program_vs(m_context);
7648                 Utils::Texture   texture_fb(m_context);
7649                 Utils::VertexArray vao(m_context);
7650
7651                 /* */
7652                 const std::string& fs =
7653                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7654                 const std::string& gs =
7655                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7656                 const std::string& tcs =
7657                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7658                 const std::string& tes =
7659                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7660                 const std::string& vs =
7661                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7662
7663                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7664                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7665                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7666                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7667                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7668
7669                 /* */
7670                 prepareAttribLocation(program_vs, program_interface);
7671                 prepareFragmentDataLoc(program_vs, program_interface);
7672
7673                 /* */
7674                 std::stringstream stream;
7675                 if ((false ==
7676                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7677                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7678                                                                                                                                 stream)) ||
7679                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7680                                                                                                                                 stream)) ||
7681                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7682                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7683                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7684                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7685                 {
7686                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7687                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7688                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7689                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7690                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7691                                                                                                 << tcu::TestLog::KernelSource(fs);
7692
7693                         return false;
7694                 }
7695
7696                 /* */
7697                 pipeline.Init();
7698                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7699                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7700                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7701                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7702                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7703                 pipeline.Bind();
7704
7705                 /* */
7706
7707                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7708                 vao.Init();
7709                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7710
7711                 /* */
7712                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7713                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7714
7715                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7716
7717                 /* */
7718                 prepareFramebuffer(framebuffer, texture_fb);
7719
7720                 /* Draw */
7721                 executeDrawCall(test_case_index);
7722
7723 #if USE_NSIGHT
7724                 m_context.getRenderContext().postIterate();
7725 #endif
7726
7727                 /* Check results */
7728                 if (false == checkResults(test_case_index, texture_fb))
7729                 {
7730                         m_context.getTestContext().getLog()
7731                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7732                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7733                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7734
7735                         result = false;
7736                 }
7737         }
7738
7739         /* Compute */
7740         if (true == isComputeRelevant(test_case_index))
7741         {
7742                 Utils::Buffer     buffer_u_cs(m_context);
7743                 Utils::Program   program(m_context);
7744                 Utils::Texture   texture_im(m_context);
7745                 Utils::VertexArray vao(m_context);
7746
7747                 /* */
7748                 const std::string& compute_shader =
7749                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7750
7751                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7752                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7753
7754                 /* */
7755                 {
7756                         std::stringstream stream;
7757
7758                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7759                         {
7760                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7761                                                                                                         << ". Inspection of compute program interface failed:\n"
7762                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7763
7764                                 return false;
7765                         }
7766                 }
7767
7768                 /* */
7769                 program.Use();
7770
7771                 /* */
7772                 vao.Init();
7773                 vao.Bind();
7774
7775                 /* */
7776                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7777
7778                 /* */
7779                 GLint image_location = program.GetUniformLocation("uni_image");
7780                 prepareImage(image_location, texture_im);
7781
7782                 /* Draw */
7783                 executeDispatchCall(test_case_index);
7784
7785 #if USE_NSIGHT
7786                 m_context.getRenderContext().postIterate();
7787 #endif
7788
7789                 /* Check results */
7790                 if (false == checkResults(test_case_index, texture_im))
7791                 {
7792                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7793                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7794                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7795
7796                         result = false;
7797                 }
7798         }
7799
7800         return result;
7801 }
7802
7803 /** Basic implementation
7804  *
7805  * @param ignored
7806  *
7807  * @return false
7808  **/
7809 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7810 {
7811         return false;
7812 }
7813
7814 /** Basic implementation
7815  *
7816  * @param ignored
7817  *
7818  * @return true
7819  **/
7820 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7821 {
7822         return true;
7823 }
7824
7825 /** Constructor
7826  *
7827  * @param context Test framework context
7828  **/
7829 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7830         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7831 {
7832         /* Nothing to be done here */
7833 }
7834
7835 /** Execute test
7836  *
7837  * @return tcu::TestNode::STOP otherwise
7838  **/
7839 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7840 {
7841         static const GLuint expected_comp = 64;
7842         static const GLuint expected_xfb  = 4;
7843         static const GLuint expected_sep  = 4;
7844         GLint                           max_comp          = 0;
7845         GLint                           max_xfb           = 0;
7846         GLint                           max_sep           = 0;
7847         bool                            test_result   = true;
7848
7849         const Functions& gl = m_context.getRenderContext().getFunctions();
7850
7851         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7852         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7853         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7854         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7855         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7856         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7857
7858         if (expected_xfb > (GLuint)max_xfb)
7859         {
7860                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7861                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7862                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7863
7864                 test_result = false;
7865         }
7866
7867         if (expected_comp > (GLuint)max_comp)
7868         {
7869                 m_context.getTestContext().getLog()
7870                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7871                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7872
7873                 test_result = false;
7874         }
7875
7876         if (expected_sep > (GLuint)max_sep)
7877         {
7878                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7879                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7880                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7881
7882                 test_result = false;
7883         }
7884
7885         /* Set result */
7886         if (true == test_result)
7887         {
7888                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7889         }
7890         else
7891         {
7892                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7893         }
7894
7895         /* Done */
7896         return tcu::TestNode::STOP;
7897 }
7898
7899 /** Constructor
7900  *
7901  * @param context Test framework context
7902  **/
7903 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7904         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7905 {
7906         /* Nothing to be done here */
7907 }
7908
7909 /** Execute test
7910  *
7911  * @return tcu::TestNode::STOP otherwise
7912  **/
7913 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7914 {
7915         GLint              length = 0;
7916         GLchar             name[64];
7917         GLint              param = 0;
7918         Utils::Program program(m_context);
7919         bool               test_result = true;
7920
7921         const Functions& gl = m_context.getRenderContext().getFunctions();
7922
7923         try
7924         {
7925                 program.Init("" /* cs */, "#version 430 core\n"
7926                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7927                                                                   "\n"
7928                                                                   "in  vec4 vs_fs;\n"
7929                                                                   "out vec4 fs_out;\n"
7930                                                                   "\n"
7931                                                                   "void main()\n"
7932                                                                   "{\n"
7933                                                                   "    fs_out = vs_fs;\n"
7934                                                                   "}\n"
7935                                                                   "\n" /* fs */,
7936                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7937                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7938                                                                                                                           "\n"
7939                                                                                                                           "in  vec4 in_vs;\n"
7940                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7941                                                                                                                           "\n"
7942                                                                                                                           "void main()\n"
7943                                                                                                                           "{\n"
7944                                                                                                                           "    vs_fs = in_vs;\n"
7945                                                                                                                           "}\n"
7946                                                                                                                           "\n" /* vs */,
7947                                          false /* separable */);
7948         }
7949         catch (Utils::Shader::InvalidSourceException& exc)
7950         {
7951                 exc.log(m_context);
7952                 TCU_FAIL(exc.what());
7953         }
7954         catch (Utils::Program::BuildException& exc)
7955         {
7956                 TCU_FAIL(exc.what());
7957         }
7958
7959         /*
7960          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
7961          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
7962          * following:
7963          *   * MAX_NAME_LENGTH,
7964          *   * MAX_NUM_ACTIVE_VARIABLES;
7965          */
7966         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
7967         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
7968                            test_result);
7969
7970         /*
7971          * - GetProgramResourceIndex should generate INVALID_ENUM when
7972          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7973          */
7974         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
7975         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7976         /*
7977          * - GetProgramResourceName should generate INVALID_ENUM when
7978          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7979          */
7980         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
7981                                                           name);
7982         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7983
7984         /* Set result */
7985         if (true == test_result)
7986         {
7987                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7988         }
7989         else
7990         {
7991                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7992         }
7993
7994         /* Done */
7995         return tcu::TestNode::STOP;
7996 }
7997
7998 /** Check if error is the expected one.
7999  *
8000  * @param expected_error Expected error
8001  * @param message        Message to log in case of error
8002  * @param test_result    Test result, set to false in case of invalid error
8003  **/
8004 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
8005 {
8006         const Functions& gl = m_context.getRenderContext().getFunctions();
8007
8008         GLenum error = gl.getError();
8009
8010         if (error != expected_error)
8011         {
8012                 m_context.getTestContext().getLog()
8013                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
8014                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
8015
8016                 test_result = false;
8017         }
8018 }
8019
8020 /** Constructor
8021  *
8022  * @param context Test framework context
8023  **/
8024 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
8025         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
8026 {
8027         /* Nothing to be done here */
8028 }
8029
8030 /** Source for given test case and stage
8031  *
8032  * @param test_case_index Index of test case
8033  * @param stage           Shader stage
8034  *
8035  * @return Shader source
8036  **/
8037 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
8038 {
8039         static const GLchar* cs = "#version 430 core\n"
8040                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8041                                                           "\n"
8042                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8043                                                           "\n"
8044                                                           "writeonly uniform uimage2D uni_image;\n"
8045                                                           "\n"
8046                                                           "void main()\n"
8047                                                           "{\n"
8048                                                           "    uint result = 1u;\n"
8049                                                           "    CONSTANT = 3;\n"
8050                                                           "\n"
8051                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8052                                                           "}\n"
8053                                                           "\n";
8054         static const GLchar* fs = "#version 430 core\n"
8055                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8056                                                           "\n"
8057                                                           "in  vec4 gs_fs;\n"
8058                                                           "out vec4 fs_out;\n"
8059                                                           "\n"
8060                                                           "void main()\n"
8061                                                           "{\n"
8062                                                           "ASSIGNMENT"
8063                                                           "    fs_out = gs_fs;\n"
8064                                                           "}\n"
8065                                                           "\n";
8066         static const GLchar* gs = "#version 430 core\n"
8067                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8068                                                           "\n"
8069                                                           "layout(points)                           in;\n"
8070                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8071                                                           "\n"
8072                                                           "in  vec4 tes_gs[];\n"
8073                                                           "out vec4 gs_fs;\n"
8074                                                           "\n"
8075                                                           "void main()\n"
8076                                                           "{\n"
8077                                                           "ASSIGNMENT"
8078                                                           "    gs_fs = tes_gs[0];\n"
8079                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8080                                                           "    EmitVertex();\n"
8081                                                           "    gs_fs = tes_gs[0];\n"
8082                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8083                                                           "    EmitVertex();\n"
8084                                                           "    gs_fs = tes_gs[0];\n"
8085                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8086                                                           "    EmitVertex();\n"
8087                                                           "    gs_fs = tes_gs[0];\n"
8088                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8089                                                           "    EmitVertex();\n"
8090                                                           "}\n"
8091                                                           "\n";
8092         static const GLchar* tcs = "#version 430 core\n"
8093                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8094                                                            "\n"
8095                                                            "layout(vertices = 1) out;\n"
8096                                                            "\n"
8097                                                            "in  vec4 vs_tcs[];\n"
8098                                                            "out vec4 tcs_tes[];\n"
8099                                                            "\n"
8100                                                            "void main()\n"
8101                                                            "{\n"
8102                                                            "\n"
8103                                                            "ASSIGNMENT"
8104                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8105                                                            "\n"
8106                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8107                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8108                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8109                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8110                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8111                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8112                                                            "}\n"
8113                                                            "\n";
8114         static const GLchar* tes = "#version 430 core\n"
8115                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8116                                                            "\n"
8117                                                            "layout(isolines, point_mode) in;\n"
8118                                                            "\n"
8119                                                            "in  vec4 tcs_tes[];\n"
8120                                                            "out vec4 tes_gs;\n"
8121                                                            "\n"
8122                                                            "void main()\n"
8123                                                            "{\n"
8124                                                            "ASSIGNMENT"
8125                                                            "    tes_gs = tcs_tes[0];\n"
8126                                                            "}\n"
8127                                                            "\n";
8128         static const GLchar* vs = "#version 430 core\n"
8129                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8130                                                           "\n"
8131                                                           "in  vec4 in_vs;\n"
8132                                                           "out vec4 vs_tcs;\n"
8133                                                           "\n"
8134                                                           "void main()\n"
8135                                                           "{\n"
8136                                                           "ASSIGNMENT"
8137                                                           "    vs_tcs = in_vs;\n"
8138                                                           "}\n"
8139                                                           "\n";
8140
8141         std::string source;
8142         testCase&   test_case = m_test_cases[test_case_index];
8143
8144         if (Utils::Shader::COMPUTE == test_case.m_stage)
8145         {
8146                 size_t position = 0;
8147
8148                 source = cs;
8149
8150                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8151         }
8152         else
8153         {
8154                 std::string assignment = "    CONSTANT = 3;\n";
8155                 size_t          position   = 0;
8156
8157                 switch (stage)
8158                 {
8159                 case Utils::Shader::FRAGMENT:
8160                         source = fs;
8161                         break;
8162                 case Utils::Shader::GEOMETRY:
8163                         source = gs;
8164                         break;
8165                 case Utils::Shader::TESS_CTRL:
8166                         source = tcs;
8167                         break;
8168                 case Utils::Shader::TESS_EVAL:
8169                         source = tes;
8170                         break;
8171                 case Utils::Shader::VERTEX:
8172                         source = vs;
8173                         break;
8174                 default:
8175                         TCU_FAIL("Invalid enum");
8176                 }
8177
8178                 if (test_case.m_stage == stage)
8179                 {
8180                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8181                 }
8182                 else
8183                 {
8184                         assignment = "";
8185                 }
8186
8187                 position = 0;
8188                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8189         }
8190
8191         return source;
8192 }
8193
8194 /** Get description of test case
8195  *
8196  * @param test_case_index Index of test case
8197  *
8198  * @return Constant name
8199  **/
8200 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8201 {
8202         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8203
8204         return result;
8205 }
8206
8207 /** Get number of test cases
8208  *
8209  * @return Number of test cases
8210  **/
8211 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8212 {
8213         return static_cast<GLuint>(m_test_cases.size());
8214 }
8215
8216 /** Selects if "compute" stage is relevant for test
8217  *
8218  * @param test_case_index Index of test case
8219  *
8220  * @return true when tested stage is compute
8221  **/
8222 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8223 {
8224         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8225 }
8226
8227 /** Prepare all test cases
8228  *
8229  **/
8230 void GLSLContantImmutablityTest::testInit()
8231 {
8232         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8233         {
8234                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8235                 {
8236                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8237
8238                         m_test_cases.push_back(test_case);
8239                 }
8240         }
8241 }
8242
8243 /** Get name of glsl constant
8244  *
8245  * @param Constant id
8246  *
8247  * @return Name of constant used in GLSL
8248  **/
8249 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8250 {
8251         const GLchar* name = "";
8252
8253         switch (constant)
8254         {
8255         case GL_ARB_ENHANCED_LAYOUTS:
8256                 name = "GL_ARB_enhanced_layouts";
8257                 break;
8258         case GL_MAX_XFB:
8259                 name = "gl_MaxTransformFeedbackBuffers";
8260                 break;
8261         case GL_MAX_XFB_INT_COMP:
8262                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8263                 break;
8264         default:
8265                 TCU_FAIL("Invalid enum");
8266         }
8267
8268         return name;
8269 }
8270
8271 /** Constructor
8272  *
8273  * @param context Test framework context
8274  **/
8275 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8276         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8277 {
8278 }
8279
8280 /** Selects if "compute" stage is relevant for test
8281  *
8282  * @param ignored
8283  *
8284  * @return false
8285  **/
8286 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8287 {
8288         return false;
8289 }
8290
8291 /** Prepare code snippet that will verify in and uniform variables
8292  *
8293  * @param ignored
8294  * @param ignored
8295  * @param stage   Shader stage
8296  *
8297  * @return Code that verify variables
8298  **/
8299 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8300                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8301                                                                                                                   Utils::Shader::STAGES stage)
8302 {
8303         /* Get constants */
8304         const Functions& gl = m_context.getRenderContext().getFunctions();
8305
8306         GLint max_transform_feedback_buffers                            = 0;
8307         GLint max_transform_feedback_interleaved_components = 0;
8308
8309         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8310         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8311         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8312         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8313
8314         std::string verification;
8315
8316         if (Utils::Shader::VERTEX == stage)
8317         {
8318                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8319                                            "    {\n"
8320                                            "        result = 0;\n"
8321                                            "    }\n"
8322                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8323                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8324                                            "    {\n"
8325                                            "        result = 0;\n"
8326                                            "    }\n"
8327                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8328                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8329                                            "    {\n"
8330                                            "        result = 0;\n"
8331                                            "    }\n";
8332
8333                 size_t position = 0;
8334                 GLchar buffer[16];
8335
8336                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8337                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8338
8339                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8340                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8341         }
8342         else
8343         {
8344                 verification = "";
8345         }
8346
8347         return verification;
8348 }
8349
8350 /** Constructor
8351  *
8352  * @param context Test framework context
8353  **/
8354 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8355         : TextureTestBase(context, "glsl_constant_integral_expression",
8356                                           "Test verifies that symbols can be used as constant integral expressions")
8357 {
8358 }
8359
8360 /** Get interface of program
8361  *
8362  * @param ignored
8363  * @param program_interface Interface of program
8364  * @param ignored
8365  **/
8366 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8367                                                                                                                          Utils::ProgramInterface& program_interface,
8368                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8369 {
8370         /* Get constants */
8371         const Functions& gl = m_context.getRenderContext().getFunctions();
8372
8373         GLint max_transform_feedback_buffers                            = 0;
8374         GLint max_transform_feedback_interleaved_components = 0;
8375
8376         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8377         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8378         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8379         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8380
8381         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8382         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8383
8384         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8385         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8386
8387         /* Globals */
8388         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8389                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8390                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8391
8392         size_t position = 0;
8393         GLchar buffer[16];
8394
8395         sprintf(buffer, "%d", gohan_div);
8396         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8397
8398         sprintf(buffer, "%d", goten_div);
8399         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8400
8401         program_interface.m_vertex.m_globals    = globals;
8402         program_interface.m_tess_ctrl.m_globals = globals;
8403         program_interface.m_tess_eval.m_globals = globals;
8404         program_interface.m_geometry.m_globals  = globals;
8405         program_interface.m_fragment.m_globals  = globals;
8406         program_interface.m_compute.m_globals   = globals;
8407 }
8408
8409 /** Prepare code snippet that will verify in and uniform variables
8410  *
8411  * @param ignored
8412  * @param ignored
8413  * @param ignored
8414  *
8415  * @return Code that verify variables
8416  **/
8417 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8418                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8419                                                                                                                                            Utils::Shader::STAGES /* stage */)
8420 {
8421         std::string verification = "{\n"
8422                                                            "        uint goku_sum = 0;\n"
8423                                                            "        uint gohan_sum = 0;\n"
8424                                                            "        uint goten_sum = 0;\n"
8425                                                            "\n"
8426                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8427                                                            "        {\n"
8428                                                            "            goku_sum += goku[i];\n"
8429                                                            "        }\n"
8430                                                            "\n"
8431                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8432                                                            "        {\n"
8433                                                            "            gohan_sum += gohan[i];\n"
8434                                                            "        }\n"
8435                                                            "\n"
8436                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8437                                                            "        {\n"
8438                                                            "            goten_sum += goten[i];\n"
8439                                                            "        }\n"
8440                                                            "\n"
8441                                                            "        if ( (1u != goku_sum)  &&\n"
8442                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8443                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8444                                                            "        {\n"
8445                                                            "            result = 0u;\n"
8446                                                            "        }\n"
8447                                                            "    }\n";
8448
8449         size_t position = 0;
8450         GLchar buffer[16];
8451
8452         sprintf(buffer, "%d", m_gohan_length);
8453         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8454
8455         sprintf(buffer, "%d", m_goten_length);
8456         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8457
8458         return verification;
8459 }
8460
8461 /** Prepare unifroms
8462  *
8463  * @param ignored
8464  * @param ignored
8465  * @param program Program object
8466  * @param ignored
8467  **/
8468 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8469                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8470                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8471 {
8472         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8473
8474         const Functions& gl = m_context.getRenderContext().getFunctions();
8475
8476         GLint goku_location  = program.GetUniformLocation("goku");
8477         GLint gohan_location = program.GetUniformLocation("gohan");
8478         GLint goten_location = program.GetUniformLocation("goten");
8479
8480         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8481         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8482         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8483 }
8484
8485 /** Prepare unifroms
8486  *
8487  * @param test_case_index   Pass as param to first implemetnation
8488  * @param program_interface Pass as param to first implemetnation
8489  * @param program           Pass as param to first implemetnation
8490  * @param ignored
8491  * @param ignored
8492  * @param ignored
8493  * @param ignored
8494  * @param vs_buffer         Pass as param to first implemetnation
8495  **/
8496 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8497                                                                                                                  Utils::ProgramInterface& program_interface,
8498                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8499                                                                                                                  Utils::Buffer& /* gs_buffer */,
8500                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8501                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8502 {
8503         /* Call first implementation */
8504         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8505 }
8506
8507 /** Constructor
8508  *
8509  * @param context Test framework context
8510  **/
8511 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8512         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8513                                           "Test verifies offsets and alignment of uniform buffer members")
8514 {
8515 }
8516
8517 /** Get interface of program
8518  *
8519  * @param test_case_index     Test case index
8520  * @param program_interface   Interface of program
8521  * @param varying_passthrough Collection of connections between in and out variables
8522  **/
8523 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8524                                                                                                                            Utils::ProgramInterface&   program_interface,
8525                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8526 {
8527         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8528                                                   "const int type_align = TYPE_ALIGN;\n"
8529                                                   "const int type_size  = TYPE_SIZE;\n";
8530
8531         Utils::Type  type                = getType(test_case_index);
8532         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8533         const GLuint base_align  = type.GetBaseAlignment(false);
8534         const GLuint array_align = type.GetBaseAlignment(true);
8535         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8536         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8537
8538         /* Calculate offsets */
8539         const GLuint first_offset  = 0;
8540         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8541
8542 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8543
8544         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8545         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8546         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8547         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8548         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8549         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8550
8551 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8552
8553         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8554         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
8555         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8556         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8557         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8558         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
8559
8560 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8561
8562         /* Prepare data */
8563         const std::vector<GLubyte>& first  = type.GenerateData();
8564         const std::vector<GLubyte>& second = type.GenerateData();
8565         const std::vector<GLubyte>& third  = type.GenerateData();
8566         const std::vector<GLubyte>& fourth = type.GenerateData();
8567
8568         m_data.resize(eigth_offset + base_stride);
8569         GLubyte* ptr = &m_data[0];
8570         memcpy(ptr + first_offset, &first[0], first.size());
8571         memcpy(ptr + second_offset, &second[0], second.size());
8572         memcpy(ptr + third_offset, &third[0], third.size());
8573         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8574         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8575         memcpy(ptr + sixth_offset, &third[0], third.size());
8576         memcpy(ptr + seventh_offset, &second[0], second.size());
8577         memcpy(ptr + eigth_offset, &first[0], first.size());
8578
8579         /* Prepare globals */
8580         size_t position = 0;
8581         GLchar buffer[16];
8582
8583         sprintf(buffer, "%d", basic_size);
8584         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8585
8586         sprintf(buffer, "%d", type_align);
8587         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8588
8589         sprintf(buffer, "%d", base_stride);
8590         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8591
8592         /* Prepare Block */
8593         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8594
8595         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8596                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8597                                                  first_offset);
8598
8599         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8600                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8601                                                  0 /* n_array_elements */, base_stride, second_offset);
8602
8603         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8604                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8605                                                  third_offset);
8606
8607         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8608                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8609                                                  fourth_offset);
8610
8611         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8612                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8613
8614         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8615                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8616
8617         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8618                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8619                                                  eigth_offset);
8620
8621         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8622
8623         /* Add globals */
8624         vs_si.m_globals = globals;
8625
8626         /* Add uniform BLOCK */
8627         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8628                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8629
8630         /* */
8631         program_interface.CloneVertexInterface(varying_passthrough);
8632 }
8633
8634 /** Get type name
8635  *
8636  * @param test_case_index Index of test case
8637  *
8638  * @return Name of type test in test_case_index
8639  **/
8640 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8641 {
8642         return getTypeName(test_case_index);
8643 }
8644
8645 /** Returns number of types to test
8646  *
8647  * @return Number of types, 34
8648  **/
8649 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8650 {
8651         return getTypesNumber();
8652 }
8653
8654 /** Prepare code snippet that will verify in and uniform variables
8655  *
8656  * @param ignored
8657  * @param ignored
8658  * @param stage   Shader stage
8659  *
8660  * @return Code that verify variables
8661  **/
8662 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8663         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8664 {
8665         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8666                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8667                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8668                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8669                                                            "    {\n"
8670                                                            "        result = 0;\n"
8671                                                            "    }";
8672
8673         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8674
8675         Utils::replaceAllTokens("PREFIX", prefix, verification);
8676
8677         return verification;
8678 }
8679
8680 /** Constructor
8681  *
8682  * @param context Test framework context
8683  **/
8684 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8685         : NegativeTestBase(
8686                   context, "uniform_block_layout_qualifier_conflict",
8687                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8688 {
8689         /* Nothing to be done here */
8690 }
8691
8692 /** Source for given test case and stage
8693  *
8694  * @param test_case_index Index of test case
8695  * @param stage           Shader stage
8696  *
8697  * @return Shader source
8698  **/
8699 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8700                                                                                                                                          Utils::Shader::STAGES stage)
8701 {
8702         static const GLchar* cs = "#version 430 core\n"
8703                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8704                                                           "\n"
8705                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8706                                                           "\n"
8707                                                           "LAYOUTuniform Block {\n"
8708                                                           "    layout(offset = 16) vec4 boy;\n"
8709                                                           "    layout(align  = 64) vec4 man;\n"
8710                                                           "} uni_block;\n"
8711                                                           "\n"
8712                                                           "writeonly uniform image2D uni_image;\n"
8713                                                           "\n"
8714                                                           "void main()\n"
8715                                                           "{\n"
8716                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8717                                                           "\n"
8718                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8719                                                           "}\n"
8720                                                           "\n";
8721         static const GLchar* fs = "#version 430 core\n"
8722                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8723                                                           "\n"
8724                                                           "LAYOUTuniform Block {\n"
8725                                                           "    layout(offset = 16) vec4 boy;\n"
8726                                                           "    layout(align  = 64) vec4 man;\n"
8727                                                           "} uni_block;\n"
8728                                                           "\n"
8729                                                           "in  vec4 gs_fs;\n"
8730                                                           "out vec4 fs_out;\n"
8731                                                           "\n"
8732                                                           "void main()\n"
8733                                                           "{\n"
8734                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8735                                                           "}\n"
8736                                                           "\n";
8737         static const GLchar* gs = "#version 430 core\n"
8738                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8739                                                           "\n"
8740                                                           "layout(points)                           in;\n"
8741                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8742                                                           "\n"
8743                                                           "LAYOUTuniform Block {\n"
8744                                                           "    layout(offset = 16) vec4 boy;\n"
8745                                                           "    layout(align  = 64) vec4 man;\n"
8746                                                           "} uni_block;\n"
8747                                                           "\n"
8748                                                           "in  vec4 tes_gs[];\n"
8749                                                           "out vec4 gs_fs;\n"
8750                                                           "\n"
8751                                                           "void main()\n"
8752                                                           "{\n"
8753                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8754                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8755                                                           "    EmitVertex();\n"
8756                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8757                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8758                                                           "    EmitVertex();\n"
8759                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8760                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8761                                                           "    EmitVertex();\n"
8762                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8763                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8764                                                           "    EmitVertex();\n"
8765                                                           "}\n"
8766                                                           "\n";
8767         static const GLchar* tcs =
8768                 "#version 430 core\n"
8769                 "#extension GL_ARB_enhanced_layouts : require\n"
8770                 "\n"
8771                 "layout(vertices = 1) out;\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 vs_tcs[];\n"
8779                 "out vec4 tcs_tes[];\n"
8780                 "\n"
8781                 "void main()\n"
8782                 "{\n"
8783                 "\n"
8784                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8785                 "\n"
8786                 "    gl_TessLevelOuter[0] = 1.0;\n"
8787                 "    gl_TessLevelOuter[1] = 1.0;\n"
8788                 "    gl_TessLevelOuter[2] = 1.0;\n"
8789                 "    gl_TessLevelOuter[3] = 1.0;\n"
8790                 "    gl_TessLevelInner[0] = 1.0;\n"
8791                 "    gl_TessLevelInner[1] = 1.0;\n"
8792                 "}\n"
8793                 "\n";
8794         static const GLchar* tes = "#version 430 core\n"
8795                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8796                                                            "\n"
8797                                                            "layout(isolines, point_mode) in;\n"
8798                                                            "\n"
8799                                                            "LAYOUTuniform Block {\n"
8800                                                            "    layout(offset = 16) vec4 boy;\n"
8801                                                            "    layout(align  = 64) vec4 man;\n"
8802                                                            "} uni_block;\n"
8803                                                            "\n"
8804                                                            "in  vec4 tcs_tes[];\n"
8805                                                            "out vec4 tes_gs;\n"
8806                                                            "\n"
8807                                                            "void main()\n"
8808                                                            "{\n"
8809                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8810                                                            "}\n"
8811                                                            "\n";
8812         static const GLchar* vs = "#version 430 core\n"
8813                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8814                                                           "\n"
8815                                                           "LAYOUTuniform Block {\n"
8816                                                           "    layout(offset = 16) vec4 boy;\n"
8817                                                           "    layout(align  = 64) vec4 man;\n"
8818                                                           "} uni_block;\n"
8819                                                           "\n"
8820                                                           "in  vec4 in_vs;\n"
8821                                                           "out vec4 vs_tcs;\n"
8822                                                           "\n"
8823                                                           "void main()\n"
8824                                                           "{\n"
8825                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8826                                                           "}\n"
8827                                                           "\n";
8828
8829         std::string   layout    = "";
8830         size_t            position  = 0;
8831         testCase&        test_case = m_test_cases[test_case_index];
8832         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8833         std::string   source;
8834
8835         if (0 != qualifier[0])
8836         {
8837                 size_t layout_position = 0;
8838
8839                 layout = "layout (QUALIFIER) ";
8840
8841                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8842         }
8843
8844         switch (stage)
8845         {
8846         case Utils::Shader::COMPUTE:
8847                 source = cs;
8848                 break;
8849         case Utils::Shader::FRAGMENT:
8850                 source = fs;
8851                 break;
8852         case Utils::Shader::GEOMETRY:
8853                 source = gs;
8854                 break;
8855         case Utils::Shader::TESS_CTRL:
8856                 source = tcs;
8857                 break;
8858         case Utils::Shader::TESS_EVAL:
8859                 source = tes;
8860                 break;
8861         case Utils::Shader::VERTEX:
8862                 source = vs;
8863                 break;
8864         default:
8865                 TCU_FAIL("Invalid enum");
8866         }
8867
8868         if (test_case.m_stage == stage)
8869         {
8870                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8871         }
8872         else
8873         {
8874                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8875         }
8876
8877         return source;
8878 }
8879
8880 /** Get description of test case
8881  *
8882  * @param test_case_index Index of test case
8883  *
8884  * @return Qualifier name
8885  **/
8886 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8887 {
8888         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8889
8890         return result;
8891 }
8892
8893 /** Get number of test cases
8894  *
8895  * @return Number of test cases
8896  **/
8897 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8898 {
8899         return static_cast<GLuint>(m_test_cases.size());
8900 }
8901
8902 /** Selects if "compute" stage is relevant for test
8903  *
8904  * @param test_case_index Index of test case
8905  *
8906  * @return true when tested stage is compute
8907  **/
8908 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8909 {
8910         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8911 }
8912
8913 /** Selects if compilation failure is expected result
8914  *
8915  * @param test_case_index Index of test case
8916  *
8917  * @return false for STD140 cases, true otherwise
8918  **/
8919 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8920 {
8921         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8922 }
8923
8924 /** Prepare all test cases
8925  *
8926  **/
8927 void UniformBlockLayoutQualifierConflictTest::testInit()
8928 {
8929         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8930         {
8931                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8932                 {
8933                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8934
8935                         m_test_cases.push_back(test_case);
8936                 }
8937         }
8938 }
8939
8940 /** Get name of glsl constant
8941  *
8942  * @param Constant id
8943  *
8944  * @return Name of constant used in GLSL
8945  **/
8946 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8947 {
8948         const GLchar* name = "";
8949
8950         switch (qualifier)
8951         {
8952         case DEFAULT:
8953                 name = "";
8954                 break;
8955         case STD140:
8956                 name = "std140";
8957                 break;
8958         case SHARED:
8959                 name = "shared";
8960                 break;
8961         case PACKED:
8962                 name = "packed";
8963                 break;
8964         default:
8965                 TCU_FAIL("Invalid enum");
8966         }
8967
8968         return name;
8969 }
8970
8971 /** Constructor
8972  *
8973  * @param context Test framework context
8974  **/
8975 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
8976         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
8977                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
8978 {
8979         /* Nothing to be done here */
8980 }
8981
8982 /** Constructor
8983  *
8984  * @param context     Test framework context
8985  * @param name        Test name
8986  * @param description Test description
8987  **/
8988 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
8989         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
8990         : NegativeTestBase(context, name, description)
8991 {
8992         /* Nothing to be done here */
8993 }
8994
8995 /** Source for given test case and stage
8996  *
8997  * @param test_case_index Index of test case
8998  * @param stage           Shader stage
8999  *
9000  * @return Shader source
9001  **/
9002 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
9003                                                                                                                                                   Utils::Shader::STAGES stage)
9004 {
9005         static const GLchar* cs = "#version 430 core\n"
9006                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9007                                                           "\n"
9008                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9009                                                           "\n"
9010                                                           "layout (std140) uniform Block {\n"
9011                                                           "    layout (offset = OFFSET) TYPE member;\n"
9012                                                           "} block;\n"
9013                                                           "\n"
9014                                                           "writeonly uniform image2D uni_image;\n"
9015                                                           "\n"
9016                                                           "void main()\n"
9017                                                           "{\n"
9018                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9019                                                           "\n"
9020                                                           "    if (TYPE(1) == block.member)\n"
9021                                                           "    {\n"
9022                                                           "        result = vec4(1, 1, 1, 1);\n"
9023                                                           "    }\n"
9024                                                           "\n"
9025                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9026                                                           "}\n"
9027                                                           "\n";
9028         static const GLchar* fs = "#version 430 core\n"
9029                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9030                                                           "\n"
9031                                                           "in  vec4 gs_fs;\n"
9032                                                           "out vec4 fs_out;\n"
9033                                                           "\n"
9034                                                           "void main()\n"
9035                                                           "{\n"
9036                                                           "    fs_out = gs_fs;\n"
9037                                                           "}\n"
9038                                                           "\n";
9039         static const GLchar* fs_tested = "#version 430 core\n"
9040                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9041                                                                          "\n"
9042                                                                          "layout (std140) uniform Block {\n"
9043                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9044                                                                          "} block;\n"
9045                                                                          "\n"
9046                                                                          "in  vec4 gs_fs;\n"
9047                                                                          "out vec4 fs_out;\n"
9048                                                                          "\n"
9049                                                                          "void main()\n"
9050                                                                          "{\n"
9051                                                                          "    if (TYPE(1) == block.member)\n"
9052                                                                          "    {\n"
9053                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9054                                                                          "    }\n"
9055                                                                          "\n"
9056                                                                          "    fs_out += gs_fs;\n"
9057                                                                          "}\n"
9058                                                                          "\n";
9059         static const GLchar* gs = "#version 430 core\n"
9060                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9061                                                           "\n"
9062                                                           "layout(points)                           in;\n"
9063                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9064                                                           "\n"
9065                                                           "in  vec4 tes_gs[];\n"
9066                                                           "out vec4 gs_fs;\n"
9067                                                           "\n"
9068                                                           "void main()\n"
9069                                                           "{\n"
9070                                                           "    gs_fs = tes_gs[0];\n"
9071                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9072                                                           "    EmitVertex();\n"
9073                                                           "    gs_fs = tes_gs[0];\n"
9074                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9075                                                           "    EmitVertex();\n"
9076                                                           "    gs_fs = tes_gs[0];\n"
9077                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9078                                                           "    EmitVertex();\n"
9079                                                           "    gs_fs = tes_gs[0];\n"
9080                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9081                                                           "    EmitVertex();\n"
9082                                                           "}\n"
9083                                                           "\n";
9084         static const GLchar* gs_tested = "#version 430 core\n"
9085                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9086                                                                          "\n"
9087                                                                          "layout(points)                           in;\n"
9088                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9089                                                                          "\n"
9090                                                                          "layout (std140) uniform Block {\n"
9091                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9092                                                                          "} block;\n"
9093                                                                          "\n"
9094                                                                          "in  vec4 tes_gs[];\n"
9095                                                                          "out vec4 gs_fs;\n"
9096                                                                          "\n"
9097                                                                          "void main()\n"
9098                                                                          "{\n"
9099                                                                          "    if (TYPE(1) == block.member)\n"
9100                                                                          "    {\n"
9101                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9102                                                                          "    }\n"
9103                                                                          "\n"
9104                                                                          "    gs_fs += tes_gs[0];\n"
9105                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9106                                                                          "    EmitVertex();\n"
9107                                                                          "    gs_fs += tes_gs[0];\n"
9108                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9109                                                                          "    EmitVertex();\n"
9110                                                                          "    gs_fs += tes_gs[0];\n"
9111                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9112                                                                          "    EmitVertex();\n"
9113                                                                          "    gs_fs += tes_gs[0];\n"
9114                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9115                                                                          "    EmitVertex();\n"
9116                                                                          "}\n"
9117                                                                          "\n";
9118         static const GLchar* tcs = "#version 430 core\n"
9119                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9120                                                            "\n"
9121                                                            "layout(vertices = 1) out;\n"
9122                                                            "\n"
9123                                                            "in  vec4 vs_tcs[];\n"
9124                                                            "out vec4 tcs_tes[];\n"
9125                                                            "\n"
9126                                                            "void main()\n"
9127                                                            "{\n"
9128                                                            "\n"
9129                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9130                                                            "\n"
9131                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9132                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9133                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9134                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9135                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9136                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9137                                                            "}\n"
9138                                                            "\n";
9139         static const GLchar* tcs_tested = "#version 430 core\n"
9140                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9141                                                                           "\n"
9142                                                                           "layout(vertices = 1) out;\n"
9143                                                                           "\n"
9144                                                                           "layout (std140) uniform Block {\n"
9145                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9146                                                                           "} block;\n"
9147                                                                           "\n"
9148                                                                           "in  vec4 vs_tcs[];\n"
9149                                                                           "out vec4 tcs_tes[];\n"
9150                                                                           "\n"
9151                                                                           "void main()\n"
9152                                                                           "{\n"
9153                                                                           "    if (TYPE(1) == block.member)\n"
9154                                                                           "    {\n"
9155                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9156                                                                           "    }\n"
9157                                                                           "\n"
9158                                                                           "\n"
9159                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9160                                                                           "\n"
9161                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9162                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9163                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9164                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9165                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9166                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9167                                                                           "}\n"
9168                                                                           "\n";
9169         static const GLchar* tes = "#version 430 core\n"
9170                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9171                                                            "\n"
9172                                                            "layout(isolines, point_mode) in;\n"
9173                                                            "\n"
9174                                                            "in  vec4 tcs_tes[];\n"
9175                                                            "out vec4 tes_gs;\n"
9176                                                            "\n"
9177                                                            "void main()\n"
9178                                                            "{\n"
9179                                                            "    tes_gs = tcs_tes[0];\n"
9180                                                            "}\n"
9181                                                            "\n";
9182         static const GLchar* tes_tested = "#version 430 core\n"
9183                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9184                                                                           "\n"
9185                                                                           "layout(isolines, point_mode) in;\n"
9186                                                                           "\n"
9187                                                                           "layout (std140) uniform Block {\n"
9188                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9189                                                                           "} block;\n"
9190                                                                           "\n"
9191                                                                           "in  vec4 tcs_tes[];\n"
9192                                                                           "out vec4 tes_gs;\n"
9193                                                                           "\n"
9194                                                                           "void main()\n"
9195                                                                           "{\n"
9196                                                                           "    if (TYPE(1) == block.member)\n"
9197                                                                           "    {\n"
9198                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9199                                                                           "    }\n"
9200                                                                           "\n"
9201                                                                           "    tes_gs += tcs_tes[0];\n"
9202                                                                           "}\n"
9203                                                                           "\n";
9204         static const GLchar* vs = "#version 430 core\n"
9205                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9206                                                           "\n"
9207                                                           "in  vec4 in_vs;\n"
9208                                                           "out vec4 vs_tcs;\n"
9209                                                           "\n"
9210                                                           "void main()\n"
9211                                                           "{\n"
9212                                                           "    vs_tcs = in_vs;\n"
9213                                                           "}\n"
9214                                                           "\n";
9215         static const GLchar* vs_tested = "#version 430 core\n"
9216                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9217                                                                          "\n"
9218                                                                          "layout (std140) uniform Block {\n"
9219                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9220                                                                          "} block;\n"
9221                                                                          "\n"
9222                                                                          "in  vec4 in_vs;\n"
9223                                                                          "out vec4 vs_tcs;\n"
9224                                                                          "\n"
9225                                                                          "void main()\n"
9226                                                                          "{\n"
9227                                                                          "    if (TYPE(1) == block.member)\n"
9228                                                                          "    {\n"
9229                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9230                                                                          "    }\n"
9231                                                                          "\n"
9232                                                                          "    vs_tcs += in_vs;\n"
9233                                                                          "}\n"
9234                                                                          "\n";
9235
9236         std::string source;
9237         testCase&   test_case = m_test_cases[test_case_index];
9238
9239         if (test_case.m_stage == stage)
9240         {
9241                 GLchar                     buffer[16];
9242                 const GLuint       offset       = test_case.m_offset;
9243                 size_t                     position  = 0;
9244                 const Utils::Type& type          = test_case.m_type;
9245                 const GLchar*     type_name = type.GetGLSLTypeName();
9246
9247                 sprintf(buffer, "%d", offset);
9248
9249                 switch (stage)
9250                 {
9251                 case Utils::Shader::COMPUTE:
9252                         source = cs;
9253                         break;
9254                 case Utils::Shader::FRAGMENT:
9255                         source = fs_tested;
9256                         break;
9257                 case Utils::Shader::GEOMETRY:
9258                         source = gs_tested;
9259                         break;
9260                 case Utils::Shader::TESS_CTRL:
9261                         source = tcs_tested;
9262                         break;
9263                 case Utils::Shader::TESS_EVAL:
9264                         source = tes_tested;
9265                         break;
9266                 case Utils::Shader::VERTEX:
9267                         source = vs_tested;
9268                         break;
9269                 default:
9270                         TCU_FAIL("Invalid enum");
9271                 }
9272
9273                 Utils::replaceToken("OFFSET", position, buffer, source);
9274                 Utils::replaceToken("TYPE", position, type_name, source);
9275                 Utils::replaceToken("TYPE", position, type_name, source);
9276         }
9277         else
9278         {
9279                 switch (stage)
9280                 {
9281                 case Utils::Shader::FRAGMENT:
9282                         source = fs;
9283                         break;
9284                 case Utils::Shader::GEOMETRY:
9285                         source = gs;
9286                         break;
9287                 case Utils::Shader::TESS_CTRL:
9288                         source = tcs;
9289                         break;
9290                 case Utils::Shader::TESS_EVAL:
9291                         source = tes;
9292                         break;
9293                 case Utils::Shader::VERTEX:
9294                         source = vs;
9295                         break;
9296                 default:
9297                         TCU_FAIL("Invalid enum");
9298                 }
9299         }
9300
9301         return source;
9302 }
9303
9304 /** Get description of test case
9305  *
9306  * @param test_case_index Index of test case
9307  *
9308  * @return Type name and offset
9309  **/
9310 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9311 {
9312         std::stringstream stream;
9313         testCase&                 test_case = m_test_cases[test_case_index];
9314
9315         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9316
9317         return stream.str();
9318 }
9319
9320 /** Get number of test cases
9321  *
9322  * @return Number of test cases
9323  **/
9324 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9325 {
9326         return static_cast<GLuint>(m_test_cases.size());
9327 }
9328
9329 /** Get the maximum size for an uniform block
9330  *
9331  * @return The maximum size in basic machine units of a uniform block.
9332  **/
9333 GLint UniformBlockMemberInvalidOffsetAlignmentTest::getMaxBlockSize()
9334 {
9335         const Functions& gl               = m_context.getRenderContext().getFunctions();
9336         GLint                    max_size = 0;
9337
9338         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9339         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9340
9341         return max_size;
9342 }
9343
9344 /** Selects if "compute" stage is relevant for test
9345  *
9346  * @param test_case_index Index of test case
9347  *
9348  * @return true when tested stage is compute
9349  **/
9350 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9351 {
9352         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9353 }
9354
9355 /** Selects if compilation failure is expected result
9356  *
9357  * @param test_case_index Index of test case
9358  *
9359  * @return should_fail field from testCase
9360  **/
9361 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9362 {
9363         return m_test_cases[test_case_index].m_should_fail;
9364 }
9365
9366 /** Checks if stage is supported
9367  *
9368  * @param stage ignored
9369  *
9370  * @return true
9371  **/
9372 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9373 {
9374         return true;
9375 }
9376
9377 /** Prepare all test cases
9378  *
9379  **/
9380 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9381 {
9382         const GLuint n_types = getTypesNumber();
9383         bool             stage_support[Utils::Shader::STAGE_MAX];
9384
9385         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9386         {
9387                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9388         }
9389
9390         for (GLuint i = 0; i < n_types; ++i)
9391         {
9392                 const Utils::Type& type           = getType(i);
9393                 const GLuint       alignment  = type.GetBaseAlignment(false);
9394                 const GLuint       type_size  = type.GetSize(true);
9395                 const GLuint       sec_to_end = getMaxBlockSize() - 2 * type_size;
9396
9397                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9398                 {
9399                         if (false == stage_support[stage])
9400                         {
9401                                 continue;
9402                         }
9403
9404                         for (GLuint offset = 0; offset <= type_size; ++offset)
9405                         {
9406                                 const GLuint modulo              = offset % alignment;
9407                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9408                                 const bool   should_fail = !is_aligned;
9409
9410                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9411
9412                                 m_test_cases.push_back(test_case);
9413                         }
9414
9415                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9416                         {
9417                                 const GLuint modulo              = offset % alignment;
9418                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9419                                 const bool   should_fail = !is_aligned;
9420
9421                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9422
9423                                 m_test_cases.push_back(test_case);
9424                         }
9425                 }
9426         }
9427 }
9428
9429 /** Constructor
9430  *
9431  * @param context Test framework context
9432  **/
9433 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9434         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9435                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9436 {
9437         /* Nothing to be done here */
9438 }
9439
9440 /** Constructor
9441  *
9442  * @param context Test framework context
9443  * @param name        Test name
9444  * @param description Test description
9445  **/
9446 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9447                                                                                                                                                                    const glw::GLchar* name,
9448                                                                                                                                                                    const glw::GLchar* description)
9449         : NegativeTestBase(context, name, description)
9450 {
9451         /* Nothing to be done here */
9452 }
9453
9454 /** Source for given test case and stage
9455  *
9456  * @param test_case_index Index of test case
9457  * @param stage           Shader stage
9458  *
9459  * @return Shader source
9460  **/
9461 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9462                                                                                                                                           Utils::Shader::STAGES stage)
9463 {
9464         static const GLchar* cs = "#version 430 core\n"
9465                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9466                                                           "\n"
9467                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9468                                                           "\n"
9469                                                           "layout (std140) uniform Block {\n"
9470                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9471                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9472                                                           "} block;\n"
9473                                                           "\n"
9474                                                           "writeonly uniform image2D uni_image;\n"
9475                                                           "\n"
9476                                                           "void main()\n"
9477                                                           "{\n"
9478                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9479                                                           "\n"
9480                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9481                                                           "        (MAN_TYPE(0) == block.man) )\n"
9482                                                           "    {\n"
9483                                                           "        result = vec4(1, 1, 1, 1);\n"
9484                                                           "    }\n"
9485                                                           "\n"
9486                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9487                                                           "}\n"
9488                                                           "\n";
9489         static const GLchar* fs = "#version 430 core\n"
9490                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9491                                                           "\n"
9492                                                           "in  vec4 gs_fs;\n"
9493                                                           "out vec4 fs_out;\n"
9494                                                           "\n"
9495                                                           "void main()\n"
9496                                                           "{\n"
9497                                                           "    fs_out = gs_fs;\n"
9498                                                           "}\n"
9499                                                           "\n";
9500         static const GLchar* fs_tested = "#version 430 core\n"
9501                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9502                                                                          "\n"
9503                                                                          "layout (std140) uniform Block {\n"
9504                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9505                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9506                                                                          "} block;\n"
9507                                                                          "\n"
9508                                                                          "in  vec4 gs_fs;\n"
9509                                                                          "out vec4 fs_out;\n"
9510                                                                          "\n"
9511                                                                          "void main()\n"
9512                                                                          "{\n"
9513                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9514                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9515                                                                          "    {\n"
9516                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9517                                                                          "    }\n"
9518                                                                          "\n"
9519                                                                          "    fs_out += gs_fs;\n"
9520                                                                          "}\n"
9521                                                                          "\n";
9522         static const GLchar* gs = "#version 430 core\n"
9523                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9524                                                           "\n"
9525                                                           "layout(points)                           in;\n"
9526                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9527                                                           "\n"
9528                                                           "in  vec4 tes_gs[];\n"
9529                                                           "out vec4 gs_fs;\n"
9530                                                           "\n"
9531                                                           "void main()\n"
9532                                                           "{\n"
9533                                                           "    gs_fs = tes_gs[0];\n"
9534                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9535                                                           "    EmitVertex();\n"
9536                                                           "    gs_fs = tes_gs[0];\n"
9537                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9538                                                           "    EmitVertex();\n"
9539                                                           "    gs_fs = tes_gs[0];\n"
9540                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9541                                                           "    EmitVertex();\n"
9542                                                           "    gs_fs = tes_gs[0];\n"
9543                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9544                                                           "    EmitVertex();\n"
9545                                                           "}\n"
9546                                                           "\n";
9547         static const GLchar* gs_tested = "#version 430 core\n"
9548                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9549                                                                          "\n"
9550                                                                          "layout(points)                           in;\n"
9551                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9552                                                                          "\n"
9553                                                                          "layout (std140) uniform Block {\n"
9554                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9555                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9556                                                                          "} block;\n"
9557                                                                          "\n"
9558                                                                          "in  vec4 tes_gs[];\n"
9559                                                                          "out vec4 gs_fs;\n"
9560                                                                          "\n"
9561                                                                          "void main()\n"
9562                                                                          "{\n"
9563                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9564                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9565                                                                          "    {\n"
9566                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9567                                                                          "    }\n"
9568                                                                          "\n"
9569                                                                          "    gs_fs += tes_gs[0];\n"
9570                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9571                                                                          "    EmitVertex();\n"
9572                                                                          "    gs_fs += tes_gs[0];\n"
9573                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9574                                                                          "    EmitVertex();\n"
9575                                                                          "    gs_fs += tes_gs[0];\n"
9576                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9577                                                                          "    EmitVertex();\n"
9578                                                                          "    gs_fs += tes_gs[0];\n"
9579                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9580                                                                          "    EmitVertex();\n"
9581                                                                          "}\n"
9582                                                                          "\n";
9583         static const GLchar* tcs = "#version 430 core\n"
9584                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9585                                                            "\n"
9586                                                            "layout(vertices = 1) out;\n"
9587                                                            "\n"
9588                                                            "in  vec4 vs_tcs[];\n"
9589                                                            "out vec4 tcs_tes[];\n"
9590                                                            "\n"
9591                                                            "void main()\n"
9592                                                            "{\n"
9593                                                            "\n"
9594                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9595                                                            "\n"
9596                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9597                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9598                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9599                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9600                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9601                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9602                                                            "}\n"
9603                                                            "\n";
9604         static const GLchar* tcs_tested = "#version 430 core\n"
9605                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9606                                                                           "\n"
9607                                                                           "layout(vertices = 1) out;\n"
9608                                                                           "\n"
9609                                                                           "layout (std140) uniform Block {\n"
9610                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9611                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9612                                                                           "} block;\n"
9613                                                                           "\n"
9614                                                                           "in  vec4 vs_tcs[];\n"
9615                                                                           "out vec4 tcs_tes[];\n"
9616                                                                           "\n"
9617                                                                           "void main()\n"
9618                                                                           "{\n"
9619                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9620                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9621                                                                           "    {\n"
9622                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9623                                                                           "    }\n"
9624                                                                           "\n"
9625                                                                           "\n"
9626                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9627                                                                           "\n"
9628                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9629                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9630                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9631                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9632                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9633                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9634                                                                           "}\n"
9635                                                                           "\n";
9636         static const GLchar* tes = "#version 430 core\n"
9637                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9638                                                            "\n"
9639                                                            "layout(isolines, point_mode) in;\n"
9640                                                            "\n"
9641                                                            "in  vec4 tcs_tes[];\n"
9642                                                            "out vec4 tes_gs;\n"
9643                                                            "\n"
9644                                                            "void main()\n"
9645                                                            "{\n"
9646                                                            "    tes_gs = tcs_tes[0];\n"
9647                                                            "}\n"
9648                                                            "\n";
9649         static const GLchar* tes_tested = "#version 430 core\n"
9650                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9651                                                                           "\n"
9652                                                                           "layout(isolines, point_mode) in;\n"
9653                                                                           "\n"
9654                                                                           "layout (std140) uniform Block {\n"
9655                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9656                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9657                                                                           "} block;\n"
9658                                                                           "\n"
9659                                                                           "in  vec4 tcs_tes[];\n"
9660                                                                           "out vec4 tes_gs;\n"
9661                                                                           "\n"
9662                                                                           "void main()\n"
9663                                                                           "{\n"
9664                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9665                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9666                                                                           "    {\n"
9667                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9668                                                                           "    }\n"
9669                                                                           "\n"
9670                                                                           "    tes_gs += tcs_tes[0];\n"
9671                                                                           "}\n"
9672                                                                           "\n";
9673         static const GLchar* vs = "#version 430 core\n"
9674                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9675                                                           "\n"
9676                                                           "in  vec4 in_vs;\n"
9677                                                           "out vec4 vs_tcs;\n"
9678                                                           "\n"
9679                                                           "void main()\n"
9680                                                           "{\n"
9681                                                           "    vs_tcs = in_vs;\n"
9682                                                           "}\n"
9683                                                           "\n";
9684         static const GLchar* vs_tested = "#version 430 core\n"
9685                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9686                                                                          "\n"
9687                                                                          "layout (std140) uniform Block {\n"
9688                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9689                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9690                                                                          "} block;\n"
9691                                                                          "\n"
9692                                                                          "in  vec4 in_vs;\n"
9693                                                                          "out vec4 vs_tcs;\n"
9694                                                                          "\n"
9695                                                                          "void main()\n"
9696                                                                          "{\n"
9697                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9698                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9699                                                                          "    {\n"
9700                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9701                                                                          "    }\n"
9702                                                                          "\n"
9703                                                                          "    vs_tcs += in_vs;\n"
9704                                                                          "}\n"
9705                                                                          "\n";
9706
9707         std::string source;
9708         testCase&   test_case = m_test_cases[test_case_index];
9709
9710         if (test_case.m_stage == stage)
9711         {
9712                 GLchar                     buffer[16];
9713                 const GLuint       boy_offset   = test_case.m_boy_offset;
9714                 const Utils::Type& boy_type              = test_case.m_boy_type;
9715                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9716                 const GLuint       man_offset   = test_case.m_man_offset;
9717                 const Utils::Type& man_type              = test_case.m_man_type;
9718                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9719                 size_t                     position              = 0;
9720
9721                 switch (stage)
9722                 {
9723                 case Utils::Shader::COMPUTE:
9724                         source = cs;
9725                         break;
9726                 case Utils::Shader::FRAGMENT:
9727                         source = fs_tested;
9728                         break;
9729                 case Utils::Shader::GEOMETRY:
9730                         source = gs_tested;
9731                         break;
9732                 case Utils::Shader::TESS_CTRL:
9733                         source = tcs_tested;
9734                         break;
9735                 case Utils::Shader::TESS_EVAL:
9736                         source = tes_tested;
9737                         break;
9738                 case Utils::Shader::VERTEX:
9739                         source = vs_tested;
9740                         break;
9741                 default:
9742                         TCU_FAIL("Invalid enum");
9743                 }
9744
9745                 sprintf(buffer, "%d", boy_offset);
9746                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9747                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9748                 sprintf(buffer, "%d", man_offset);
9749                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9750                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9751                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9752                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9753         }
9754         else
9755         {
9756                 switch (stage)
9757                 {
9758                 case Utils::Shader::FRAGMENT:
9759                         source = fs;
9760                         break;
9761                 case Utils::Shader::GEOMETRY:
9762                         source = gs;
9763                         break;
9764                 case Utils::Shader::TESS_CTRL:
9765                         source = tcs;
9766                         break;
9767                 case Utils::Shader::TESS_EVAL:
9768                         source = tes;
9769                         break;
9770                 case Utils::Shader::VERTEX:
9771                         source = vs;
9772                         break;
9773                 default:
9774                         TCU_FAIL("Invalid enum");
9775                 }
9776         }
9777
9778         return source;
9779 }
9780
9781 /** Get description of test case
9782  *
9783  * @param test_case_index Index of test case
9784  *
9785  * @return Type name and offset
9786  **/
9787 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9788 {
9789         std::stringstream stream;
9790         testCase&                 test_case = m_test_cases[test_case_index];
9791
9792         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9793                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9794
9795         return stream.str();
9796 }
9797
9798 /** Get number of test cases
9799  *
9800  * @return Number of test cases
9801  **/
9802 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9803 {
9804         return static_cast<GLuint>(m_test_cases.size());
9805 }
9806
9807 /** Selects if "compute" stage is relevant for test
9808  *
9809  * @param test_case_index Index of test case
9810  *
9811  * @return true when tested stage is compute
9812  **/
9813 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9814 {
9815         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9816 }
9817
9818 /** Checks if stage is supported
9819  *
9820  * @param stage ignored
9821  *
9822  * @return true
9823  **/
9824 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9825 {
9826         return true;
9827 }
9828
9829 /** Prepare all test cases
9830  *
9831  **/
9832 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9833 {
9834         const GLuint n_types = getTypesNumber();
9835         bool             stage_support[Utils::Shader::STAGE_MAX];
9836
9837         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9838         {
9839                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9840         }
9841
9842         for (GLuint i = 0; i < n_types; ++i)
9843         {
9844                 const Utils::Type& boy_type = getType(i);
9845                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9846
9847                 for (GLuint j = 0; j < n_types; ++j)
9848                 {
9849                         const Utils::Type& man_type  = getType(j);
9850                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9851                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9852
9853                         const GLuint boy_offset           = lcm(boy_size, man_size);
9854                         const GLuint man_after_start  = boy_offset + 1;
9855                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9856                         const GLuint man_before_start = boy_offset - man_align;
9857                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9858
9859                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9860                         {
9861                                 if (false == stage_support[stage])
9862                                 {
9863                                         continue;
9864                                 }
9865
9866                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9867                                 {
9868                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9869                                                                                    (Utils::Shader::STAGES)stage };
9870
9871                                         m_test_cases.push_back(test_case);
9872                                 }
9873
9874                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9875                                 {
9876                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9877                                                                                    (Utils::Shader::STAGES)stage };
9878
9879                                         m_test_cases.push_back(test_case);
9880                                 }
9881
9882                                 /* Boy offset, should be fine for both types */
9883                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9884
9885                                 m_test_cases.push_back(test_case);
9886                         }
9887                 }
9888         }
9889 }
9890
9891 /** Find greatest common divisor for a and b
9892  *
9893  * @param a A argument
9894  * @param b B argument
9895  *
9896  * @return Found gcd value
9897  **/
9898 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9899 {
9900         if ((0 != a) && (0 == b))
9901         {
9902                 return a;
9903         }
9904         else
9905         {
9906                 GLuint greater = std::max(a, b);
9907                 GLuint lesser  = std::min(a, b);
9908
9909                 return gcd(lesser, greater % lesser);
9910         }
9911 }
9912
9913 /** Find lowest common multiple for a and b
9914  *
9915  * @param a A argument
9916  * @param b B argument
9917  *
9918  * @return Found gcd value
9919  **/
9920 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9921 {
9922         return (a * b) / gcd(a, b);
9923 }
9924
9925 /** Constructor
9926  *
9927  * @param context Test framework context
9928  **/
9929 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9930         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9931                                            "Test verifies that align qualifier requires value that is a power of 2")
9932 {
9933         /* Nothing to be done here */
9934 }
9935
9936 /** Constructor
9937  *
9938  * @param context Test framework context
9939  * @param name        Test name
9940  * @param description Test description
9941  **/
9942 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9943                                                                                                                                                            const glw::GLchar* name,
9944                                                                                                                                                            const glw::GLchar* description)
9945         : NegativeTestBase(context, name, description)
9946 {
9947         /* Nothing to be done here */
9948 }
9949
9950 /** Source for given test case and stage
9951  *
9952  * @param test_case_index Index of test case
9953  * @param stage           Shader stage
9954  *
9955  * @return Shader source
9956  **/
9957 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
9958 {
9959         static const GLchar* cs = "#version 430 core\n"
9960                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9961                                                           "\n"
9962                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9963                                                           "\n"
9964                                                           "layout (std140) uniform Block {\n"
9965                                                           "    vec4 boy;\n"
9966                                                           "    layout (align = ALIGN) TYPE man;\n"
9967                                                           "} block;\n"
9968                                                           "\n"
9969                                                           "writeonly uniform image2D uni_image;\n"
9970                                                           "\n"
9971                                                           "void main()\n"
9972                                                           "{\n"
9973                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9974                                                           "\n"
9975                                                           "    if (TYPE(0) == block.man)\n"
9976                                                           "    {\n"
9977                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
9978                                                           "    }\n"
9979                                                           "\n"
9980                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9981                                                           "}\n"
9982                                                           "\n";
9983         static const GLchar* fs = "#version 430 core\n"
9984                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9985                                                           "\n"
9986                                                           "in  vec4 gs_fs;\n"
9987                                                           "out vec4 fs_out;\n"
9988                                                           "\n"
9989                                                           "void main()\n"
9990                                                           "{\n"
9991                                                           "    fs_out = gs_fs;\n"
9992                                                           "}\n"
9993                                                           "\n";
9994         static const GLchar* fs_tested = "#version 430 core\n"
9995                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9996                                                                          "\n"
9997                                                                          "layout (std140) uniform Block {\n"
9998                                                                          "    vec4 boy;\n"
9999                                                                          "    layout (align = ALIGN) TYPE man;\n"
10000                                                                          "} block;\n"
10001                                                                          "\n"
10002                                                                          "in  vec4 gs_fs;\n"
10003                                                                          "out vec4 fs_out;\n"
10004                                                                          "\n"
10005                                                                          "void main()\n"
10006                                                                          "{\n"
10007                                                                          "    if (TYPE(0) == block.man)\n"
10008                                                                          "    {\n"
10009                                                                          "        fs_out = block.boy;\n"
10010                                                                          "    }\n"
10011                                                                          "\n"
10012                                                                          "    fs_out += gs_fs;\n"
10013                                                                          "}\n"
10014                                                                          "\n";
10015         static const GLchar* gs = "#version 430 core\n"
10016                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10017                                                           "\n"
10018                                                           "layout(points)                           in;\n"
10019                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10020                                                           "\n"
10021                                                           "in  vec4 tes_gs[];\n"
10022                                                           "out vec4 gs_fs;\n"
10023                                                           "\n"
10024                                                           "void main()\n"
10025                                                           "{\n"
10026                                                           "    gs_fs = tes_gs[0];\n"
10027                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10028                                                           "    EmitVertex();\n"
10029                                                           "    gs_fs = tes_gs[0];\n"
10030                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10031                                                           "    EmitVertex();\n"
10032                                                           "    gs_fs = tes_gs[0];\n"
10033                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10034                                                           "    EmitVertex();\n"
10035                                                           "    gs_fs = tes_gs[0];\n"
10036                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10037                                                           "    EmitVertex();\n"
10038                                                           "}\n"
10039                                                           "\n";
10040         static const GLchar* gs_tested = "#version 430 core\n"
10041                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10042                                                                          "\n"
10043                                                                          "layout(points)                           in;\n"
10044                                                                          "layout(triangle_strip, max_vertices = 4) out;\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 tes_gs[];\n"
10052                                                                          "out vec4 gs_fs;\n"
10053                                                                          "\n"
10054                                                                          "void main()\n"
10055                                                                          "{\n"
10056                                                                          "    if (TYPE(0) == block.man)\n"
10057                                                                          "    {\n"
10058                                                                          "        gs_fs = block.boy;\n"
10059                                                                          "    }\n"
10060                                                                          "\n"
10061                                                                          "    gs_fs += tes_gs[0];\n"
10062                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10063                                                                          "    EmitVertex();\n"
10064                                                                          "    gs_fs += tes_gs[0];\n"
10065                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10066                                                                          "    EmitVertex();\n"
10067                                                                          "    gs_fs += tes_gs[0];\n"
10068                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10069                                                                          "    EmitVertex();\n"
10070                                                                          "    gs_fs += tes_gs[0];\n"
10071                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10072                                                                          "    EmitVertex();\n"
10073                                                                          "}\n"
10074                                                                          "\n";
10075         static const GLchar* tcs = "#version 430 core\n"
10076                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10077                                                            "\n"
10078                                                            "layout(vertices = 1) out;\n"
10079                                                            "\n"
10080                                                            "in  vec4 vs_tcs[];\n"
10081                                                            "out vec4 tcs_tes[];\n"
10082                                                            "\n"
10083                                                            "void main()\n"
10084                                                            "{\n"
10085                                                            "\n"
10086                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10087                                                            "\n"
10088                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10089                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10090                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10091                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10092                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10093                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10094                                                            "}\n"
10095                                                            "\n";
10096         static const GLchar* tcs_tested = "#version 430 core\n"
10097                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10098                                                                           "\n"
10099                                                                           "layout(vertices = 1) out;\n"
10100                                                                           "\n"
10101                                                                           "layout (std140) uniform Block {\n"
10102                                                                           "    vec4 boy;\n"
10103                                                                           "    layout (align = ALIGN) TYPE man;\n"
10104                                                                           "} block;\n"
10105                                                                           "\n"
10106                                                                           "in  vec4 vs_tcs[];\n"
10107                                                                           "out vec4 tcs_tes[];\n"
10108                                                                           "\n"
10109                                                                           "void main()\n"
10110                                                                           "{\n"
10111                                                                           "    if (TYPE(0) == block.man)\n"
10112                                                                           "    {\n"
10113                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10114                                                                           "    }\n"
10115                                                                           "\n"
10116                                                                           "\n"
10117                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10118                                                                           "\n"
10119                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10120                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10121                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10122                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10123                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10124                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10125                                                                           "}\n"
10126                                                                           "\n";
10127         static const GLchar* tes = "#version 430 core\n"
10128                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10129                                                            "\n"
10130                                                            "layout(isolines, point_mode) in;\n"
10131                                                            "\n"
10132                                                            "in  vec4 tcs_tes[];\n"
10133                                                            "out vec4 tes_gs;\n"
10134                                                            "\n"
10135                                                            "void main()\n"
10136                                                            "{\n"
10137                                                            "    tes_gs = tcs_tes[0];\n"
10138                                                            "}\n"
10139                                                            "\n";
10140         static const GLchar* tes_tested = "#version 430 core\n"
10141                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10142                                                                           "\n"
10143                                                                           "layout(isolines, point_mode) in;\n"
10144                                                                           "\n"
10145                                                                           "layout (std140) uniform Block {\n"
10146                                                                           "    vec4 boy;\n"
10147                                                                           "    layout (align = ALIGN) TYPE man;\n"
10148                                                                           "} block;\n"
10149                                                                           "\n"
10150                                                                           "in  vec4 tcs_tes[];\n"
10151                                                                           "out vec4 tes_gs;\n"
10152                                                                           "\n"
10153                                                                           "void main()\n"
10154                                                                           "{\n"
10155                                                                           "    if (TYPE(0) == block.man)\n"
10156                                                                           "    {\n"
10157                                                                           "        tes_gs = block.boy;\n"
10158                                                                           "    }\n"
10159                                                                           "\n"
10160                                                                           "    tes_gs += tcs_tes[0];\n"
10161                                                                           "}\n"
10162                                                                           "\n";
10163         static const GLchar* vs = "#version 430 core\n"
10164                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10165                                                           "\n"
10166                                                           "in  vec4 in_vs;\n"
10167                                                           "out vec4 vs_tcs;\n"
10168                                                           "\n"
10169                                                           "void main()\n"
10170                                                           "{\n"
10171                                                           "    vs_tcs = in_vs;\n"
10172                                                           "}\n"
10173                                                           "\n";
10174         static const GLchar* vs_tested = "#version 430 core\n"
10175                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10176                                                                          "\n"
10177                                                                          "layout (std140) uniform Block {\n"
10178                                                                          "    vec4 boy;\n"
10179                                                                          "    layout (align = ALIGN) TYPE man;\n"
10180                                                                          "} block;\n"
10181                                                                          "\n"
10182                                                                          "in  vec4 in_vs;\n"
10183                                                                          "out vec4 vs_tcs;\n"
10184                                                                          "\n"
10185                                                                          "void main()\n"
10186                                                                          "{\n"
10187                                                                          "    if (TYPE(0) == block.man)\n"
10188                                                                          "    {\n"
10189                                                                          "        vs_tcs = block.boy;\n"
10190                                                                          "    }\n"
10191                                                                          "\n"
10192                                                                          "    vs_tcs += in_vs;\n"
10193                                                                          "}\n"
10194                                                                          "\n";
10195
10196         std::string source;
10197         testCase&   test_case = m_test_cases[test_case_index];
10198
10199         if (test_case.m_stage == stage)
10200         {
10201                 GLchar                     buffer[16];
10202                 const GLuint       alignment = test_case.m_alignment;
10203                 const Utils::Type& type          = test_case.m_type;
10204                 const GLchar*     type_name = type.GetGLSLTypeName();
10205                 size_t                     position  = 0;
10206
10207                 switch (stage)
10208                 {
10209                 case Utils::Shader::COMPUTE:
10210                         source = cs;
10211                         break;
10212                 case Utils::Shader::FRAGMENT:
10213                         source = fs_tested;
10214                         break;
10215                 case Utils::Shader::GEOMETRY:
10216                         source = gs_tested;
10217                         break;
10218                 case Utils::Shader::TESS_CTRL:
10219                         source = tcs_tested;
10220                         break;
10221                 case Utils::Shader::TESS_EVAL:
10222                         source = tes_tested;
10223                         break;
10224                 case Utils::Shader::VERTEX:
10225                         source = vs_tested;
10226                         break;
10227                 default:
10228                         TCU_FAIL("Invalid enum");
10229                 }
10230
10231                 sprintf(buffer, "%d", alignment);
10232                 Utils::replaceToken("ALIGN", position, buffer, source);
10233                 Utils::replaceToken("TYPE", position, type_name, source);
10234                 Utils::replaceToken("TYPE", position, type_name, source);
10235         }
10236         else
10237         {
10238                 switch (stage)
10239                 {
10240                 case Utils::Shader::FRAGMENT:
10241                         source = fs;
10242                         break;
10243                 case Utils::Shader::GEOMETRY:
10244                         source = gs;
10245                         break;
10246                 case Utils::Shader::TESS_CTRL:
10247                         source = tcs;
10248                         break;
10249                 case Utils::Shader::TESS_EVAL:
10250                         source = tes;
10251                         break;
10252                 case Utils::Shader::VERTEX:
10253                         source = vs;
10254                         break;
10255                 default:
10256                         TCU_FAIL("Invalid enum");
10257                 }
10258         }
10259
10260         return source;
10261 }
10262
10263 /** Get description of test case
10264  *
10265  * @param test_case_index Index of test case
10266  *
10267  * @return Type name and offset
10268  **/
10269 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10270 {
10271         std::stringstream stream;
10272         testCase&                 test_case = m_test_cases[test_case_index];
10273
10274         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10275
10276         return stream.str();
10277 }
10278
10279 /** Get number of test cases
10280  *
10281  * @return Number of test cases
10282  **/
10283 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10284 {
10285         return static_cast<GLuint>(m_test_cases.size());
10286 }
10287
10288 /** Selects if "compute" stage is relevant for test
10289  *
10290  * @param test_case_index Index of test case
10291  *
10292  * @return true when tested stage is compute
10293  **/
10294 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10295 {
10296         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10297 }
10298
10299 /** Checks if stage is supported
10300  *
10301  * @param ignored
10302  *
10303  * @return true
10304  **/
10305 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10306 {
10307         return true;
10308 }
10309
10310 /** Selects if compilation failure is expected result
10311  *
10312  * @param test_case_index Index of test case
10313  *
10314  * @return should_fail field from testCase
10315  **/
10316 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10317 {
10318         return m_test_cases[test_case_index].m_should_fail;
10319 }
10320
10321 /** Prepare all test cases
10322  *
10323  **/
10324 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10325 {
10326         static const GLuint dmat4_size = 128;
10327         const GLuint            n_types = getTypesNumber();
10328         bool                            stage_support[Utils::Shader::STAGE_MAX];
10329
10330         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10331         {
10332                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10333         }
10334
10335         for (GLuint j = 0; j < n_types; ++j)
10336         {
10337                 const Utils::Type& type = getType(j);
10338
10339                 for (GLuint align = 0; align <= dmat4_size; ++align)
10340                 {
10341
10342 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10343
10344                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10345
10346 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10347
10348                         const bool should_fail = !isPowerOf2(align);
10349
10350 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10351
10352                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10353                         {
10354                                 if (false == stage_support[stage])
10355                                 {
10356                                         continue;
10357                                 }
10358
10359                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10360
10361                                 m_test_cases.push_back(test_case);
10362                         }
10363                 }
10364         }
10365 }
10366
10367 /** Check if value is power of 2
10368  *
10369  * @param val Tested value
10370  *
10371  * @return true if val is power of 2, false otherwise
10372  **/
10373 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10374 {
10375         if (0 == val)
10376         {
10377                 return false;
10378         }
10379
10380         return (0 == (val & (val - 1)));
10381 }
10382
10383 /** Constructor
10384  *
10385  * @param context Test framework context
10386  **/
10387 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10388         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10389 {
10390 }
10391
10392 /** Get interface of program
10393  *
10394  * @param ignored
10395  * @param program_interface Interface of program
10396  * @param varying_passthrough Collection of connections between in and out variables
10397  **/
10398 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10399                                                                                                         Utils::ProgramInterface&   program_interface,
10400                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10401 {
10402         static const Utils::Type vec4 = Utils::Type::vec4;
10403
10404 #if WRKARD_UNIFORMBLOCKALIGNMENT
10405
10406         static const GLuint block_align = 16;
10407
10408 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10409
10410         static const GLuint block_align = 64;
10411
10412 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10413
10414         static const GLuint vec4_stride = 16;
10415         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10416
10417         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10418          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10419          */
10420         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10421         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10422         const GLuint third_offset =
10423                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10424         const GLuint fourth_offset =
10425                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10426         const GLuint fifth_offset =
10427                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10428         const GLuint sixth_offset =
10429                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10430
10431         Utils::Interface* structure = program_interface.Structure("Data");
10432
10433         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10434                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10435
10436         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10437                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10438                                           Utils::Type::vec4.GetSize() /* offset */);
10439
10440         /* Prepare Block */
10441         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10442
10443         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10444                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10445
10446         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10447                                                  0 /* n_array_elements */, data_stride, second_offset);
10448
10449         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10450                                                  2 /* n_array_elements */, data_stride, third_offset);
10451
10452         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10453                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10454
10455         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10456                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10457
10458         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10459                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10460
10461         const GLuint stride = calculateStride(*vs_uni_block);
10462         m_data.resize(stride);
10463         generateData(*vs_uni_block, 0, m_data);
10464
10465         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10466
10467 /* Add uniform BLOCK */
10468 #if WRKARD_UNIFORMBLOCKALIGNMENT
10469         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10470                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10471 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10472         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10473                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10474 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10475
10476         program_interface.CloneVertexInterface(varying_passthrough);
10477 }
10478
10479 /** Constructor
10480  *
10481  * @param context Test framework context
10482  **/
10483 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10484         : TextureTestBase(context, "ssb_member_offset_and_align",
10485                                           "Test verifies offsets and alignment of storage buffer members")
10486 {
10487 }
10488
10489 /** Get interface of program
10490  *
10491  * @param test_case_index     Test case index
10492  * @param program_interface   Interface of program
10493  * @param varying_passthrough Collection of connections between in and out variables
10494  **/
10495 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10496                                                                                                           Utils::ProgramInterface&   program_interface,
10497                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10498 {
10499         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10500                                                   "const int type_align = TYPE_ALIGN;\n"
10501                                                   "const int type_size  = TYPE_SIZE;\n";
10502
10503         Utils::Type  type                = getType(test_case_index);
10504         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10505         const GLuint base_align  = type.GetBaseAlignment(false);
10506         const GLuint array_align = type.GetBaseAlignment(true);
10507         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10508         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10509
10510         /* Calculate offsets */
10511         const GLuint first_offset  = 0;
10512         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10513
10514 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10515
10516         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10517         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10518         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10519         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10520         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10521         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10522
10523 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10524
10525         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10526         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
10527         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10528         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10529         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10530         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
10531
10532 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10533
10534         /* Prepare data */
10535         const std::vector<GLubyte>& first  = type.GenerateData();
10536         const std::vector<GLubyte>& second = type.GenerateData();
10537         const std::vector<GLubyte>& third  = type.GenerateData();
10538         const std::vector<GLubyte>& fourth = type.GenerateData();
10539
10540         m_data.resize(eigth_offset + base_stride);
10541         GLubyte* ptr = &m_data[0];
10542         memcpy(ptr + first_offset, &first[0], first.size());
10543         memcpy(ptr + second_offset, &second[0], second.size());
10544         memcpy(ptr + third_offset, &third[0], third.size());
10545         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10546         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10547         memcpy(ptr + sixth_offset, &third[0], third.size());
10548         memcpy(ptr + seventh_offset, &second[0], second.size());
10549         memcpy(ptr + eigth_offset, &first[0], first.size());
10550
10551         /* Prepare globals */
10552         size_t position = 0;
10553         GLchar buffer[16];
10554
10555         sprintf(buffer, "%d", basic_size);
10556         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10557
10558         sprintf(buffer, "%d", type_align);
10559         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10560
10561         sprintf(buffer, "%d", base_stride);
10562         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10563
10564         /* Prepare Block */
10565         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10566
10567         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10568                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10569                                                  first_offset);
10570
10571         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10572                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10573                                                  0 /* n_array_elements */, base_stride, second_offset);
10574
10575         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10576                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10577                                                  third_offset);
10578
10579         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10580                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10581                                                  fourth_offset);
10582
10583         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10584                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10585
10586         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10587                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10588
10589         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10590                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10591                                                  eigth_offset);
10592
10593         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10594
10595         /* Add globals */
10596         vs_si.m_globals = globals;
10597
10598         /* Add uniform BLOCK */
10599         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10600                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10601
10602         /* */
10603         program_interface.CloneVertexInterface(varying_passthrough);
10604 }
10605
10606 /** Get type name
10607  *
10608  * @param test_case_index Index of test case
10609  *
10610  * @return Name of type test in test_case_index
10611  **/
10612 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10613 {
10614         return getTypeName(test_case_index);
10615 }
10616
10617 /** Returns number of types to test
10618  *
10619  * @return Number of types, 34
10620  **/
10621 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10622 {
10623         return getTypesNumber();
10624 }
10625
10626 /** Prepare code snippet that will verify in and uniform variables
10627  *
10628  * @param ignored
10629  * @param ignored
10630  * @param stage   Shader stage
10631  *
10632  * @return Code that verify variables
10633  **/
10634 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10635                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10636                                                                                                                                 Utils::Shader::STAGES stage)
10637 {
10638         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10639                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10640                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10641                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10642                                                            "    {\n"
10643                                                            "        result = 0;\n"
10644                                                            "    }";
10645
10646         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10647
10648         Utils::replaceAllTokens("PREFIX", prefix, verification);
10649
10650         return verification;
10651 }
10652
10653 /** Selects if "draw" stages are relevant for test
10654  *
10655  * @param ignored
10656  *
10657  * @return true if all stages support shader storage buffers, false otherwise
10658  **/
10659 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10660 {
10661         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10662         GLint                    gs_supported_buffers  = 0;
10663         GLint                    tcs_supported_buffers = 0;
10664         GLint                    tes_supported_buffers = 0;
10665         GLint                    vs_supported_buffers  = 0;
10666
10667         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10668         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10669         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10670         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10671
10672         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10673
10674         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10675                         (1 <= vs_supported_buffers));
10676 }
10677
10678 /** Constructor
10679  *
10680  * @param context Test framework context
10681  **/
10682 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10683         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10684                                                                                                                                  "offset and/or align qualifiers are used with storage "
10685                                                                                                                                  "block")
10686 {
10687         /* Nothing to be done here */
10688 }
10689
10690 /** Source for given test case and stage
10691  *
10692  * @param test_case_index Index of test case
10693  * @param stage           Shader stage
10694  *
10695  * @return Shader source
10696  **/
10697 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10698 {
10699         static const GLchar* cs = "#version 430 core\n"
10700                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10701                                                           "\n"
10702                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10703                                                           "\n"
10704                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10705                                                           "    layout(offset = 16) vec4 boy;\n"
10706                                                           "    layout(align  = 64) vec4 man;\n"
10707                                                           "} uni_block;\n"
10708                                                           "\n"
10709                                                           "writeonly uniform image2D uni_image;\n"
10710                                                           "\n"
10711                                                           "void main()\n"
10712                                                           "{\n"
10713                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10714                                                           "\n"
10715                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10716                                                           "}\n"
10717                                                           "\n";
10718         static const GLchar* fs = "#version 430 core\n"
10719                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10720                                                           "\n"
10721                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10722                                                           "    layout(offset = 16) vec4 boy;\n"
10723                                                           "    layout(align  = 64) vec4 man;\n"
10724                                                           "} uni_block;\n"
10725                                                           "\n"
10726                                                           "in  vec4 gs_fs;\n"
10727                                                           "out vec4 fs_out;\n"
10728                                                           "\n"
10729                                                           "void main()\n"
10730                                                           "{\n"
10731                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10732                                                           "}\n"
10733                                                           "\n";
10734         static const GLchar* gs = "#version 430 core\n"
10735                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10736                                                           "\n"
10737                                                           "layout(points)                           in;\n"
10738                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10739                                                           "\n"
10740                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10741                                                           "    layout(offset = 16) vec4 boy;\n"
10742                                                           "    layout(align  = 64) vec4 man;\n"
10743                                                           "} uni_block;\n"
10744                                                           "\n"
10745                                                           "in  vec4 tes_gs[];\n"
10746                                                           "out vec4 gs_fs;\n"
10747                                                           "\n"
10748                                                           "void main()\n"
10749                                                           "{\n"
10750                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10751                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10752                                                           "    EmitVertex();\n"
10753                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10754                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10755                                                           "    EmitVertex();\n"
10756                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10757                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10758                                                           "    EmitVertex();\n"
10759                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10760                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10761                                                           "    EmitVertex();\n"
10762                                                           "}\n"
10763                                                           "\n";
10764         static const GLchar* tcs =
10765                 "#version 430 core\n"
10766                 "#extension GL_ARB_enhanced_layouts : require\n"
10767                 "\n"
10768                 "layout(vertices = 1) out;\n"
10769                 "\n"
10770                 "layout (QUALIFIERbinding = BINDING) buffer tcs_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 vs_tcs[];\n"
10776                 "out vec4 tcs_tes[];\n"
10777                 "\n"
10778                 "void main()\n"
10779                 "{\n"
10780                 "\n"
10781                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10782                 "\n"
10783                 "    gl_TessLevelOuter[0] = 1.0;\n"
10784                 "    gl_TessLevelOuter[1] = 1.0;\n"
10785                 "    gl_TessLevelOuter[2] = 1.0;\n"
10786                 "    gl_TessLevelOuter[3] = 1.0;\n"
10787                 "    gl_TessLevelInner[0] = 1.0;\n"
10788                 "    gl_TessLevelInner[1] = 1.0;\n"
10789                 "}\n"
10790                 "\n";
10791         static const GLchar* tes = "#version 430 core\n"
10792                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10793                                                            "\n"
10794                                                            "layout(isolines, point_mode) in;\n"
10795                                                            "\n"
10796                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10797                                                            "    layout(offset = 16) vec4 boy;\n"
10798                                                            "    layout(align  = 64) vec4 man;\n"
10799                                                            "} uni_block;\n"
10800                                                            "\n"
10801                                                            "in  vec4 tcs_tes[];\n"
10802                                                            "out vec4 tes_gs;\n"
10803                                                            "\n"
10804                                                            "void main()\n"
10805                                                            "{\n"
10806                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10807                                                            "}\n"
10808                                                            "\n";
10809         static const GLchar* vs = "#version 430 core\n"
10810                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10811                                                           "\n"
10812                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_Block {\n"
10813                                                           "    layout(offset = 16) vec4 boy;\n"
10814                                                           "    layout(align  = 64) vec4 man;\n"
10815                                                           "} uni_block;\n"
10816                                                           "\n"
10817                                                           "in  vec4 in_vs;\n"
10818                                                           "out vec4 vs_tcs;\n"
10819                                                           "\n"
10820                                                           "void main()\n"
10821                                                           "{\n"
10822                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10823                                                           "}\n"
10824                                                           "\n";
10825
10826         GLchar          buffer[16];
10827         size_t          position = 0;
10828         std::string source;
10829         testCase&   test_case = m_test_cases[test_case_index];
10830         std::string qualifier = getQualifierName(test_case.m_qualifier);
10831
10832         if (false == qualifier.empty())
10833         {
10834                 qualifier.append(", ");
10835         }
10836
10837         sprintf(buffer, "%d", stage);
10838
10839         switch (stage)
10840         {
10841         case Utils::Shader::COMPUTE:
10842                 source = cs;
10843                 break;
10844         case Utils::Shader::FRAGMENT:
10845                 source = fs;
10846                 break;
10847         case Utils::Shader::GEOMETRY:
10848                 source = gs;
10849                 break;
10850         case Utils::Shader::TESS_CTRL:
10851                 source = tcs;
10852                 break;
10853         case Utils::Shader::TESS_EVAL:
10854                 source = tes;
10855                 break;
10856         case Utils::Shader::VERTEX:
10857                 source = vs;
10858                 break;
10859         default:
10860                 TCU_FAIL("Invalid enum");
10861         }
10862
10863         if (test_case.m_stage == stage)
10864         {
10865                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10866         }
10867         else
10868         {
10869                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10870         }
10871
10872         Utils::replaceToken("BINDING", position, buffer, source);
10873
10874         return source;
10875 }
10876
10877 /** Get description of test case
10878  *
10879  * @param test_case_index Index of test case
10880  *
10881  * @return Qualifier name
10882  **/
10883 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10884 {
10885         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10886
10887         return result;
10888 }
10889
10890 /** Get number of test cases
10891  *
10892  * @return Number of test cases
10893  **/
10894 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10895 {
10896         return static_cast<GLuint>(m_test_cases.size());
10897 }
10898
10899 /** Selects if "compute" stage is relevant for test
10900  *
10901  * @param test_case_index Index of test case
10902  *
10903  * @return true when tested stage is compute
10904  **/
10905 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10906 {
10907         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10908 }
10909
10910 /** Selects if compilation failure is expected result
10911  *
10912  * @param test_case_index Index of test case
10913  *
10914  * @return false for STD140 and STD430 cases, true otherwise
10915  **/
10916 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10917 {
10918         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10919
10920         return !((STD140 == qualifier) || (STD430 == qualifier));
10921 }
10922
10923 /** Checks if stage is supported
10924  *
10925  * @param stage Shader stage
10926  *
10927  * @return true if supported, false otherwise
10928  **/
10929 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10930 {
10931         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10932         GLint                    max_supported_buffers = 0;
10933         GLenum                   pname                             = 0;
10934
10935         switch (stage)
10936         {
10937         case Utils::Shader::COMPUTE:
10938                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10939                 break;
10940         case Utils::Shader::FRAGMENT:
10941                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10942                 break;
10943         case Utils::Shader::GEOMETRY:
10944                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10945                 break;
10946         case Utils::Shader::TESS_CTRL:
10947                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10948                 break;
10949         case Utils::Shader::TESS_EVAL:
10950                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
10951                 break;
10952         case Utils::Shader::VERTEX:
10953                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
10954                 break;
10955         default:
10956                 TCU_FAIL("Invalid enum");
10957         }
10958
10959         gl.getIntegerv(pname, &max_supported_buffers);
10960         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10961
10962         return 1 <= max_supported_buffers;
10963 }
10964
10965 /** Prepare all test cases
10966  *
10967  **/
10968 void SSBLayoutQualifierConflictTest::testInit()
10969 {
10970         bool stage_support[Utils::Shader::STAGE_MAX];
10971
10972         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10973         {
10974                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10975         }
10976
10977         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
10978         {
10979                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10980                 {
10981                         if (false == stage_support[stage])
10982                         {
10983                                 continue;
10984                         }
10985
10986                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
10987
10988                         m_test_cases.push_back(test_case);
10989                 }
10990         }
10991 }
10992
10993 /** Get name of glsl constant
10994  *
10995  * @param Constant id
10996  *
10997  * @return Name of constant used in GLSL
10998  **/
10999 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
11000 {
11001         const GLchar* name = "";
11002
11003         switch (qualifier)
11004         {
11005         case DEFAULT:
11006                 name = "";
11007                 break;
11008         case STD140:
11009                 name = "std140";
11010                 break;
11011         case STD430:
11012                 name = "std430";
11013                 break;
11014         case SHARED:
11015                 name = "shared";
11016                 break;
11017         case PACKED:
11018                 name = "packed";
11019                 break;
11020         default:
11021                 TCU_FAIL("Invalid enum");
11022         }
11023
11024         return name;
11025 }
11026
11027 /** Constructor
11028  *
11029  * @param context Test framework context
11030  **/
11031 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
11032         : UniformBlockMemberInvalidOffsetAlignmentTest(
11033                   context, "ssb_member_invalid_offset_alignment",
11034                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
11035 {
11036         /* Nothing to be done here */
11037 }
11038
11039 /** Get the maximum size for a shader storage block
11040  *
11041  * @return The maximum size in basic machine units of a shader storage block.
11042  **/
11043 GLint SSBMemberInvalidOffsetAlignmentTest::getMaxBlockSize()
11044 {
11045         const Functions& gl               = m_context.getRenderContext().getFunctions();
11046         GLint                    max_size = 0;
11047
11048         gl.getIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_size);
11049         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11050
11051         return max_size;
11052 }
11053
11054 /** Source for given test case and stage
11055  *
11056  * @param test_case_index Index of test case
11057  * @param stage           Shader stage
11058  *
11059  * @return Shader source
11060  **/
11061 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11062 {
11063         static const GLchar* cs = "#version 430 core\n"
11064                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11065                                                           "\n"
11066                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11067                                                           "\n"
11068                                                           "layout (std140) buffer Block {\n"
11069                                                           "    layout (offset = OFFSET) TYPE member;\n"
11070                                                           "} block;\n"
11071                                                           "\n"
11072                                                           "writeonly uniform image2D uni_image;\n"
11073                                                           "\n"
11074                                                           "void main()\n"
11075                                                           "{\n"
11076                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11077                                                           "\n"
11078                                                           "    if (TYPE(1) == block.member)\n"
11079                                                           "    {\n"
11080                                                           "        result = vec4(1, 1, 1, 1);\n"
11081                                                           "    }\n"
11082                                                           "\n"
11083                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11084                                                           "}\n"
11085                                                           "\n";
11086         static const GLchar* fs = "#version 430 core\n"
11087                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11088                                                           "\n"
11089                                                           "in  vec4 gs_fs;\n"
11090                                                           "out vec4 fs_out;\n"
11091                                                           "\n"
11092                                                           "void main()\n"
11093                                                           "{\n"
11094                                                           "    fs_out = gs_fs;\n"
11095                                                           "}\n"
11096                                                           "\n";
11097         static const GLchar* fs_tested = "#version 430 core\n"
11098                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11099                                                                          "\n"
11100                                                                          "layout (std140) buffer Block {\n"
11101                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11102                                                                          "} block;\n"
11103                                                                          "\n"
11104                                                                          "in  vec4 gs_fs;\n"
11105                                                                          "out vec4 fs_out;\n"
11106                                                                          "\n"
11107                                                                          "void main()\n"
11108                                                                          "{\n"
11109                                                                          "    if (TYPE(1) == block.member)\n"
11110                                                                          "    {\n"
11111                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11112                                                                          "    }\n"
11113                                                                          "\n"
11114                                                                          "    fs_out += gs_fs;\n"
11115                                                                          "}\n"
11116                                                                          "\n";
11117         static const GLchar* gs = "#version 430 core\n"
11118                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11119                                                           "\n"
11120                                                           "layout(points)                           in;\n"
11121                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11122                                                           "\n"
11123                                                           "in  vec4 tes_gs[];\n"
11124                                                           "out vec4 gs_fs;\n"
11125                                                           "\n"
11126                                                           "void main()\n"
11127                                                           "{\n"
11128                                                           "    gs_fs = tes_gs[0];\n"
11129                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11130                                                           "    EmitVertex();\n"
11131                                                           "    gs_fs = tes_gs[0];\n"
11132                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11133                                                           "    EmitVertex();\n"
11134                                                           "    gs_fs = tes_gs[0];\n"
11135                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11136                                                           "    EmitVertex();\n"
11137                                                           "    gs_fs = tes_gs[0];\n"
11138                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11139                                                           "    EmitVertex();\n"
11140                                                           "}\n"
11141                                                           "\n";
11142         static const GLchar* gs_tested = "#version 430 core\n"
11143                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11144                                                                          "\n"
11145                                                                          "layout(points)                           in;\n"
11146                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11147                                                                          "\n"
11148                                                                          "layout (std140) buffer Block {\n"
11149                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11150                                                                          "} block;\n"
11151                                                                          "\n"
11152                                                                          "in  vec4 tes_gs[];\n"
11153                                                                          "out vec4 gs_fs;\n"
11154                                                                          "\n"
11155                                                                          "void main()\n"
11156                                                                          "{\n"
11157                                                                          "    if (TYPE(1) == block.member)\n"
11158                                                                          "    {\n"
11159                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11160                                                                          "    }\n"
11161                                                                          "\n"
11162                                                                          "    gs_fs += tes_gs[0];\n"
11163                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11164                                                                          "    EmitVertex();\n"
11165                                                                          "    gs_fs += tes_gs[0];\n"
11166                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11167                                                                          "    EmitVertex();\n"
11168                                                                          "    gs_fs += tes_gs[0];\n"
11169                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11170                                                                          "    EmitVertex();\n"
11171                                                                          "    gs_fs += tes_gs[0];\n"
11172                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11173                                                                          "    EmitVertex();\n"
11174                                                                          "}\n"
11175                                                                          "\n";
11176         static const GLchar* tcs = "#version 430 core\n"
11177                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11178                                                            "\n"
11179                                                            "layout(vertices = 1) out;\n"
11180                                                            "\n"
11181                                                            "in  vec4 vs_tcs[];\n"
11182                                                            "out vec4 tcs_tes[];\n"
11183                                                            "\n"
11184                                                            "void main()\n"
11185                                                            "{\n"
11186                                                            "\n"
11187                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11188                                                            "\n"
11189                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11190                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11191                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11192                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11193                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11194                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11195                                                            "}\n"
11196                                                            "\n";
11197         static const GLchar* tcs_tested = "#version 430 core\n"
11198                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11199                                                                           "\n"
11200                                                                           "layout(vertices = 1) out;\n"
11201                                                                           "\n"
11202                                                                           "layout (std140) buffer Block {\n"
11203                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11204                                                                           "} block;\n"
11205                                                                           "\n"
11206                                                                           "in  vec4 vs_tcs[];\n"
11207                                                                           "out vec4 tcs_tes[];\n"
11208                                                                           "\n"
11209                                                                           "void main()\n"
11210                                                                           "{\n"
11211                                                                           "    if (TYPE(1) == block.member)\n"
11212                                                                           "    {\n"
11213                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11214                                                                           "    }\n"
11215                                                                           "\n"
11216                                                                           "\n"
11217                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11218                                                                           "\n"
11219                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11220                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11221                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11222                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11223                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11224                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11225                                                                           "}\n"
11226                                                                           "\n";
11227         static const GLchar* tes = "#version 430 core\n"
11228                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11229                                                            "\n"
11230                                                            "layout(isolines, point_mode) in;\n"
11231                                                            "\n"
11232                                                            "in  vec4 tcs_tes[];\n"
11233                                                            "out vec4 tes_gs;\n"
11234                                                            "\n"
11235                                                            "void main()\n"
11236                                                            "{\n"
11237                                                            "    tes_gs = tcs_tes[0];\n"
11238                                                            "}\n"
11239                                                            "\n";
11240         static const GLchar* tes_tested = "#version 430 core\n"
11241                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11242                                                                           "\n"
11243                                                                           "layout(isolines, point_mode) in;\n"
11244                                                                           "\n"
11245                                                                           "layout (std140) buffer Block {\n"
11246                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11247                                                                           "} block;\n"
11248                                                                           "\n"
11249                                                                           "in  vec4 tcs_tes[];\n"
11250                                                                           "out vec4 tes_gs;\n"
11251                                                                           "\n"
11252                                                                           "void main()\n"
11253                                                                           "{\n"
11254                                                                           "    if (TYPE(1) == block.member)\n"
11255                                                                           "    {\n"
11256                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11257                                                                           "    }\n"
11258                                                                           "\n"
11259                                                                           "    tes_gs += tcs_tes[0];\n"
11260                                                                           "}\n"
11261                                                                           "\n";
11262         static const GLchar* vs = "#version 430 core\n"
11263                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11264                                                           "\n"
11265                                                           "in  vec4 in_vs;\n"
11266                                                           "out vec4 vs_tcs;\n"
11267                                                           "\n"
11268                                                           "void main()\n"
11269                                                           "{\n"
11270                                                           "    vs_tcs = in_vs;\n"
11271                                                           "}\n"
11272                                                           "\n";
11273         static const GLchar* vs_tested = "#version 430 core\n"
11274                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11275                                                                          "\n"
11276                                                                          "layout (std140) buffer Block {\n"
11277                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11278                                                                          "} block;\n"
11279                                                                          "\n"
11280                                                                          "in  vec4 in_vs;\n"
11281                                                                          "out vec4 vs_tcs;\n"
11282                                                                          "\n"
11283                                                                          "void main()\n"
11284                                                                          "{\n"
11285                                                                          "    if (TYPE(1) == block.member)\n"
11286                                                                          "    {\n"
11287                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11288                                                                          "    }\n"
11289                                                                          "\n"
11290                                                                          "    vs_tcs += in_vs;\n"
11291                                                                          "}\n"
11292                                                                          "\n";
11293
11294         std::string source;
11295         testCase&   test_case = m_test_cases[test_case_index];
11296
11297         if (test_case.m_stage == stage)
11298         {
11299                 GLchar                     buffer[16];
11300                 const GLuint       offset       = test_case.m_offset;
11301                 size_t                     position  = 0;
11302                 const Utils::Type& type          = test_case.m_type;
11303                 const GLchar*     type_name = type.GetGLSLTypeName();
11304
11305                 sprintf(buffer, "%d", offset);
11306
11307                 switch (stage)
11308                 {
11309                 case Utils::Shader::COMPUTE:
11310                         source = cs;
11311                         break;
11312                 case Utils::Shader::FRAGMENT:
11313                         source = fs_tested;
11314                         break;
11315                 case Utils::Shader::GEOMETRY:
11316                         source = gs_tested;
11317                         break;
11318                 case Utils::Shader::TESS_CTRL:
11319                         source = tcs_tested;
11320                         break;
11321                 case Utils::Shader::TESS_EVAL:
11322                         source = tes_tested;
11323                         break;
11324                 case Utils::Shader::VERTEX:
11325                         source = vs_tested;
11326                         break;
11327                 default:
11328                         TCU_FAIL("Invalid enum");
11329                 }
11330
11331                 Utils::replaceToken("OFFSET", position, buffer, source);
11332                 Utils::replaceToken("TYPE", position, type_name, source);
11333                 Utils::replaceToken("TYPE", position, type_name, source);
11334         }
11335         else
11336         {
11337                 switch (stage)
11338                 {
11339                 case Utils::Shader::FRAGMENT:
11340                         source = fs;
11341                         break;
11342                 case Utils::Shader::GEOMETRY:
11343                         source = gs;
11344                         break;
11345                 case Utils::Shader::TESS_CTRL:
11346                         source = tcs;
11347                         break;
11348                 case Utils::Shader::TESS_EVAL:
11349                         source = tes;
11350                         break;
11351                 case Utils::Shader::VERTEX:
11352                         source = vs;
11353                         break;
11354                 default:
11355                         TCU_FAIL("Invalid enum");
11356                 }
11357         }
11358
11359         return source;
11360 }
11361
11362 /** Checks if stage is supported
11363  *
11364  * @param stage Shader stage
11365  *
11366  * @return true if supported, false otherwise
11367  **/
11368 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11369 {
11370         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11371         GLint                    max_supported_buffers = 0;
11372         GLenum                   pname                             = 0;
11373
11374         switch (stage)
11375         {
11376         case Utils::Shader::COMPUTE:
11377                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11378                 break;
11379         case Utils::Shader::FRAGMENT:
11380                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11381                 break;
11382         case Utils::Shader::GEOMETRY:
11383                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11384                 break;
11385         case Utils::Shader::TESS_CTRL:
11386                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11387                 break;
11388         case Utils::Shader::TESS_EVAL:
11389                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11390                 break;
11391         case Utils::Shader::VERTEX:
11392                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11393                 break;
11394         default:
11395                 TCU_FAIL("Invalid enum");
11396         }
11397
11398         gl.getIntegerv(pname, &max_supported_buffers);
11399         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11400
11401         return 1 <= max_supported_buffers;
11402 }
11403
11404 /** Constructor
11405  *
11406  * @param context Test framework context
11407  **/
11408 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11409         : UniformBlockMemberOverlappingOffsetsTest(
11410                   context, "ssb_member_overlapping_offsets",
11411                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11412 {
11413         /* Nothing to be done here */
11414 }
11415
11416 /** Source for given test case and stage
11417  *
11418  * @param test_case_index Index of test case
11419  * @param stage           Shader stage
11420  *
11421  * @return Shader source
11422  **/
11423 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11424 {
11425         static const GLchar* cs = "#version 430 core\n"
11426                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11427                                                           "\n"
11428                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11429                                                           "\n"
11430                                                           "layout (std140) buffer Block {\n"
11431                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11432                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11433                                                           "} block;\n"
11434                                                           "\n"
11435                                                           "writeonly uniform image2D uni_image;\n"
11436                                                           "\n"
11437                                                           "void main()\n"
11438                                                           "{\n"
11439                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11440                                                           "\n"
11441                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11442                                                           "        (MAN_TYPE(0) == block.man) )\n"
11443                                                           "    {\n"
11444                                                           "        result = vec4(1, 1, 1, 1);\n"
11445                                                           "    }\n"
11446                                                           "\n"
11447                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11448                                                           "}\n"
11449                                                           "\n";
11450         static const GLchar* fs = "#version 430 core\n"
11451                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11452                                                           "\n"
11453                                                           "in  vec4 gs_fs;\n"
11454                                                           "out vec4 fs_out;\n"
11455                                                           "\n"
11456                                                           "void main()\n"
11457                                                           "{\n"
11458                                                           "    fs_out = gs_fs;\n"
11459                                                           "}\n"
11460                                                           "\n";
11461         static const GLchar* fs_tested = "#version 430 core\n"
11462                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11463                                                                          "\n"
11464                                                                          "layout (std140) buffer Block {\n"
11465                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11466                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11467                                                                          "} block;\n"
11468                                                                          "\n"
11469                                                                          "in  vec4 gs_fs;\n"
11470                                                                          "out vec4 fs_out;\n"
11471                                                                          "\n"
11472                                                                          "void main()\n"
11473                                                                          "{\n"
11474                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11475                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11476                                                                          "    {\n"
11477                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11478                                                                          "    }\n"
11479                                                                          "\n"
11480                                                                          "    fs_out += gs_fs;\n"
11481                                                                          "}\n"
11482                                                                          "\n";
11483         static const GLchar* gs = "#version 430 core\n"
11484                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11485                                                           "\n"
11486                                                           "layout(points)                           in;\n"
11487                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11488                                                           "\n"
11489                                                           "in  vec4 tes_gs[];\n"
11490                                                           "out vec4 gs_fs;\n"
11491                                                           "\n"
11492                                                           "void main()\n"
11493                                                           "{\n"
11494                                                           "    gs_fs = tes_gs[0];\n"
11495                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11496                                                           "    EmitVertex();\n"
11497                                                           "    gs_fs = tes_gs[0];\n"
11498                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11499                                                           "    EmitVertex();\n"
11500                                                           "    gs_fs = tes_gs[0];\n"
11501                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11502                                                           "    EmitVertex();\n"
11503                                                           "    gs_fs = tes_gs[0];\n"
11504                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11505                                                           "    EmitVertex();\n"
11506                                                           "}\n"
11507                                                           "\n";
11508         static const GLchar* gs_tested = "#version 430 core\n"
11509                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11510                                                                          "\n"
11511                                                                          "layout(points)                           in;\n"
11512                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11513                                                                          "\n"
11514                                                                          "layout (std140) buffer Block {\n"
11515                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11516                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11517                                                                          "} block;\n"
11518                                                                          "\n"
11519                                                                          "in  vec4 tes_gs[];\n"
11520                                                                          "out vec4 gs_fs;\n"
11521                                                                          "\n"
11522                                                                          "void main()\n"
11523                                                                          "{\n"
11524                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11525                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11526                                                                          "    {\n"
11527                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11528                                                                          "    }\n"
11529                                                                          "\n"
11530                                                                          "    gs_fs += tes_gs[0];\n"
11531                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11532                                                                          "    EmitVertex();\n"
11533                                                                          "    gs_fs += tes_gs[0];\n"
11534                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11535                                                                          "    EmitVertex();\n"
11536                                                                          "    gs_fs += tes_gs[0];\n"
11537                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11538                                                                          "    EmitVertex();\n"
11539                                                                          "    gs_fs += tes_gs[0];\n"
11540                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11541                                                                          "    EmitVertex();\n"
11542                                                                          "}\n"
11543                                                                          "\n";
11544         static const GLchar* tcs = "#version 430 core\n"
11545                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11546                                                            "\n"
11547                                                            "layout(vertices = 1) out;\n"
11548                                                            "\n"
11549                                                            "in  vec4 vs_tcs[];\n"
11550                                                            "out vec4 tcs_tes[];\n"
11551                                                            "\n"
11552                                                            "void main()\n"
11553                                                            "{\n"
11554                                                            "\n"
11555                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11556                                                            "\n"
11557                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11558                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11559                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11560                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11561                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11562                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11563                                                            "}\n"
11564                                                            "\n";
11565         static const GLchar* tcs_tested = "#version 430 core\n"
11566                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11567                                                                           "\n"
11568                                                                           "layout(vertices = 1) out;\n"
11569                                                                           "\n"
11570                                                                           "layout (std140) buffer Block {\n"
11571                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11572                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11573                                                                           "} block;\n"
11574                                                                           "\n"
11575                                                                           "in  vec4 vs_tcs[];\n"
11576                                                                           "out vec4 tcs_tes[];\n"
11577                                                                           "\n"
11578                                                                           "void main()\n"
11579                                                                           "{\n"
11580                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11581                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11582                                                                           "    {\n"
11583                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11584                                                                           "    }\n"
11585                                                                           "\n"
11586                                                                           "\n"
11587                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11588                                                                           "\n"
11589                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11590                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11591                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11592                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11593                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11594                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11595                                                                           "}\n"
11596                                                                           "\n";
11597         static const GLchar* tes = "#version 430 core\n"
11598                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11599                                                            "\n"
11600                                                            "layout(isolines, point_mode) in;\n"
11601                                                            "\n"
11602                                                            "in  vec4 tcs_tes[];\n"
11603                                                            "out vec4 tes_gs;\n"
11604                                                            "\n"
11605                                                            "void main()\n"
11606                                                            "{\n"
11607                                                            "    tes_gs = tcs_tes[0];\n"
11608                                                            "}\n"
11609                                                            "\n";
11610         static const GLchar* tes_tested = "#version 430 core\n"
11611                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11612                                                                           "\n"
11613                                                                           "layout(isolines, point_mode) in;\n"
11614                                                                           "\n"
11615                                                                           "layout (std140) buffer Block {\n"
11616                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11617                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11618                                                                           "} block;\n"
11619                                                                           "\n"
11620                                                                           "in  vec4 tcs_tes[];\n"
11621                                                                           "out vec4 tes_gs;\n"
11622                                                                           "\n"
11623                                                                           "void main()\n"
11624                                                                           "{\n"
11625                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11626                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11627                                                                           "    {\n"
11628                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11629                                                                           "    }\n"
11630                                                                           "\n"
11631                                                                           "    tes_gs += tcs_tes[0];\n"
11632                                                                           "}\n"
11633                                                                           "\n";
11634         static const GLchar* vs = "#version 430 core\n"
11635                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11636                                                           "\n"
11637                                                           "in  vec4 in_vs;\n"
11638                                                           "out vec4 vs_tcs;\n"
11639                                                           "\n"
11640                                                           "void main()\n"
11641                                                           "{\n"
11642                                                           "    vs_tcs = in_vs;\n"
11643                                                           "}\n"
11644                                                           "\n";
11645         static const GLchar* vs_tested = "#version 430 core\n"
11646                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11647                                                                          "\n"
11648                                                                          "layout (std140) buffer Block {\n"
11649                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11650                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11651                                                                          "} block;\n"
11652                                                                          "\n"
11653                                                                          "in  vec4 in_vs;\n"
11654                                                                          "out vec4 vs_tcs;\n"
11655                                                                          "\n"
11656                                                                          "void main()\n"
11657                                                                          "{\n"
11658                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11659                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11660                                                                          "    {\n"
11661                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11662                                                                          "    }\n"
11663                                                                          "\n"
11664                                                                          "    vs_tcs += in_vs;\n"
11665                                                                          "}\n"
11666                                                                          "\n";
11667
11668         std::string source;
11669         testCase&   test_case = m_test_cases[test_case_index];
11670
11671         if (test_case.m_stage == stage)
11672         {
11673                 GLchar                     buffer[16];
11674                 const GLuint       boy_offset   = test_case.m_boy_offset;
11675                 const Utils::Type& boy_type              = test_case.m_boy_type;
11676                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11677                 const GLuint       man_offset   = test_case.m_man_offset;
11678                 const Utils::Type& man_type              = test_case.m_man_type;
11679                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11680                 size_t                     position              = 0;
11681
11682                 switch (stage)
11683                 {
11684                 case Utils::Shader::COMPUTE:
11685                         source = cs;
11686                         break;
11687                 case Utils::Shader::FRAGMENT:
11688                         source = fs_tested;
11689                         break;
11690                 case Utils::Shader::GEOMETRY:
11691                         source = gs_tested;
11692                         break;
11693                 case Utils::Shader::TESS_CTRL:
11694                         source = tcs_tested;
11695                         break;
11696                 case Utils::Shader::TESS_EVAL:
11697                         source = tes_tested;
11698                         break;
11699                 case Utils::Shader::VERTEX:
11700                         source = vs_tested;
11701                         break;
11702                 default:
11703                         TCU_FAIL("Invalid enum");
11704                 }
11705
11706                 sprintf(buffer, "%d", boy_offset);
11707                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11708                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11709                 sprintf(buffer, "%d", man_offset);
11710                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11711                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11712                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11713                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11714         }
11715         else
11716         {
11717                 switch (stage)
11718                 {
11719                 case Utils::Shader::FRAGMENT:
11720                         source = fs;
11721                         break;
11722                 case Utils::Shader::GEOMETRY:
11723                         source = gs;
11724                         break;
11725                 case Utils::Shader::TESS_CTRL:
11726                         source = tcs;
11727                         break;
11728                 case Utils::Shader::TESS_EVAL:
11729                         source = tes;
11730                         break;
11731                 case Utils::Shader::VERTEX:
11732                         source = vs;
11733                         break;
11734                 default:
11735                         TCU_FAIL("Invalid enum");
11736                 }
11737         }
11738
11739         return source;
11740 }
11741
11742 /** Checks if stage is supported
11743  *
11744  * @param stage Shader stage
11745  *
11746  * @return true if supported, false otherwise
11747  **/
11748 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11749 {
11750         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11751         GLint                    max_supported_buffers = 0;
11752         GLenum                   pname                             = 0;
11753
11754         switch (stage)
11755         {
11756         case Utils::Shader::COMPUTE:
11757                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11758                 break;
11759         case Utils::Shader::FRAGMENT:
11760                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11761                 break;
11762         case Utils::Shader::GEOMETRY:
11763                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11764                 break;
11765         case Utils::Shader::TESS_CTRL:
11766                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11767                 break;
11768         case Utils::Shader::TESS_EVAL:
11769                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11770                 break;
11771         case Utils::Shader::VERTEX:
11772                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11773                 break;
11774         default:
11775                 TCU_FAIL("Invalid enum");
11776         }
11777
11778         gl.getIntegerv(pname, &max_supported_buffers);
11779         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11780
11781         return 1 <= max_supported_buffers;
11782 }
11783
11784 /** Constructor
11785  *
11786  * @param context Test framework context
11787  **/
11788 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11789         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11790                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11791 {
11792         /* Nothing to be done here */
11793 }
11794
11795 /** Source for given test case and stage
11796  *
11797  * @param test_case_index Index of test case
11798  * @param stage           Shader stage
11799  *
11800  * @return Shader source
11801  **/
11802 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11803 {
11804         static const GLchar* cs = "#version 430 core\n"
11805                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11806                                                           "\n"
11807                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11808                                                           "\n"
11809                                                           "layout (std140) buffer Block {\n"
11810                                                           "    vec4 boy;\n"
11811                                                           "    layout (align = ALIGN) TYPE man;\n"
11812                                                           "} block;\n"
11813                                                           "\n"
11814                                                           "writeonly uniform image2D uni_image;\n"
11815                                                           "\n"
11816                                                           "void main()\n"
11817                                                           "{\n"
11818                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11819                                                           "\n"
11820                                                           "    if (TYPE(0) == block.man)\n"
11821                                                           "    {\n"
11822                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11823                                                           "    }\n"
11824                                                           "\n"
11825                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11826                                                           "}\n"
11827                                                           "\n";
11828         static const GLchar* fs = "#version 430 core\n"
11829                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11830                                                           "\n"
11831                                                           "in  vec4 gs_fs;\n"
11832                                                           "out vec4 fs_out;\n"
11833                                                           "\n"
11834                                                           "void main()\n"
11835                                                           "{\n"
11836                                                           "    fs_out = gs_fs;\n"
11837                                                           "}\n"
11838                                                           "\n";
11839         static const GLchar* fs_tested = "#version 430 core\n"
11840                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11841                                                                          "\n"
11842                                                                          "layout (std140) buffer Block {\n"
11843                                                                          "    vec4 boy;\n"
11844                                                                          "    layout (align = ALIGN) TYPE man;\n"
11845                                                                          "} block;\n"
11846                                                                          "\n"
11847                                                                          "in  vec4 gs_fs;\n"
11848                                                                          "out vec4 fs_out;\n"
11849                                                                          "\n"
11850                                                                          "void main()\n"
11851                                                                          "{\n"
11852                                                                          "    if (TYPE(0) == block.man)\n"
11853                                                                          "    {\n"
11854                                                                          "        fs_out = block.boy;\n"
11855                                                                          "    }\n"
11856                                                                          "\n"
11857                                                                          "    fs_out += gs_fs;\n"
11858                                                                          "}\n"
11859                                                                          "\n";
11860         static const GLchar* gs = "#version 430 core\n"
11861                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11862                                                           "\n"
11863                                                           "layout(points)                           in;\n"
11864                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11865                                                           "\n"
11866                                                           "in  vec4 tes_gs[];\n"
11867                                                           "out vec4 gs_fs;\n"
11868                                                           "\n"
11869                                                           "void main()\n"
11870                                                           "{\n"
11871                                                           "    gs_fs = tes_gs[0];\n"
11872                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11873                                                           "    EmitVertex();\n"
11874                                                           "    gs_fs = tes_gs[0];\n"
11875                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11876                                                           "    EmitVertex();\n"
11877                                                           "    gs_fs = tes_gs[0];\n"
11878                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11879                                                           "    EmitVertex();\n"
11880                                                           "    gs_fs = tes_gs[0];\n"
11881                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11882                                                           "    EmitVertex();\n"
11883                                                           "}\n"
11884                                                           "\n";
11885         static const GLchar* gs_tested = "#version 430 core\n"
11886                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11887                                                                          "\n"
11888                                                                          "layout(points)                           in;\n"
11889                                                                          "layout(triangle_strip, max_vertices = 4) out;\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 tes_gs[];\n"
11897                                                                          "out vec4 gs_fs;\n"
11898                                                                          "\n"
11899                                                                          "void main()\n"
11900                                                                          "{\n"
11901                                                                          "    if (TYPE(0) == block.man)\n"
11902                                                                          "    {\n"
11903                                                                          "        gs_fs = block.boy;\n"
11904                                                                          "    }\n"
11905                                                                          "\n"
11906                                                                          "    gs_fs += tes_gs[0];\n"
11907                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11908                                                                          "    EmitVertex();\n"
11909                                                                          "    gs_fs += tes_gs[0];\n"
11910                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11911                                                                          "    EmitVertex();\n"
11912                                                                          "    gs_fs += tes_gs[0];\n"
11913                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11914                                                                          "    EmitVertex();\n"
11915                                                                          "    gs_fs += tes_gs[0];\n"
11916                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11917                                                                          "    EmitVertex();\n"
11918                                                                          "}\n"
11919                                                                          "\n";
11920         static const GLchar* tcs = "#version 430 core\n"
11921                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11922                                                            "\n"
11923                                                            "layout(vertices = 1) out;\n"
11924                                                            "\n"
11925                                                            "in  vec4 vs_tcs[];\n"
11926                                                            "out vec4 tcs_tes[];\n"
11927                                                            "\n"
11928                                                            "void main()\n"
11929                                                            "{\n"
11930                                                            "\n"
11931                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11932                                                            "\n"
11933                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11934                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11935                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11936                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11937                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11938                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11939                                                            "}\n"
11940                                                            "\n";
11941         static const GLchar* tcs_tested = "#version 430 core\n"
11942                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11943                                                                           "\n"
11944                                                                           "layout(vertices = 1) out;\n"
11945                                                                           "\n"
11946                                                                           "layout (std140) buffer Block {\n"
11947                                                                           "    vec4 boy;\n"
11948                                                                           "    layout (align = ALIGN) TYPE man;\n"
11949                                                                           "} block;\n"
11950                                                                           "\n"
11951                                                                           "in  vec4 vs_tcs[];\n"
11952                                                                           "out vec4 tcs_tes[];\n"
11953                                                                           "\n"
11954                                                                           "void main()\n"
11955                                                                           "{\n"
11956                                                                           "    if (TYPE(0) == block.man)\n"
11957                                                                           "    {\n"
11958                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
11959                                                                           "    }\n"
11960                                                                           "\n"
11961                                                                           "\n"
11962                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11963                                                                           "\n"
11964                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11965                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11966                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11967                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11968                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11969                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11970                                                                           "}\n"
11971                                                                           "\n";
11972         static const GLchar* tes = "#version 430 core\n"
11973                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11974                                                            "\n"
11975                                                            "layout(isolines, point_mode) in;\n"
11976                                                            "\n"
11977                                                            "in  vec4 tcs_tes[];\n"
11978                                                            "out vec4 tes_gs;\n"
11979                                                            "\n"
11980                                                            "void main()\n"
11981                                                            "{\n"
11982                                                            "    tes_gs = tcs_tes[0];\n"
11983                                                            "}\n"
11984                                                            "\n";
11985         static const GLchar* tes_tested = "#version 430 core\n"
11986                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11987                                                                           "\n"
11988                                                                           "layout(isolines, point_mode) in;\n"
11989                                                                           "\n"
11990                                                                           "layout (std140) buffer Block {\n"
11991                                                                           "    vec4 boy;\n"
11992                                                                           "    layout (align = ALIGN) TYPE man;\n"
11993                                                                           "} block;\n"
11994                                                                           "\n"
11995                                                                           "in  vec4 tcs_tes[];\n"
11996                                                                           "out vec4 tes_gs;\n"
11997                                                                           "\n"
11998                                                                           "void main()\n"
11999                                                                           "{\n"
12000                                                                           "    if (TYPE(0) == block.man)\n"
12001                                                                           "    {\n"
12002                                                                           "        tes_gs = block.boy;\n"
12003                                                                           "    }\n"
12004                                                                           "\n"
12005                                                                           "    tes_gs += tcs_tes[0];\n"
12006                                                                           "}\n"
12007                                                                           "\n";
12008         static const GLchar* vs = "#version 430 core\n"
12009                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12010                                                           "\n"
12011                                                           "in  vec4 in_vs;\n"
12012                                                           "out vec4 vs_tcs;\n"
12013                                                           "\n"
12014                                                           "void main()\n"
12015                                                           "{\n"
12016                                                           "    vs_tcs = in_vs;\n"
12017                                                           "}\n"
12018                                                           "\n";
12019         static const GLchar* vs_tested = "#version 430 core\n"
12020                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12021                                                                          "\n"
12022                                                                          "layout (std140) buffer Block {\n"
12023                                                                          "    vec4 boy;\n"
12024                                                                          "    layout (align = ALIGN) TYPE man;\n"
12025                                                                          "} block;\n"
12026                                                                          "\n"
12027                                                                          "in  vec4 in_vs;\n"
12028                                                                          "out vec4 vs_tcs;\n"
12029                                                                          "\n"
12030                                                                          "void main()\n"
12031                                                                          "{\n"
12032                                                                          "    if (TYPE(0) == block.man)\n"
12033                                                                          "    {\n"
12034                                                                          "        vs_tcs = block.boy;\n"
12035                                                                          "    }\n"
12036                                                                          "\n"
12037                                                                          "    vs_tcs += in_vs;\n"
12038                                                                          "}\n"
12039                                                                          "\n";
12040
12041         std::string source;
12042         testCase&   test_case = m_test_cases[test_case_index];
12043
12044         if (test_case.m_stage == stage)
12045         {
12046                 GLchar                     buffer[16];
12047                 const GLuint       alignment = test_case.m_alignment;
12048                 const Utils::Type& type          = test_case.m_type;
12049                 const GLchar*     type_name = type.GetGLSLTypeName();
12050                 size_t                     position  = 0;
12051
12052                 switch (stage)
12053                 {
12054                 case Utils::Shader::COMPUTE:
12055                         source = cs;
12056                         break;
12057                 case Utils::Shader::FRAGMENT:
12058                         source = fs_tested;
12059                         break;
12060                 case Utils::Shader::GEOMETRY:
12061                         source = gs_tested;
12062                         break;
12063                 case Utils::Shader::TESS_CTRL:
12064                         source = tcs_tested;
12065                         break;
12066                 case Utils::Shader::TESS_EVAL:
12067                         source = tes_tested;
12068                         break;
12069                 case Utils::Shader::VERTEX:
12070                         source = vs_tested;
12071                         break;
12072                 default:
12073                         TCU_FAIL("Invalid enum");
12074                 }
12075
12076                 sprintf(buffer, "%d", alignment);
12077                 Utils::replaceToken("ALIGN", position, buffer, source);
12078                 Utils::replaceToken("TYPE", position, type_name, source);
12079                 Utils::replaceToken("TYPE", position, type_name, source);
12080         }
12081         else
12082         {
12083                 switch (stage)
12084                 {
12085                 case Utils::Shader::FRAGMENT:
12086                         source = fs;
12087                         break;
12088                 case Utils::Shader::GEOMETRY:
12089                         source = gs;
12090                         break;
12091                 case Utils::Shader::TESS_CTRL:
12092                         source = tcs;
12093                         break;
12094                 case Utils::Shader::TESS_EVAL:
12095                         source = tes;
12096                         break;
12097                 case Utils::Shader::VERTEX:
12098                         source = vs;
12099                         break;
12100                 default:
12101                         TCU_FAIL("Invalid enum");
12102                 }
12103         }
12104
12105         return source;
12106 }
12107
12108 /** Checks if stage is supported
12109  *
12110  * @param stage Shader stage
12111  *
12112  * @return true if supported, false otherwise
12113  **/
12114 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12115 {
12116         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12117         GLint                    max_supported_buffers = 0;
12118         GLenum                   pname                             = 0;
12119
12120         switch (stage)
12121         {
12122         case Utils::Shader::COMPUTE:
12123                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12124                 break;
12125         case Utils::Shader::FRAGMENT:
12126                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12127                 break;
12128         case Utils::Shader::GEOMETRY:
12129                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12130                 break;
12131         case Utils::Shader::TESS_CTRL:
12132                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12133                 break;
12134         case Utils::Shader::TESS_EVAL:
12135                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12136                 break;
12137         case Utils::Shader::VERTEX:
12138                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12139                 break;
12140         default:
12141                 TCU_FAIL("Invalid enum");
12142         }
12143
12144         gl.getIntegerv(pname, &max_supported_buffers);
12145         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12146
12147         return 1 <= max_supported_buffers;
12148 }
12149
12150 /** Constructor
12151  *
12152  * @param context Test framework context
12153  **/
12154 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12155         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12156 {
12157 }
12158
12159 /** Get interface of program
12160  *
12161  * @param ignored
12162  * @param program_interface Interface of program
12163  * @param varying_passthrough Collection of connections between in and out variables
12164  **/
12165 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12166                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12167 {
12168         static const Utils::Type vec4 = Utils::Type::vec4;
12169
12170 #if WRKARD_UNIFORMBLOCKALIGNMENT
12171
12172         static const GLuint block_align = 16;
12173
12174 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12175
12176         static const GLuint block_align = 64;
12177
12178 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12179
12180         static const GLuint fifth_align = 16;
12181         static const GLuint vec4_stride = 16;
12182         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12183
12184         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12185         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12186         const GLuint third_offset =
12187                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12188         const GLuint fourth_offset =
12189                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12190         const GLuint fifth_offset =
12191                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12192         const GLuint sixth_offset =
12193                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12194
12195         Utils::Interface* structure = program_interface.Structure("Data");
12196
12197         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12198                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12199
12200         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12201                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12202                                           Utils::Type::vec4.GetSize() /* offset */);
12203
12204         /* Prepare Block */
12205         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12206
12207         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12208                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12209
12210         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12211                                                  0 /* n_array_elements */, data_stride, second_offset);
12212
12213         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12214                                                  2 /* n_array_elements */, data_stride, third_offset);
12215
12216         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12217                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12218
12219         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12220                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12221
12222         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12223                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12224
12225         const GLuint stride = calculateStride(*vs_buf_Block);
12226         m_data.resize(stride);
12227         generateData(*vs_buf_Block, 0, m_data);
12228
12229         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12230
12231 /* Add uniform BLOCK */
12232 #if WRKARD_UNIFORMBLOCKALIGNMENT
12233         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12234                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12235 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12236         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12237                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12238 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12239
12240         program_interface.CloneVertexInterface(varying_passthrough);
12241 }
12242
12243 /** Selects if "draw" stages are relevant for test
12244  *
12245  * @param ignored
12246  *
12247  * @return true if all stages support shader storage buffers, false otherwise
12248  **/
12249 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12250 {
12251         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12252         GLint                    gs_supported_buffers  = 0;
12253         GLint                    tcs_supported_buffers = 0;
12254         GLint                    tes_supported_buffers = 0;
12255         GLint                    vs_supported_buffers  = 0;
12256
12257         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12258         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12259         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12260         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12261
12262         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12263
12264         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12265                         (1 <= vs_supported_buffers));
12266 }
12267
12268 /** Constructor
12269  *
12270  * @param context Test framework context
12271  **/
12272 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12273         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12274 {
12275 }
12276
12277 /** Constructor
12278  *
12279  * @param context          Test context
12280  * @param test_name        Name of test
12281  * @param test_description Description of test
12282  **/
12283 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12284                                                                                    const glw::GLchar* test_description)
12285         : TextureTestBase(context, test_name, test_description)
12286 {
12287 }
12288
12289 /** Get interface of program
12290  *
12291  * @param test_case_index     Test case
12292  * @param program_interface   Interface of program
12293  * @param varying_passthrough Collection of connections between in and out variables
12294  **/
12295 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12296                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12297 {
12298         const Utils::Type type = getType(test_case_index);
12299
12300         m_first_data = type.GenerateDataPacked();
12301         m_last_data  = type.GenerateDataPacked();
12302
12303         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12304         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12305         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12306         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12307         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12308 }
12309
12310 /** Get type name
12311  *
12312  * @param test_case_index Index of test case
12313  *
12314  * @return Name of type test in test_case_index
12315  **/
12316 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12317 {
12318         return getTypeName(test_case_index);
12319 }
12320
12321 /** Returns number of types to test
12322  *
12323  * @return Number of types, 34
12324  **/
12325 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12326 {
12327         return getTypesNumber();
12328 }
12329
12330 /** Selects if "compute" stage is relevant for test
12331  *
12332  * @param ignored
12333  *
12334  * @return false
12335  **/
12336 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12337 {
12338         return false;
12339 }
12340
12341 /**
12342  *
12343  *
12344  **/
12345 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12346 {
12347         GLchar          buffer[16];
12348         std::string globals = "const uint first_input_location  = 0u;\n"
12349                                                   "const uint first_output_location = 0u;\n"
12350                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12351                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12352         size_t position = 100; /* Skip first part */
12353
12354         sprintf(buffer, "%d", last_in_loc);
12355         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12356
12357         sprintf(buffer, "%d", last_out_loc);
12358         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12359
12360         return globals;
12361 }
12362
12363 /**
12364  *
12365  **/
12366 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12367                                                                                           Utils::ProgramInterface&   program_interface,
12368                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12369 {
12370         const GLuint array_length  = 1;
12371         const GLuint first_in_loc  = 0;
12372         const GLuint first_out_loc = 0;
12373         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12374         size_t           position         = 0;
12375
12376         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12377
12378         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12379
12380         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12381         const GLchar* qual_first_out = "layout (location = first_output_location)";
12382         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12383         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12384
12385         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12386         const GLuint                    type_size = type.GetSize();
12387
12388         std::string first_in_name  = "PREFIXfirst";
12389         std::string first_out_name = "PREFIXfirst";
12390         std::string last_in_name   = "PREFIXlast";
12391         std::string last_out_name  = "PREFIXlast";
12392
12393         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12394         position = 0;
12395         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12396         position = 0;
12397         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12398         position = 0;
12399         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12400
12401         if (Utils::Shader::FRAGMENT == stage)
12402         {
12403                 qual_first_in = "layout (location = first_input_location) flat";
12404                 qual_last_in  = "layout (location = last_input_location)  flat";
12405         }
12406         if (Utils::Shader::GEOMETRY == stage)
12407         {
12408                 qual_first_out = "layout (location = first_output_location) flat";
12409                 qual_last_out  = "layout (location = last_output_location)  flat";
12410         }
12411
12412         Utils::Variable* first_in = si.Input(
12413                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12414                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12415                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12416
12417         Utils::Variable* last_in =
12418                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12419                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12420                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12421                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12422
12423         if (Utils::Shader::FRAGMENT != stage)
12424         {
12425                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12426
12427                 Utils::Variable* first_out =
12428                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12429                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12430                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12431                                           m_first_data.size() /* data_size */);
12432
12433                 Utils::Variable* last_out = si.Output(
12434                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12435                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12436                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12437
12438                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12439
12440                 varying_passthrough.Add(stage, first_in, first_out);
12441                 varying_passthrough.Add(stage, last_in, last_out);
12442         }
12443         else
12444         {
12445                 /* No outputs for fragment shader, so last_output_location can be 0 */
12446                 si.m_globals = prepareGlobals(last_in_loc, 0);
12447         }
12448 }
12449
12450 /** This test should be run with separable programs
12451  *
12452  * @param ignored
12453  *
12454  * @return true
12455  **/
12456 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12457 {
12458         return false;
12459 }
12460
12461 /* Constants used by VertexAttribLocationsTest */
12462 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12463 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12464 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12465 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12466 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12467
12468 /** Constructor
12469  *
12470  * @param context Test framework context
12471  **/
12472 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12473         : TextureTestBase(context, "vertex_attrib_locations",
12474                                           "Test verifies that attribute locations are respected by drawing operations")
12475 {
12476 }
12477
12478 /** Execute proper draw command for test case
12479  *
12480  * @param test_case_index Index of test case
12481  **/
12482 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12483 {
12484         const Functions& gl = m_context.getRenderContext().getFunctions();
12485
12486         switch (test_case_index)
12487         {
12488         case DRAWARRAYS:
12489                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12490                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12491                 break;
12492         case DRAWARRAYSINSTANCED:
12493                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12494                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12495                 break;
12496         case DRAWELEMENTS:
12497                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL);
12498                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12499                 break;
12500         case DRAWELEMENTSBASEVERTEX:
12501                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_base_vertex);
12502                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12503                 break;
12504         case DRAWELEMENTSINSTANCED:
12505                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances);
12506                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12507                 break;
12508         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12509                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12510                                                                                          m_base_instance);
12511                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12512                 break;
12513         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12514                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12515                                                                                    m_base_vertex);
12516                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12517                 break;
12518         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12519                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL,
12520                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12521                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12522                 break;
12523         default:
12524                 TCU_FAIL("Invalid enum");
12525         }
12526 }
12527
12528 /** Get interface of program
12529  *
12530  * @param ignored
12531  * @param program_interface   Interface of program
12532  * @param ignored
12533  **/
12534 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12535                                                                                                         Utils::ProgramInterface& program_interface,
12536                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12537 {
12538         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12539
12540         /* Globals */
12541         si.m_globals = "const uint vertex_index_location   = 2;\n"
12542                                    "const uint instance_index_location = 5;\n";
12543
12544         /* Attributes */
12545         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12546                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12547                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12548                          (GLvoid*)0 /* data */, 0 /* data_size */);
12549         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12550                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12551                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12552                          (GLvoid*)0 /* data */, 0 /* data_size */);
12553 }
12554
12555 /** Get name of test case
12556  *
12557  * @param test_case_index Index of test case
12558  *
12559  * @return Name of test case
12560  **/
12561 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12562 {
12563         std::string result;
12564
12565         switch (test_case_index)
12566         {
12567         case DRAWARRAYS:
12568                 result = "DrawArrays";
12569                 break;
12570         case DRAWARRAYSINSTANCED:
12571                 result = "DrawArraysInstanced";
12572                 break;
12573         case DRAWELEMENTS:
12574                 result = "DrawElements";
12575                 break;
12576         case DRAWELEMENTSBASEVERTEX:
12577                 result = "DrawElementsBaseVertex";
12578                 break;
12579         case DRAWELEMENTSINSTANCED:
12580                 result = "DrawElementsInstanced";
12581                 break;
12582         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12583                 result = "DrawElementsInstancedBaseInstance";
12584                 break;
12585         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12586                 result = "DrawElementsInstancedBaseVertex";
12587                 break;
12588         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12589                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12590                 break;
12591         default:
12592                 TCU_FAIL("Invalid enum");
12593         }
12594
12595         return result;
12596 }
12597
12598 /** Get number of test cases
12599  *
12600  * @return Number of test cases
12601  **/
12602 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12603 {
12604         return TESTCASES_MAX;
12605 }
12606
12607 /** Prepare code snippet that will verify in and uniform variables
12608  *
12609  * @param ignored
12610  * @param ignored
12611  * @param stage   Shader stage
12612  *
12613  * @return Code that verify variables
12614  **/
12615 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12616                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12617                                                                                                                           Utils::Shader::STAGES stage)
12618 {
12619         std::string verification;
12620
12621         if (Utils::Shader::VERTEX == stage)
12622         {
12623
12624 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12625
12626                 verification = "if (gl_InstanceID != instance_index)\n"
12627                                            "    {\n"
12628                                            "        result = 12u;\n"
12629                                            "    }\n"
12630                                            "    else if (gl_VertexID != vertex_index)\n"
12631                                            "    {\n"
12632                                            "        result = 11u;\n"
12633                                            "    }\n";
12634
12635 #else
12636
12637                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12638                                            "        (gl_InstanceID != instance_index) )\n"
12639                                            "    {\n"
12640                                            "        result = 0u;\n"
12641                                            "    }\n";
12642
12643 #endif
12644         }
12645         else
12646         {
12647                 verification = "";
12648         }
12649
12650         return verification;
12651 }
12652
12653 /** Selects if "compute" stage is relevant for test
12654  *
12655  * @param ignored
12656  *
12657  * @return false
12658  **/
12659 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12660 {
12661         return false;
12662 }
12663
12664 /** Prepare attributes, vertex array object and array buffer
12665  *
12666  * @param ignored
12667  * @param ignored Interface of program
12668  * @param buffer  Array buffer
12669  * @param vao     Vertex array object
12670  **/
12671 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12672                                                                                                   Utils::ProgramInterface& /* program_interface */,
12673                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12674 {
12675         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12676         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12677
12678         std::vector<GLuint> buffer_data;
12679         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12680
12681         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12682
12683         /*
12684          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12685          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12686          */
12687         if (test_case_index >= 2)
12688         {
12689                 buffer.m_buffer = Utils::Buffer::Element;
12690         }
12691         vao.Bind();
12692         buffer.Bind();
12693
12694         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12695                                   0 /* stride */, 0 /* offset */);
12696
12697         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12698                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12699         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12700         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12701         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12702                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12703         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12704                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12705
12706         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12707         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12708
12709         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12710 }
12711
12712 /** This test should be run with separable programs
12713  *
12714  * @param ignored
12715  *
12716  * @return true
12717  **/
12718 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12719 {
12720         return false;
12721 }
12722
12723 /** Constructor
12724  *
12725  * @param context Test framework context
12726  **/
12727 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12728         : VaryingLocationsTest(context, "varying_array_locations",
12729                                                    "Test verifies that input and output locations are respected for arrays")
12730 {
12731 }
12732
12733 /**
12734  *
12735  **/
12736 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12737                                                                                                    Utils::ProgramInterface&   program_interface,
12738                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12739 {
12740         const GLuint array_length  = 1u;
12741         const GLuint first_in_loc  = 0;
12742         const GLuint first_out_loc = 0;
12743         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12744         size_t           position         = 0;
12745
12746         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12747
12748         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12749
12750         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12751         const GLchar* qual_first_out = "layout (location = first_output_location)";
12752         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12753         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12754
12755         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12756         const GLuint                    type_size = type.GetSize();
12757
12758         std::string first_in_name  = "PREFIXfirst";
12759         std::string first_out_name = "PREFIXfirst";
12760         std::string last_in_name   = "PREFIXlast";
12761         std::string last_out_name  = "PREFIXlast";
12762
12763         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12764         position = 0;
12765         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12766         position = 0;
12767         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12768         position = 0;
12769         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12770
12771         if (Utils::Shader::FRAGMENT == stage)
12772         {
12773                 qual_first_in = "layout (location = first_input_location) flat";
12774                 qual_last_in  = "layout (location = last_input_location)  flat";
12775         }
12776         if (Utils::Shader::GEOMETRY == stage)
12777         {
12778                 qual_first_out = "layout (location = first_output_location) flat";
12779                 qual_last_out  = "layout (location = last_output_location)  flat";
12780         }
12781
12782         Utils::Variable* first_in =
12783                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12784                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12785                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12786                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12787
12788         Utils::Variable* last_in =
12789                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12790                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12791                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12792                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12793
12794         if (Utils::Shader::FRAGMENT != stage)
12795         {
12796                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12797
12798                 Utils::Variable* first_out =
12799                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12800                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12801                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12802                                           (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12803
12804                 Utils::Variable* last_out =
12805                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12806                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12807                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12808                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12809
12810                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12811
12812                 varying_passthrough.Add(stage, first_in, first_out);
12813                 varying_passthrough.Add(stage, last_in, last_out);
12814         }
12815         else
12816         {
12817                 /* No outputs for fragment shader, so last_output_location can be 0 */
12818                 si.m_globals = prepareGlobals(last_in_loc, 0);
12819         }
12820 }
12821
12822 /** Constructor
12823  *
12824  * @param context Test framework context
12825  **/
12826 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12827         : TextureTestBase(context, "varying_structure_locations",
12828                                           "Test verifies that locations are respected when structures are used as in and out ")
12829 {
12830 }
12831
12832 /** Prepare code snippet that will pass in variables to out variables
12833  *
12834  * @param ignored
12835  * @param varying_passthrough Collection of connections between in and out variables
12836  * @param stage               Shader stage
12837  *
12838  * @return Code that pass in variables to next stage
12839  **/
12840 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12841                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12842                                                                                                                   Utils::Shader::STAGES          stage)
12843 {
12844         std::string result;
12845
12846         if (Utils::Shader::VERTEX != stage)
12847         {
12848                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12849         }
12850         else
12851         {
12852                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12853                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12854         }
12855
12856         return result;
12857 }
12858
12859 /** Get interface of program
12860  *
12861  * @param test_case_index     Test case
12862  * @param program_interface   Interface of program
12863  * @param varying_passthrough Collection of connections between in and out variables
12864  **/
12865 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12866                                                                                                                 Utils::ProgramInterface&   program_interface,
12867                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12868 {
12869         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12870         const Utils::Type               type = getType(test_case_index);
12871
12872         /* Prepare data */
12873         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12874         m_single_data = type.GenerateDataPacked();
12875         m_array_data  = type.GenerateDataPacked();
12876
12877         m_data.resize(m_single_data.size() + m_array_data.size());
12878         GLubyte* ptr = (GLubyte*)&m_data[0];
12879         memcpy(ptr, &m_single_data[0], m_single_data.size());
12880         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12881
12882         Utils::Interface* structure = program_interface.Structure("Data");
12883
12884         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12885                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12886
12887         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12888         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12889                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12890
12891         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12892                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12893                          m_single_data.size() /* data_size */);
12894
12895         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12896                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12897                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12898
12899         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12900                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12901                           m_data.size() /* data_size */);
12902
12903         program_interface.CloneVertexInterface(varying_passthrough);
12904 }
12905
12906 /** Get type name
12907  *
12908  * @param test_case_index Index of test case
12909  *
12910  * @return Name of type test in test_case_index
12911  **/
12912 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12913 {
12914         return getTypeName(test_case_index);
12915 }
12916
12917 /** Returns number of types to test
12918  *
12919  * @return Number of types, 34
12920  **/
12921 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12922 {
12923         return getTypesNumber();
12924 }
12925
12926 /** Selects if "compute" stage is relevant for test
12927  *
12928  * @param ignored
12929  *
12930  * @return false
12931  **/
12932 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12933 {
12934         return false;
12935 }
12936
12937 /** This test should be run with separable programs
12938  *
12939  * @param ignored
12940  *
12941  * @return true
12942  **/
12943 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12944 {
12945         return false;
12946 }
12947
12948 /** Constructor
12949  *
12950  * @param context          Test context
12951  * @param test_name        Name of test
12952  * @param test_description Description of test
12953  **/
12954 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
12955         : NegativeTestBase(context, "varying_structure_member_location",
12956                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
12957 {
12958 }
12959
12960 /** Source for given test case and stage
12961  *
12962  * @param test_case_index Index of test case
12963  * @param stage           Shader stage
12964  *
12965  * @return Shader source
12966  **/
12967 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
12968 {
12969         static const GLchar* struct_definition = "struct Data {\n"
12970                                                                                          "    vec4 gohan;\n"
12971                                                                                          "    layout (location = 4) vec4 goten;\n"
12972                                                                                          "};\n";
12973         static const GLchar* input_var  = "in Data data;\n";
12974         static const GLchar* output_var = "out Data data;\n";
12975         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
12976         static const GLchar* output_use = "    data.gohan = result / 2;\n"
12977                                                                           "    data.goten = result / 4 - data.gohan;\n";
12978         static const GLchar* fs = "#version 430 core\n"
12979                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12980                                                           "\n"
12981                                                           "in  vec4 gs_fs;\n"
12982                                                           "out vec4 fs_out;\n"
12983                                                           "\n"
12984                                                           "void main()\n"
12985                                                           "{\n"
12986                                                           "    fs_out = gs_fs;\n"
12987                                                           "}\n"
12988                                                           "\n";
12989         static const GLchar* fs_tested = "#version 430 core\n"
12990                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12991                                                                          "\n"
12992                                                                          "STRUCT_DEFINITION"
12993                                                                          "\n"
12994                                                                          "VARIABLE_DEFINITION"
12995                                                                          "\n"
12996                                                                          "in  vec4 gs_fs;\n"
12997                                                                          "out vec4 fs_out;\n"
12998                                                                          "\n"
12999                                                                          "void main()\n"
13000                                                                          "{\n"
13001                                                                          "    vec4 result = gs_fs;\n"
13002                                                                          "\n"
13003                                                                          "VARIABLE_USE"
13004                                                                          "\n"
13005                                                                          "    fs_out += result;\n"
13006                                                                          "}\n"
13007                                                                          "\n";
13008         static const GLchar* gs = "#version 430 core\n"
13009                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13010                                                           "\n"
13011                                                           "layout(points)                           in;\n"
13012                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13013                                                           "\n"
13014                                                           "in  vec4 tes_gs[];\n"
13015                                                           "out vec4 gs_fs;\n"
13016                                                           "\n"
13017                                                           "void main()\n"
13018                                                           "{\n"
13019                                                           "    gs_fs = tes_gs[0];\n"
13020                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13021                                                           "    EmitVertex();\n"
13022                                                           "    gs_fs = tes_gs[0];\n"
13023                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13024                                                           "    EmitVertex();\n"
13025                                                           "    gs_fs = tes_gs[0];\n"
13026                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13027                                                           "    EmitVertex();\n"
13028                                                           "    gs_fs = tes_gs[0];\n"
13029                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13030                                                           "    EmitVertex();\n"
13031                                                           "}\n"
13032                                                           "\n";
13033         static const GLchar* gs_tested = "#version 430 core\n"
13034                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13035                                                                          "\n"
13036                                                                          "layout(points)                           in;\n"
13037                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13038                                                                          "\n"
13039                                                                          "STRUCT_DEFINITION"
13040                                                                          "\n"
13041                                                                          "VARIABLE_DEFINITION"
13042                                                                          "\n"
13043                                                                          "in  vec4 tes_gs[];\n"
13044                                                                          "out vec4 gs_fs;\n"
13045                                                                          "\n"
13046                                                                          "void main()\n"
13047                                                                          "{\n"
13048                                                                          "    vec4 result = tes_gs[0];\n"
13049                                                                          "\n"
13050                                                                          "VARIABLE_USE"
13051                                                                          "\n"
13052                                                                          "    gs_fs = result;\n"
13053                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13054                                                                          "    EmitVertex();\n"
13055                                                                          "    gs_fs = result;\n"
13056                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13057                                                                          "    EmitVertex();\n"
13058                                                                          "    gs_fs = result;\n"
13059                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13060                                                                          "    EmitVertex();\n"
13061                                                                          "    gs_fs = result;\n"
13062                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13063                                                                          "    EmitVertex();\n"
13064                                                                          "}\n"
13065                                                                          "\n";
13066         static const GLchar* tcs = "#version 430 core\n"
13067                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13068                                                            "\n"
13069                                                            "layout(vertices = 1) out;\n"
13070                                                            "\n"
13071                                                            "in  vec4 vs_tcs[];\n"
13072                                                            "out vec4 tcs_tes[];\n"
13073                                                            "\n"
13074                                                            "void main()\n"
13075                                                            "{\n"
13076                                                            "\n"
13077                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13078                                                            "\n"
13079                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13080                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13081                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13082                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13083                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13084                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13085                                                            "}\n"
13086                                                            "\n";
13087         static const GLchar* tcs_tested = "#version 430 core\n"
13088                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13089                                                                           "\n"
13090                                                                           "layout(vertices = 1) out;\n"
13091                                                                           "\n"
13092                                                                           "STRUCT_DEFINITION"
13093                                                                           "\n"
13094                                                                           "VARIABLE_DEFINITION"
13095                                                                           "\n"
13096                                                                           "in  vec4 vs_tcs[];\n"
13097                                                                           "out vec4 tcs_tes[];\n"
13098                                                                           "\n"
13099                                                                           "void main()\n"
13100                                                                           "{\n"
13101                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13102                                                                           "\n"
13103                                                                           "VARIABLE_USE"
13104                                                                           "\n"
13105                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13106                                                                           "\n"
13107                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13108                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13109                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13110                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13111                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13112                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13113                                                                           "}\n"
13114                                                                           "\n";
13115         static const GLchar* tes = "#version 430 core\n"
13116                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13117                                                            "\n"
13118                                                            "layout(isolines, point_mode) in;\n"
13119                                                            "\n"
13120                                                            "in  vec4 tcs_tes[];\n"
13121                                                            "out vec4 tes_gs;\n"
13122                                                            "\n"
13123                                                            "void main()\n"
13124                                                            "{\n"
13125                                                            "    tes_gs = tcs_tes[0];\n"
13126                                                            "}\n"
13127                                                            "\n";
13128         static const GLchar* tes_tested = "#version 430 core\n"
13129                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13130                                                                           "\n"
13131                                                                           "layout(isolines, point_mode) in;\n"
13132                                                                           "\n"
13133                                                                           "STRUCT_DEFINITION"
13134                                                                           "\n"
13135                                                                           "VARIABLE_DEFINITION"
13136                                                                           "\n"
13137                                                                           "in  vec4 tcs_tes[];\n"
13138                                                                           "out vec4 tes_gs;\n"
13139                                                                           "\n"
13140                                                                           "void main()\n"
13141                                                                           "{\n"
13142                                                                           "    vec4 result = tcs_tes[0];\n"
13143                                                                           "\n"
13144                                                                           "VARIABLE_USE"
13145                                                                           "\n"
13146                                                                           "    tes_gs += result;\n"
13147                                                                           "}\n"
13148                                                                           "\n";
13149         static const GLchar* vs = "#version 430 core\n"
13150                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13151                                                           "\n"
13152                                                           "in  vec4 in_vs;\n"
13153                                                           "out vec4 vs_tcs;\n"
13154                                                           "\n"
13155                                                           "void main()\n"
13156                                                           "{\n"
13157                                                           "    vs_tcs = in_vs;\n"
13158                                                           "}\n"
13159                                                           "\n";
13160         static const GLchar* vs_tested = "#version 430 core\n"
13161                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13162                                                                          "\n"
13163                                                                          "STRUCT_DEFINITION"
13164                                                                          "\n"
13165                                                                          "VARIABLE_DEFINITION"
13166                                                                          "\n"
13167                                                                          "in  vec4 in_vs;\n"
13168                                                                          "out vec4 vs_tcs;\n"
13169                                                                          "\n"
13170                                                                          "void main()\n"
13171                                                                          "{\n"
13172                                                                          "    vec4 result = in_vs;\n"
13173                                                                          "\n"
13174                                                                          "VARIABLE_USE"
13175                                                                          "\n"
13176                                                                          "    vs_tcs += result;\n"
13177                                                                          "}\n"
13178                                                                          "\n";
13179
13180         std::string   source;
13181         testCase&        test_case               = m_test_cases[test_case_index];
13182         const GLchar* var_definition = 0;
13183         const GLchar* var_use            = 0;
13184
13185         if (true == test_case.m_is_input)
13186         {
13187                 var_definition = input_var;
13188                 var_use            = input_use;
13189         }
13190         else
13191         {
13192                 var_definition = output_var;
13193                 var_use            = output_use;
13194         }
13195
13196         if (test_case.m_stage == stage)
13197         {
13198                 size_t position = 0;
13199
13200                 switch (stage)
13201                 {
13202                 case Utils::Shader::FRAGMENT:
13203                         source = fs_tested;
13204                         break;
13205                 case Utils::Shader::GEOMETRY:
13206                         source = gs_tested;
13207                         break;
13208                 case Utils::Shader::TESS_CTRL:
13209                         source = tcs_tested;
13210                         break;
13211                 case Utils::Shader::TESS_EVAL:
13212                         source = tes_tested;
13213                         break;
13214                 case Utils::Shader::VERTEX:
13215                         source = vs_tested;
13216                         break;
13217                 default:
13218                         TCU_FAIL("Invalid enum");
13219                 }
13220
13221                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13222                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13223                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13224         }
13225         else
13226         {
13227                 switch (stage)
13228                 {
13229                 case Utils::Shader::FRAGMENT:
13230                         source = fs;
13231                         break;
13232                 case Utils::Shader::GEOMETRY:
13233                         source = gs;
13234                         break;
13235                 case Utils::Shader::TESS_CTRL:
13236                         source = tcs;
13237                         break;
13238                 case Utils::Shader::TESS_EVAL:
13239                         source = tes;
13240                         break;
13241                 case Utils::Shader::VERTEX:
13242                         source = vs;
13243                         break;
13244                 default:
13245                         TCU_FAIL("Invalid enum");
13246                 }
13247         }
13248
13249         return source;
13250 }
13251
13252 /** Get description of test case
13253  *
13254  * @param test_case_index Index of test case
13255  *
13256  * @return Test case description
13257  **/
13258 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13259 {
13260         std::stringstream stream;
13261         testCase&                 test_case = m_test_cases[test_case_index];
13262
13263         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13264
13265         if (true == test_case.m_is_input)
13266         {
13267                 stream << "input";
13268         }
13269         else
13270         {
13271                 stream << "output";
13272         }
13273
13274         return stream.str();
13275 }
13276
13277 /** Get number of test cases
13278  *
13279  * @return Number of test cases
13280  **/
13281 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13282 {
13283         return static_cast<GLuint>(m_test_cases.size());
13284 }
13285
13286 /** Selects if "compute" stage is relevant for test
13287  *
13288  * @param ignored
13289  *
13290  * @return false
13291  **/
13292 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13293 {
13294         return false;
13295 }
13296
13297 /** Prepare all test cases
13298  *
13299  **/
13300 void VaryingStructureMemberLocationTest::testInit()
13301 {
13302         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13303         {
13304                 if (Utils::Shader::COMPUTE == stage)
13305                 {
13306                         continue;
13307                 }
13308
13309                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13310                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13311
13312                 m_test_cases.push_back(test_case_in);
13313
13314                 if (Utils::Shader::FRAGMENT != stage)
13315                 {
13316                         m_test_cases.push_back(test_case_out);
13317                 }
13318         }
13319 }
13320
13321 /** Constructor
13322  *
13323  * @param context Test framework context
13324  **/
13325 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13326         : TextureTestBase(context, "varying_block_locations",
13327                                           "Test verifies that locations are respected when blocks are used as in and out ")
13328 {
13329 }
13330
13331 /** Prepare code snippet that will pass in variables to out variables
13332  *
13333  * @param ignored
13334  * @param varying_passthrough Collection of connections between in and out variables
13335  * @param stage               Shader stage
13336  *
13337  * @return Code that pass in variables to next stage
13338  **/
13339 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13340                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13341                                                                                                           Utils::Shader::STAGES          stage)
13342 {
13343         std::string result;
13344
13345         if (Utils::Shader::VERTEX != stage)
13346         {
13347                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13348         }
13349         else
13350         {
13351                 result = "vs_tcs_block.third  = vs_in_third;\n"
13352                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13353                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13354         }
13355
13356         return result;
13357 }
13358
13359 /** Get interface of program
13360  *
13361  * @param ignored
13362  * @param program_interface   Interface of program
13363  * @param varying_passthrough Collection of connections between in and out variables
13364  **/
13365 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13366                                                                                                         Utils::ProgramInterface&   program_interface,
13367                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13368 {
13369         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13370         const Utils::Type               vec4 = Utils::Type::vec4;
13371
13372         /* Prepare data */
13373         m_third_data  = vec4.GenerateData();
13374         m_fourth_data = vec4.GenerateData();
13375         m_fifth_data  = vec4.GenerateData();
13376
13377         /* Memory layout is different from location layout */
13378         const GLuint fifth_offset  = 0u;
13379         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13380         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13381
13382         m_data.resize(fourth_offset + m_fourth_data.size());
13383         GLubyte* ptr = (GLubyte*)&m_data[0];
13384         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13385         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13386         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13387
13388         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13389
13390         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13391                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13392
13393         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13394                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13395
13396         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13397                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13398
13399         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13400                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13401                           m_data.size() /* data_size */);
13402
13403         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13404                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13405                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13406
13407         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13408                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13409                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13410
13411         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13412                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13413                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13414
13415         program_interface.CloneVertexInterface(varying_passthrough);
13416 }
13417
13418 /** Selects if "compute" stage is relevant for test
13419  *
13420  * @param ignored
13421  *
13422  * @return false
13423  **/
13424 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13425 {
13426         return false;
13427 }
13428
13429 /** This test should be run with separable programs
13430  *
13431  * @param ignored
13432  *
13433  * @return true
13434  **/
13435 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13436 {
13437         return false;
13438 }
13439
13440 /** Constructor
13441  *
13442  * @param context Test framework context
13443  **/
13444 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13445         : NegativeTestBase(
13446                   context, "varying_block_member_locations",
13447                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13448 {
13449 }
13450
13451 /** Source for given test case and stage
13452  *
13453  * @param test_case_index Index of test case
13454  * @param stage           Shader stage
13455  *
13456  * @return Shader source
13457  **/
13458 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13459 {
13460         static const GLchar* block_definition_all = "Goku {\n"
13461                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13462                                                                                                 "    layout (location = 4) vec4 goten;\n"
13463                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13464                                                                                                 "} gokuARRAY;\n";
13465         static const GLchar* block_definition_default = "Goku {\n"
13466                                                                                                         "    vec4 gohan;\n"
13467                                                                                                         "    vec4 goten;\n"
13468                                                                                                         "    vec4 chichi;\n"
13469                                                                                                         "} gokuARRAY;\n";
13470         static const GLchar* block_definition_one = "Goku {\n"
13471                                                                                                 "    vec4 gohan;\n"
13472                                                                                                 "    layout (location = 4) vec4 goten;\n"
13473                                                                                                 "    vec4 chichi;\n"
13474                                                                                                 "} gokuARRAY;\n";
13475         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13476         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13477                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13478                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13479         static const GLchar* fs = "#version 430 core\n"
13480                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13481                                                           "\n"
13482                                                           "in  vec4 gs_fs;\n"
13483                                                           "out vec4 fs_out;\n"
13484                                                           "\n"
13485                                                           "void main()\n"
13486                                                           "{\n"
13487                                                           "    fs_out = gs_fs;\n"
13488                                                           "}\n"
13489                                                           "\n";
13490         static const GLchar* fs_tested = "#version 430 core\n"
13491                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13492                                                                          "\n"
13493                                                                          "DIRECTION BLOCK_DEFINITION"
13494                                                                          "\n"
13495                                                                          "in  vec4 gs_fs;\n"
13496                                                                          "out vec4 fs_out;\n"
13497                                                                          "\n"
13498                                                                          "void main()\n"
13499                                                                          "{\n"
13500                                                                          "    vec4 result = gs_fs;\n"
13501                                                                          "\n"
13502                                                                          "VARIABLE_USE"
13503                                                                          "\n"
13504                                                                          "    fs_out = result;\n"
13505                                                                          "}\n"
13506                                                                          "\n";
13507         static const GLchar* gs = "#version 430 core\n"
13508                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13509                                                           "\n"
13510                                                           "layout(points)                           in;\n"
13511                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13512                                                           "\n"
13513                                                           "in  vec4 tes_gs[];\n"
13514                                                           "out vec4 gs_fs;\n"
13515                                                           "\n"
13516                                                           "void main()\n"
13517                                                           "{\n"
13518                                                           "    gs_fs = tes_gs[0];\n"
13519                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13520                                                           "    EmitVertex();\n"
13521                                                           "    gs_fs = tes_gs[0];\n"
13522                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13523                                                           "    EmitVertex();\n"
13524                                                           "    gs_fs = tes_gs[0];\n"
13525                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13526                                                           "    EmitVertex();\n"
13527                                                           "    gs_fs = tes_gs[0];\n"
13528                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13529                                                           "    EmitVertex();\n"
13530                                                           "}\n"
13531                                                           "\n";
13532         static const GLchar* gs_tested = "#version 430 core\n"
13533                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13534                                                                          "\n"
13535                                                                          "layout(points)                           in;\n"
13536                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13537                                                                          "\n"
13538                                                                          "DIRECTION BLOCK_DEFINITION"
13539                                                                          "\n"
13540                                                                          "in  vec4 tes_gs[];\n"
13541                                                                          "out vec4 gs_fs;\n"
13542                                                                          "\n"
13543                                                                          "void main()\n"
13544                                                                          "{\n"
13545                                                                          "    vec4 result = tes_gs[0];\n"
13546                                                                          "\n"
13547                                                                          "VARIABLE_USE"
13548                                                                          "\n"
13549                                                                          "    gs_fs = result;\n"
13550                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13551                                                                          "    EmitVertex();\n"
13552                                                                          "    gs_fs = result;\n"
13553                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13554                                                                          "    EmitVertex();\n"
13555                                                                          "    gs_fs = result;\n"
13556                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13557                                                                          "    EmitVertex();\n"
13558                                                                          "    gs_fs = result;\n"
13559                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13560                                                                          "    EmitVertex();\n"
13561                                                                          "}\n"
13562                                                                          "\n";
13563         static const GLchar* tcs = "#version 430 core\n"
13564                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13565                                                            "\n"
13566                                                            "layout(vertices = 1) out;\n"
13567                                                            "\n"
13568                                                            "in  vec4 vs_tcs[];\n"
13569                                                            "out vec4 tcs_tes[];\n"
13570                                                            "\n"
13571                                                            "void main()\n"
13572                                                            "{\n"
13573                                                            "\n"
13574                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13575                                                            "\n"
13576                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13577                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13578                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13579                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13580                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13581                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13582                                                            "}\n"
13583                                                            "\n";
13584         static const GLchar* tcs_tested = "#version 430 core\n"
13585                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13586                                                                           "\n"
13587                                                                           "layout(vertices = 1) out;\n"
13588                                                                           "\n"
13589                                                                           "DIRECTION BLOCK_DEFINITION"
13590                                                                           "\n"
13591                                                                           "in  vec4 vs_tcs[];\n"
13592                                                                           "out vec4 tcs_tes[];\n"
13593                                                                           "\n"
13594                                                                           "void main()\n"
13595                                                                           "{\n"
13596                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13597                                                                           "\n"
13598                                                                           "VARIABLE_USE"
13599                                                                           "\n"
13600                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13601                                                                           "\n"
13602                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13603                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13604                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13605                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13606                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13607                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13608                                                                           "}\n"
13609                                                                           "\n";
13610         static const GLchar* tes = "#version 430 core\n"
13611                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13612                                                            "\n"
13613                                                            "layout(isolines, point_mode) in;\n"
13614                                                            "\n"
13615                                                            "in  vec4 tcs_tes[];\n"
13616                                                            "out vec4 tes_gs;\n"
13617                                                            "\n"
13618                                                            "void main()\n"
13619                                                            "{\n"
13620                                                            "    tes_gs = tcs_tes[0];\n"
13621                                                            "}\n"
13622                                                            "\n";
13623         static const GLchar* tes_tested = "#version 430 core\n"
13624                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13625                                                                           "\n"
13626                                                                           "layout(isolines, point_mode) in;\n"
13627                                                                           "\n"
13628                                                                           "DIRECTION BLOCK_DEFINITION"
13629                                                                           "\n"
13630                                                                           "in  vec4 tcs_tes[];\n"
13631                                                                           "out vec4 tes_gs;\n"
13632                                                                           "\n"
13633                                                                           "void main()\n"
13634                                                                           "{\n"
13635                                                                           "    vec4 result = tcs_tes[0];\n"
13636                                                                           "\n"
13637                                                                           "VARIABLE_USE"
13638                                                                           "\n"
13639                                                                           "    tes_gs = result;\n"
13640                                                                           "}\n"
13641                                                                           "\n";
13642         static const GLchar* vs = "#version 430 core\n"
13643                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13644                                                           "\n"
13645                                                           "in  vec4 in_vs;\n"
13646                                                           "out vec4 vs_tcs;\n"
13647                                                           "\n"
13648                                                           "void main()\n"
13649                                                           "{\n"
13650                                                           "    vs_tcs = in_vs;\n"
13651                                                           "}\n"
13652                                                           "\n";
13653         static const GLchar* vs_tested = "#version 430 core\n"
13654                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13655                                                                          "\n"
13656                                                                          "DIRECTION BLOCK_DEFINITION"
13657                                                                          "\n"
13658                                                                          "in  vec4 in_vs;\n"
13659                                                                          "out vec4 vs_tcs;\n"
13660                                                                          "\n"
13661                                                                          "void main()\n"
13662                                                                          "{\n"
13663                                                                          "    vec4 result = in_vs;\n"
13664                                                                          "\n"
13665                                                                          "VARIABLE_USE"
13666                                                                          "\n"
13667                                                                          "    vs_tcs = result;\n"
13668                                                                          "}\n"
13669                                                                          "\n";
13670
13671         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13672                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13673                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13674                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13675                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13676                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13677
13678         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13679                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13680                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13681                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13682                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13683                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13684
13685         static const bool require_modifications_in[6][6] = {
13686                 /* cs  */ { false, false, false, false, false, false },
13687                 /* vs  */ { false, true, false, false, false, false },
13688                 /* tcs */ { false, true, true, false, false, false },
13689                 /* tes */ { false, false, true, true, false, false },
13690                 /* gs  */ { false, false, false, true, true, false },
13691                 /* fs  */ { false, false, false, false, true, true }
13692         };
13693
13694         static const bool require_modifications_out[6][6] = {
13695                 /* cs  */ { false, false, false, false, false, false },
13696                 /* vs  */ { false, true, true, false, false, false },
13697                 /* tcs */ { false, false, true, true, false, false },
13698                 /* tes */ { false, false, false, true, true, false },
13699                 /* gs  */ { false, false, false, false, true, true },
13700                 /* fs  */ { false, false, false, false, false, false }
13701         };
13702
13703         const GLchar* array                                     = "";
13704         const GLchar* direction                         = "out";
13705         const GLchar* index                                     = "";
13706         bool              require_modifications = false;
13707         std::string   source;
13708         testCase&        test_case = m_test_cases[test_case_index];
13709         const GLchar* var_use   = output_use;
13710
13711         if (true == test_case.m_is_input)
13712         {
13713                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13714                 source                            = shaders_in[test_case.m_stage][stage];
13715
13716                 if (test_case.m_stage == stage)
13717                 {
13718                         direction = "in";
13719                         var_use   = input_use;
13720                 }
13721         }
13722         else
13723         {
13724                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13725                 source                            = shaders_out[test_case.m_stage][stage];
13726
13727                 if (test_case.m_stage != stage)
13728                 {
13729                         direction = "in";
13730                         var_use   = input_use;
13731                 }
13732         }
13733
13734         const GLchar* definition = test_case.m_qualify_all ? block_definition_all
13735                         : block_definition_default;
13736
13737         if (test_case.m_stage == stage)
13738         {
13739                 if (true == test_case.m_qualify_all)
13740                 {
13741                         definition = block_definition_all;
13742                 }
13743                 else
13744                 {
13745                         definition = block_definition_one;
13746                 }
13747         }
13748
13749         // Geometry shader inputs, tessellation control shader inputs and outputs, and tessellation evaluation
13750         // inputs all have an additional level of arrayness relative to other shader inputs and outputs.
13751         switch (stage)
13752         {
13753         case Utils::Shader::FRAGMENT:
13754                 break;
13755         case Utils::Shader::TESS_CTRL:
13756                 array = "[]";
13757                 index = "[gl_InvocationID]";
13758                 break;
13759         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13760         // the GS input block is an array, so the DS output can't be declared as an array
13761         case Utils::Shader::GEOMETRY:
13762         case Utils::Shader::TESS_EVAL:
13763         {
13764                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13765                 {
13766                         array = "[]";
13767                         index = "[0]";
13768                 }
13769                 else // match DS output and GS input
13770                 {
13771                         array = "";
13772                         index = "";
13773                 }
13774         }
13775         break;
13776         case Utils::Shader::VERTEX:
13777                 break;
13778         default:
13779                 TCU_FAIL("Invalid enum");
13780         }
13781
13782         if (true == require_modifications)
13783         {
13784                 size_t position = 0;
13785                 size_t temp;
13786
13787                 Utils::replaceToken("DIRECTION", position, direction, source);
13788                 temp = position;
13789                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13790                 position = temp;
13791                 Utils::replaceToken("ARRAY", position, array, source);
13792                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13793
13794                 Utils::replaceAllTokens("INDEX", index, source);
13795         }
13796         else
13797         {
13798                 switch (stage)
13799                 {
13800                 case Utils::Shader::FRAGMENT:
13801                         source = fs;
13802                         break;
13803                 case Utils::Shader::GEOMETRY:
13804                         source = gs;
13805                         break;
13806                 case Utils::Shader::TESS_CTRL:
13807                         source = tcs;
13808                         break;
13809                 case Utils::Shader::TESS_EVAL:
13810                         source = tes;
13811                         break;
13812                 case Utils::Shader::VERTEX:
13813                         source = vs;
13814                         break;
13815                 default:
13816                         TCU_FAIL("Invalid enum");
13817                 }
13818         }
13819
13820         return source;
13821 }
13822
13823 /** Get description of test case
13824  *
13825  * @param test_case_index Index of test case
13826  *
13827  * @return Test case description
13828  **/
13829 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13830 {
13831         std::stringstream stream;
13832         testCase&                 test_case = m_test_cases[test_case_index];
13833
13834         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13835
13836         if (true == test_case.m_is_input)
13837         {
13838                 stream << "input";
13839         }
13840         else
13841         {
13842                 stream << "output";
13843         }
13844
13845         if (true == test_case.m_qualify_all)
13846         {
13847                 stream << ", all members qualified";
13848         }
13849         else
13850         {
13851                 stream << ", not all members qualified";
13852         }
13853
13854         return stream.str();
13855 }
13856
13857 /** Get number of test cases
13858  *
13859  * @return Number of test cases
13860  **/
13861 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13862 {
13863         return static_cast<GLuint>(m_test_cases.size());
13864 }
13865
13866 /** Selects if "compute" stage is relevant for test
13867  *
13868  * @param ignored
13869  *
13870  * @return false
13871  **/
13872 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13873 {
13874         return false;
13875 }
13876
13877 /** Selects if compilation failure is expected result
13878  *
13879  * @param test_case_index Index of test case
13880  *
13881  * @return false when all members are qualified, true otherwise
13882  **/
13883 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13884 {
13885         return (true != m_test_cases[test_case_index].m_qualify_all);
13886 }
13887
13888 /** Prepare all test cases
13889  *
13890  **/
13891 void VaryingBlockMemberLocationsTest::testInit()
13892 {
13893         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13894         {
13895                 if (Utils::Shader::COMPUTE == stage)
13896                 {
13897                         continue;
13898                 }
13899
13900                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13901                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13902                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13903                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13904
13905                 if (Utils::Shader::VERTEX != stage)
13906                 {
13907                         m_test_cases.push_back(test_case_in_all);
13908                         m_test_cases.push_back(test_case_in_one);
13909                 }
13910
13911                 if (Utils::Shader::FRAGMENT != stage)
13912                 {
13913                         m_test_cases.push_back(test_case_out_all);
13914                         m_test_cases.push_back(test_case_out_one);
13915                 }
13916         }
13917 }
13918
13919 /** Constructor
13920  *
13921  * @param context Test framework context
13922  **/
13923 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13924         : NegativeTestBase(
13925                   context, "varying_block_automatic_member_locations",
13926                   "Test verifies that compiler assigns subsequent locations to block members, even if this causes errors")
13927 {
13928 }
13929
13930 /** Source for given test case and stage
13931  *
13932  * @param test_case_index Index of test case
13933  * @param stage           Shader stage
13934  *
13935  * @return Shader source
13936  **/
13937 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13938                                                                                                                                           Utils::Shader::STAGES stage)
13939 {
13940         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13941                                                                                         "    vec4 goku;\n"
13942                                                                                         "    vec4 gohan[4];\n"
13943                                                                                         "    vec4 goten;\n"
13944                                                                                         "    layout (location = 1) vec4 chichi;\n"
13945                                                                                         "    vec4 pan;\n"
13946                                                                                         "} dbzARRAY;\n";
13947         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13948                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13949                                                                          "dbzINDEX.pan;\n";
13950         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
13951                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
13952                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
13953                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
13954                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
13955                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
13956                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
13957                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
13958                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
13959         static const GLchar* fs = "#version 430 core\n"
13960                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13961                                                           "\n"
13962                                                           "in  vec4 gs_fs;\n"
13963                                                           "out vec4 fs_out;\n"
13964                                                           "\n"
13965                                                           "void main()\n"
13966                                                           "{\n"
13967                                                           "    fs_out = gs_fs;\n"
13968                                                           "}\n"
13969                                                           "\n";
13970         static const GLchar* fs_tested = "#version 430 core\n"
13971                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13972                                                                          "\n"
13973                                                                          "BLOCK_DEFINITION"
13974                                                                          "\n"
13975                                                                          "in  vec4 gs_fs;\n"
13976                                                                          "out vec4 fs_out;\n"
13977                                                                          "\n"
13978                                                                          "void main()\n"
13979                                                                          "{\n"
13980                                                                          "    vec4 result = gs_fs;\n"
13981                                                                          "\n"
13982                                                                          "VARIABLE_USE"
13983                                                                          "\n"
13984                                                                          "    fs_out += result;\n"
13985                                                                          "}\n"
13986                                                                          "\n";
13987         static const GLchar* gs = "#version 430 core\n"
13988                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13989                                                           "\n"
13990                                                           "layout(points)                           in;\n"
13991                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13992                                                           "\n"
13993                                                           "in  vec4 tes_gs[];\n"
13994                                                           "out vec4 gs_fs;\n"
13995                                                           "\n"
13996                                                           "void main()\n"
13997                                                           "{\n"
13998                                                           "    gs_fs = tes_gs[0];\n"
13999                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14000                                                           "    EmitVertex();\n"
14001                                                           "    gs_fs = tes_gs[0];\n"
14002                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14003                                                           "    EmitVertex();\n"
14004                                                           "    gs_fs = tes_gs[0];\n"
14005                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14006                                                           "    EmitVertex();\n"
14007                                                           "    gs_fs = tes_gs[0];\n"
14008                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14009                                                           "    EmitVertex();\n"
14010                                                           "}\n"
14011                                                           "\n";
14012         static const GLchar* gs_tested = "#version 430 core\n"
14013                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14014                                                                          "\n"
14015                                                                          "layout(points)                           in;\n"
14016                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14017                                                                          "\n"
14018                                                                          "BLOCK_DEFINITION"
14019                                                                          "\n"
14020                                                                          "in  vec4 tes_gs[];\n"
14021                                                                          "out vec4 gs_fs;\n"
14022                                                                          "\n"
14023                                                                          "void main()\n"
14024                                                                          "{\n"
14025                                                                          "    vec4 result = tes_gs[0];\n"
14026                                                                          "\n"
14027                                                                          "VARIABLE_USE"
14028                                                                          "\n"
14029                                                                          "    gs_fs = result;\n"
14030                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14031                                                                          "    EmitVertex();\n"
14032                                                                          "    gs_fs = result;\n"
14033                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14034                                                                          "    EmitVertex();\n"
14035                                                                          "    gs_fs = result;\n"
14036                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14037                                                                          "    EmitVertex();\n"
14038                                                                          "    gs_fs = result;\n"
14039                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14040                                                                          "    EmitVertex();\n"
14041                                                                          "}\n"
14042                                                                          "\n";
14043         static const GLchar* tcs = "#version 430 core\n"
14044                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14045                                                            "\n"
14046                                                            "layout(vertices = 1) out;\n"
14047                                                            "\n"
14048                                                            "in  vec4 vs_tcs[];\n"
14049                                                            "out vec4 tcs_tes[];\n"
14050                                                            "\n"
14051                                                            "void main()\n"
14052                                                            "{\n"
14053                                                            "\n"
14054                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14055                                                            "\n"
14056                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14057                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14058                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14059                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14060                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14061                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14062                                                            "}\n"
14063                                                            "\n";
14064         static const GLchar* tcs_tested = "#version 430 core\n"
14065                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14066                                                                           "\n"
14067                                                                           "layout(vertices = 1) out;\n"
14068                                                                           "\n"
14069                                                                           "BLOCK_DEFINITION"
14070                                                                           "\n"
14071                                                                           "in  vec4 vs_tcs[];\n"
14072                                                                           "out vec4 tcs_tes[];\n"
14073                                                                           "\n"
14074                                                                           "void main()\n"
14075                                                                           "{\n"
14076                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14077                                                                           "\n"
14078                                                                           "VARIABLE_USE"
14079                                                                           "\n"
14080                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14081                                                                           "\n"
14082                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14083                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14084                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14085                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14086                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14087                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14088                                                                           "}\n"
14089                                                                           "\n";
14090         static const GLchar* tes = "#version 430 core\n"
14091                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14092                                                            "\n"
14093                                                            "layout(isolines, point_mode) in;\n"
14094                                                            "\n"
14095                                                            "in  vec4 tcs_tes[];\n"
14096                                                            "out vec4 tes_gs;\n"
14097                                                            "\n"
14098                                                            "void main()\n"
14099                                                            "{\n"
14100                                                            "    tes_gs = tcs_tes[0];\n"
14101                                                            "}\n"
14102                                                            "\n";
14103         static const GLchar* tes_tested = "#version 430 core\n"
14104                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14105                                                                           "\n"
14106                                                                           "layout(isolines, point_mode) in;\n"
14107                                                                           "\n"
14108                                                                           "BLOCK_DEFINITION"
14109                                                                           "\n"
14110                                                                           "in  vec4 tcs_tes[];\n"
14111                                                                           "out vec4 tes_gs;\n"
14112                                                                           "\n"
14113                                                                           "void main()\n"
14114                                                                           "{\n"
14115                                                                           "    vec4 result = tcs_tes[0];\n"
14116                                                                           "\n"
14117                                                                           "VARIABLE_USE"
14118                                                                           "\n"
14119                                                                           "    tes_gs += result;\n"
14120                                                                           "}\n"
14121                                                                           "\n";
14122         static const GLchar* vs = "#version 430 core\n"
14123                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14124                                                           "\n"
14125                                                           "in  vec4 in_vs;\n"
14126                                                           "out vec4 vs_tcs;\n"
14127                                                           "\n"
14128                                                           "void main()\n"
14129                                                           "{\n"
14130                                                           "    vs_tcs = in_vs;\n"
14131                                                           "}\n"
14132                                                           "\n";
14133         static const GLchar* vs_tested = "#version 430 core\n"
14134                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14135                                                                          "\n"
14136                                                                          "BLOCK_DEFINITION"
14137                                                                          "\n"
14138                                                                          "in  vec4 in_vs;\n"
14139                                                                          "out vec4 vs_tcs;\n"
14140                                                                          "\n"
14141                                                                          "void main()\n"
14142                                                                          "{\n"
14143                                                                          "    vec4 result = in_vs;\n"
14144                                                                          "\n"
14145                                                                          "VARIABLE_USE"
14146                                                                          "\n"
14147                                                                          "    vs_tcs += result;\n"
14148                                                                          "}\n"
14149                                                                          "\n";
14150
14151         const GLchar* array             = "";
14152         const GLchar* direction = "out";
14153         const GLchar* index             = "";
14154         std::string   source;
14155         testCase&        test_case = m_test_cases[test_case_index];
14156         const GLchar* var_use   = output_use;
14157
14158         if (true == test_case.m_is_input)
14159         {
14160                 direction = "in ";
14161                 var_use   = input_use;
14162         }
14163
14164         if (test_case.m_stage == stage)
14165         {
14166                 size_t position = 0;
14167                 size_t temp;
14168
14169                 switch (stage)
14170                 {
14171                 case Utils::Shader::FRAGMENT:
14172                         source = fs_tested;
14173                         break;
14174                 case Utils::Shader::GEOMETRY:
14175                         source = gs_tested;
14176                         array  = "[]";
14177                         index  = "[0]";
14178                         break;
14179                 case Utils::Shader::TESS_CTRL:
14180                         source = tcs_tested;
14181                         array  = "[]";
14182                         index  = "[gl_InvocationID]";
14183                         break;
14184                 case Utils::Shader::TESS_EVAL:
14185                         source = tes_tested;
14186                         array  = "[]";
14187                         index  = "[0]";
14188                         break;
14189                 case Utils::Shader::VERTEX:
14190                         source = vs_tested;
14191                         break;
14192                 default:
14193                         TCU_FAIL("Invalid enum");
14194                 }
14195
14196                 temp = position;
14197                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14198                 position = temp;
14199                 Utils::replaceToken("DIRECTION", position, direction, source);
14200                 Utils::replaceToken("ARRAY", position, array, source);
14201                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14202
14203                 Utils::replaceAllTokens("INDEX", index, source);
14204         }
14205         else
14206         {
14207                 switch (stage)
14208                 {
14209                 case Utils::Shader::FRAGMENT:
14210                         source = fs;
14211                         break;
14212                 case Utils::Shader::GEOMETRY:
14213                         source = gs;
14214                         break;
14215                 case Utils::Shader::TESS_CTRL:
14216                         source = tcs;
14217                         break;
14218                 case Utils::Shader::TESS_EVAL:
14219                         source = tes;
14220                         break;
14221                 case Utils::Shader::VERTEX:
14222                         source = vs;
14223                         break;
14224                 default:
14225                         TCU_FAIL("Invalid enum");
14226                 }
14227         }
14228
14229         return source;
14230 }
14231
14232 /** Get description of test case
14233  *
14234  * @param test_case_index Index of test case
14235  *
14236  * @return Test case description
14237  **/
14238 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14239 {
14240         std::stringstream stream;
14241         testCase&                 test_case = m_test_cases[test_case_index];
14242
14243         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14244
14245         if (true == test_case.m_is_input)
14246         {
14247                 stream << "input";
14248         }
14249         else
14250         {
14251                 stream << "output";
14252         }
14253
14254         return stream.str();
14255 }
14256
14257 /** Get number of test cases
14258  *
14259  * @return Number of test cases
14260  **/
14261 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14262 {
14263         return static_cast<GLuint>(m_test_cases.size());
14264 }
14265
14266 /** Selects if "compute" stage is relevant for test
14267  *
14268  * @param ignored
14269  *
14270  * @return false
14271  **/
14272 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14273 {
14274         return false;
14275 }
14276
14277 /** Prepare all test cases
14278  *
14279  **/
14280 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14281 {
14282         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14283         {
14284                 if (Utils::Shader::COMPUTE == stage)
14285                 {
14286                         continue;
14287                 }
14288
14289                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14290                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14291
14292                 if (Utils::Shader::VERTEX != stage)
14293                 {
14294                         m_test_cases.push_back(test_case_in);
14295                 }
14296
14297                 if (Utils::Shader::FRAGMENT != stage)
14298                 {
14299                         m_test_cases.push_back(test_case_out);
14300                 }
14301         }
14302 }
14303
14304 /** Constructor
14305  *
14306  * @param context Test framework context
14307  **/
14308 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14309         : NegativeTestBase(context, "varying_location_limit",
14310                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14311 {
14312 }
14313
14314 /** Source for given test case and stage
14315  *
14316  * @param test_case_index Index of test case
14317  * @param stage           Shader stage
14318  *
14319  * @return Shader source
14320  **/
14321 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14322 {
14323         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14324         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14325                                                                          "    {\n"
14326                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14327                                                                          "    }\n";
14328         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14329                                                                           "    if (vec4(0) == result)\n"
14330                                                                           "    {\n"
14331                                                                           "        gokuINDEX = TYPE(1);\n"
14332                                                                           "    }\n";
14333         static const GLchar* fs = "#version 430 core\n"
14334                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14335                                                           "\n"
14336                                                           "in  vec4 gs_fs;\n"
14337                                                           "out vec4 fs_out;\n"
14338                                                           "\n"
14339                                                           "void main()\n"
14340                                                           "{\n"
14341                                                           "    fs_out = gs_fs;\n"
14342                                                           "}\n"
14343                                                           "\n";
14344         static const GLchar* fs_tested = "#version 430 core\n"
14345                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14346                                                                          "\n"
14347                                                                          "VAR_DEFINITION"
14348                                                                          "\n"
14349                                                                          "in  vec4 gs_fs;\n"
14350                                                                          "out vec4 fs_out;\n"
14351                                                                          "\n"
14352                                                                          "void main()\n"
14353                                                                          "{\n"
14354                                                                          "    vec4 result = gs_fs;\n"
14355                                                                          "\n"
14356                                                                          "VARIABLE_USE"
14357                                                                          "\n"
14358                                                                          "    fs_out += result;\n"
14359                                                                          "}\n"
14360                                                                          "\n";
14361         static const GLchar* gs = "#version 430 core\n"
14362                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14363                                                           "\n"
14364                                                           "layout(points)                           in;\n"
14365                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14366                                                           "\n"
14367                                                           "in  vec4 tes_gs[];\n"
14368                                                           "out vec4 gs_fs;\n"
14369                                                           "\n"
14370                                                           "void main()\n"
14371                                                           "{\n"
14372                                                           "    gs_fs = tes_gs[0];\n"
14373                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14374                                                           "    EmitVertex();\n"
14375                                                           "    gs_fs = tes_gs[0];\n"
14376                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14377                                                           "    EmitVertex();\n"
14378                                                           "    gs_fs = tes_gs[0];\n"
14379                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14380                                                           "    EmitVertex();\n"
14381                                                           "    gs_fs = tes_gs[0];\n"
14382                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14383                                                           "    EmitVertex();\n"
14384                                                           "}\n"
14385                                                           "\n";
14386         static const GLchar* gs_tested = "#version 430 core\n"
14387                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14388                                                                          "\n"
14389                                                                          "layout(points)                           in;\n"
14390                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14391                                                                          "\n"
14392                                                                          "VAR_DEFINITION"
14393                                                                          "\n"
14394                                                                          "in  vec4 tes_gs[];\n"
14395                                                                          "out vec4 gs_fs;\n"
14396                                                                          "\n"
14397                                                                          "void main()\n"
14398                                                                          "{\n"
14399                                                                          "    vec4 result = tes_gs[0];\n"
14400                                                                          "\n"
14401                                                                          "VARIABLE_USE"
14402                                                                          "\n"
14403                                                                          "    gs_fs = result;\n"
14404                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14405                                                                          "    EmitVertex();\n"
14406                                                                          "    gs_fs = result;\n"
14407                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14408                                                                          "    EmitVertex();\n"
14409                                                                          "    gs_fs = result;\n"
14410                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14411                                                                          "    EmitVertex();\n"
14412                                                                          "    gs_fs = result;\n"
14413                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14414                                                                          "    EmitVertex();\n"
14415                                                                          "}\n"
14416                                                                          "\n";
14417         static const GLchar* tcs = "#version 430 core\n"
14418                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14419                                                            "\n"
14420                                                            "layout(vertices = 1) out;\n"
14421                                                            "\n"
14422                                                            "in  vec4 vs_tcs[];\n"
14423                                                            "out vec4 tcs_tes[];\n"
14424                                                            "\n"
14425                                                            "void main()\n"
14426                                                            "{\n"
14427                                                            "\n"
14428                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14429                                                            "\n"
14430                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14431                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14432                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14433                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14434                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14435                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14436                                                            "}\n"
14437                                                            "\n";
14438         static const GLchar* tcs_tested = "#version 430 core\n"
14439                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14440                                                                           "\n"
14441                                                                           "layout(vertices = 1) out;\n"
14442                                                                           "\n"
14443                                                                           "VAR_DEFINITION"
14444                                                                           "\n"
14445                                                                           "in  vec4 vs_tcs[];\n"
14446                                                                           "out vec4 tcs_tes[];\n"
14447                                                                           "\n"
14448                                                                           "void main()\n"
14449                                                                           "{\n"
14450                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14451                                                                           "\n"
14452                                                                           "VARIABLE_USE"
14453                                                                           "\n"
14454                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14455                                                                           "\n"
14456                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14457                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14458                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14459                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14460                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14461                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14462                                                                           "}\n"
14463                                                                           "\n";
14464         static const GLchar* tes = "#version 430 core\n"
14465                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14466                                                            "\n"
14467                                                            "layout(isolines, point_mode) in;\n"
14468                                                            "\n"
14469                                                            "in  vec4 tcs_tes[];\n"
14470                                                            "out vec4 tes_gs;\n"
14471                                                            "\n"
14472                                                            "void main()\n"
14473                                                            "{\n"
14474                                                            "    tes_gs = tcs_tes[0];\n"
14475                                                            "}\n"
14476                                                            "\n";
14477         static const GLchar* tes_tested = "#version 430 core\n"
14478                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14479                                                                           "\n"
14480                                                                           "layout(isolines, point_mode) in;\n"
14481                                                                           "\n"
14482                                                                           "VAR_DEFINITION"
14483                                                                           "\n"
14484                                                                           "in  vec4 tcs_tes[];\n"
14485                                                                           "out vec4 tes_gs;\n"
14486                                                                           "\n"
14487                                                                           "void main()\n"
14488                                                                           "{\n"
14489                                                                           "    vec4 result = tcs_tes[0];\n"
14490                                                                           "\n"
14491                                                                           "VARIABLE_USE"
14492                                                                           "\n"
14493                                                                           "    tes_gs += result;\n"
14494                                                                           "}\n"
14495                                                                           "\n";
14496         static const GLchar* vs = "#version 430 core\n"
14497                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14498                                                           "\n"
14499                                                           "in  vec4 in_vs;\n"
14500                                                           "out vec4 vs_tcs;\n"
14501                                                           "\n"
14502                                                           "void main()\n"
14503                                                           "{\n"
14504                                                           "    vs_tcs = in_vs;\n"
14505                                                           "}\n"
14506                                                           "\n";
14507         static const GLchar* vs_tested = "#version 430 core\n"
14508                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14509                                                                          "\n"
14510                                                                          "VAR_DEFINITION"
14511                                                                          "\n"
14512                                                                          "in  vec4 in_vs;\n"
14513                                                                          "out vec4 vs_tcs;\n"
14514                                                                          "\n"
14515                                                                          "void main()\n"
14516                                                                          "{\n"
14517                                                                          "    vec4 result = in_vs;\n"
14518                                                                          "\n"
14519                                                                          "VARIABLE_USE"
14520                                                                          "\n"
14521                                                                          "    vs_tcs += result;\n"
14522                                                                          "}\n"
14523                                                                          "\n";
14524
14525         std::string source;
14526         testCase&   test_case = m_test_cases[test_case_index];
14527
14528         if (test_case.m_stage == stage)
14529         {
14530                 const GLchar*                    array = "";
14531                 GLchar                                   buffer[16];
14532                 const GLchar*                    direction = "in ";
14533                 const GLchar*                    flat     = "";
14534                 const GLchar*                    index   = "";
14535                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14536                 size_t                                   position  = 0;
14537                 size_t                                   temp;
14538                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14539                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14540                 const GLchar*                    var_use   = input_use;
14541
14542                 if (false == test_case.m_is_input)
14543                 {
14544                         direction = "out";
14545                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14546                         storage   = Utils::Variable::VARYING_OUTPUT;
14547                         var_use   = output_use;
14548                 }
14549
14550                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14551                 {
14552                         flat = "flat";
14553                 }
14554
14555                 sprintf(buffer, "%d", last);
14556
14557                 switch (stage)
14558                 {
14559                 case Utils::Shader::FRAGMENT:
14560                         source = fs_tested;
14561                         break;
14562                 case Utils::Shader::GEOMETRY:
14563                         source = gs_tested;
14564                         array  = "[]";
14565                         index  = "[0]";
14566                         break;
14567                 case Utils::Shader::TESS_CTRL:
14568                         source = tcs_tested;
14569                         array  = "[]";
14570                         index  = "[gl_InvocationID]";
14571                         break;
14572                 case Utils::Shader::TESS_EVAL:
14573                         source = tes_tested;
14574                         array  = "[]";
14575                         index  = "[0]";
14576                         break;
14577                 case Utils::Shader::VERTEX:
14578                         source = vs_tested;
14579                         break;
14580                 default:
14581                         TCU_FAIL("Invalid enum");
14582                 }
14583
14584                 temp = position;
14585                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14586                 position = temp;
14587                 Utils::replaceToken("LAST", position, buffer, source);
14588                 Utils::replaceToken("FLAT", position, flat, source);
14589                 Utils::replaceToken("DIRECTION", position, direction, source);
14590                 Utils::replaceToken("ARRAY", position, array, source);
14591                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14592
14593                 Utils::replaceAllTokens("TYPE", type_name, source);
14594                 Utils::replaceAllTokens("INDEX", index, source);
14595         }
14596         else
14597         {
14598                 switch (stage)
14599                 {
14600                 case Utils::Shader::FRAGMENT:
14601                         source = fs;
14602                         break;
14603                 case Utils::Shader::GEOMETRY:
14604                         source = gs;
14605                         break;
14606                 case Utils::Shader::TESS_CTRL:
14607                         source = tcs;
14608                         break;
14609                 case Utils::Shader::TESS_EVAL:
14610                         source = tes;
14611                         break;
14612                 case Utils::Shader::VERTEX:
14613                         source = vs;
14614                         break;
14615                 default:
14616                         TCU_FAIL("Invalid enum");
14617                 }
14618         }
14619
14620         return source;
14621 }
14622
14623 /** Get description of test case
14624  *
14625  * @param test_case_index Index of test case
14626  *
14627  * @return Test case description
14628  **/
14629 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14630 {
14631         std::stringstream stream;
14632         testCase&                 test_case = m_test_cases[test_case_index];
14633
14634         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14635                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14636
14637         if (true == test_case.m_is_input)
14638         {
14639                 stream << "input";
14640         }
14641         else
14642         {
14643                 stream << "output";
14644         }
14645
14646         return stream.str();
14647 }
14648
14649 /** Get number of test cases
14650  *
14651  * @return Number of test cases
14652  **/
14653 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14654 {
14655         return static_cast<GLuint>(m_test_cases.size());
14656 }
14657
14658 /** Selects if "compute" stage is relevant for test
14659  *
14660  * @param ignored
14661  *
14662  * @return false
14663  **/
14664 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14665 {
14666         return false;
14667 }
14668
14669 /** Prepare all test cases
14670  *
14671  **/
14672 void VaryingLocationLimitTest::testInit()
14673 {
14674         const GLuint n_types = getTypesNumber();
14675
14676         for (GLuint i = 0; i < n_types; ++i)
14677         {
14678                 const Utils::Type& type = getType(i);
14679
14680                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14681                 {
14682                         if (Utils::Shader::COMPUTE == stage)
14683                         {
14684                                 continue;
14685                         }
14686
14687                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14688                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14689
14690                         m_test_cases.push_back(test_case_in);
14691
14692                         if (Utils::Shader::FRAGMENT != stage)
14693                         {
14694                                 m_test_cases.push_back(test_case_out);
14695                         }
14696                 }
14697         }
14698 }
14699
14700 /** Constructor
14701  *
14702  * @param context Test framework context
14703  **/
14704 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14705         : VaryingLocationsTest(context, "varying_components",
14706                                                    "Test verifies that input and output components are respected")
14707 {
14708 }
14709
14710 /** Constructor
14711  *
14712  * @param context          Test framework context
14713  * @param test_name        Name of test
14714  * @param test_description Description of test
14715  **/
14716 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14717                                                                                          const glw::GLchar* test_description)
14718         : VaryingLocationsTest(context, test_name, test_description)
14719 {
14720 }
14721
14722 /** Get interface of program
14723  *
14724  * @param test_case_index     Test case
14725  * @param program_interface   Interface of program
14726  * @param varying_passthrough Collection of connections between in and out variables
14727  **/
14728 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14729                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14730 {
14731         GLuint                             array_length = getArrayLength();
14732         const testCase&            test_case    = m_test_cases[test_case_index];
14733         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14734         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14735
14736         /* Zero means no array, however we still need at least 1 slot of data */
14737         if (0 == array_length)
14738         {
14739                 array_length += 1;
14740         }
14741
14742         /* Generate data */
14743         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14744         const size_t                            data_size = data.size();
14745
14746         /* Prepare data for variables */
14747         m_data.resize(array_length * data_size);
14748
14749         GLubyte*           dst = &m_data[0];
14750         const GLubyte* src = &data[0];
14751
14752         for (GLuint i = 0; i < array_length; ++i)
14753         {
14754                 memcpy(dst + data_size * i, src, data_size);
14755         }
14756
14757         /* Prepare interface for each stage */
14758         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14759         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14760         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14761         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14762         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14763 }
14764
14765 /** Get type name
14766  *
14767  * @param test_case_index Index of test case
14768  *
14769  * @return Name of type test in test_case_index
14770  **/
14771 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14772 {
14773         std::string name;
14774
14775         const testCase& test_case = m_test_cases[test_case_index];
14776
14777         name = "Type: ";
14778
14779         switch (test_case.m_type)
14780         {
14781         case Utils::Type::Double:
14782                 name.append(Utils::Type::_double.GetGLSLTypeName());
14783                 break;
14784         case Utils::Type::Float:
14785                 name.append(Utils::Type::_float.GetGLSLTypeName());
14786                 break;
14787         case Utils::Type::Int:
14788                 name.append(Utils::Type::_int.GetGLSLTypeName());
14789                 break;
14790         case Utils::Type::Uint:
14791                 name.append(Utils::Type::uint.GetGLSLTypeName());
14792                 break;
14793         }
14794
14795         name.append(", layout: ");
14796
14797         switch (test_case.m_layout)
14798         {
14799         case GVEC4:
14800                 name.append("GVEC4");
14801                 break;
14802         case SCALAR_GVEC3:
14803                 name.append("SCALAR_GVEC3");
14804                 break;
14805         case GVEC3_SCALAR:
14806                 name.append("GVEC3_SCALAR");
14807                 break;
14808         case GVEC2_GVEC2:
14809                 name.append("GVEC2_GVEC2");
14810                 break;
14811         case GVEC2_SCALAR_SCALAR:
14812                 name.append("GVEC2_SCALAR_SCALAR");
14813                 break;
14814         case SCALAR_GVEC2_SCALAR:
14815                 name.append("SCALAR_GVEC2_SCALAR");
14816                 break;
14817         case SCALAR_SCALAR_GVEC2:
14818                 name.append("SCALAR_SCALAR_GVEC2");
14819                 break;
14820         case SCALAR_SCALAR_SCALAR_SCALAR:
14821                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14822                 break;
14823         }
14824
14825         return name;
14826 }
14827
14828 /** Returns number of types to test
14829  *
14830  * @return Number of types, 34
14831  **/
14832 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14833 {
14834         return static_cast<GLuint>(m_test_cases.size());
14835 }
14836
14837 /* Prepare test cases */
14838 void VaryingComponentsTest::testInit()
14839 {
14840         // FIXME: add tests for doubles, which have specific rules
14841
14842         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14843         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14844         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14845         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14846         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14847         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14848         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14849         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14850
14851         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14852         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14853         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14854         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14855         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14856         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14857         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14858         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14859
14860         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14861         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14862         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14863         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14864         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14865         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14866         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14867         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14868 }
14869
14870 /** Inform that test use components
14871  *
14872  * @param ignored
14873  *
14874  * @return true
14875  **/
14876 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14877 {
14878         return true;
14879 }
14880
14881 /** Get length of arrays that should be used during test
14882  *
14883  * @return 0u - no array at all
14884  **/
14885 GLuint VaryingComponentsTest::getArrayLength()
14886 {
14887         return 0;
14888 }
14889
14890 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14891 {
14892         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14893
14894         globals.append("const uint comp_x = 0u;\n"
14895                                    "const uint comp_y = 1u;\n"
14896                                    "const uint comp_z = 2u;\n"
14897                                    "const uint comp_w = 3u;\n");
14898
14899         return globals;
14900 }
14901
14902 /**
14903  *
14904  **/
14905 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14906                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14907 {
14908         GLchar            buffer[16];
14909         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14910         size_t            position = 0;
14911         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14912
14913         Utils::replaceToken("PREFIX", position, prefix, result);
14914         Utils::replaceToken("NAME", position, name, result);
14915
14916         sprintf(buffer, "%d", location);
14917         Utils::replaceToken("LOCATION", position, buffer, result);
14918
14919         sprintf(buffer, "%d", component);
14920         Utils::replaceToken("COMPONENT", position, buffer, result);
14921
14922         return result;
14923 }
14924
14925 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14926                                                                                                          const glw::GLchar* interpolation)
14927 {
14928         size_t          position   = 0;
14929         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14930
14931         Utils::replaceToken("LOCATION", position, location, qualifiers);
14932         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14933         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14934
14935         return qualifiers;
14936 }
14937
14938 /**
14939  *
14940  **/
14941 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14942                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14943                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14944 {
14945         const GLuint                    array_length = getArrayLength();
14946         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14947         descriptor                              desc_in[8];
14948         descriptor                              desc_out[8];
14949         const GLuint                    first_in_loc  = 0;
14950         const GLuint                    first_out_loc = 0;
14951         const GLchar*                   interpolation = "";
14952         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
14953         GLuint                                  last_out_loc  = 0;
14954         GLuint                                  n_desc            = 0;
14955         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
14956
14957         /* Select interpolation */
14958         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
14959         {
14960                 interpolation = " flat";
14961         }
14962
14963         if (Utils::Shader::FRAGMENT != stage)
14964         {
14965                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
14966         }
14967
14968         switch (test_case.m_layout)
14969         {
14970         case GVEC4:
14971                 n_desc = 2;
14972                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
14973                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
14974
14975                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
14976                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
14977                 break;
14978         case SCALAR_GVEC3:
14979                 n_desc = 4;
14980                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14981                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14982                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
14983                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
14984
14985                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14986                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14987                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
14988                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
14989                 break;
14990         case GVEC3_SCALAR:
14991                 n_desc = 4;
14992                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
14993                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
14994                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14995                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14996
14997                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
14998                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
14999                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15000                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15001                 break;
15002         case GVEC2_GVEC2:
15003                 n_desc = 4;
15004                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
15005                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
15006                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
15007                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
15008
15009                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
15010                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
15011                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15012                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15013                 break;
15014         case GVEC2_SCALAR_SCALAR:
15015                 n_desc = 6;
15016                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
15017                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
15018                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15019                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15020                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15021                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15022
15023                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
15024                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
15025                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15026                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15027                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15028                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15029                 break;
15030         case SCALAR_GVEC2_SCALAR:
15031                 n_desc = 6;
15032                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15033                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15034                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
15035                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
15036                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15037                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15038
15039                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15040                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15041                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
15042                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
15043                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15044                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15045                 break;
15046         case SCALAR_SCALAR_GVEC2:
15047                 n_desc = 6;
15048                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15049                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15050                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15051                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15052                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
15053                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
15054
15055                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15056                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15057                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15058                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15059                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15060                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15061                 break;
15062         case SCALAR_SCALAR_SCALAR_SCALAR:
15063                 n_desc = 8;
15064                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15065                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15066                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15067                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15068                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15069                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15070                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15071                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15072
15073                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15074                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15075                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15076                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15077                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15078                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15079                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15080                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15081                 break;
15082         }
15083
15084         for (GLuint i = 0; i < n_desc; ++i)
15085         {
15086                 const descriptor& in_desc = desc_in[i];
15087
15088                 Utils::Variable* in =
15089                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15090
15091                 if (Utils::Shader::FRAGMENT != stage)
15092                 {
15093                         const descriptor& out_desc = desc_out[i];
15094
15095                         Utils::Variable* out =
15096                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15097
15098                         varying_passthrough.Add(stage, in, out);
15099                 }
15100         }
15101
15102         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15103 }
15104
15105 /**
15106  *
15107  **/
15108 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15109                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15110                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15111 {
15112         const GLuint       array_length   = getArrayLength();
15113         const GLuint       component_size = basic_type.GetSize();
15114         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15115         const GLuint       offset                 = desc.m_component * component_size;
15116         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15117         const GLuint       size                   = desc.m_n_rows * component_size;
15118         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15119         Utils::Variable*   var                    = 0;
15120
15121         if (Utils::Variable::VARYING_INPUT == storage)
15122         {
15123                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15124                                            desc.m_location /* expected_location */, type, /* built_in_type */
15125                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15126                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15127         }
15128         else
15129         {
15130                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15131                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15132                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15133                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15134         }
15135
15136         return var;
15137 }
15138
15139 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15140                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15141                                                                                            const glw::GLchar* name)
15142 {
15143         m_component             = component;
15144         m_component_str = component_str;
15145         m_location              = location;
15146         m_location_str  = location_str;
15147         m_n_rows                = n_rows;
15148         m_name                  = name;
15149 }
15150
15151 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15152         : m_layout(layout), m_type(type)
15153 {
15154 }
15155
15156 /** Constructor
15157  *
15158  * @param context Test framework context
15159  **/
15160 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15161         : VaryingComponentsTest(context, "varying_array_components",
15162                                                         "Test verifies that input and output components are respected for arrays")
15163 {
15164 }
15165
15166 /** Get length of arrays that should be used during test
15167  *
15168  * @return 4u
15169  **/
15170 GLuint VaryingArrayComponentsTest::getArrayLength()
15171 {
15172         return 4u;
15173 }
15174
15175 /** Constructor
15176  *
15177  * @param context Test framework context
15178  **/
15179 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15180         : NegativeTestBase(context, "varying_exceeding_components",
15181                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15182 {
15183 }
15184
15185 /** Source for given test case and stage
15186  *
15187  * @param test_case_index Index of test case
15188  * @param stage           Shader stage
15189  *
15190  * @return Shader source
15191  **/
15192 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15193 {
15194         static const GLchar* var_definition_arr =
15195                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15196         static const GLchar* var_definition_one =
15197                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15198         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15199                                                                                  "    {\n"
15200                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15201                                                                                  "    }\n";
15202         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15203                                                                                  "    {\n"
15204                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15205                                                                                  "    }\n";
15206         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15207                                                                                   "    if (vec4(0) == result)\n"
15208                                                                                   "    {\n"
15209                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15210                                                                                   "    }\n";
15211         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15212                                                                                   "    if (vec4(0) == result)\n"
15213                                                                                   "    {\n"
15214                                                                                   "        gokuINDEX = TYPE(1);\n"
15215                                                                                   "    }\n";
15216         static const GLchar* fs = "#version 430 core\n"
15217                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15218                                                           "\n"
15219                                                           "in  vec4 gs_fs;\n"
15220                                                           "out vec4 fs_out;\n"
15221                                                           "\n"
15222                                                           "void main()\n"
15223                                                           "{\n"
15224                                                           "    fs_out = gs_fs;\n"
15225                                                           "}\n"
15226                                                           "\n";
15227         static const GLchar* fs_tested = "#version 430 core\n"
15228                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15229                                                                          "\n"
15230                                                                          "VAR_DEFINITION"
15231                                                                          "\n"
15232                                                                          "in  vec4 gs_fs;\n"
15233                                                                          "out vec4 fs_out;\n"
15234                                                                          "\n"
15235                                                                          "void main()\n"
15236                                                                          "{\n"
15237                                                                          "    vec4 result = gs_fs;\n"
15238                                                                          "\n"
15239                                                                          "VARIABLE_USE"
15240                                                                          "\n"
15241                                                                          "    fs_out += result;\n"
15242                                                                          "}\n"
15243                                                                          "\n";
15244         static const GLchar* gs = "#version 430 core\n"
15245                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15246                                                           "\n"
15247                                                           "layout(points)                           in;\n"
15248                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15249                                                           "\n"
15250                                                           "in  vec4 tes_gs[];\n"
15251                                                           "out vec4 gs_fs;\n"
15252                                                           "\n"
15253                                                           "void main()\n"
15254                                                           "{\n"
15255                                                           "    gs_fs = tes_gs[0];\n"
15256                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15257                                                           "    EmitVertex();\n"
15258                                                           "    gs_fs = tes_gs[0];\n"
15259                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15260                                                           "    EmitVertex();\n"
15261                                                           "    gs_fs = tes_gs[0];\n"
15262                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15263                                                           "    EmitVertex();\n"
15264                                                           "    gs_fs = tes_gs[0];\n"
15265                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15266                                                           "    EmitVertex();\n"
15267                                                           "}\n"
15268                                                           "\n";
15269         static const GLchar* gs_tested = "#version 430 core\n"
15270                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15271                                                                          "\n"
15272                                                                          "layout(points)                           in;\n"
15273                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15274                                                                          "\n"
15275                                                                          "VAR_DEFINITION"
15276                                                                          "\n"
15277                                                                          "in  vec4 tes_gs[];\n"
15278                                                                          "out vec4 gs_fs;\n"
15279                                                                          "\n"
15280                                                                          "void main()\n"
15281                                                                          "{\n"
15282                                                                          "    vec4 result = tes_gs[0];\n"
15283                                                                          "\n"
15284                                                                          "VARIABLE_USE"
15285                                                                          "\n"
15286                                                                          "    gs_fs = result;\n"
15287                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15288                                                                          "    EmitVertex();\n"
15289                                                                          "    gs_fs = result;\n"
15290                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15291                                                                          "    EmitVertex();\n"
15292                                                                          "    gs_fs = result;\n"
15293                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15294                                                                          "    EmitVertex();\n"
15295                                                                          "    gs_fs = result;\n"
15296                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15297                                                                          "    EmitVertex();\n"
15298                                                                          "}\n"
15299                                                                          "\n";
15300         static const GLchar* tcs = "#version 430 core\n"
15301                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15302                                                            "\n"
15303                                                            "layout(vertices = 1) out;\n"
15304                                                            "\n"
15305                                                            "in  vec4 vs_tcs[];\n"
15306                                                            "out vec4 tcs_tes[];\n"
15307                                                            "\n"
15308                                                            "void main()\n"
15309                                                            "{\n"
15310                                                            "\n"
15311                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15312                                                            "\n"
15313                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15314                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15315                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15316                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15317                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15318                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15319                                                            "}\n"
15320                                                            "\n";
15321         static const GLchar* tcs_tested = "#version 430 core\n"
15322                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15323                                                                           "\n"
15324                                                                           "layout(vertices = 1) out;\n"
15325                                                                           "\n"
15326                                                                           "VAR_DEFINITION"
15327                                                                           "\n"
15328                                                                           "in  vec4 vs_tcs[];\n"
15329                                                                           "out vec4 tcs_tes[];\n"
15330                                                                           "\n"
15331                                                                           "void main()\n"
15332                                                                           "{\n"
15333                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15334                                                                           "\n"
15335                                                                           "VARIABLE_USE"
15336                                                                           "\n"
15337                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15338                                                                           "\n"
15339                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15340                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15341                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15342                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15343                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15344                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15345                                                                           "}\n"
15346                                                                           "\n";
15347         static const GLchar* tes = "#version 430 core\n"
15348                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15349                                                            "\n"
15350                                                            "layout(isolines, point_mode) in;\n"
15351                                                            "\n"
15352                                                            "in  vec4 tcs_tes[];\n"
15353                                                            "out vec4 tes_gs;\n"
15354                                                            "\n"
15355                                                            "void main()\n"
15356                                                            "{\n"
15357                                                            "    tes_gs = tcs_tes[0];\n"
15358                                                            "}\n"
15359                                                            "\n";
15360         static const GLchar* tes_tested = "#version 430 core\n"
15361                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15362                                                                           "\n"
15363                                                                           "layout(isolines, point_mode) in;\n"
15364                                                                           "\n"
15365                                                                           "VAR_DEFINITION"
15366                                                                           "\n"
15367                                                                           "in  vec4 tcs_tes[];\n"
15368                                                                           "out vec4 tes_gs;\n"
15369                                                                           "\n"
15370                                                                           "void main()\n"
15371                                                                           "{\n"
15372                                                                           "    vec4 result = tcs_tes[0];\n"
15373                                                                           "\n"
15374                                                                           "VARIABLE_USE"
15375                                                                           "\n"
15376                                                                           "    tes_gs += result;\n"
15377                                                                           "}\n"
15378                                                                           "\n";
15379         static const GLchar* vs = "#version 430 core\n"
15380                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15381                                                           "\n"
15382                                                           "in  vec4 in_vs;\n"
15383                                                           "out vec4 vs_tcs;\n"
15384                                                           "\n"
15385                                                           "void main()\n"
15386                                                           "{\n"
15387                                                           "    vs_tcs = in_vs;\n"
15388                                                           "}\n"
15389                                                           "\n";
15390         static const GLchar* vs_tested = "#version 430 core\n"
15391                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15392                                                                          "\n"
15393                                                                          "VAR_DEFINITION"
15394                                                                          "\n"
15395                                                                          "in  vec4 in_vs;\n"
15396                                                                          "out vec4 vs_tcs;\n"
15397                                                                          "\n"
15398                                                                          "void main()\n"
15399                                                                          "{\n"
15400                                                                          "    vec4 result = in_vs;\n"
15401                                                                          "\n"
15402                                                                          "VARIABLE_USE"
15403                                                                          "\n"
15404                                                                          "    vs_tcs += result;\n"
15405                                                                          "}\n"
15406                                                                          "\n";
15407
15408         std::string source;
15409         testCase&   test_case = m_test_cases[test_case_index];
15410
15411         if (test_case.m_stage == stage)
15412         {
15413                 const GLchar* array = "";
15414                 GLchar            buffer[16];
15415                 const GLchar* var_definition = 0;
15416                 const GLchar* direction          = "in ";
15417                 const GLchar* index                      = "";
15418                 size_t            position               = 0;
15419                 size_t            temp;
15420                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15421                 const GLchar* var_use   = 0;
15422
15423                 if (false == test_case.m_is_input)
15424                 {
15425                         direction = "out";
15426
15427                         if (false == test_case.m_is_array)
15428                         {
15429                                 var_definition = var_definition_one;
15430                                 var_use            = output_use_one;
15431                         }
15432                         else
15433                         {
15434                                 var_definition = var_definition_arr;
15435                                 var_use            = output_use_arr;
15436                         }
15437                 }
15438                 else
15439                 {
15440                         if (false == test_case.m_is_array)
15441                         {
15442                                 var_definition = var_definition_one;
15443                                 var_use            = input_use_one;
15444                         }
15445                         else
15446                         {
15447                                 var_definition = var_definition_arr;
15448                                 var_use            = input_use_arr;
15449                         }
15450                 }
15451
15452                 sprintf(buffer, "%d", test_case.m_component);
15453
15454                 switch (stage)
15455                 {
15456                 case Utils::Shader::FRAGMENT:
15457                         source = fs_tested;
15458                         break;
15459                 case Utils::Shader::GEOMETRY:
15460                         source = gs_tested;
15461                         array  = "[]";
15462                         index  = "[0]";
15463                         break;
15464                 case Utils::Shader::TESS_CTRL:
15465                         source = tcs_tested;
15466                         array  = "[]";
15467                         index  = "[gl_InvocationID]";
15468                         break;
15469                 case Utils::Shader::TESS_EVAL:
15470                         source = tes_tested;
15471                         array  = "[]";
15472                         index  = "[0]";
15473                         break;
15474                 case Utils::Shader::VERTEX:
15475                         source = vs_tested;
15476                         break;
15477                 default:
15478                         TCU_FAIL("Invalid enum");
15479                 }
15480
15481                 temp = position;
15482                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15483                 position = temp;
15484                 Utils::replaceToken("COMPONENT", position, buffer, source);
15485                 Utils::replaceToken("DIRECTION", position, direction, source);
15486                 Utils::replaceToken("ARRAY", position, array, source);
15487                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15488
15489                 Utils::replaceAllTokens("TYPE", type_name, source);
15490                 Utils::replaceAllTokens("INDEX", index, source);
15491         }
15492         else
15493         {
15494                 switch (stage)
15495                 {
15496                 case Utils::Shader::FRAGMENT:
15497                         source = fs;
15498                         break;
15499                 case Utils::Shader::GEOMETRY:
15500                         source = gs;
15501                         break;
15502                 case Utils::Shader::TESS_CTRL:
15503                         source = tcs;
15504                         break;
15505                 case Utils::Shader::TESS_EVAL:
15506                         source = tes;
15507                         break;
15508                 case Utils::Shader::VERTEX:
15509                         source = vs;
15510                         break;
15511                 default:
15512                         TCU_FAIL("Invalid enum");
15513                 }
15514         }
15515
15516         return source;
15517 }
15518
15519 /** Get description of test case
15520  *
15521  * @param test_case_index Index of test case
15522  *
15523  * @return Test case description
15524  **/
15525 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15526 {
15527         std::stringstream stream;
15528         testCase&                 test_case = m_test_cases[test_case_index];
15529
15530         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15531                    << " type: " << test_case.m_type.GetGLSLTypeName();
15532
15533         if (true == test_case.m_is_array)
15534         {
15535                 stream << "[1]";
15536         }
15537
15538         stream << ", direction: ";
15539
15540         if (true == test_case.m_is_input)
15541         {
15542                 stream << "input";
15543         }
15544         else
15545         {
15546                 stream << "output";
15547         }
15548
15549         stream << ", component: " << test_case.m_component;
15550
15551         return stream.str();
15552 }
15553
15554 /** Get number of test cases
15555  *
15556  * @return Number of test cases
15557  **/
15558 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15559 {
15560         return static_cast<GLuint>(m_test_cases.size());
15561 }
15562
15563 /** Selects if "compute" stage is relevant for test
15564  *
15565  * @param ignored
15566  *
15567  * @return false
15568  **/
15569 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15570 {
15571         return false;
15572 }
15573
15574 /** Prepare all test cases
15575  *
15576  **/
15577 void VaryingExceedingComponentsTest::testInit()
15578 {
15579         static const GLuint n_components_per_location = 4;
15580         const GLuint            n_types                                   = getTypesNumber();
15581
15582         for (GLuint i = 0; i < n_types; ++i)
15583         {
15584                 const Utils::Type& type                          = getType(i);
15585                 const GLuint       n_req_components  = type.m_n_rows;
15586                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15587                 const GLuint       invalid_component = valid_component + 1;
15588
15589                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15590                 {
15591                         if (Utils::Shader::COMPUTE == stage)
15592                         {
15593                                 continue;
15594                         }
15595
15596                         /* Component cannot be used for matrices */
15597                         if (1 != type.m_n_columns)
15598                         {
15599                                 continue;
15600                         }
15601
15602                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15603                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15604                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15605                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15606
15607                         m_test_cases.push_back(test_case_in_arr);
15608                         m_test_cases.push_back(test_case_in_one);
15609
15610                         if (Utils::Shader::FRAGMENT != stage)
15611                         {
15612                                 m_test_cases.push_back(test_case_out_arr);
15613                                 m_test_cases.push_back(test_case_out_one);
15614                         }
15615                 }
15616         }
15617 }
15618
15619 /** Constructor
15620  *
15621  * @param context Test framework context
15622  **/
15623 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15624         : NegativeTestBase(context, "varying_component_without_location",
15625                                            "Test verifies that compiler reports error when component qualifier is used without location")
15626 {
15627 }
15628
15629 /** Source for given test case and stage
15630  *
15631  * @param test_case_index Index of test case
15632  * @param stage           Shader stage
15633  *
15634  * @return Shader source
15635  **/
15636 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15637 {
15638         static const GLchar* var_definition = "layout (component = COMPONENT) FLAT DIRECTION TYPE gokuARRAY;\n";
15639         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15640                                                                          "    {\n"
15641                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15642                                                                          "    }\n";
15643         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15644                                                                           "    if (vec4(0) == result)\n"
15645                                                                           "    {\n"
15646                                                                           "        gokuINDEX = TYPE(1);\n"
15647                                                                           "    }\n";
15648         static const GLchar* fs = "#version 430 core\n"
15649                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15650                                                           "\n"
15651                                                           "in  vec4 gs_fs;\n"
15652                                                           "out vec4 fs_out;\n"
15653                                                           "\n"
15654                                                           "void main()\n"
15655                                                           "{\n"
15656                                                           "    fs_out = gs_fs;\n"
15657                                                           "}\n"
15658                                                           "\n";
15659         static const GLchar* fs_tested = "#version 430 core\n"
15660                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15661                                                                          "\n"
15662                                                                          "VAR_DEFINITION"
15663                                                                          "\n"
15664                                                                          "in  vec4 gs_fs;\n"
15665                                                                          "out vec4 fs_out;\n"
15666                                                                          "\n"
15667                                                                          "void main()\n"
15668                                                                          "{\n"
15669                                                                          "    vec4 result = gs_fs;\n"
15670                                                                          "\n"
15671                                                                          "VARIABLE_USE"
15672                                                                          "\n"
15673                                                                          "    fs_out = result;\n"
15674                                                                          "}\n"
15675                                                                          "\n";
15676         static const GLchar* gs = "#version 430 core\n"
15677                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15678                                                           "\n"
15679                                                           "layout(points)                           in;\n"
15680                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15681                                                           "\n"
15682                                                           "in  vec4 tes_gs[];\n"
15683                                                           "out vec4 gs_fs;\n"
15684                                                           "\n"
15685                                                           "void main()\n"
15686                                                           "{\n"
15687                                                           "    gs_fs = tes_gs[0];\n"
15688                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15689                                                           "    EmitVertex();\n"
15690                                                           "    gs_fs = tes_gs[0];\n"
15691                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15692                                                           "    EmitVertex();\n"
15693                                                           "    gs_fs = tes_gs[0];\n"
15694                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15695                                                           "    EmitVertex();\n"
15696                                                           "    gs_fs = tes_gs[0];\n"
15697                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15698                                                           "    EmitVertex();\n"
15699                                                           "}\n"
15700                                                           "\n";
15701         static const GLchar* gs_tested = "#version 430 core\n"
15702                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15703                                                                          "\n"
15704                                                                          "layout(points)                           in;\n"
15705                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15706                                                                          "\n"
15707                                                                          "VAR_DEFINITION"
15708                                                                          "\n"
15709                                                                          "in  vec4 tes_gs[];\n"
15710                                                                          "out vec4 gs_fs;\n"
15711                                                                          "\n"
15712                                                                          "void main()\n"
15713                                                                          "{\n"
15714                                                                          "    vec4 result = tes_gs[0];\n"
15715                                                                          "\n"
15716                                                                          "VARIABLE_USE"
15717                                                                          "\n"
15718                                                                          "    gs_fs = result;\n"
15719                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15720                                                                          "    EmitVertex();\n"
15721                                                                          "    gs_fs = result;\n"
15722                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15723                                                                          "    EmitVertex();\n"
15724                                                                          "    gs_fs = result;\n"
15725                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15726                                                                          "    EmitVertex();\n"
15727                                                                          "    gs_fs = result;\n"
15728                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15729                                                                          "    EmitVertex();\n"
15730                                                                          "}\n"
15731                                                                          "\n";
15732         static const GLchar* tcs = "#version 430 core\n"
15733                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15734                                                            "\n"
15735                                                            "layout(vertices = 1) out;\n"
15736                                                            "\n"
15737                                                            "in  vec4 vs_tcs[];\n"
15738                                                            "out vec4 tcs_tes[];\n"
15739                                                            "\n"
15740                                                            "void main()\n"
15741                                                            "{\n"
15742                                                            "\n"
15743                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15744                                                            "\n"
15745                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15746                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15747                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15748                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15749                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15750                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15751                                                            "}\n"
15752                                                            "\n";
15753         static const GLchar* tcs_tested = "#version 430 core\n"
15754                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15755                                                                           "\n"
15756                                                                           "layout(vertices = 1) out;\n"
15757                                                                           "\n"
15758                                                                           "VAR_DEFINITION"
15759                                                                           "\n"
15760                                                                           "in  vec4 vs_tcs[];\n"
15761                                                                           "out vec4 tcs_tes[];\n"
15762                                                                           "\n"
15763                                                                           "void main()\n"
15764                                                                           "{\n"
15765                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15766                                                                           "\n"
15767                                                                           "VARIABLE_USE"
15768                                                                           "\n"
15769                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15770                                                                           "\n"
15771                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15772                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15773                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15774                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15775                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15776                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15777                                                                           "}\n"
15778                                                                           "\n";
15779         static const GLchar* tes = "#version 430 core\n"
15780                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15781                                                            "\n"
15782                                                            "layout(isolines, point_mode) in;\n"
15783                                                            "\n"
15784                                                            "in  vec4 tcs_tes[];\n"
15785                                                            "out vec4 tes_gs;\n"
15786                                                            "\n"
15787                                                            "void main()\n"
15788                                                            "{\n"
15789                                                            "    tes_gs = tcs_tes[0];\n"
15790                                                            "}\n"
15791                                                            "\n";
15792         static const GLchar* tes_tested = "#version 430 core\n"
15793                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15794                                                                           "\n"
15795                                                                           "layout(isolines, point_mode) in;\n"
15796                                                                           "\n"
15797                                                                           "VAR_DEFINITION"
15798                                                                           "\n"
15799                                                                           "in  vec4 tcs_tes[];\n"
15800                                                                           "out vec4 tes_gs;\n"
15801                                                                           "\n"
15802                                                                           "void main()\n"
15803                                                                           "{\n"
15804                                                                           "    vec4 result = tcs_tes[0];\n"
15805                                                                           "\n"
15806                                                                           "VARIABLE_USE"
15807                                                                           "\n"
15808                                                                           "    tes_gs = result;\n"
15809                                                                           "}\n"
15810                                                                           "\n";
15811         static const GLchar* vs = "#version 430 core\n"
15812                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15813                                                           "\n"
15814                                                           "in  vec4 in_vs;\n"
15815                                                           "out vec4 vs_tcs;\n"
15816                                                           "\n"
15817                                                           "void main()\n"
15818                                                           "{\n"
15819                                                           "    vs_tcs = in_vs;\n"
15820                                                           "}\n"
15821                                                           "\n";
15822         static const GLchar* vs_tested = "#version 430 core\n"
15823                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15824                                                                          "\n"
15825                                                                          "VAR_DEFINITION"
15826                                                                          "\n"
15827                                                                          "in  vec4 in_vs;\n"
15828                                                                          "out vec4 vs_tcs;\n"
15829                                                                          "\n"
15830                                                                          "void main()\n"
15831                                                                          "{\n"
15832                                                                          "    vec4 result = in_vs;\n"
15833                                                                          "\n"
15834                                                                          "VARIABLE_USE"
15835                                                                          "\n"
15836                                                                          "    vs_tcs = result;\n"
15837                                                                          "}\n"
15838                                                                          "\n";
15839
15840         std::string source;
15841         testCase&   test_case = m_test_cases[test_case_index];
15842
15843         if (test_case.m_stage == stage)
15844         {
15845                 const GLchar* array = "";
15846                 GLchar            buffer[16];
15847                 const GLchar* direction = "in ";
15848                 const GLchar* index             = "";
15849                 size_t            position  = 0;
15850                 size_t            temp;
15851                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15852                 const GLchar* var_use   = input_use;
15853                 const GLchar* flat              = "flat";
15854
15855                 if (false == test_case.m_is_input)
15856                 {
15857                         direction = "out";
15858                         var_use   = output_use;
15859                 }
15860
15861                 sprintf(buffer, "%d", test_case.m_component);
15862
15863                 switch (stage)
15864                 {
15865                 case Utils::Shader::FRAGMENT:
15866                         source = fs_tested;
15867                         break;
15868                 case Utils::Shader::GEOMETRY:
15869                         source = gs_tested;
15870                         array  = "[]";
15871                         index  = "[0]";
15872                         break;
15873                 case Utils::Shader::TESS_CTRL:
15874                         source = tcs_tested;
15875                         array  = "[]";
15876                         index  = "[gl_InvocationID]";
15877                         break;
15878                 case Utils::Shader::TESS_EVAL:
15879                         source = tes_tested;
15880                         array  = "[]";
15881                         index  = "[0]";
15882                         break;
15883                 case Utils::Shader::VERTEX:
15884                         source = vs_tested;
15885                         flat   = "";
15886                         break;
15887                 default:
15888                         TCU_FAIL("Invalid enum");
15889                 }
15890
15891                 temp = position;
15892                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15893                 position = temp;
15894                 Utils::replaceToken("COMPONENT", position, buffer, source);
15895                 Utils::replaceToken("FLAT", position, flat, source);
15896                 Utils::replaceToken("DIRECTION", position, direction, source);
15897                 Utils::replaceToken("ARRAY", position, array, source);
15898                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15899
15900                 Utils::replaceAllTokens("TYPE", type_name, source);
15901                 Utils::replaceAllTokens("INDEX", index, source);
15902         }
15903         else
15904         {
15905                 switch (stage)
15906                 {
15907                 case Utils::Shader::FRAGMENT:
15908                         source = fs;
15909                         break;
15910                 case Utils::Shader::GEOMETRY:
15911                         source = gs;
15912                         break;
15913                 case Utils::Shader::TESS_CTRL:
15914                         source = tcs;
15915                         break;
15916                 case Utils::Shader::TESS_EVAL:
15917                         source = tes;
15918                         break;
15919                 case Utils::Shader::VERTEX:
15920                         source = vs;
15921                         break;
15922                 default:
15923                         TCU_FAIL("Invalid enum");
15924                 }
15925         }
15926
15927         return source;
15928 }
15929
15930 /** Get description of test case
15931  *
15932  * @param test_case_index Index of test case
15933  *
15934  * @return Test case description
15935  **/
15936 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15937 {
15938         std::stringstream stream;
15939         testCase&                 test_case = m_test_cases[test_case_index];
15940
15941         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15942                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15943
15944         if (true == test_case.m_is_input)
15945         {
15946                 stream << "input";
15947         }
15948         else
15949         {
15950                 stream << "output";
15951         }
15952
15953         stream << ", component: " << test_case.m_component;
15954
15955         return stream.str();
15956 }
15957
15958 /** Get number of test cases
15959  *
15960  * @return Number of test cases
15961  **/
15962 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
15963 {
15964         return static_cast<GLuint>(m_test_cases.size());
15965 }
15966
15967 /** Selects if "compute" stage is relevant for test
15968  *
15969  * @param ignored
15970  *
15971  * @return false
15972  **/
15973 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
15974 {
15975         return false;
15976 }
15977
15978 /** Prepare all test cases
15979  *
15980  **/
15981 void VaryingComponentWithoutLocationTest::testInit()
15982 {
15983         static const GLuint n_components_per_location = 4;
15984         const GLuint            n_types                                   = getTypesNumber();
15985
15986         for (GLuint i = 0; i < n_types; ++i)
15987         {
15988                 const Utils::Type& type                         = getType(i);
15989                 const GLuint       n_req_components = type.m_n_rows;
15990                 const GLuint       valid_component  = n_components_per_location - n_req_components;
15991
15992                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15993                 {
15994                         if (Utils::Shader::COMPUTE == stage)
15995                         {
15996                                 continue;
15997                         }
15998
15999                         /* Component cannot be used for matrices */
16000                         if (1 != type.m_n_columns)
16001                         {
16002                                 continue;
16003                         }
16004
16005                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
16006                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
16007
16008                         m_test_cases.push_back(test_case_in);
16009
16010                         if (Utils::Shader::FRAGMENT != stage)
16011                         {
16012                                 m_test_cases.push_back(test_case_out);
16013                         }
16014                 }
16015         }
16016 }
16017
16018 /** Constructor
16019  *
16020  * @param context Test framework context
16021  **/
16022 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
16023         : NegativeTestBase(context, "varying_component_of_invalid_type",
16024                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
16025 {
16026 }
16027
16028 /** Source for given test case and stage
16029  *
16030  * @param test_case_index Index of test case
16031  * @param stage           Shader stage
16032  *
16033  * @return Shader source
16034  **/
16035 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16036 {
16037         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
16038                                                                                                 "    TYPE member;\n"
16039                                                                                                 "} gokuARRAY[1];\n";
16040         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
16041                                                                                                 "    TYPE member;\n"
16042                                                                                                 "} gokuARRAY;\n";
16043         static const GLchar* matrix_definition_arr =
16044                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
16045         static const GLchar* matrix_definition_one =
16046                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
16047         static const GLchar* struct_definition_arr =
16048                 "struct Goku {\n"
16049                 "    TYPE member;\n"
16050                 "};\n"
16051                 "\n"
16052                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
16053         static const GLchar* struct_definition_one =
16054                 "struct Goku {\n"
16055                 "    TYPE member;\n"
16056                 "};\n"
16057                 "\n"
16058                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
16059         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
16060                                                                                                 "    {\n"
16061                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16062                                                                                                 "    }\n";
16063         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
16064                                                                                                 "    {\n"
16065                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16066                                                                                                 "    }\n";
16067         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
16068                                                                                                  "    if (vec4(0) == result)\n"
16069                                                                                                  "    {\n"
16070                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
16071                                                                                                  "    }\n";
16072         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
16073                                                                                                  "    if (vec4(0) == result)\n"
16074                                                                                                  "    {\n"
16075                                                                                                  "        gokuINDEX = TYPE(1);\n"
16076                                                                                                  "    }\n";
16077         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16078                                                                                                 "    {\n"
16079                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16080                                                                                                 "    }\n";
16081         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16082                                                                                                 "    {\n"
16083                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16084                                                                                                 "    }\n";
16085         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16086                                                                                                  "    if (vec4(0) == result)\n"
16087                                                                                                  "    {\n"
16088                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16089                                                                                                  "    }\n";
16090         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16091                                                                                                  "    if (vec4(0) == result)\n"
16092                                                                                                  "    {\n"
16093                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16094                                                                                                  "    }\n";
16095         static const GLchar* fs = "#version 430 core\n"
16096                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16097                                                           "\n"
16098                                                           "in  vec4 gs_fs;\n"
16099                                                           "out vec4 fs_out;\n"
16100                                                           "\n"
16101                                                           "void main()\n"
16102                                                           "{\n"
16103                                                           "    fs_out = gs_fs;\n"
16104                                                           "}\n"
16105                                                           "\n";
16106         static const GLchar* fs_tested = "#version 430 core\n"
16107                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16108                                                                          "\n"
16109                                                                          "VAR_DEFINITION"
16110                                                                          "\n"
16111                                                                          "in  vec4 gs_fs;\n"
16112                                                                          "out vec4 fs_out;\n"
16113                                                                          "\n"
16114                                                                          "void main()\n"
16115                                                                          "{\n"
16116                                                                          "    vec4 result = gs_fs;\n"
16117                                                                          "\n"
16118                                                                          "VARIABLE_USE"
16119                                                                          "\n"
16120                                                                          "    fs_out += result;\n"
16121                                                                          "}\n"
16122                                                                          "\n";
16123         static const GLchar* gs = "#version 430 core\n"
16124                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16125                                                           "\n"
16126                                                           "layout(points)                           in;\n"
16127                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16128                                                           "\n"
16129                                                           "in  vec4 tes_gs[];\n"
16130                                                           "out vec4 gs_fs;\n"
16131                                                           "\n"
16132                                                           "void main()\n"
16133                                                           "{\n"
16134                                                           "    gs_fs = tes_gs[0];\n"
16135                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16136                                                           "    EmitVertex();\n"
16137                                                           "    gs_fs = tes_gs[0];\n"
16138                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16139                                                           "    EmitVertex();\n"
16140                                                           "    gs_fs = tes_gs[0];\n"
16141                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16142                                                           "    EmitVertex();\n"
16143                                                           "    gs_fs = tes_gs[0];\n"
16144                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16145                                                           "    EmitVertex();\n"
16146                                                           "}\n"
16147                                                           "\n";
16148         static const GLchar* gs_tested = "#version 430 core\n"
16149                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16150                                                                          "\n"
16151                                                                          "layout(points)                           in;\n"
16152                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16153                                                                          "\n"
16154                                                                          "VAR_DEFINITION"
16155                                                                          "\n"
16156                                                                          "in  vec4 tes_gs[];\n"
16157                                                                          "out vec4 gs_fs;\n"
16158                                                                          "\n"
16159                                                                          "void main()\n"
16160                                                                          "{\n"
16161                                                                          "    vec4 result = tes_gs[0];\n"
16162                                                                          "\n"
16163                                                                          "VARIABLE_USE"
16164                                                                          "\n"
16165                                                                          "    gs_fs = result;\n"
16166                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16167                                                                          "    EmitVertex();\n"
16168                                                                          "    gs_fs = result;\n"
16169                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16170                                                                          "    EmitVertex();\n"
16171                                                                          "    gs_fs = result;\n"
16172                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16173                                                                          "    EmitVertex();\n"
16174                                                                          "    gs_fs = result;\n"
16175                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16176                                                                          "    EmitVertex();\n"
16177                                                                          "}\n"
16178                                                                          "\n";
16179         static const GLchar* tcs = "#version 430 core\n"
16180                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16181                                                            "\n"
16182                                                            "layout(vertices = 1) out;\n"
16183                                                            "\n"
16184                                                            "in  vec4 vs_tcs[];\n"
16185                                                            "out vec4 tcs_tes[];\n"
16186                                                            "\n"
16187                                                            "void main()\n"
16188                                                            "{\n"
16189                                                            "\n"
16190                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16191                                                            "\n"
16192                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16193                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16194                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16195                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16196                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16197                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16198                                                            "}\n"
16199                                                            "\n";
16200         static const GLchar* tcs_tested = "#version 430 core\n"
16201                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16202                                                                           "\n"
16203                                                                           "layout(vertices = 1) out;\n"
16204                                                                           "\n"
16205                                                                           "VAR_DEFINITION"
16206                                                                           "\n"
16207                                                                           "in  vec4 vs_tcs[];\n"
16208                                                                           "out vec4 tcs_tes[];\n"
16209                                                                           "\n"
16210                                                                           "void main()\n"
16211                                                                           "{\n"
16212                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16213                                                                           "\n"
16214                                                                           "VARIABLE_USE"
16215                                                                           "\n"
16216                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16217                                                                           "\n"
16218                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16219                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16220                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16221                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16222                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16223                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16224                                                                           "}\n"
16225                                                                           "\n";
16226         static const GLchar* tes = "#version 430 core\n"
16227                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16228                                                            "\n"
16229                                                            "layout(isolines, point_mode) in;\n"
16230                                                            "\n"
16231                                                            "in  vec4 tcs_tes[];\n"
16232                                                            "out vec4 tes_gs;\n"
16233                                                            "\n"
16234                                                            "void main()\n"
16235                                                            "{\n"
16236                                                            "    tes_gs = tcs_tes[0];\n"
16237                                                            "}\n"
16238                                                            "\n";
16239         static const GLchar* tes_tested = "#version 430 core\n"
16240                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16241                                                                           "\n"
16242                                                                           "layout(isolines, point_mode) in;\n"
16243                                                                           "\n"
16244                                                                           "VAR_DEFINITION"
16245                                                                           "\n"
16246                                                                           "in  vec4 tcs_tes[];\n"
16247                                                                           "out vec4 tes_gs;\n"
16248                                                                           "\n"
16249                                                                           "void main()\n"
16250                                                                           "{\n"
16251                                                                           "    vec4 result = tcs_tes[0];\n"
16252                                                                           "\n"
16253                                                                           "VARIABLE_USE"
16254                                                                           "\n"
16255                                                                           "    tes_gs += result;\n"
16256                                                                           "}\n"
16257                                                                           "\n";
16258         static const GLchar* vs = "#version 430 core\n"
16259                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16260                                                           "\n"
16261                                                           "in  vec4 in_vs;\n"
16262                                                           "out vec4 vs_tcs;\n"
16263                                                           "\n"
16264                                                           "void main()\n"
16265                                                           "{\n"
16266                                                           "    vs_tcs = in_vs;\n"
16267                                                           "}\n"
16268                                                           "\n";
16269         static const GLchar* vs_tested = "#version 430 core\n"
16270                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16271                                                                          "\n"
16272                                                                          "VAR_DEFINITION"
16273                                                                          "\n"
16274                                                                          "in  vec4 in_vs;\n"
16275                                                                          "out vec4 vs_tcs;\n"
16276                                                                          "\n"
16277                                                                          "void main()\n"
16278                                                                          "{\n"
16279                                                                          "    vec4 result = in_vs;\n"
16280                                                                          "\n"
16281                                                                          "VARIABLE_USE"
16282                                                                          "\n"
16283                                                                          "    vs_tcs += result;\n"
16284                                                                          "}\n"
16285                                                                          "\n";
16286
16287         std::string source;
16288         testCase&   test_case = m_test_cases[test_case_index];
16289
16290         if (test_case.m_stage == stage)
16291         {
16292                 const GLchar* array = "";
16293                 GLchar            buffer[16];
16294                 const GLchar* var_definition = 0;
16295                 const GLchar* direction          = "in ";
16296                 const GLchar* index                      = "";
16297                 size_t            position               = 0;
16298                 size_t            temp;
16299                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16300                 const GLchar* var_use   = 0;
16301
16302                 if (false == test_case.m_is_input)
16303                 {
16304                         direction = "out";
16305
16306                         if (false == test_case.m_is_array)
16307                         {
16308                                 switch (test_case.m_case)
16309                                 {
16310                                 case BLOCK:
16311                                         var_definition = block_definition_one;
16312                                         var_use            = member_output_use_one;
16313                                         break;
16314                                 case MATRIX:
16315                                         var_definition = matrix_definition_one;
16316                                         var_use            = matrix_output_use_one;
16317                                         break;
16318                                 case STRUCT:
16319                                         var_definition = struct_definition_one;
16320                                         var_use            = member_output_use_one;
16321                                         break;
16322                                 default:
16323                                         TCU_FAIL("Invalid enum");
16324                                 }
16325                         }
16326                         else
16327                         {
16328                                 switch (test_case.m_case)
16329                                 {
16330                                 case BLOCK:
16331                                         var_definition = block_definition_arr;
16332                                         var_use            = member_output_use_arr;
16333                                         break;
16334                                 case MATRIX:
16335                                         var_definition = matrix_definition_arr;
16336                                         var_use            = matrix_output_use_arr;
16337                                         break;
16338                                 case STRUCT:
16339                                         var_definition = struct_definition_arr;
16340                                         var_use            = member_output_use_arr;
16341                                         break;
16342                                 default:
16343                                         TCU_FAIL("Invalid enum");
16344                                 }
16345                         }
16346                 }
16347                 else
16348                 {
16349                         if (false == test_case.m_is_array)
16350                         {
16351                                 switch (test_case.m_case)
16352                                 {
16353                                 case BLOCK:
16354                                         var_definition = block_definition_one;
16355                                         var_use            = member_input_use_one;
16356                                         break;
16357                                 case MATRIX:
16358                                         var_definition = matrix_definition_one;
16359                                         var_use            = matrix_input_use_one;
16360                                         break;
16361                                 case STRUCT:
16362                                         var_definition = struct_definition_one;
16363                                         var_use            = member_input_use_one;
16364                                         break;
16365                                 default:
16366                                         TCU_FAIL("Invalid enum");
16367                                 }
16368                         }
16369                         else
16370                         {
16371                                 switch (test_case.m_case)
16372                                 {
16373                                 case BLOCK:
16374                                         var_definition = block_definition_arr;
16375                                         var_use            = member_input_use_arr;
16376                                         break;
16377                                 case MATRIX:
16378                                         var_definition = matrix_definition_arr;
16379                                         var_use            = matrix_input_use_arr;
16380                                         break;
16381                                 case STRUCT:
16382                                         var_definition = struct_definition_arr;
16383                                         var_use            = member_input_use_arr;
16384                                         break;
16385                                 default:
16386                                         TCU_FAIL("Invalid enum");
16387                                 }
16388                         }
16389                 }
16390
16391                 sprintf(buffer, "%d", test_case.m_component);
16392
16393                 switch (stage)
16394                 {
16395                 case Utils::Shader::FRAGMENT:
16396                         source = fs_tested;
16397                         break;
16398                 case Utils::Shader::GEOMETRY:
16399                         source = gs_tested;
16400                         array  = "[]";
16401                         index  = "[0]";
16402                         break;
16403                 case Utils::Shader::TESS_CTRL:
16404                         source = tcs_tested;
16405                         array  = "[]";
16406                         index  = "[gl_InvocationID]";
16407                         break;
16408                 case Utils::Shader::TESS_EVAL:
16409                         source = tes_tested;
16410                         array  = "[]";
16411                         index  = "[0]";
16412                         break;
16413                 case Utils::Shader::VERTEX:
16414                         source = vs_tested;
16415                         break;
16416                 default:
16417                         TCU_FAIL("Invalid enum");
16418                 }
16419
16420                 temp = position;
16421                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16422                 position = temp;
16423                 Utils::replaceToken("COMPONENT", position, buffer, source);
16424                 Utils::replaceToken("DIRECTION", position, direction, source);
16425                 Utils::replaceToken("ARRAY", position, array, source);
16426                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16427
16428                 Utils::replaceAllTokens("TYPE", type_name, source);
16429                 Utils::replaceAllTokens("INDEX", index, source);
16430         }
16431         else
16432         {
16433                 switch (stage)
16434                 {
16435                 case Utils::Shader::FRAGMENT:
16436                         source = fs;
16437                         break;
16438                 case Utils::Shader::GEOMETRY:
16439                         source = gs;
16440                         break;
16441                 case Utils::Shader::TESS_CTRL:
16442                         source = tcs;
16443                         break;
16444                 case Utils::Shader::TESS_EVAL:
16445                         source = tes;
16446                         break;
16447                 case Utils::Shader::VERTEX:
16448                         source = vs;
16449                         break;
16450                 default:
16451                         TCU_FAIL("Invalid enum");
16452                 }
16453         }
16454
16455         return source;
16456 }
16457
16458 /** Get description of test case
16459  *
16460  * @param test_case_index Index of test case
16461  *
16462  * @return Test case description
16463  **/
16464 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16465 {
16466         std::stringstream stream;
16467         testCase&                 test_case = m_test_cases[test_case_index];
16468
16469         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16470                    << " type: " << test_case.m_type.GetGLSLTypeName();
16471
16472         if (true == test_case.m_is_array)
16473         {
16474                 stream << "[1]";
16475         }
16476
16477         stream << ", direction: ";
16478
16479         if (true == test_case.m_is_input)
16480         {
16481                 stream << "input";
16482         }
16483         else
16484         {
16485                 stream << "output";
16486         }
16487
16488         stream << ", component: " << test_case.m_component;
16489
16490         return stream.str();
16491 }
16492
16493 /** Get number of test cases
16494  *
16495  * @return Number of test cases
16496  **/
16497 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16498 {
16499         return static_cast<GLuint>(m_test_cases.size());
16500 }
16501
16502 /** Selects if "compute" stage is relevant for test
16503  *
16504  * @param ignored
16505  *
16506  * @return false
16507  **/
16508 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16509 {
16510         return false;
16511 }
16512
16513 /** Prepare all test cases
16514  *
16515  **/
16516 void VaryingComponentOfInvalidTypeTest::testInit()
16517 {
16518         static const GLuint n_components_per_location = 4;
16519         const GLuint            n_types                                   = getTypesNumber();
16520
16521         for (GLuint i = 0; i < n_types; ++i)
16522         {
16523                 const Utils::Type& type                         = getType(i);
16524                 const GLuint       n_req_components = type.m_n_rows;
16525                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16526
16527                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16528                 {
16529                         if (Utils::Shader::COMPUTE == stage)
16530                         {
16531                                 continue;
16532                         }
16533
16534                         /* Use different CASE for matrices */
16535                         if (1 != type.m_n_columns)
16536                         {
16537                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16538                                 testCase test_case_in_one = {
16539                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16540                                 };
16541                                 testCase test_case_out_arr = {
16542                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16543                                 };
16544                                 testCase test_case_out_one = {
16545                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16546                                 };
16547
16548                                 m_test_cases.push_back(test_case_in_arr);
16549                                 m_test_cases.push_back(test_case_in_one);
16550
16551                                 if (Utils::Shader::FRAGMENT != stage)
16552                                 {
16553                                         m_test_cases.push_back(test_case_out_arr);
16554                                         m_test_cases.push_back(test_case_out_one);
16555                                 }
16556                         }
16557                         else
16558                         {
16559                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16560                                 {
16561                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16562                                                                                                   type };
16563                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16564                                                                                                   type };
16565                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16566                                                                                                    type };
16567                                         testCase test_case_out_one = {
16568                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16569                                         };
16570
16571                                         if (Utils::Shader::VERTEX != stage)
16572                                         {
16573                                                 m_test_cases.push_back(test_case_in_arr);
16574                                                 m_test_cases.push_back(test_case_in_one);
16575                                         }
16576
16577                                         if (Utils::Shader::FRAGMENT != stage)
16578                                         {
16579                                                 m_test_cases.push_back(test_case_out_arr);
16580                                                 m_test_cases.push_back(test_case_out_one);
16581                                         }
16582                                 }
16583                         }
16584                 }
16585         }
16586 }
16587
16588 /** Constructor
16589  *
16590  * @param context Test framework context
16591  **/
16592 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16593         : NegativeTestBase(context, "input_component_aliasing",
16594                                            "Test verifies that compiler reports component aliasing as error")
16595 {
16596 }
16597
16598 /** Source for given test case and stage
16599  *
16600  * @param test_case_index Index of test case
16601  * @param stage           Shader stage
16602  *
16603  * @return Shader source
16604  **/
16605 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16606 {
16607         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16608                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16609         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16610                                                                         "    {\n"
16611                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16612                                                                         "    }\n";
16613         static const GLchar* fs = "#version 430 core\n"
16614                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16615                                                           "\n"
16616                                                           "in  vec4 gs_fs;\n"
16617                                                           "out vec4 fs_out;\n"
16618                                                           "\n"
16619                                                           "void main()\n"
16620                                                           "{\n"
16621                                                           "    fs_out = gs_fs;\n"
16622                                                           "}\n"
16623                                                           "\n";
16624         static const GLchar* fs_tested = "#version 430 core\n"
16625                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16626                                                                          "\n"
16627                                                                          "VAR_DEFINITION"
16628                                                                          "\n"
16629                                                                          "in  vec4 gs_fs;\n"
16630                                                                          "out vec4 fs_out;\n"
16631                                                                          "\n"
16632                                                                          "void main()\n"
16633                                                                          "{\n"
16634                                                                          "    vec4 result = gs_fs;\n"
16635                                                                          "\n"
16636                                                                          "VARIABLE_USE"
16637                                                                          "\n"
16638                                                                          "    fs_out += result;\n"
16639                                                                          "}\n"
16640                                                                          "\n";
16641         static const GLchar* gs = "#version 430 core\n"
16642                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16643                                                           "\n"
16644                                                           "layout(points)                           in;\n"
16645                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16646                                                           "\n"
16647                                                           "in  vec4 tes_gs[];\n"
16648                                                           "out vec4 gs_fs;\n"
16649                                                           "\n"
16650                                                           "void main()\n"
16651                                                           "{\n"
16652                                                           "    gs_fs = tes_gs[0];\n"
16653                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16654                                                           "    EmitVertex();\n"
16655                                                           "    gs_fs = tes_gs[0];\n"
16656                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16657                                                           "    EmitVertex();\n"
16658                                                           "    gs_fs = tes_gs[0];\n"
16659                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16660                                                           "    EmitVertex();\n"
16661                                                           "    gs_fs = tes_gs[0];\n"
16662                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16663                                                           "    EmitVertex();\n"
16664                                                           "}\n"
16665                                                           "\n";
16666         static const GLchar* gs_tested = "#version 430 core\n"
16667                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16668                                                                          "\n"
16669                                                                          "layout(points)                           in;\n"
16670                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16671                                                                          "\n"
16672                                                                          "VAR_DEFINITION"
16673                                                                          "\n"
16674                                                                          "in  vec4 tes_gs[];\n"
16675                                                                          "out vec4 gs_fs;\n"
16676                                                                          "\n"
16677                                                                          "void main()\n"
16678                                                                          "{\n"
16679                                                                          "    vec4 result = tes_gs[0];\n"
16680                                                                          "\n"
16681                                                                          "VARIABLE_USE"
16682                                                                          "\n"
16683                                                                          "    gs_fs = result;\n"
16684                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16685                                                                          "    EmitVertex();\n"
16686                                                                          "    gs_fs = result;\n"
16687                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16688                                                                          "    EmitVertex();\n"
16689                                                                          "    gs_fs = result;\n"
16690                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16691                                                                          "    EmitVertex();\n"
16692                                                                          "    gs_fs = result;\n"
16693                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16694                                                                          "    EmitVertex();\n"
16695                                                                          "}\n"
16696                                                                          "\n";
16697         static const GLchar* tcs = "#version 430 core\n"
16698                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16699                                                            "\n"
16700                                                            "layout(vertices = 1) out;\n"
16701                                                            "\n"
16702                                                            "in  vec4 vs_tcs[];\n"
16703                                                            "out vec4 tcs_tes[];\n"
16704                                                            "\n"
16705                                                            "void main()\n"
16706                                                            "{\n"
16707                                                            "\n"
16708                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16709                                                            "\n"
16710                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16711                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16712                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16713                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16714                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16715                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16716                                                            "}\n"
16717                                                            "\n";
16718         static const GLchar* tcs_tested = "#version 430 core\n"
16719                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16720                                                                           "\n"
16721                                                                           "layout(vertices = 1) out;\n"
16722                                                                           "\n"
16723                                                                           "VAR_DEFINITION"
16724                                                                           "\n"
16725                                                                           "in  vec4 vs_tcs[];\n"
16726                                                                           "out vec4 tcs_tes[];\n"
16727                                                                           "\n"
16728                                                                           "void main()\n"
16729                                                                           "{\n"
16730                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16731                                                                           "\n"
16732                                                                           "VARIABLE_USE"
16733                                                                           "\n"
16734                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16735                                                                           "\n"
16736                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16737                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16738                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16739                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16740                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16741                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16742                                                                           "}\n"
16743                                                                           "\n";
16744         static const GLchar* tes = "#version 430 core\n"
16745                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16746                                                            "\n"
16747                                                            "layout(isolines, point_mode) in;\n"
16748                                                            "\n"
16749                                                            "in  vec4 tcs_tes[];\n"
16750                                                            "out vec4 tes_gs;\n"
16751                                                            "\n"
16752                                                            "void main()\n"
16753                                                            "{\n"
16754                                                            "    tes_gs = tcs_tes[0];\n"
16755                                                            "}\n"
16756                                                            "\n";
16757         static const GLchar* tes_tested = "#version 430 core\n"
16758                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16759                                                                           "\n"
16760                                                                           "layout(isolines, point_mode) in;\n"
16761                                                                           "\n"
16762                                                                           "VAR_DEFINITION"
16763                                                                           "\n"
16764                                                                           "in  vec4 tcs_tes[];\n"
16765                                                                           "out vec4 tes_gs;\n"
16766                                                                           "\n"
16767                                                                           "void main()\n"
16768                                                                           "{\n"
16769                                                                           "    vec4 result = tcs_tes[0];\n"
16770                                                                           "\n"
16771                                                                           "VARIABLE_USE"
16772                                                                           "\n"
16773                                                                           "    tes_gs += result;\n"
16774                                                                           "}\n"
16775                                                                           "\n";
16776         static const GLchar* vs = "#version 430 core\n"
16777                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16778                                                           "\n"
16779                                                           "in  vec4 in_vs;\n"
16780                                                           "out vec4 vs_tcs;\n"
16781                                                           "\n"
16782                                                           "void main()\n"
16783                                                           "{\n"
16784                                                           "    vs_tcs = in_vs;\n"
16785                                                           "}\n"
16786                                                           "\n";
16787         static const GLchar* vs_tested = "#version 430 core\n"
16788                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16789                                                                          "\n"
16790                                                                          "VAR_DEFINITION"
16791                                                                          "\n"
16792                                                                          "in  vec4 in_vs;\n"
16793                                                                          "out vec4 vs_tcs;\n"
16794                                                                          "\n"
16795                                                                          "void main()\n"
16796                                                                          "{\n"
16797                                                                          "    vec4 result = in_vs;\n"
16798                                                                          "\n"
16799                                                                          "VARIABLE_USE"
16800                                                                          "\n"
16801                                                                          "    vs_tcs += result;\n"
16802                                                                          "}\n"
16803                                                                          "\n";
16804
16805         std::string source;
16806         testCase&   test_case = m_test_cases[test_case_index];
16807
16808         if (test_case.m_stage == stage)
16809         {
16810                 const GLchar* array = "";
16811                 GLchar            buffer_gohan[16];
16812                 GLchar            buffer_goten[16];
16813                 const GLchar* flat                = "";
16814                 const GLchar* index               = "";
16815                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16816                 size_t            position      = 0;
16817                 size_t            temp;
16818                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16819                 const GLchar* var_use   = test_one;
16820
16821                 if (true == is_flat_req)
16822                 {
16823                         flat = "flat";
16824                 }
16825
16826                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16827                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16828
16829                 switch (stage)
16830                 {
16831                 case Utils::Shader::FRAGMENT:
16832                         source = fs_tested;
16833                         break;
16834                 case Utils::Shader::GEOMETRY:
16835                         source = gs_tested;
16836                         array  = "[]";
16837                         index  = "[0]";
16838                         break;
16839                 case Utils::Shader::TESS_CTRL:
16840                         source = tcs_tested;
16841                         array  = "[]";
16842                         index  = "[gl_InvocationID]";
16843                         break;
16844                 case Utils::Shader::TESS_EVAL:
16845                         source = tes_tested;
16846                         array  = "[]";
16847                         index  = "[0]";
16848                         break;
16849                 case Utils::Shader::VERTEX:
16850                         source = vs_tested;
16851                         break;
16852                 default:
16853                         TCU_FAIL("Invalid enum");
16854                 }
16855
16856                 temp = position;
16857                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16858                 position = temp;
16859                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16860                 Utils::replaceToken("ARRAY", position, array, source);
16861                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16862                 Utils::replaceToken("ARRAY", position, array, source);
16863                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16864
16865                 Utils::replaceAllTokens("FLAT", flat, source);
16866                 Utils::replaceAllTokens("TYPE", type_name, source);
16867                 Utils::replaceAllTokens("INDEX", index, source);
16868         }
16869         else
16870         {
16871                 switch (stage)
16872                 {
16873                 case Utils::Shader::FRAGMENT:
16874                         source = fs;
16875                         break;
16876                 case Utils::Shader::GEOMETRY:
16877                         source = gs;
16878                         break;
16879                 case Utils::Shader::TESS_CTRL:
16880                         source = tcs;
16881                         break;
16882                 case Utils::Shader::TESS_EVAL:
16883                         source = tes;
16884                         break;
16885                 case Utils::Shader::VERTEX:
16886                         source = vs;
16887                         break;
16888                 default:
16889                         TCU_FAIL("Invalid enum");
16890                 }
16891         }
16892
16893         return source;
16894 }
16895
16896 /** Get description of test case
16897  *
16898  * @param test_case_index Index of test case
16899  *
16900  * @return Test case description
16901  **/
16902 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16903 {
16904         std::stringstream stream;
16905         testCase&                 test_case = m_test_cases[test_case_index];
16906
16907         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16908                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16909                    << " & " << test_case.m_component_goten;
16910
16911         return stream.str();
16912 }
16913
16914 /** Get number of test cases
16915  *
16916  * @return Number of test cases
16917  **/
16918 GLuint InputComponentAliasingTest::getTestCaseNumber()
16919 {
16920         return static_cast<GLuint>(m_test_cases.size());
16921 }
16922
16923 /** Selects if "compute" stage is relevant for test
16924  *
16925  * @param ignored
16926  *
16927  * @return false
16928  **/
16929 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16930 {
16931         return false;
16932 }
16933
16934 /** Selects if compilation failure is expected result
16935  *
16936  * @param test_case_index Index of test case
16937  *
16938  * @return false for VS that use only single variable, true otherwise
16939  **/
16940 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16941 {
16942         testCase& test_case = m_test_cases[test_case_index];
16943
16944         return (Utils::Shader::VERTEX != test_case.m_stage);
16945 }
16946
16947 /** Prepare all test cases
16948  *
16949  **/
16950 void InputComponentAliasingTest::testInit()
16951 {
16952         const GLuint            n_types                                   = getTypesNumber();
16953
16954         for (GLuint i = 0; i < n_types; ++i)
16955         {
16956                 const Utils::Type& type                                          = getType(i);
16957                 const bool                 use_double                            = (Utils::Type::Double == type.m_basic_type);
16958                 const GLuint       n_components_per_location = use_double ? 2 : 4;
16959                 const GLuint       n_req_components                      = type.m_n_rows;
16960                 const GLint                valid_component                       = (GLint)n_components_per_location - (GLint)n_req_components;
16961                 const GLuint       component_size                        = use_double ? 2 : 1;
16962                 /* Skip matrices */
16963                 if (1 != type.m_n_columns)
16964                 {
16965                         continue;
16966                 }
16967                 /* Skip dvec3/dvec4 which doesn't support the component qualifier */
16968                 if (valid_component < 0)
16969                 {
16970                         continue;
16971                 }
16972
16973                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16974                 {
16975                         if (Utils::Shader::COMPUTE == stage)
16976                         {
16977                                 continue;
16978                         }
16979
16980                         for (GLuint gohan = 0; gohan <= (GLuint)valid_component; ++gohan)
16981                         {
16982                                 const GLint first_aliasing = gohan - n_req_components + 1;
16983                                 const GLint last_aliasing  = gohan + n_req_components - 1;
16984
16985                                 const GLuint goten_start = std::max(0, first_aliasing);
16986                                 const GLuint goten_stop  = std::min(valid_component, last_aliasing);
16987
16988                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
16989                                 {
16990                                         testCase test_case = { gohan * component_size, goten * component_size, (Utils::Shader::STAGES)stage,
16991                                                                                    type };
16992
16993                                         m_test_cases.push_back(test_case);
16994                                 }
16995                         }
16996                 }
16997         }
16998 }
16999
17000 /** Constructor
17001  *
17002  * @param context Test framework context
17003  **/
17004 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
17005         : NegativeTestBase(context, "output_component_aliasing",
17006                                            "Test verifies that compiler reports component aliasing as error")
17007 {
17008 }
17009
17010 /** Source for given test case and stage
17011  *
17012  * @param test_case_index Index of test case
17013  * @param stage           Shader stage
17014  *
17015  * @return Shader source
17016  **/
17017 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
17018 {
17019         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
17020                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
17021         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
17022                                                                   "    gotenINDEX = TYPE(0);\n";
17023         static const GLchar* fs = "#version 430 core\n"
17024                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17025                                                           "\n"
17026                                                           "in  vec4 gs_fs;\n"
17027                                                           "out vec4 fs_out;\n"
17028                                                           "\n"
17029                                                           "void main()\n"
17030                                                           "{\n"
17031                                                           "    fs_out = gs_fs;\n"
17032                                                           "}\n"
17033                                                           "\n";
17034         static const GLchar* fs_tested = "#version 430 core\n"
17035                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17036                                                                          "\n"
17037                                                                          "VAR_DEFINITION"
17038                                                                          "\n"
17039                                                                          "in  vec4 gs_fs;\n"
17040                                                                          "out vec4 fs_out;\n"
17041                                                                          "\n"
17042                                                                          "void main()\n"
17043                                                                          "{\n"
17044                                                                          "    vec4 result = gs_fs;\n"
17045                                                                          "\n"
17046                                                                          "VARIABLE_USE"
17047                                                                          "\n"
17048                                                                          "    fs_out += result;\n"
17049                                                                          "}\n"
17050                                                                          "\n";
17051         static const GLchar* gs = "#version 430 core\n"
17052                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17053                                                           "\n"
17054                                                           "layout(points)                           in;\n"
17055                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17056                                                           "\n"
17057                                                           "in  vec4 tes_gs[];\n"
17058                                                           "out vec4 gs_fs;\n"
17059                                                           "\n"
17060                                                           "void main()\n"
17061                                                           "{\n"
17062                                                           "    gs_fs = tes_gs[0];\n"
17063                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17064                                                           "    EmitVertex();\n"
17065                                                           "    gs_fs = tes_gs[0];\n"
17066                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17067                                                           "    EmitVertex();\n"
17068                                                           "    gs_fs = tes_gs[0];\n"
17069                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17070                                                           "    EmitVertex();\n"
17071                                                           "    gs_fs = tes_gs[0];\n"
17072                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17073                                                           "    EmitVertex();\n"
17074                                                           "}\n"
17075                                                           "\n";
17076         static const GLchar* gs_tested = "#version 430 core\n"
17077                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17078                                                                          "\n"
17079                                                                          "layout(points)                           in;\n"
17080                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17081                                                                          "\n"
17082                                                                          "VAR_DEFINITION"
17083                                                                          "\n"
17084                                                                          "in  vec4 tes_gs[];\n"
17085                                                                          "out vec4 gs_fs;\n"
17086                                                                          "\n"
17087                                                                          "void main()\n"
17088                                                                          "{\n"
17089                                                                          "    vec4 result = tes_gs[0];\n"
17090                                                                          "\n"
17091                                                                          "VARIABLE_USE"
17092                                                                          "\n"
17093                                                                          "    gs_fs = result;\n"
17094                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17095                                                                          "    EmitVertex();\n"
17096                                                                          "    gs_fs = result;\n"
17097                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17098                                                                          "    EmitVertex();\n"
17099                                                                          "    gs_fs = result;\n"
17100                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17101                                                                          "    EmitVertex();\n"
17102                                                                          "    gs_fs = result;\n"
17103                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17104                                                                          "    EmitVertex();\n"
17105                                                                          "}\n"
17106                                                                          "\n";
17107         static const GLchar* tcs = "#version 430 core\n"
17108                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17109                                                            "\n"
17110                                                            "layout(vertices = 1) out;\n"
17111                                                            "\n"
17112                                                            "in  vec4 vs_tcs[];\n"
17113                                                            "out vec4 tcs_tes[];\n"
17114                                                            "\n"
17115                                                            "void main()\n"
17116                                                            "{\n"
17117                                                            "\n"
17118                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17119                                                            "\n"
17120                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17121                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17122                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17123                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17124                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17125                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17126                                                            "}\n"
17127                                                            "\n";
17128         static const GLchar* tcs_tested = "#version 430 core\n"
17129                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17130                                                                           "\n"
17131                                                                           "layout(vertices = 1) out;\n"
17132                                                                           "\n"
17133                                                                           "VAR_DEFINITION"
17134                                                                           "\n"
17135                                                                           "in  vec4 vs_tcs[];\n"
17136                                                                           "out vec4 tcs_tes[];\n"
17137                                                                           "\n"
17138                                                                           "void main()\n"
17139                                                                           "{\n"
17140                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17141                                                                           "\n"
17142                                                                           "VARIABLE_USE"
17143                                                                           "\n"
17144                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17145                                                                           "\n"
17146                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17147                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17148                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17149                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17150                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17151                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17152                                                                           "}\n"
17153                                                                           "\n";
17154         static const GLchar* tes = "#version 430 core\n"
17155                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17156                                                            "\n"
17157                                                            "layout(isolines, point_mode) in;\n"
17158                                                            "\n"
17159                                                            "in  vec4 tcs_tes[];\n"
17160                                                            "out vec4 tes_gs;\n"
17161                                                            "\n"
17162                                                            "void main()\n"
17163                                                            "{\n"
17164                                                            "    tes_gs = tcs_tes[0];\n"
17165                                                            "}\n"
17166                                                            "\n";
17167         static const GLchar* tes_tested = "#version 430 core\n"
17168                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17169                                                                           "\n"
17170                                                                           "layout(isolines, point_mode) in;\n"
17171                                                                           "\n"
17172                                                                           "VAR_DEFINITION"
17173                                                                           "\n"
17174                                                                           "in  vec4 tcs_tes[];\n"
17175                                                                           "out vec4 tes_gs;\n"
17176                                                                           "\n"
17177                                                                           "void main()\n"
17178                                                                           "{\n"
17179                                                                           "    vec4 result = tcs_tes[0];\n"
17180                                                                           "\n"
17181                                                                           "VARIABLE_USE"
17182                                                                           "\n"
17183                                                                           "    tes_gs += result;\n"
17184                                                                           "}\n"
17185                                                                           "\n";
17186         static const GLchar* vs = "#version 430 core\n"
17187                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17188                                                           "\n"
17189                                                           "in  vec4 in_vs;\n"
17190                                                           "out vec4 vs_tcs;\n"
17191                                                           "\n"
17192                                                           "void main()\n"
17193                                                           "{\n"
17194                                                           "    vs_tcs = in_vs;\n"
17195                                                           "}\n"
17196                                                           "\n";
17197         static const GLchar* vs_tested = "#version 430 core\n"
17198                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17199                                                                          "\n"
17200                                                                          "VAR_DEFINITION"
17201                                                                          "\n"
17202                                                                          "in  vec4 in_vs;\n"
17203                                                                          "out vec4 vs_tcs;\n"
17204                                                                          "\n"
17205                                                                          "void main()\n"
17206                                                                          "{\n"
17207                                                                          "    vec4 result = in_vs;\n"
17208                                                                          "\n"
17209                                                                          "VARIABLE_USE"
17210                                                                          "\n"
17211                                                                          "    vs_tcs += result;\n"
17212                                                                          "}\n"
17213                                                                          "\n";
17214
17215         std::string source;
17216         testCase&   test_case = m_test_cases[test_case_index];
17217
17218         if (test_case.m_stage == stage)
17219         {
17220                 const GLchar* array = "";
17221                 GLchar            buffer_gohan[16];
17222                 GLchar            buffer_goten[16];
17223                 const GLchar* index     = "";
17224                 size_t            position = 0;
17225                 size_t            temp;
17226                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17227
17228                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17229                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17230
17231                 switch (stage)
17232                 {
17233                 case Utils::Shader::FRAGMENT:
17234                         source = fs_tested;
17235                         break;
17236                 case Utils::Shader::GEOMETRY:
17237                         source = gs_tested;
17238                         array  = "[]";
17239                         index  = "[0]";
17240                         break;
17241                 case Utils::Shader::TESS_CTRL:
17242                         source = tcs_tested;
17243                         array  = "[]";
17244                         index  = "[gl_InvocationID]";
17245                         break;
17246                 case Utils::Shader::TESS_EVAL:
17247                         source = tes_tested;
17248                         array  = "[]";
17249                         index  = "[0]";
17250                         break;
17251                 case Utils::Shader::VERTEX:
17252                         source = vs_tested;
17253                         break;
17254                 default:
17255                         TCU_FAIL("Invalid enum");
17256                 }
17257
17258                 temp = position;
17259                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17260                 position = temp;
17261                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17262                 Utils::replaceToken("ARRAY", position, array, source);
17263                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17264                 Utils::replaceToken("ARRAY", position, array, source);
17265                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17266
17267                 Utils::replaceAllTokens("TYPE", type_name, source);
17268                 Utils::replaceAllTokens("INDEX", index, source);
17269         }
17270         else
17271         {
17272                 switch (stage)
17273                 {
17274                 case Utils::Shader::FRAGMENT:
17275                         source = fs;
17276                         break;
17277                 case Utils::Shader::GEOMETRY:
17278                         source = gs;
17279                         break;
17280                 case Utils::Shader::TESS_CTRL:
17281                         source = tcs;
17282                         break;
17283                 case Utils::Shader::TESS_EVAL:
17284                         source = tes;
17285                         break;
17286                 case Utils::Shader::VERTEX:
17287                         source = vs;
17288                         break;
17289                 default:
17290                         TCU_FAIL("Invalid enum");
17291                 }
17292         }
17293
17294         return source;
17295 }
17296
17297 /** Get description of test case
17298  *
17299  * @param test_case_index Index of test case
17300  *
17301  * @return Test case description
17302  **/
17303 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17304 {
17305         std::stringstream stream;
17306         testCase&                 test_case = m_test_cases[test_case_index];
17307
17308         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17309                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17310                    << " & " << test_case.m_component_goten;
17311
17312         return stream.str();
17313 }
17314
17315 /** Get number of test cases
17316  *
17317  * @return Number of test cases
17318  **/
17319 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17320 {
17321         return static_cast<GLuint>(m_test_cases.size());
17322 }
17323
17324 /** Selects if "compute" stage is relevant for test
17325  *
17326  * @param ignored
17327  *
17328  * @return false
17329  **/
17330 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17331 {
17332         return false;
17333 }
17334
17335 /** Prepare all test cases
17336  *
17337  **/
17338 void OutputComponentAliasingTest::testInit()
17339 {
17340         static const GLuint n_components_per_location = 4;
17341         const GLuint            n_types                                   = getTypesNumber();
17342
17343         for (GLuint i = 0; i < n_types; ++i)
17344         {
17345                 const Utils::Type& type                         = getType(i);
17346                 const GLuint       n_req_components = type.m_n_rows;
17347                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17348
17349                 /* Skip matrices */
17350                 if (1 != type.m_n_columns)
17351                 {
17352                         continue;
17353                 }
17354
17355                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17356                 {
17357                         if (Utils::Shader::COMPUTE == stage)
17358                         {
17359                                 continue;
17360                         }
17361
17362                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17363                         {
17364                                 continue;
17365                         }
17366
17367                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17368                         {
17369                                 const GLint first_aliasing = gohan - n_req_components + 1;
17370                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17371
17372                                 const GLuint goten_start = std::max(0, first_aliasing);
17373                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17374
17375                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17376                                 {
17377                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17378
17379                                         m_test_cases.push_back(test_case);
17380                                 }
17381                         }
17382                 }
17383         }
17384 }
17385
17386 /** Constructor
17387  *
17388  * @param context Test framework context
17389  **/
17390 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17391         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17392                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17393 {
17394 }
17395
17396 /** Source for given test case and stage
17397  *
17398  * @param test_case_index Index of test case
17399  * @param stage           Shader stage
17400  *
17401  * @return Shader source
17402  **/
17403 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17404                                                                                                                                            Utils::Shader::STAGES stage)
17405 {
17406         static const GLchar* var_definition =
17407                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17408                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17409         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17410                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17411                                                                          "    {\n"
17412                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17413                                                                          "    }\n";
17414         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17415                                                                           "    gotenINDEX = TYPE(1);\n"
17416                                                                           "    if (vec4(0) == result)\n"
17417                                                                           "    {\n"
17418                                                                           "        gohanINDEX = TYPE(1);\n"
17419                                                                           "        gotenINDEX = TYPE(0);\n"
17420                                                                           "    }\n";
17421         static const GLchar* fs = "#version 430 core\n"
17422                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17423                                                           "\n"
17424                                                           "in  vec4 gs_fs;\n"
17425                                                           "out vec4 fs_out;\n"
17426                                                           "\n"
17427                                                           "void main()\n"
17428                                                           "{\n"
17429                                                           "    fs_out = gs_fs;\n"
17430                                                           "}\n"
17431                                                           "\n";
17432         static const GLchar* fs_tested = "#version 430 core\n"
17433                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17434                                                                          "\n"
17435                                                                          "VAR_DEFINITION"
17436                                                                          "\n"
17437                                                                          "in  vec4 gs_fs;\n"
17438                                                                          "out vec4 fs_out;\n"
17439                                                                          "\n"
17440                                                                          "void main()\n"
17441                                                                          "{\n"
17442                                                                          "    vec4 result = gs_fs;\n"
17443                                                                          "\n"
17444                                                                          "VARIABLE_USE"
17445                                                                          "\n"
17446                                                                          "    fs_out += result;\n"
17447                                                                          "}\n"
17448                                                                          "\n";
17449         static const GLchar* gs = "#version 430 core\n"
17450                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17451                                                           "\n"
17452                                                           "layout(points)                           in;\n"
17453                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17454                                                           "\n"
17455                                                           "in  vec4 tes_gs[];\n"
17456                                                           "out vec4 gs_fs;\n"
17457                                                           "\n"
17458                                                           "void main()\n"
17459                                                           "{\n"
17460                                                           "    gs_fs = tes_gs[0];\n"
17461                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17462                                                           "    EmitVertex();\n"
17463                                                           "    gs_fs = tes_gs[0];\n"
17464                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17465                                                           "    EmitVertex();\n"
17466                                                           "    gs_fs = tes_gs[0];\n"
17467                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17468                                                           "    EmitVertex();\n"
17469                                                           "    gs_fs = tes_gs[0];\n"
17470                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17471                                                           "    EmitVertex();\n"
17472                                                           "}\n"
17473                                                           "\n";
17474         static const GLchar* gs_tested = "#version 430 core\n"
17475                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17476                                                                          "\n"
17477                                                                          "layout(points)                           in;\n"
17478                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17479                                                                          "\n"
17480                                                                          "VAR_DEFINITION"
17481                                                                          "\n"
17482                                                                          "in  vec4 tes_gs[];\n"
17483                                                                          "out vec4 gs_fs;\n"
17484                                                                          "\n"
17485                                                                          "void main()\n"
17486                                                                          "{\n"
17487                                                                          "    vec4 result = tes_gs[0];\n"
17488                                                                          "\n"
17489                                                                          "VARIABLE_USE"
17490                                                                          "\n"
17491                                                                          "    gs_fs = result;\n"
17492                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17493                                                                          "    EmitVertex();\n"
17494                                                                          "    gs_fs = result;\n"
17495                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17496                                                                          "    EmitVertex();\n"
17497                                                                          "    gs_fs = result;\n"
17498                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17499                                                                          "    EmitVertex();\n"
17500                                                                          "    gs_fs = result;\n"
17501                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17502                                                                          "    EmitVertex();\n"
17503                                                                          "}\n"
17504                                                                          "\n";
17505         static const GLchar* tcs = "#version 430 core\n"
17506                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17507                                                            "\n"
17508                                                            "layout(vertices = 1) out;\n"
17509                                                            "\n"
17510                                                            "in  vec4 vs_tcs[];\n"
17511                                                            "out vec4 tcs_tes[];\n"
17512                                                            "\n"
17513                                                            "void main()\n"
17514                                                            "{\n"
17515                                                            "\n"
17516                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17517                                                            "\n"
17518                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17519                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17520                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17521                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17522                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17523                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17524                                                            "}\n"
17525                                                            "\n";
17526         static const GLchar* tcs_tested = "#version 430 core\n"
17527                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17528                                                                           "\n"
17529                                                                           "layout(vertices = 1) out;\n"
17530                                                                           "\n"
17531                                                                           "VAR_DEFINITION"
17532                                                                           "\n"
17533                                                                           "in  vec4 vs_tcs[];\n"
17534                                                                           "out vec4 tcs_tes[];\n"
17535                                                                           "\n"
17536                                                                           "void main()\n"
17537                                                                           "{\n"
17538                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17539                                                                           "\n"
17540                                                                           "VARIABLE_USE"
17541                                                                           "\n"
17542                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17543                                                                           "\n"
17544                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17545                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17546                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17547                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17548                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17549                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17550                                                                           "}\n"
17551                                                                           "\n";
17552         static const GLchar* tes = "#version 430 core\n"
17553                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17554                                                            "\n"
17555                                                            "layout(isolines, point_mode) in;\n"
17556                                                            "\n"
17557                                                            "in  vec4 tcs_tes[];\n"
17558                                                            "out vec4 tes_gs;\n"
17559                                                            "\n"
17560                                                            "void main()\n"
17561                                                            "{\n"
17562                                                            "    tes_gs = tcs_tes[0];\n"
17563                                                            "}\n"
17564                                                            "\n";
17565         static const GLchar* tes_tested = "#version 430 core\n"
17566                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17567                                                                           "\n"
17568                                                                           "layout(isolines, point_mode) in;\n"
17569                                                                           "\n"
17570                                                                           "VAR_DEFINITION"
17571                                                                           "\n"
17572                                                                           "in  vec4 tcs_tes[];\n"
17573                                                                           "out vec4 tes_gs;\n"
17574                                                                           "\n"
17575                                                                           "void main()\n"
17576                                                                           "{\n"
17577                                                                           "    vec4 result = tcs_tes[0];\n"
17578                                                                           "\n"
17579                                                                           "VARIABLE_USE"
17580                                                                           "\n"
17581                                                                           "    tes_gs += result;\n"
17582                                                                           "}\n"
17583                                                                           "\n";
17584         static const GLchar* vs = "#version 430 core\n"
17585                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17586                                                           "\n"
17587                                                           "in  vec4 in_vs;\n"
17588                                                           "out vec4 vs_tcs;\n"
17589                                                           "\n"
17590                                                           "void main()\n"
17591                                                           "{\n"
17592                                                           "    vs_tcs = in_vs;\n"
17593                                                           "}\n"
17594                                                           "\n";
17595         static const GLchar* vs_tested = "#version 430 core\n"
17596                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17597                                                                          "\n"
17598                                                                          "VAR_DEFINITION"
17599                                                                          "\n"
17600                                                                          "in  vec4 in_vs;\n"
17601                                                                          "out vec4 vs_tcs;\n"
17602                                                                          "\n"
17603                                                                          "void main()\n"
17604                                                                          "{\n"
17605                                                                          "    vec4 result = in_vs;\n"
17606                                                                          "\n"
17607                                                                          "VARIABLE_USE"
17608                                                                          "\n"
17609                                                                          "    vs_tcs += result;\n"
17610                                                                          "}\n"
17611                                                                          "\n";
17612
17613         std::string source;
17614         testCase&   test_case = m_test_cases[test_case_index];
17615
17616         if (test_case.m_stage == stage)
17617         {
17618                 const GLchar*                    array = "";
17619                 GLchar                                   buffer_gohan[16];
17620                 GLchar                                   buffer_goten[16];
17621                 const GLchar*                    direction  = "in ";
17622                 const GLchar*                    flat_gohan = "";
17623                 const GLchar*                    flat_goten = "";
17624                 const GLchar*                    index          = "";
17625                 size_t                                   position   = 0;
17626                 size_t                                   temp;
17627                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17628                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17629                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17630                 const GLchar*                    var_use                 = input_use;
17631
17632                 if (false == test_case.m_is_input)
17633                 {
17634                         direction = "out";
17635                         storage   = Utils::Variable::VARYING_OUTPUT;
17636                         var_use   = output_use;
17637                 }
17638
17639                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17640                 {
17641                         flat_gohan = "flat";
17642                 }
17643
17644                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17645                 {
17646                         flat_goten = "flat";
17647                 }
17648
17649                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17650                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17651
17652                 switch (stage)
17653                 {
17654                 case Utils::Shader::FRAGMENT:
17655                         source = fs_tested;
17656                         break;
17657                 case Utils::Shader::GEOMETRY:
17658                         source = gs_tested;
17659                         array  = "[]";
17660                         index  = "[0]";
17661                         break;
17662                 case Utils::Shader::TESS_CTRL:
17663                         source = tcs_tested;
17664                         array  = "[]";
17665                         index  = "[gl_InvocationID]";
17666                         break;
17667                 case Utils::Shader::TESS_EVAL:
17668                         source = tes_tested;
17669                         array  = "[]";
17670                         index  = "[0]";
17671                         break;
17672                 case Utils::Shader::VERTEX:
17673                         source = vs_tested;
17674                         break;
17675                 default:
17676                         TCU_FAIL("Invalid enum");
17677                 }
17678
17679                 temp = position;
17680                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17681                 position = temp;
17682                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17683                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17684                 Utils::replaceToken("DIRECTION", position, direction, source);
17685                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17686                 Utils::replaceToken("ARRAY", position, array, source);
17687                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17688                 Utils::replaceToken("FLAT", position, flat_goten, source);
17689                 Utils::replaceToken("DIRECTION", position, direction, source);
17690                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17691                 Utils::replaceToken("ARRAY", position, array, source);
17692
17693                 temp = position;
17694                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17695                 position = temp;
17696                 if (true == test_case.m_is_input)
17697                 {
17698                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17699                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17700                 }
17701                 else
17702                 {
17703                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17704                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17705                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17706                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17707                 }
17708
17709                 Utils::replaceAllTokens("INDEX", index, source);
17710         }
17711         else
17712         {
17713                 switch (stage)
17714                 {
17715                 case Utils::Shader::FRAGMENT:
17716                         source = fs;
17717                         break;
17718                 case Utils::Shader::GEOMETRY:
17719                         source = gs;
17720                         break;
17721                 case Utils::Shader::TESS_CTRL:
17722                         source = tcs;
17723                         break;
17724                 case Utils::Shader::TESS_EVAL:
17725                         source = tes;
17726                         break;
17727                 case Utils::Shader::VERTEX:
17728                         source = vs;
17729                         break;
17730                 default:
17731                         TCU_FAIL("Invalid enum");
17732                 }
17733         }
17734
17735         return source;
17736 }
17737
17738 /** Get description of test case
17739  *
17740  * @param test_case_index Index of test case
17741  *
17742  * @return Test case description
17743  **/
17744 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17745 {
17746         std::stringstream stream;
17747         testCase&                 test_case = m_test_cases[test_case_index];
17748
17749         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17750                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17751                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17752
17753         if (true == test_case.m_is_input)
17754         {
17755                 stream << "input";
17756         }
17757         else
17758         {
17759                 stream << "output";
17760         }
17761
17762         return stream.str();
17763 }
17764
17765 /** Get number of test cases
17766  *
17767  * @return Number of test cases
17768  **/
17769 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17770 {
17771         return static_cast<GLuint>(m_test_cases.size());
17772 }
17773
17774 /** Selects if "compute" stage is relevant for test
17775  *
17776  * @param ignored
17777  *
17778  * @return false
17779  **/
17780 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17781 {
17782         return false;
17783 }
17784
17785 /** Prepare all test cases
17786  *
17787  **/
17788 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17789 {
17790         static const GLuint n_components_per_location = 4;
17791         const GLuint            n_types                                   = getTypesNumber();
17792
17793         for (GLuint i = 0; i < n_types; ++i)
17794         {
17795                 const Utils::Type& type_gohan              = getType(i);
17796                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17797
17798                 /* Skip matrices */
17799                 if (1 != type_gohan.m_n_columns)
17800                 {
17801                         continue;
17802                 }
17803
17804                 for (GLuint j = 0; j < n_types; ++j)
17805                 {
17806                         const Utils::Type& type_goten              = getType(j);
17807                         const bool                 is_float_type_goten = isFloatType(type_goten);
17808
17809                         /* Skip matrices */
17810                         if (1 != type_goten.m_n_columns)
17811                         {
17812                                 continue;
17813                         }
17814
17815                         /* Skip valid combinations */
17816                         if (is_float_type_gohan == is_float_type_goten)
17817                         {
17818                                 continue;
17819                         }
17820
17821                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17822                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17823                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17824                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17825
17826                         /* Skip pairs that cannot fit into one location */
17827                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17828                         {
17829                                 continue;
17830                         }
17831
17832                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17833                         {
17834                                 /* Skip compute shader */
17835                                 if (Utils::Shader::COMPUTE == stage)
17836                                 {
17837                                         continue;
17838                                 }
17839
17840                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17841                                 {
17842                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17843                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17844
17845                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17846                                         const GLuint goten_upper_limit = last_aliasing + 1;
17847
17848                                         /* Compoennets before gohan */
17849                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17850                                         {
17851                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17852                                                                                                   type_gohan, type_goten };
17853                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17854                                                                                                    type_gohan, type_goten };
17855
17856                                                 m_test_cases.push_back(test_case_in);
17857
17858                                                 /* Skip double outputs in fragment shader */
17859                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17860                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17861                                                 {
17862                                                         m_test_cases.push_back(test_case_out);
17863                                                 }
17864                                         }
17865
17866                                         /* Components after gohan */
17867                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17868                                         {
17869                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17870                                                                                                   type_gohan, type_goten };
17871                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17872                                                                                                    type_gohan, type_goten };
17873
17874                                                 m_test_cases.push_back(test_case_in);
17875
17876                                                 /* Skip double outputs in fragment shader */
17877                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17878                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17879                                                 {
17880                                                         m_test_cases.push_back(test_case_out);
17881                                                 }
17882                                         }
17883                                 }
17884                         }
17885                 }
17886         }
17887 }
17888
17889 /** Check if given type is float
17890  *
17891  * @param type Type in question
17892  *
17893  * @return true if tpye is float, false otherwise
17894  **/
17895 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17896 {
17897         bool is_float = false;
17898
17899         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17900         {
17901                 is_float = true;
17902         }
17903
17904         return is_float;
17905 }
17906
17907 /** Constructor
17908  *
17909  * @param context Test framework context
17910  **/
17911 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17912         deqp::Context& context)
17913         : NegativeTestBase(
17914                   context, "varying_location_aliasing_with_mixed_interpolation",
17915                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17916 {
17917 }
17918
17919 /** Source for given test case and stage
17920  *
17921  * @param test_case_index Index of test case
17922  * @param stage           Shader stage
17923  *
17924  * @return Shader source
17925  **/
17926 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17927                                                                                                                                                            Utils::Shader::STAGES stage)
17928 {
17929         static const GLchar* var_definition =
17930                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17931                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17932         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17933                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17934                                                                          "    {\n"
17935                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17936                                                                          "    }\n";
17937         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17938                                                                           "    gotenINDEX = TYPE(1);\n"
17939                                                                           "    if (vec4(0) == result)\n"
17940                                                                           "    {\n"
17941                                                                           "        gohanINDEX = TYPE(1);\n"
17942                                                                           "        gotenINDEX = TYPE(0);\n"
17943                                                                           "    }\n";
17944         static const GLchar* fs = "#version 430 core\n"
17945                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17946                                                           "\n"
17947                                                           "in  vec4 gs_fs;\n"
17948                                                           "out vec4 fs_out;\n"
17949                                                           "\n"
17950                                                           "void main()\n"
17951                                                           "{\n"
17952                                                           "    fs_out = gs_fs;\n"
17953                                                           "}\n"
17954                                                           "\n";
17955         static const GLchar* fs_tested = "#version 430 core\n"
17956                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17957                                                                          "\n"
17958                                                                          "VAR_DEFINITION"
17959                                                                          "\n"
17960                                                                          "in  vec4 gs_fs;\n"
17961                                                                          "out vec4 fs_out;\n"
17962                                                                          "\n"
17963                                                                          "void main()\n"
17964                                                                          "{\n"
17965                                                                          "    vec4 result = gs_fs;\n"
17966                                                                          "\n"
17967                                                                          "VARIABLE_USE"
17968                                                                          "\n"
17969                                                                          "    fs_out = result;\n"
17970                                                                          "}\n"
17971                                                                          "\n";
17972         static const GLchar* gs = "#version 430 core\n"
17973                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17974                                                           "\n"
17975                                                           "layout(points)                           in;\n"
17976                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17977                                                           "\n"
17978                                                           "in  vec4 tes_gs[];\n"
17979                                                           "out vec4 gs_fs;\n"
17980                                                           "\n"
17981                                                           "void main()\n"
17982                                                           "{\n"
17983                                                           "    gs_fs = tes_gs[0];\n"
17984                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17985                                                           "    EmitVertex();\n"
17986                                                           "    gs_fs = tes_gs[0];\n"
17987                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17988                                                           "    EmitVertex();\n"
17989                                                           "    gs_fs = tes_gs[0];\n"
17990                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17991                                                           "    EmitVertex();\n"
17992                                                           "    gs_fs = tes_gs[0];\n"
17993                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17994                                                           "    EmitVertex();\n"
17995                                                           "}\n"
17996                                                           "\n";
17997         static const GLchar* gs_tested = "#version 430 core\n"
17998                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17999                                                                          "\n"
18000                                                                          "layout(points)                           in;\n"
18001                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18002                                                                          "\n"
18003                                                                          "VAR_DEFINITION"
18004                                                                          "\n"
18005                                                                          "in  vec4 tes_gs[];\n"
18006                                                                          "out vec4 gs_fs;\n"
18007                                                                          "\n"
18008                                                                          "void main()\n"
18009                                                                          "{\n"
18010                                                                          "    vec4 result = tes_gs[0];\n"
18011                                                                          "\n"
18012                                                                          "VARIABLE_USE"
18013                                                                          "\n"
18014                                                                          "    gs_fs = result;\n"
18015                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18016                                                                          "    EmitVertex();\n"
18017                                                                          "    gs_fs = result;\n"
18018                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18019                                                                          "    EmitVertex();\n"
18020                                                                          "    gs_fs = result;\n"
18021                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18022                                                                          "    EmitVertex();\n"
18023                                                                          "    gs_fs = result;\n"
18024                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18025                                                                          "    EmitVertex();\n"
18026                                                                          "}\n"
18027                                                                          "\n";
18028         static const GLchar* tcs = "#version 430 core\n"
18029                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18030                                                            "\n"
18031                                                            "layout(vertices = 1) out;\n"
18032                                                            "\n"
18033                                                            "in  vec4 vs_tcs[];\n"
18034                                                            "out vec4 tcs_tes[];\n"
18035                                                            "\n"
18036                                                            "void main()\n"
18037                                                            "{\n"
18038                                                            "\n"
18039                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18040                                                            "\n"
18041                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18042                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18043                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18044                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18045                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18046                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18047                                                            "}\n"
18048                                                            "\n";
18049         static const GLchar* tcs_tested = "#version 430 core\n"
18050                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18051                                                                           "\n"
18052                                                                           "layout(vertices = 1) out;\n"
18053                                                                           "\n"
18054                                                                           "VAR_DEFINITION"
18055                                                                           "\n"
18056                                                                           "in  vec4 vs_tcs[];\n"
18057                                                                           "out vec4 tcs_tes[];\n"
18058                                                                           "\n"
18059                                                                           "void main()\n"
18060                                                                           "{\n"
18061                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18062                                                                           "\n"
18063                                                                           "VARIABLE_USE"
18064                                                                           "\n"
18065                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18066                                                                           "\n"
18067                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18068                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18069                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18070                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18071                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18072                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18073                                                                           "}\n"
18074                                                                           "\n";
18075         static const GLchar* tes = "#version 430 core\n"
18076                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18077                                                            "\n"
18078                                                            "layout(isolines, point_mode) in;\n"
18079                                                            "\n"
18080                                                            "in  vec4 tcs_tes[];\n"
18081                                                            "out vec4 tes_gs;\n"
18082                                                            "\n"
18083                                                            "void main()\n"
18084                                                            "{\n"
18085                                                            "    tes_gs = tcs_tes[0];\n"
18086                                                            "}\n"
18087                                                            "\n";
18088         static const GLchar* tes_tested = "#version 430 core\n"
18089                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18090                                                                           "\n"
18091                                                                           "layout(isolines, point_mode) in;\n"
18092                                                                           "\n"
18093                                                                           "VAR_DEFINITION"
18094                                                                           "\n"
18095                                                                           "in  vec4 tcs_tes[];\n"
18096                                                                           "out vec4 tes_gs;\n"
18097                                                                           "\n"
18098                                                                           "void main()\n"
18099                                                                           "{\n"
18100                                                                           "    vec4 result = tcs_tes[0];\n"
18101                                                                           "\n"
18102                                                                           "VARIABLE_USE"
18103                                                                           "\n"
18104                                                                           "    tes_gs += result;\n"
18105                                                                           "}\n"
18106                                                                           "\n";
18107         static const GLchar* vs = "#version 430 core\n"
18108                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18109                                                           "\n"
18110                                                           "in  vec4 in_vs;\n"
18111                                                           "out vec4 vs_tcs;\n"
18112                                                           "\n"
18113                                                           "void main()\n"
18114                                                           "{\n"
18115                                                           "    vs_tcs = in_vs;\n"
18116                                                           "}\n"
18117                                                           "\n";
18118         static const GLchar* vs_tested = "#version 430 core\n"
18119                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18120                                                                          "\n"
18121                                                                          "VAR_DEFINITION"
18122                                                                          "\n"
18123                                                                          "in  vec4 in_vs;\n"
18124                                                                          "out vec4 vs_tcs;\n"
18125                                                                          "\n"
18126                                                                          "void main()\n"
18127                                                                          "{\n"
18128                                                                          "    vec4 result = in_vs;\n"
18129                                                                          "\n"
18130                                                                          "VARIABLE_USE"
18131                                                                          "\n"
18132                                                                          "    vs_tcs += result;\n"
18133                                                                          "}\n"
18134                                                                          "\n";
18135
18136         std::string source;
18137         testCase&   test_case = m_test_cases[test_case_index];
18138
18139         if (test_case.m_stage == stage)
18140         {
18141                 const GLchar* array = "";
18142                 GLchar            buffer_gohan[16];
18143                 GLchar            buffer_goten[16];
18144                 const GLchar* direction = "in ";
18145                 const GLchar* index             = "";
18146                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18147                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18148                 size_t            position  = 0;
18149                 size_t            temp;
18150                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18151                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18152                 const GLchar* var_use             = input_use;
18153
18154                 if (false == test_case.m_is_input)
18155                 {
18156                         direction = "out";
18157
18158                         var_use = output_use;
18159                 }
18160
18161                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18162                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18163
18164                 switch (stage)
18165                 {
18166                 case Utils::Shader::FRAGMENT:
18167                         source = fs_tested;
18168                         break;
18169                 case Utils::Shader::GEOMETRY:
18170                         source = gs_tested;
18171                         array  = "[]";
18172                         index  = "[0]";
18173                         break;
18174                 case Utils::Shader::TESS_CTRL:
18175                         source = tcs_tested;
18176                         array  = "[]";
18177                         index  = "[gl_InvocationID]";
18178                         break;
18179                 case Utils::Shader::TESS_EVAL:
18180                         source = tes_tested;
18181                         array  = "[]";
18182                         index  = "[0]";
18183                         break;
18184                 case Utils::Shader::VERTEX:
18185                         source = vs_tested;
18186                         break;
18187                 default:
18188                         TCU_FAIL("Invalid enum");
18189                 }
18190
18191                 temp = position;
18192                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18193                 position = temp;
18194                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18195                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18196                 Utils::replaceToken("DIRECTION", position, direction, source);
18197                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18198                 Utils::replaceToken("ARRAY", position, array, source);
18199                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18200                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18201                 Utils::replaceToken("DIRECTION", position, direction, source);
18202                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18203                 Utils::replaceToken("ARRAY", position, array, source);
18204
18205                 temp = position;
18206                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18207                 position = temp;
18208                 if (true == test_case.m_is_input)
18209                 {
18210                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18211                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18212                 }
18213                 else
18214                 {
18215                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18216                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18217                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18218                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18219                 }
18220
18221                 Utils::replaceAllTokens("INDEX", index, source);
18222         }
18223         else
18224         {
18225                 switch (stage)
18226                 {
18227                 case Utils::Shader::FRAGMENT:
18228                         source = fs;
18229                         break;
18230                 case Utils::Shader::GEOMETRY:
18231                         source = gs;
18232                         break;
18233                 case Utils::Shader::TESS_CTRL:
18234                         source = tcs;
18235                         break;
18236                 case Utils::Shader::TESS_EVAL:
18237                         source = tes;
18238                         break;
18239                 case Utils::Shader::VERTEX:
18240                         source = vs;
18241                         break;
18242                 default:
18243                         TCU_FAIL("Invalid enum");
18244                 }
18245         }
18246
18247         return source;
18248 }
18249
18250 /** Get description of test case
18251  *
18252  * @param test_case_index Index of test case
18253  *
18254  * @return Test case description
18255  **/
18256 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18257 {
18258         std::stringstream stream;
18259         testCase&                 test_case = m_test_cases[test_case_index];
18260
18261         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18262                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18263                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18264                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18265                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18266
18267         if (true == test_case.m_is_input)
18268         {
18269                 stream << "input";
18270         }
18271         else
18272         {
18273                 stream << "output";
18274         }
18275
18276         return stream.str();
18277 }
18278
18279 /** Get number of test cases
18280  *
18281  * @return Number of test cases
18282  **/
18283 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18284 {
18285         return static_cast<GLuint>(m_test_cases.size());
18286 }
18287
18288 /** Selects if "compute" stage is relevant for test
18289  *
18290  * @param ignored
18291  *
18292  * @return false
18293  **/
18294 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18295 {
18296         return false;
18297 }
18298
18299 /** Prepare all test cases
18300  *
18301  **/
18302 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18303 {
18304         static const GLuint n_components_per_location = 4;
18305         const GLuint            n_types                                   = getTypesNumber();
18306
18307         for (GLuint i = 0; i < n_types; ++i)
18308         {
18309                 const Utils::Type& type_gohan              = getType(i);
18310                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18311
18312                 /* Skip matrices */
18313                 if (1 != type_gohan.m_n_columns)
18314                 {
18315                         continue;
18316                 }
18317
18318                 for (GLuint j = 0; j < n_types; ++j)
18319                 {
18320                         const Utils::Type& type_goten              = getType(j);
18321                         const bool                 is_float_type_goten = isFloatType(type_goten);
18322
18323                         /* Skip matrices */
18324                         if (1 != type_goten.m_n_columns)
18325                         {
18326                                 continue;
18327                         }
18328
18329                         /* Skip invalid combinations */
18330                         if (is_float_type_gohan != is_float_type_goten)
18331                         {
18332                                 continue;
18333                         }
18334
18335                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18336                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18337
18338                         /* Skip pairs that cannot fit into one location */
18339                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18340                         {
18341                                 continue;
18342                         }
18343
18344                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18345                         {
18346                                 /* Skip compute shader */
18347                                 if (Utils::Shader::COMPUTE == stage)
18348                                 {
18349                                         continue;
18350                                 }
18351
18352                                 const GLuint gohan = 0;
18353                                 const GLuint goten = gohan + n_req_components_gohan;
18354
18355                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18356                                 {
18357                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18358                                         {
18359                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18360                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18361                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18362                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18363                                                 const bool is_gohan_accepted_as_fs_in =
18364                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18365                                                 const bool is_goten_accepted_as_fs_in =
18366                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18367                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18368
18369                                                 /* Skip when both are the same */
18370                                                 if (int_gohan == int_goten)
18371                                                 {
18372                                                         continue;
18373                                                 }
18374
18375                                                 testCase test_case_in = { gohan,
18376                                                                                                   goten,
18377                                                                                                   (INTERPOLATIONS)int_gohan,
18378                                                                                                   (INTERPOLATIONS)int_goten,
18379                                                                                                   true,
18380                                                                                                   (Utils::Shader::STAGES)stage,
18381                                                                                                   type_gohan,
18382                                                                                                   type_goten };
18383
18384                                                 testCase test_case_out = { gohan,
18385                                                                                                    goten,
18386                                                                                                    (INTERPOLATIONS)int_gohan,
18387                                                                                                    (INTERPOLATIONS)int_goten,
18388                                                                                                    false,
18389                                                                                                    (Utils::Shader::STAGES)stage,
18390                                                                                                    type_gohan,
18391                                                                                                    type_goten };
18392
18393                                                 /* Skip inputs in:
18394                                                  * vertex shader,
18395                                                  * fragment shader when not flat double is used
18396                                                  */
18397                                                 if ((Utils::Shader::VERTEX != stage) &&
18398                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18399                                                 {
18400                                                         m_test_cases.push_back(test_case_in);
18401                                                 }
18402
18403                                                 /* Skip outputs in fragment shader */
18404                                                 if (Utils::Shader::FRAGMENT != stage)
18405                                                 {
18406                                                         m_test_cases.push_back(test_case_out);
18407                                                 }
18408                                         }
18409                                 }
18410                         }
18411                 }
18412         }
18413 }
18414
18415 /** Get interpolation qualifier
18416  *
18417  * @param interpolation Enumeration
18418  *
18419  * @return GLSL qualifier
18420  **/
18421 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18422 {
18423         const GLchar* result = 0;
18424
18425         switch (interpolation)
18426         {
18427         case SMOOTH:
18428                 result = "smooth";
18429                 break;
18430         case FLAT:
18431                 result = "flat";
18432                 break;
18433         case NO_PERSPECTIVE:
18434                 result = "noperspective";
18435                 break;
18436         default:
18437                 TCU_FAIL("Invalid enum");
18438         }
18439
18440         return result;
18441 }
18442
18443 /** Check if given type is float
18444  *
18445  * @param type Type in question
18446  *
18447  * @return true if tpye is float, false otherwise
18448  **/
18449 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18450 {
18451         bool is_float = false;
18452
18453         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18454         {
18455                 is_float = true;
18456         }
18457
18458         return is_float;
18459 }
18460
18461 /** Constructor
18462  *
18463  * @param context Test framework context
18464  **/
18465 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18466         deqp::Context& context)
18467         : NegativeTestBase(
18468                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18469                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18470 {
18471 }
18472
18473 /** Source for given test case and stage
18474  *
18475  * @param test_case_index Index of test case
18476  * @param stage           Shader stage
18477  *
18478  * @return Shader source
18479  **/
18480 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18481                                                                                                                                                                   Utils::Shader::STAGES stage)
18482 {
18483         static const GLchar* var_definition =
18484                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18485                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18486         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18487                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18488                                                                          "    {\n"
18489                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18490                                                                          "    }\n";
18491         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18492                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18493                                                                           "    if (vec4(0) == result)\n"
18494                                                                           "    {\n"
18495                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18496                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18497                                                                           "    }\n";
18498         static const GLchar* fs = "#version 430 core\n"
18499                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18500                                                           "\n"
18501                                                           "in  vec4 gs_fs;\n"
18502                                                           "out vec4 fs_out;\n"
18503                                                           "\n"
18504                                                           "void main()\n"
18505                                                           "{\n"
18506                                                           "    fs_out = gs_fs;\n"
18507                                                           "}\n"
18508                                                           "\n";
18509         static const GLchar* fs_tested = "#version 430 core\n"
18510                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18511                                                                          "\n"
18512                                                                          "VAR_DEFINITION"
18513                                                                          "\n"
18514                                                                          "in  vec4 gs_fs;\n"
18515                                                                          "out vec4 fs_out;\n"
18516                                                                          "\n"
18517                                                                          "void main()\n"
18518                                                                          "{\n"
18519                                                                          "    vec4 result = gs_fs;\n"
18520                                                                          "\n"
18521                                                                          "VARIABLE_USE"
18522                                                                          "\n"
18523                                                                          "    fs_out = result;\n"
18524                                                                          "}\n"
18525                                                                          "\n";
18526         static const GLchar* gs = "#version 430 core\n"
18527                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18528                                                           "\n"
18529                                                           "layout(points)                           in;\n"
18530                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18531                                                           "\n"
18532                                                           "in  vec4 tes_gs[];\n"
18533                                                           "out vec4 gs_fs;\n"
18534                                                           "\n"
18535                                                           "void main()\n"
18536                                                           "{\n"
18537                                                           "    gs_fs = tes_gs[0];\n"
18538                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18539                                                           "    EmitVertex();\n"
18540                                                           "    gs_fs = tes_gs[0];\n"
18541                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18542                                                           "    EmitVertex();\n"
18543                                                           "    gs_fs = tes_gs[0];\n"
18544                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18545                                                           "    EmitVertex();\n"
18546                                                           "    gs_fs = tes_gs[0];\n"
18547                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18548                                                           "    EmitVertex();\n"
18549                                                           "}\n"
18550                                                           "\n";
18551         static const GLchar* gs_tested = "#version 430 core\n"
18552                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18553                                                                          "\n"
18554                                                                          "layout(points)                           in;\n"
18555                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18556                                                                          "\n"
18557                                                                          "VAR_DEFINITION"
18558                                                                          "\n"
18559                                                                          "in  vec4 tes_gs[];\n"
18560                                                                          "out vec4 gs_fs;\n"
18561                                                                          "\n"
18562                                                                          "void main()\n"
18563                                                                          "{\n"
18564                                                                          "    vec4 result = tes_gs[0];\n"
18565                                                                          "\n"
18566                                                                          "VARIABLE_USE"
18567                                                                          "\n"
18568                                                                          "    gs_fs = result;\n"
18569                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18570                                                                          "    EmitVertex();\n"
18571                                                                          "    gs_fs = result;\n"
18572                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18573                                                                          "    EmitVertex();\n"
18574                                                                          "    gs_fs = result;\n"
18575                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18576                                                                          "    EmitVertex();\n"
18577                                                                          "    gs_fs = result;\n"
18578                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18579                                                                          "    EmitVertex();\n"
18580                                                                          "}\n"
18581                                                                          "\n";
18582         static const GLchar* tcs = "#version 430 core\n"
18583                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18584                                                            "\n"
18585                                                            "layout(vertices = 1) out;\n"
18586                                                            "\n"
18587                                                            "in  vec4 vs_tcs[];\n"
18588                                                            "out vec4 tcs_tes[];\n"
18589                                                            "\n"
18590                                                            "void main()\n"
18591                                                            "{\n"
18592                                                            "\n"
18593                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18594                                                            "\n"
18595                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18596                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18597                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18598                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18599                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18600                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18601                                                            "}\n"
18602                                                            "\n";
18603         static const GLchar* tcs_tested = "#version 430 core\n"
18604                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18605                                                                           "\n"
18606                                                                           "layout(vertices = 1) out;\n"
18607                                                                           "\n"
18608                                                                           "VAR_DEFINITION"
18609                                                                           "\n"
18610                                                                           "in  vec4 vs_tcs[];\n"
18611                                                                           "out vec4 tcs_tes[];\n"
18612                                                                           "\n"
18613                                                                           "void main()\n"
18614                                                                           "{\n"
18615                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18616                                                                           "\n"
18617                                                                           "VARIABLE_USE"
18618                                                                           "\n"
18619                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18620                                                                           "\n"
18621                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18622                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18623                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18624                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18625                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18626                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18627                                                                           "}\n"
18628                                                                           "\n";
18629         static const GLchar* tes = "#version 430 core\n"
18630                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18631                                                            "\n"
18632                                                            "layout(isolines, point_mode) in;\n"
18633                                                            "\n"
18634                                                            "in  vec4 tcs_tes[];\n"
18635                                                            "out vec4 tes_gs;\n"
18636                                                            "\n"
18637                                                            "void main()\n"
18638                                                            "{\n"
18639                                                            "    tes_gs = tcs_tes[0];\n"
18640                                                            "}\n"
18641                                                            "\n";
18642         static const GLchar* tes_tested = "#version 430 core\n"
18643                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18644                                                                           "\n"
18645                                                                           "layout(isolines, point_mode) in;\n"
18646                                                                           "\n"
18647                                                                           "VAR_DEFINITION"
18648                                                                           "\n"
18649                                                                           "in  vec4 tcs_tes[];\n"
18650                                                                           "out vec4 tes_gs;\n"
18651                                                                           "\n"
18652                                                                           "void main()\n"
18653                                                                           "{\n"
18654                                                                           "    vec4 result = tcs_tes[0];\n"
18655                                                                           "\n"
18656                                                                           "VARIABLE_USE"
18657                                                                           "\n"
18658                                                                           "    tes_gs += result;\n"
18659                                                                           "}\n"
18660                                                                           "\n";
18661         static const GLchar* vs = "#version 430 core\n"
18662                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18663                                                           "\n"
18664                                                           "in  vec4 in_vs;\n"
18665                                                           "out vec4 vs_tcs;\n"
18666                                                           "\n"
18667                                                           "void main()\n"
18668                                                           "{\n"
18669                                                           "    vs_tcs = in_vs;\n"
18670                                                           "}\n"
18671                                                           "\n";
18672         static const GLchar* vs_tested = "#version 430 core\n"
18673                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18674                                                                          "\n"
18675                                                                          "VAR_DEFINITION"
18676                                                                          "\n"
18677                                                                          "in  vec4 in_vs;\n"
18678                                                                          "out vec4 vs_tcs;\n"
18679                                                                          "\n"
18680                                                                          "void main()\n"
18681                                                                          "{\n"
18682                                                                          "    vec4 result = in_vs;\n"
18683                                                                          "\n"
18684                                                                          "VARIABLE_USE"
18685                                                                          "\n"
18686                                                                          "    vs_tcs += result;\n"
18687                                                                          "}\n"
18688                                                                          "\n";
18689
18690         std::string source;
18691         testCase&   test_case = m_test_cases[test_case_index];
18692
18693         if (test_case.m_stage == stage)
18694         {
18695                 const GLchar* array_gohan = "";
18696                 const GLchar* array_goten = "";
18697                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18698                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18699                 GLchar            buffer_gohan[16];
18700                 GLchar            buffer_goten[16];
18701                 const GLchar* direction   = "in ";
18702                 const GLchar* index_gohan = "";
18703                 const GLchar* index_goten = "";
18704                 const GLchar* int_gohan   = test_case.m_int_gohan;
18705                 const GLchar* int_goten   = test_case.m_int_goten;
18706                 size_t            position      = 0;
18707                 size_t            temp;
18708                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18709                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18710                 const GLchar* var_use             = input_use;
18711
18712                 if (false == test_case.m_is_input)
18713                 {
18714                         direction = "out";
18715
18716                         var_use = output_use;
18717                 }
18718
18719                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18720                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18721
18722                 switch (stage)
18723                 {
18724                 case Utils::Shader::FRAGMENT:
18725                         source = fs_tested;
18726                         break;
18727                 case Utils::Shader::GEOMETRY:
18728                         source          = gs_tested;
18729                         array_gohan = "[]";
18730                         index_gohan = "[0]";
18731                         array_goten = "[]";
18732                         index_goten = "[0]";
18733                         break;
18734                 case Utils::Shader::TESS_CTRL:
18735                         source = tcs_tested;
18736                         if (PATCH != test_case.m_aux_gohan)
18737                         {
18738                                 array_gohan = "[]";
18739                                 index_gohan = "[gl_InvocationID]";
18740                         }
18741                         if (PATCH != test_case.m_aux_goten)
18742                         {
18743                                 array_goten = "[]";
18744                                 index_goten = "[gl_InvocationID]";
18745                         }
18746                         break;
18747                 case Utils::Shader::TESS_EVAL:
18748                         source          = tes_tested;
18749                         array_gohan = "[]";
18750                         index_gohan = "[0]";
18751                         array_goten = "[]";
18752                         index_goten = "[0]";
18753                         break;
18754                 case Utils::Shader::VERTEX:
18755                         source = vs_tested;
18756                         break;
18757                 default:
18758                         TCU_FAIL("Invalid enum");
18759                 }
18760
18761                 temp = position;
18762                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18763                 position = temp;
18764                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18765                 Utils::replaceToken("AUX", position, aux_gohan, source);
18766                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18767                 Utils::replaceToken("DIRECTION", position, direction, source);
18768                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18769                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18770                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18771                 Utils::replaceToken("AUX", position, aux_goten, source);
18772                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18773                 Utils::replaceToken("DIRECTION", position, direction, source);
18774                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18775                 Utils::replaceToken("ARRAY", position, array_goten, source);
18776
18777                 temp = position;
18778                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18779                 position = temp;
18780                 if (true == test_case.m_is_input)
18781                 {
18782                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18783                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18784                 }
18785                 else
18786                 {
18787                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18788                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18789                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18790                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18791                 }
18792
18793                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18794                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18795         }
18796         else
18797         {
18798                 switch (stage)
18799                 {
18800                 case Utils::Shader::FRAGMENT:
18801                         source = fs;
18802                         break;
18803                 case Utils::Shader::GEOMETRY:
18804                         source = gs;
18805                         break;
18806                 case Utils::Shader::TESS_CTRL:
18807                         source = tcs;
18808                         break;
18809                 case Utils::Shader::TESS_EVAL:
18810                         source = tes;
18811                         break;
18812                 case Utils::Shader::VERTEX:
18813                         source = vs;
18814                         break;
18815                 default:
18816                         TCU_FAIL("Invalid enum");
18817                 }
18818         }
18819
18820         return source;
18821 }
18822
18823 /** Get description of test case
18824  *
18825  * @param test_case_index Index of test case
18826  *
18827  * @return Test case description
18828  **/
18829 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18830 {
18831         std::stringstream stream;
18832         testCase&                 test_case = m_test_cases[test_case_index];
18833
18834         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18835                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18836                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18837                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18838
18839         if (true == test_case.m_is_input)
18840         {
18841                 stream << "input";
18842         }
18843         else
18844         {
18845                 stream << "output";
18846         }
18847
18848         return stream.str();
18849 }
18850
18851 /** Get number of test cases
18852  *
18853  * @return Number of test cases
18854  **/
18855 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18856 {
18857         return static_cast<GLuint>(m_test_cases.size());
18858 }
18859
18860 /** Selects if "compute" stage is relevant for test
18861  *
18862  * @param ignored
18863  *
18864  * @return false
18865  **/
18866 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18867 {
18868         return false;
18869 }
18870
18871 /** Prepare all test cases
18872  *
18873  **/
18874 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18875 {
18876         static const GLuint n_components_per_location = 4;
18877         const GLuint            n_types                                   = getTypesNumber();
18878
18879         for (GLuint i = 0; i < n_types; ++i)
18880         {
18881                 const Utils::Type& type_gohan              = getType(i);
18882                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18883
18884                 /* Skip matrices */
18885                 if (1 != type_gohan.m_n_columns)
18886                 {
18887                         continue;
18888                 }
18889
18890                 for (GLuint j = 0; j < n_types; ++j)
18891                 {
18892                         const Utils::Type& type_goten              = getType(j);
18893                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18894                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18895                         const bool                 is_float_type_goten = isFloatType(type_goten);
18896
18897                         /* Skip matrices */
18898                         if (1 != type_goten.m_n_columns)
18899                         {
18900                                 continue;
18901                         }
18902
18903                         /* Skip invalid combinations */
18904                         if (is_float_type_gohan != is_float_type_goten)
18905                         {
18906                                 continue;
18907                         }
18908
18909                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18910                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18911
18912                         /* Skip pairs that cannot fit into one location */
18913                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18914                         {
18915                                 continue;
18916                         }
18917
18918                         const GLuint gohan = 0;
18919                         const GLuint goten = gohan + n_req_components_gohan;
18920
18921                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18922                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18923
18924                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18925                                                                                   type_gohan, type_goten };
18926
18927                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18928                                                                                   type_gohan, type_goten };
18929
18930                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18931                                                                                   type_gohan, type_goten };
18932
18933                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18934                                                                                   type_gohan, type_goten };
18935
18936                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18937                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18938                                                                                  type_gohan,   type_goten };
18939
18940                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18941                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18942                                                                                  type_gohan,   type_goten };
18943
18944                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18945                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18946                                                                                  type_gohan,   type_goten };
18947
18948                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
18949                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18950                                                                                  type_gohan,   type_goten };
18951
18952                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
18953                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18954                                                                                  type_gohan,   type_goten };
18955
18956                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
18957                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18958                                                                                  type_gohan,   type_goten };
18959
18960                         m_test_cases.push_back(test_case_tcs_np);
18961                         m_test_cases.push_back(test_case_tcs_pn);
18962                         m_test_cases.push_back(test_case_tes_np);
18963                         m_test_cases.push_back(test_case_tes_pn);
18964                         m_test_cases.push_back(test_case_fs_nc);
18965                         m_test_cases.push_back(test_case_fs_cn);
18966                         m_test_cases.push_back(test_case_fs_ns);
18967                         m_test_cases.push_back(test_case_fs_sn);
18968                         m_test_cases.push_back(test_case_fs_cs);
18969                         m_test_cases.push_back(test_case_fs_sc);
18970                 }
18971         }
18972 }
18973
18974 /** Get auxiliary storage qualifier
18975  *
18976  * @param aux Enumeration
18977  *
18978  * @return GLSL qualifier
18979  **/
18980 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
18981 {
18982         const GLchar* result = 0;
18983
18984         switch (aux)
18985         {
18986         case NONE:
18987                 result = "";
18988                 break;
18989         case PATCH:
18990                 result = "patch";
18991                 break;
18992         case CENTROID:
18993                 result = "centroid";
18994                 break;
18995         case SAMPLE:
18996                 result = "sample";
18997                 break;
18998         default:
18999                 TCU_FAIL("Invalid enum");
19000         }
19001
19002         return result;
19003 }
19004
19005 /** Check if given type is float
19006  *
19007  * @param type Type in question
19008  *
19009  * @return true if tpye is float, false otherwise
19010  **/
19011 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
19012 {
19013         bool is_float = false;
19014
19015         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
19016         {
19017                 is_float = true;
19018         }
19019
19020         return is_float;
19021 }
19022
19023 /* Constants used by VertexAttribLocationAPITest */
19024 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
19025
19026 /** Constructor
19027  *
19028  * @param context Test framework context
19029  **/
19030 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
19031         : TextureTestBase(context, "vertex_attrib_location_api",
19032                                           "Test verifies that attribute locations API works as expected")
19033 {
19034 }
19035
19036 /** Does BindAttribLocation for "goten" and relink program
19037  *
19038  * @param program           Program object
19039  * @param program_interface Interface of program
19040  **/
19041 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
19042                                                                                                                 Utils::ProgramInterface& program_interface)
19043 {
19044         const Functions& gl = m_context.getRenderContext().getFunctions();
19045
19046         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
19047         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
19048
19049         program.Link(gl, program.m_id);
19050
19051         /* We still need to get locations for gohan and chichi */
19052         TextureTestBase::prepareAttribLocation(program, program_interface);
19053 }
19054
19055 /** Get interface of program
19056  *
19057  * @param ignored
19058  * @param program_interface   Interface of program
19059  * @param ignored
19060  **/
19061 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19062                                                                                                           Utils::ProgramInterface& program_interface,
19063                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19064 {
19065         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19066         const Utils::Type&              type      = Utils::Type::vec4;
19067         const GLuint                    type_size = type.GetSize();
19068
19069         /* Offsets */
19070         const GLuint chichi_offset = 0;
19071         const GLuint goten_offset  = chichi_offset + type_size;
19072         const GLuint gohan_offset  = goten_offset + type_size;
19073         const GLuint goku_offset   = gohan_offset + type_size;
19074
19075         /* Locations */
19076         const GLuint goku_location  = 2;
19077         const GLuint goten_location = m_goten_location;
19078
19079         /* Generate data */
19080         m_goku_data   = type.GenerateDataPacked();
19081         m_gohan_data  = type.GenerateDataPacked();
19082         m_goten_data  = type.GenerateDataPacked();
19083         m_chichi_data = type.GenerateDataPacked();
19084
19085         /* Globals */
19086         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19087
19088         /* Attributes */
19089         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19090                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19091                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19092                          m_goku_data.size() /* data_size */);
19093
19094         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19095                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19096                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19097                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19098
19099         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19100                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19101                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19102                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19103
19104         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19105                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19106                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19107                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19108 }
19109
19110 /** Selects if "compute" stage is relevant for test
19111  *
19112  * @param ignored
19113  *
19114  * @return false
19115  **/
19116 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19117 {
19118         return false;
19119 }
19120
19121 /* Constants used by FragmentDataLocationAPITest */
19122 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19123
19124 /** Constructor
19125  *
19126  * @param context Test framework context
19127  **/
19128 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19129         : TextureTestBase(context, "fragment_data_location_api",
19130                                           "Test verifies that fragment data locations API works as expected")
19131         , m_goku(context)
19132         , m_gohan(context)
19133         , m_goten(context)
19134         , m_chichi(context)
19135 {
19136 }
19137
19138 /** Verifies contents of drawn images
19139  *
19140  * @param ignored
19141  * @param ignored
19142  *
19143  * @return true if images are filled with expected values, false otherwise
19144  **/
19145 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19146 {
19147         static const GLuint size                        = m_width * m_height;
19148         static const GLuint expected_goku   = 0xff000000;
19149         static const GLuint expected_gohan  = 0xff0000ff;
19150         static const GLuint expected_goten  = 0xff00ff00;
19151         static const GLuint expected_chichi = 0xffff0000;
19152
19153         std::vector<GLuint> data;
19154         data.resize(size);
19155
19156         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19157
19158         for (GLuint i = 0; i < size; ++i)
19159         {
19160                 const GLuint color = data[i];
19161
19162                 if (expected_goku != color)
19163                 {
19164                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19165                                                                                                 << tcu::TestLog::EndMessage;
19166                         return false;
19167                 }
19168         }
19169
19170         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19171
19172         for (GLuint i = 0; i < size; ++i)
19173         {
19174                 const GLuint color = data[i];
19175
19176                 if (expected_gohan != color)
19177                 {
19178                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19179                                                                                                 << tcu::TestLog::EndMessage;
19180                         return false;
19181                 }
19182         }
19183
19184         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19185
19186         for (GLuint i = 0; i < size; ++i)
19187         {
19188                 const GLuint color = data[i];
19189
19190                 if (expected_goten != color)
19191                 {
19192                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19193                                                                                                 << tcu::TestLog::EndMessage;
19194                         return false;
19195                 }
19196         }
19197
19198         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19199
19200         for (GLuint i = 0; i < size; ++i)
19201         {
19202                 const GLuint color = data[i];
19203
19204                 if (expected_chichi != color)
19205                 {
19206                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19207                                                                                                 << tcu::TestLog::EndMessage;
19208                         return false;
19209                 }
19210         }
19211
19212         return true;
19213 }
19214
19215 /** Prepare code snippet that will set out variables
19216  *
19217  * @param ignored
19218  * @param ignored
19219  * @param stage               Shader stage
19220  *
19221  * @return Code that pass in variables to next stage
19222  **/
19223 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19224                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19225                                                                                                                 Utils::Shader::STAGES stage)
19226 {
19227         std::string result;
19228
19229         /* Skip for compute shader */
19230         if (Utils::Shader::FRAGMENT != stage)
19231         {
19232                 result = "";
19233         }
19234         else
19235         {
19236                 result = "chichi = vec4(0, 0, 1, 1);\n"
19237                                  "    goku   = vec4(0, 0, 0, 1);\n"
19238                                  "    goten  = vec4(0, 1, 0, 1);\n"
19239                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19240         }
19241
19242         return result;
19243 }
19244
19245 /** Get interface of program
19246  *
19247  * @param ignored
19248  * @param program_interface Interface of program
19249  * @param ignored
19250  **/
19251 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19252                                                                                                           Utils::ProgramInterface& program_interface,
19253                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19254 {
19255         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19256         const Utils::Type&              type = Utils::Type::vec4;
19257
19258         /* Locations */
19259         m_goku_location = 2;
19260
19261         /* Globals */
19262         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19263
19264         /* Attributes */
19265         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19266                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19267                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19268
19269         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19270                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19271                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19272
19273         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19274                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19275                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19276
19277         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19278                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19279                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19280 }
19281
19282 /** Selects if "compute" stage is relevant for test
19283  *
19284  * @param ignored
19285  *
19286  * @return false
19287  **/
19288 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19289 {
19290         return false;
19291 }
19292
19293 /** Get locations for all outputs with automatic_location
19294  *
19295  * @param program           Program object
19296  * @param program_interface Interface of program
19297  **/
19298 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19299                                                                                                                  Utils::ProgramInterface& program_interface)
19300 {
19301         /* Bind location of goten */
19302         const Functions& gl = m_context.getRenderContext().getFunctions();
19303
19304         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19305         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19306
19307         program.Link(gl, program.m_id);
19308
19309         /* Prepare locations for gohan and chichi */
19310         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19311
19312         /* Get all locations */
19313         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19314
19315         Utils::Variable::PtrVector& outputs = si.m_outputs;
19316
19317         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19318         {
19319                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19320
19321                 if (0 == desc.m_name.compare("gohan"))
19322                 {
19323                         m_gohan_location = desc.m_expected_location;
19324                 }
19325                 else if (0 == desc.m_name.compare("chichi"))
19326                 {
19327                         m_chichi_location = desc.m_expected_location;
19328                 }
19329
19330                 /* Locations of goku and goten are fixed */
19331         }
19332 }
19333
19334 /** Prepare framebuffer with single texture as color attachment
19335  *
19336  * @param framebuffer     Framebuffer
19337  * @param color_0_texture Texture that will used as color attachment
19338  **/
19339 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19340 {
19341         /* Let parent prepare its stuff */
19342         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19343
19344         /* Prepare data */
19345         std::vector<GLuint> texture_data;
19346         texture_data.resize(m_width * m_height);
19347
19348         for (GLuint i = 0; i < texture_data.size(); ++i)
19349         {
19350                 texture_data[i] = 0x20406080;
19351         }
19352
19353         /* Prepare textures */
19354         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19355
19356         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19357
19358         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19359
19360         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19361
19362         /* Attach textures to framebuffer */
19363         framebuffer.Bind();
19364         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19365         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19366         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19367         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19368
19369         /* Set up drawbuffers */
19370         const Functions& gl = m_context.getRenderContext().getFunctions();
19371         // The fragment shader can have more than 4 color outputs, but it only care about 4 (goku, gohan, goten, chichi).
19372         // We will first initialize all draw buffers to NONE and then set the real value for the 4 outputs we care about
19373         GLint maxDrawBuffers = 0;
19374         gl.getIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
19375
19376         std::vector<GLenum> buffers(maxDrawBuffers, GL_NONE);
19377         buffers[m_chichi_location] = GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location);
19378         buffers[m_goten_location]  = GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location);
19379         buffers[m_goku_location]   = GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location);
19380         buffers[m_gohan_location]  = GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location);
19381
19382         gl.drawBuffers(maxDrawBuffers, buffers.data());
19383         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19384 }
19385
19386 /** Constructor
19387  *
19388  * @param context Test framework context
19389  **/
19390 XFBInputTest::XFBInputTest(deqp::Context& context)
19391         : NegativeTestBase(context, "xfb_input",
19392                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19393 {
19394 }
19395
19396 /** Source for given test case and stage
19397  *
19398  * @param test_case_index Index of test case
19399  * @param stage           Shader stage
19400  *
19401  * @return Shader source
19402  **/
19403 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19404 {
19405         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19406         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19407         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19408         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19409         static const GLchar* fs                                    = "#version 430 core\n"
19410                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19411                                                           "\n"
19412                                                           "in  vec4 gs_fs;\n"
19413                                                           "out vec4 fs_out;\n"
19414                                                           "\n"
19415                                                           "void main()\n"
19416                                                           "{\n"
19417                                                           "    fs_out = gs_fs;\n"
19418                                                           "}\n"
19419                                                           "\n";
19420         static const GLchar* fs_tested = "#version 430 core\n"
19421                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19422                                                                          "\n"
19423                                                                          "VAR_DEFINITION"
19424                                                                          "\n"
19425                                                                          "in  vec4 gs_fs;\n"
19426                                                                          "out vec4 fs_out;\n"
19427                                                                          "\n"
19428                                                                          "void main()\n"
19429                                                                          "{\n"
19430                                                                          "    vec4 result = gs_fs;\n"
19431                                                                          "\n"
19432                                                                          "VARIABLE_USE"
19433                                                                          "\n"
19434                                                                          "    fs_out = result;\n"
19435                                                                          "}\n"
19436                                                                          "\n";
19437         static const GLchar* gs = "#version 430 core\n"
19438                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19439                                                           "\n"
19440                                                           "layout(points)                           in;\n"
19441                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19442                                                           "\n"
19443                                                           "in  vec4 tes_gs[];\n"
19444                                                           "out vec4 gs_fs;\n"
19445                                                           "\n"
19446                                                           "void main()\n"
19447                                                           "{\n"
19448                                                           "    gs_fs = tes_gs[0];\n"
19449                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19450                                                           "    EmitVertex();\n"
19451                                                           "    gs_fs = tes_gs[0];\n"
19452                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19453                                                           "    EmitVertex();\n"
19454                                                           "    gs_fs = tes_gs[0];\n"
19455                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19456                                                           "    EmitVertex();\n"
19457                                                           "    gs_fs = tes_gs[0];\n"
19458                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19459                                                           "    EmitVertex();\n"
19460                                                           "}\n"
19461                                                           "\n";
19462         static const GLchar* gs_tested = "#version 430 core\n"
19463                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19464                                                                          "\n"
19465                                                                          "layout(points)                           in;\n"
19466                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19467                                                                          "\n"
19468                                                                          "VAR_DEFINITION"
19469                                                                          "\n"
19470                                                                          "in  vec4 tes_gs[];\n"
19471                                                                          "out vec4 gs_fs;\n"
19472                                                                          "\n"
19473                                                                          "void main()\n"
19474                                                                          "{\n"
19475                                                                          "    vec4 result = tes_gs[0];\n"
19476                                                                          "\n"
19477                                                                          "VARIABLE_USE"
19478                                                                          "\n"
19479                                                                          "    gs_fs = result;\n"
19480                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19481                                                                          "    EmitVertex();\n"
19482                                                                          "    gs_fs = result;\n"
19483                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19484                                                                          "    EmitVertex();\n"
19485                                                                          "    gs_fs = result;\n"
19486                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19487                                                                          "    EmitVertex();\n"
19488                                                                          "    gs_fs = result;\n"
19489                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19490                                                                          "    EmitVertex();\n"
19491                                                                          "}\n"
19492                                                                          "\n";
19493         static const GLchar* tcs = "#version 430 core\n"
19494                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19495                                                            "\n"
19496                                                            "layout(vertices = 1) out;\n"
19497                                                            "\n"
19498                                                            "in  vec4 vs_tcs[];\n"
19499                                                            "out vec4 tcs_tes[];\n"
19500                                                            "\n"
19501                                                            "void main()\n"
19502                                                            "{\n"
19503                                                            "\n"
19504                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19505                                                            "\n"
19506                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19507                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19508                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19509                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19510                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19511                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19512                                                            "}\n"
19513                                                            "\n";
19514         static const GLchar* tcs_tested = "#version 430 core\n"
19515                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19516                                                                           "\n"
19517                                                                           "layout(vertices = 1) out;\n"
19518                                                                           "\n"
19519                                                                           "VAR_DEFINITION"
19520                                                                           "\n"
19521                                                                           "in  vec4 vs_tcs[];\n"
19522                                                                           "out vec4 tcs_tes[];\n"
19523                                                                           "\n"
19524                                                                           "void main()\n"
19525                                                                           "{\n"
19526                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19527                                                                           "\n"
19528                                                                           "VARIABLE_USE"
19529                                                                           "\n"
19530                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19531                                                                           "\n"
19532                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19533                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19534                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19535                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19536                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19537                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19538                                                                           "}\n"
19539                                                                           "\n";
19540         static const GLchar* tes = "#version 430 core\n"
19541                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19542                                                            "\n"
19543                                                            "layout(isolines, point_mode) in;\n"
19544                                                            "\n"
19545                                                            "in  vec4 tcs_tes[];\n"
19546                                                            "out vec4 tes_gs;\n"
19547                                                            "\n"
19548                                                            "void main()\n"
19549                                                            "{\n"
19550                                                            "    tes_gs = tcs_tes[0];\n"
19551                                                            "}\n"
19552                                                            "\n";
19553         static const GLchar* tes_tested = "#version 430 core\n"
19554                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19555                                                                           "\n"
19556                                                                           "layout(isolines, point_mode) in;\n"
19557                                                                           "\n"
19558                                                                           "VAR_DEFINITION"
19559                                                                           "\n"
19560                                                                           "in  vec4 tcs_tes[];\n"
19561                                                                           "out vec4 tes_gs;\n"
19562                                                                           "\n"
19563                                                                           "void main()\n"
19564                                                                           "{\n"
19565                                                                           "    vec4 result = tcs_tes[0];\n"
19566                                                                           "\n"
19567                                                                           "VARIABLE_USE"
19568                                                                           "\n"
19569                                                                           "    tes_gs += result;\n"
19570                                                                           "}\n"
19571                                                                           "\n";
19572         static const GLchar* vs = "#version 430 core\n"
19573                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19574                                                           "\n"
19575                                                           "in  vec4 in_vs;\n"
19576                                                           "out vec4 vs_tcs;\n"
19577                                                           "\n"
19578                                                           "void main()\n"
19579                                                           "{\n"
19580                                                           "    vs_tcs = in_vs;\n"
19581                                                           "}\n"
19582                                                           "\n";
19583         static const GLchar* vs_tested = "#version 430 core\n"
19584                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19585                                                                          "\n"
19586                                                                          "VAR_DEFINITION"
19587                                                                          "\n"
19588                                                                          "in  vec4 in_vs;\n"
19589                                                                          "out vec4 vs_tcs;\n"
19590                                                                          "\n"
19591                                                                          "void main()\n"
19592                                                                          "{\n"
19593                                                                          "    vec4 result = in_vs;\n"
19594                                                                          "\n"
19595                                                                          "VARIABLE_USE"
19596                                                                          "\n"
19597                                                                          "    vs_tcs += result;\n"
19598                                                                          "}\n"
19599                                                                          "\n";
19600
19601         std::string source;
19602         testCase&   test_case = m_test_cases[test_case_index];
19603
19604         if (test_case.m_stage == stage)
19605         {
19606                 const GLchar* array     = "";
19607                 const GLchar* index     = "";
19608                 size_t            position = 0;
19609                 size_t            temp;
19610                 const GLchar* var_definition = 0;
19611                 const GLchar* var_use            = input_use;
19612
19613                 switch (test_case.m_qualifier)
19614                 {
19615                 case BUFFER:
19616                         var_definition = buffer_var_definition;
19617                         break;
19618                 case OFFSET:
19619                         var_definition = offset_var_definition;
19620                         break;
19621                 case STRIDE:
19622                         var_definition = stride_var_definition;
19623                         break;
19624                 default:
19625                         TCU_FAIL("Invalid enum");
19626                 }
19627
19628                 switch (stage)
19629                 {
19630                 case Utils::Shader::FRAGMENT:
19631                         source = fs_tested;
19632                         break;
19633                 case Utils::Shader::GEOMETRY:
19634                         source = gs_tested;
19635                         array  = "[]";
19636                         index  = "[0]";
19637                         break;
19638                 case Utils::Shader::TESS_CTRL:
19639                         source = tcs_tested;
19640                         array  = "[]";
19641                         index  = "[gl_InvocationID]";
19642                         break;
19643                 case Utils::Shader::TESS_EVAL:
19644                         source = tes_tested;
19645                         array  = "[]";
19646                         index  = "[0]";
19647                         break;
19648                 case Utils::Shader::VERTEX:
19649                         source = vs_tested;
19650                         break;
19651                 default:
19652                         TCU_FAIL("Invalid enum");
19653                 }
19654
19655                 temp = position;
19656                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19657                 position = temp;
19658                 Utils::replaceToken("ARRAY", position, array, source);
19659                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19660
19661                 Utils::replaceAllTokens("INDEX", index, source);
19662         }
19663         else
19664         {
19665                 switch (stage)
19666                 {
19667                 case Utils::Shader::FRAGMENT:
19668                         source = fs;
19669                         break;
19670                 case Utils::Shader::GEOMETRY:
19671                         source = gs;
19672                         break;
19673                 case Utils::Shader::TESS_CTRL:
19674                         source = tcs;
19675                         break;
19676                 case Utils::Shader::TESS_EVAL:
19677                         source = tes;
19678                         break;
19679                 case Utils::Shader::VERTEX:
19680                         source = vs;
19681                         break;
19682                 default:
19683                         TCU_FAIL("Invalid enum");
19684                 }
19685         }
19686
19687         return source;
19688 }
19689
19690 /** Get description of test case
19691  *
19692  * @param test_case_index Index of test case
19693  *
19694  * @return Test case description
19695  **/
19696 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19697 {
19698         std::stringstream stream;
19699         testCase&                 test_case = m_test_cases[test_case_index];
19700
19701         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19702
19703         switch (test_case.m_qualifier)
19704         {
19705         case BUFFER:
19706                 stream << "xfb_buffer";
19707                 break;
19708         case OFFSET:
19709                 stream << "xfb_offset";
19710                 break;
19711         case STRIDE:
19712                 stream << "xfb_stride";
19713                 break;
19714         default:
19715                 TCU_FAIL("Invalid enum");
19716         }
19717
19718         return stream.str();
19719 }
19720
19721 /** Get number of test cases
19722  *
19723  * @return Number of test cases
19724  **/
19725 GLuint XFBInputTest::getTestCaseNumber()
19726 {
19727         return static_cast<GLuint>(m_test_cases.size());
19728 }
19729
19730 /** Selects if "compute" stage is relevant for test
19731  *
19732  * @param ignored
19733  *
19734  * @return false
19735  **/
19736 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19737 {
19738         return false;
19739 }
19740
19741 /** Prepare all test cases
19742  *
19743  **/
19744 void XFBInputTest::testInit()
19745 {
19746         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19747         {
19748                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19749                 {
19750                         if (Utils::Shader::COMPUTE == stage)
19751                         {
19752                                 continue;
19753                         }
19754
19755                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19756
19757                         m_test_cases.push_back(test_case);
19758                 }
19759         }
19760 }
19761
19762 /* Constants used by XFBAllStagesTest */
19763 const GLuint XFBAllStagesTest::m_gs_index = 3;
19764
19765 /** Constructor
19766  *
19767  * @param context Test context
19768  **/
19769 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19770         : BufferTestBase(context, "xfb_all_stages",
19771                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19772 {
19773         /* Nothing to be done here */
19774 }
19775
19776 /** Get descriptors of buffers necessary for test
19777  *
19778  * @param ignored
19779  * @param out_descriptors Descriptors of buffers used by test
19780  **/
19781 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19782                                                                                         bufferDescriptor::Vector& out_descriptors)
19783 {
19784         static const GLuint n_stages = 4;
19785         const Utils::Type&  vec4         = Utils::Type::vec4;
19786
19787         /* Data */
19788         tcu::Vec4 sum;
19789
19790         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19791         out_descriptors.resize(n_stages * 2 + 1);
19792
19793         /* */
19794         for (GLuint i = 0; i < n_stages; ++i)
19795         {
19796                 /* Get references */
19797                 bufferDescriptor& uniform = out_descriptors[i + 0];
19798                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19799
19800                 /* Index */
19801                 uniform.m_index = i;
19802                 xfb.m_index             = i;
19803
19804                 /* Target */
19805                 uniform.m_target = Utils::Buffer::Uniform;
19806                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19807
19808                 /* Data */
19809                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19810
19811                 sum += var;
19812
19813                 uniform.m_initial_data.resize(vec4.GetSize());
19814                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19815
19816                 xfb.m_initial_data = vec4.GenerateDataPacked();
19817
19818                 if (m_gs_index != i)
19819                 {
19820                         xfb.m_expected_data = xfb.m_initial_data;
19821                 }
19822                 else
19823                 {
19824                         xfb.m_expected_data.resize(vec4.GetSize());
19825                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19826                 }
19827         }
19828
19829         /* FS */
19830         {
19831                 /* Get reference */
19832                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19833
19834                 /* Index */
19835                 uniform.m_index = n_stages;
19836
19837                 /* Target */
19838                 uniform.m_target = Utils::Buffer::Uniform;
19839
19840                 /* Data */
19841                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19842
19843                 uniform.m_initial_data.resize(vec4.GetSize());
19844                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19845         }
19846 }
19847
19848 /** Get body of main function for given shader stage
19849  *
19850  * @param ignored
19851  * @param stage            Shader stage
19852  * @param out_assignments  Set to empty
19853  * @param out_calculations Set to empty
19854  **/
19855 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19856                                                                          std::string& out_assignments, std::string& out_calculations)
19857 {
19858         out_calculations = "";
19859
19860         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19861         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19862         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19863         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19864         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19865
19866         const GLchar* assignments = 0;
19867         switch (stage)
19868         {
19869         case Utils::Shader::FRAGMENT:
19870                 assignments = fs;
19871                 break;
19872         case Utils::Shader::GEOMETRY:
19873                 assignments = gs;
19874                 break;
19875         case Utils::Shader::TESS_CTRL:
19876                 assignments = tcs;
19877                 break;
19878         case Utils::Shader::TESS_EVAL:
19879                 assignments = tes;
19880                 break;
19881         case Utils::Shader::VERTEX:
19882                 assignments = vs;
19883                 break;
19884         default:
19885                 TCU_FAIL("Invalid enum");
19886         }
19887
19888         out_assignments = assignments;
19889 }
19890
19891 /** Get interface of shader
19892  *
19893  * @param ignored
19894  * @param stage         Shader stage
19895  * @param out_interface Set to ""
19896  **/
19897 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19898                                                                                   std::string& out_interface)
19899 {
19900         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19901                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19902                                                           "    vec4 uni_vs;\n"
19903                                                           "};\n";
19904         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19905                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19906                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19907                                                            "    vec4 uni_tcs;\n"
19908                                                            "};\n";
19909         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19910                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19911                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19912                                                            "    vec4 uni_tes;\n"
19913                                                            "};\n";
19914         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19915                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19916                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19917                                                           "    vec4 uni_gs;\n"
19918                                                           "};\n";
19919         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19920                                                           "                       out     vec4 fs_out;\n"
19921                                                           "layout(binding    = 4) uniform fs_block {\n"
19922                                                           "    vec4 uni_fs;\n"
19923                                                           "};\n";
19924
19925         const GLchar* interface = 0;
19926         switch (stage)
19927         {
19928         case Utils::Shader::FRAGMENT:
19929                 interface = fs;
19930                 break;
19931         case Utils::Shader::GEOMETRY:
19932                 interface = gs;
19933                 break;
19934         case Utils::Shader::TESS_CTRL:
19935                 interface = tcs;
19936                 break;
19937         case Utils::Shader::TESS_EVAL:
19938                 interface = tes;
19939                 break;
19940         case Utils::Shader::VERTEX:
19941                 interface = vs;
19942                 break;
19943         default:
19944                 TCU_FAIL("Invalid enum");
19945         }
19946
19947         out_interface = interface;
19948 }
19949
19950 /* Constants used by XFBStrideOfEmptyListTest */
19951 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
19952
19953 /** Constructor
19954  *
19955  * @param context Test context
19956  **/
19957 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
19958         : BufferTestBase(context, "xfb_stride_of_empty_list",
19959                                          "Test verifies that xfb_stride qualifier is respected when no xfb_offset is specified")
19960 {
19961         /* Nothing to be done here */
19962 }
19963
19964 /** Execute drawArrays for single vertex
19965  *
19966  * @param test_case_index Index of test case
19967  *
19968  * @return true if proper error is reported
19969  **/
19970 bool XFBStrideOfEmptyListTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
19971 {
19972         const Functions& gl             = m_context.getRenderContext().getFunctions();
19973         bool                     result = true;
19974
19975         /* Draw */
19976         gl.disable(GL_RASTERIZER_DISCARD);
19977         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
19978
19979         gl.beginTransformFeedback(GL_POINTS);
19980         GLenum error = gl.getError();
19981         switch (test_case_index)
19982         {
19983         case VALID:
19984                 if (GL_NO_ERROR != error)
19985                 {
19986                         gl.endTransformFeedback();
19987                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
19988                 }
19989
19990                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
19991                 error = gl.getError();
19992
19993                 gl.endTransformFeedback();
19994                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
19995                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
19996
19997                 break;
19998
19999         case FIRST_MISSING:
20000                 if (GL_NO_ERROR == error)
20001                 {
20002                         gl.endTransformFeedback();
20003                 }
20004
20005                 if (GL_INVALID_OPERATION != error)
20006                 {
20007                         m_context.getTestContext().getLog()
20008                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
20009                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20010                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20011
20012                         result = false;
20013                 }
20014
20015                 break;
20016
20017         case SECOND_MISSING:
20018                 if (GL_NO_ERROR == error)
20019                 {
20020                         gl.endTransformFeedback();
20021                 }
20022
20023                 if (GL_INVALID_OPERATION != error)
20024                 {
20025                         m_context.getTestContext().getLog()
20026                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
20027                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20028                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20029
20030                         result = false;
20031                 }
20032
20033                 break;
20034         }
20035
20036         /* Done */
20037         return result;
20038 }
20039
20040 /** Get descriptors of buffers necessary for test
20041  *
20042  * @param test_case_index Index of test case
20043  * @param out_descriptors Descriptors of buffers used by test
20044  **/
20045 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
20046                                                                                                         bufferDescriptor::Vector& out_descriptors)
20047 {
20048         switch (test_case_index)
20049         {
20050         case VALID:
20051         {
20052                 /* Test needs single uniform and two xfbs */
20053                 out_descriptors.resize(3);
20054
20055                 /* Get references */
20056                 bufferDescriptor& uniform = out_descriptors[0];
20057                 bufferDescriptor& xfb_0   = out_descriptors[1];
20058                 bufferDescriptor& xfb_1   = out_descriptors[2];
20059
20060                 /* Index */
20061                 uniform.m_index = 0;
20062                 xfb_0.m_index   = 0;
20063                 xfb_1.m_index   = 1;
20064
20065                 /* Target */
20066                 uniform.m_target = Utils::Buffer::Uniform;
20067                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20068                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20069
20070                 /* Data */
20071                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20072
20073                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20074                 xfb_0.m_expected_data = uniform.m_initial_data;
20075
20076                 /* Data, contents are the same as no modification is expected */
20077                 xfb_1.m_initial_data.resize(m_stride);
20078                 xfb_1.m_expected_data.resize(m_stride);
20079
20080                 for (GLuint i = 0; i < m_stride; ++i)
20081                 {
20082                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20083                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20084                 }
20085         }
20086
20087         break;
20088
20089         case FIRST_MISSING:
20090         {
20091                 /* Test needs single uniform and two xfbs */
20092                 out_descriptors.resize(2);
20093
20094                 /* Get references */
20095                 bufferDescriptor& uniform = out_descriptors[0];
20096                 bufferDescriptor& xfb_1   = out_descriptors[1];
20097
20098                 /* Index */
20099                 uniform.m_index = 0;
20100                 xfb_1.m_index   = 1;
20101
20102                 /* Target */
20103                 uniform.m_target = Utils::Buffer::Uniform;
20104                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20105
20106                 /* Data */
20107                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20108
20109                 /* Draw call will not be executed, contents does not matter */
20110                 xfb_1.m_initial_data.resize(m_stride);
20111         }
20112
20113         break;
20114
20115         case SECOND_MISSING:
20116         {
20117                 /* Test needs single uniform and two xfbs */
20118                 out_descriptors.resize(2);
20119
20120                 /* Get references */
20121                 bufferDescriptor& uniform = out_descriptors[0];
20122                 bufferDescriptor& xfb_0   = out_descriptors[1];
20123
20124                 /* Index */
20125                 uniform.m_index = 0;
20126                 xfb_0.m_index   = 0;
20127
20128                 /* Target */
20129                 uniform.m_target = Utils::Buffer::Uniform;
20130                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20131
20132                 /* Data */
20133                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20134
20135                 /* Draw call will not be executed, contents does not matter */
20136                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20137         }
20138
20139         break;
20140         }
20141 }
20142
20143 /** Get body of main function for given shader stage
20144  *
20145  * @param ignored
20146  * @param stage            Shader stage
20147  * @param out_assignments  Set to empty
20148  * @param out_calculations Set to empty
20149  **/
20150 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20151                                                                                          std::string& out_assignments, std::string& out_calculations)
20152 {
20153         out_calculations = "";
20154
20155         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20156         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20157
20158         const GLchar* assignments = "";
20159         switch (stage)
20160         {
20161         case Utils::Shader::FRAGMENT:
20162                 assignments = fs;
20163                 break;
20164         case Utils::Shader::GEOMETRY:
20165                 assignments = gs;
20166                 break;
20167         default:
20168                 break;
20169         }
20170
20171         out_assignments = assignments;
20172 }
20173
20174 /** Get interface of shader
20175  *
20176  * @param ignored
20177  * @param stage            Shader stage
20178  * @param out_interface    Set to ""
20179  **/
20180 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20181                                                                                                   std::string& out_interface)
20182 {
20183         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20184                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20185                                                           "\n"
20186                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20187                                                           "    vec4 uni_gs;\n"
20188                                                           "};\n";
20189         static const GLchar* fs = "in  vec4 gs_fs;\n"
20190                                                           "out vec4 fs_out;\n";
20191
20192         switch (stage)
20193         {
20194         case Utils::Shader::FRAGMENT:
20195                 out_interface = fs;
20196                 break;
20197         case Utils::Shader::GEOMETRY:
20198                 out_interface = gs;
20199                 break;
20200         default:
20201                 out_interface = "";
20202                 return;
20203         }
20204 }
20205
20206 /** Returns buffer details in human readable form.
20207  *
20208  * @param test_case_index Index of test case
20209  *
20210  * @return Case description
20211  **/
20212 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20213 {
20214         std::string result;
20215
20216         switch (test_case_index)
20217         {
20218         case VALID:
20219                 result = "Valid case";
20220                 break;
20221         case FIRST_MISSING:
20222                 result = "Missing xfb at index 0";
20223                 break;
20224         case SECOND_MISSING:
20225                 result = "Missing xfb at index 1";
20226                 break;
20227         default:
20228                 TCU_FAIL("Invalid enum");
20229         }
20230
20231         return result;
20232 }
20233
20234 /** Get number of test cases
20235  *
20236  * @return 3
20237  **/
20238 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20239 {
20240         return 3;
20241 }
20242
20243 /* Constants used by XFBStrideOfEmptyListTest */
20244 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20245
20246 /** Constructor
20247  *
20248  * @param context Test context
20249  **/
20250 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20251         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20252                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20253 {
20254         /* Nothing to be done here */
20255 }
20256
20257 /** Execute drawArrays for single vertex
20258  *
20259  * @param test_case_index Index of test case
20260  *
20261  * @return true if proper error is reported
20262  **/
20263 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
20264 {
20265         const Functions& gl             = m_context.getRenderContext().getFunctions();
20266         bool                     result = true;
20267
20268         /* Draw */
20269         gl.disable(GL_RASTERIZER_DISCARD);
20270         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20271
20272         gl.beginTransformFeedback(GL_POINTS);
20273         GLenum error = gl.getError();
20274         switch (test_case_index)
20275         {
20276         case VALID:
20277                 if (GL_NO_ERROR != error)
20278                 {
20279                         gl.endTransformFeedback();
20280                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20281                 }
20282
20283                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20284                 error = gl.getError();
20285
20286                 gl.endTransformFeedback();
20287                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20288                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20289
20290                 break;
20291
20292         case FIRST_MISSING:
20293                 if (GL_NO_ERROR == error)
20294                 {
20295                         gl.endTransformFeedback();
20296                 }
20297
20298                 if (GL_INVALID_OPERATION != error)
20299                 {
20300                         m_context.getTestContext().getLog()
20301                                 << tcu::TestLog::Message << "XFB at index 0, that is declared as empty, is missing. It was expected "
20302                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20303                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20304
20305                         result = false;
20306                 }
20307
20308                 break;
20309
20310         case SECOND_MISSING:
20311                 if (GL_NO_ERROR == error)
20312                 {
20313                         gl.endTransformFeedback();
20314                 }
20315
20316                 if (GL_INVALID_OPERATION != error)
20317                 {
20318                         m_context.getTestContext().getLog()
20319                                 << tcu::TestLog::Message << "XFB at index 1, that is written by GS, is missing. It was expected that "
20320                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20321                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20322
20323                         result = false;
20324                 }
20325
20326                 break;
20327         }
20328
20329         /* Done */
20330         return result;
20331 }
20332
20333 /** Get descriptors of buffers necessary for test
20334  *
20335  * @param test_case_index Index of test case
20336  * @param out_descriptors Descriptors of buffers used by test
20337  **/
20338 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20339                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20340 {
20341         switch (test_case_index)
20342         {
20343         case VALID:
20344         {
20345                 /* Test needs single uniform and two xfbs */
20346                 out_descriptors.resize(3);
20347
20348                 /* Get references */
20349                 bufferDescriptor& uniform = out_descriptors[0];
20350                 bufferDescriptor& xfb_0   = out_descriptors[1];
20351                 bufferDescriptor& xfb_1   = out_descriptors[2];
20352
20353                 /* Index */
20354                 uniform.m_index = 0;
20355                 xfb_0.m_index   = 0;
20356                 xfb_1.m_index   = 1;
20357
20358                 /* Target */
20359                 uniform.m_target = Utils::Buffer::Uniform;
20360                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20361                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20362
20363                 /* Data */
20364                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20365
20366                 /* Data, contents are the same as no modification is expected */
20367                 xfb_0.m_initial_data.resize(m_stride);
20368                 xfb_0.m_expected_data.resize(m_stride);
20369
20370                 for (GLuint i = 0; i < m_stride; ++i)
20371                 {
20372                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20373                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20374                 }
20375
20376                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20377                 xfb_1.m_expected_data = uniform.m_initial_data;
20378         }
20379
20380         break;
20381
20382         case FIRST_MISSING:
20383         {
20384                 /* Test needs single uniform and two xfbs */
20385                 out_descriptors.resize(2);
20386
20387                 /* Get references */
20388                 bufferDescriptor& uniform = out_descriptors[0];
20389                 bufferDescriptor& xfb_1   = out_descriptors[1];
20390
20391                 /* Index */
20392                 uniform.m_index = 0;
20393                 xfb_1.m_index   = 1;
20394
20395                 /* Target */
20396                 uniform.m_target = Utils::Buffer::Uniform;
20397                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20398
20399                 /* Data */
20400                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20401
20402                 /* Draw call will not be executed, contents does not matter */
20403                 xfb_1.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20404         }
20405
20406         break;
20407
20408         case SECOND_MISSING:
20409         {
20410                 /* Test needs single uniform and two xfbs */
20411                 out_descriptors.resize(2);
20412
20413                 /* Get references */
20414                 bufferDescriptor& uniform = out_descriptors[0];
20415                 bufferDescriptor& xfb_0   = out_descriptors[1];
20416
20417                 /* Index */
20418                 uniform.m_index = 0;
20419                 xfb_0.m_index   = 0;
20420
20421                 /* Target */
20422                 uniform.m_target = Utils::Buffer::Uniform;
20423                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20424
20425                 /* Data */
20426                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20427
20428                 /* Draw call will not be executed, contents does not matter */
20429                 xfb_0.m_initial_data.resize(m_stride);
20430         }
20431
20432         break;
20433         }
20434 }
20435
20436 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20437  *
20438  * @param ignored
20439  * @param captured_varyings Vector of varying names to be captured
20440  **/
20441 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20442                                                                                                                  Utils::Program::NameVector& captured_varyings)
20443 {
20444         captured_varyings.push_back("gs_fs");
20445 }
20446
20447 /** Get body of main function for given shader stage
20448  *
20449  * @param ignored
20450  * @param stage            Shader stage
20451  * @param out_assignments  Set to empty
20452  * @param out_calculations Set to empty
20453  **/
20454 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20455                                                                                                    std::string& out_assignments, std::string& out_calculations)
20456 {
20457         out_calculations = "";
20458
20459         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20460         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20461
20462         const GLchar* assignments = "";
20463         switch (stage)
20464         {
20465         case Utils::Shader::FRAGMENT:
20466                 assignments = fs;
20467                 break;
20468         case Utils::Shader::GEOMETRY:
20469                 assignments = gs;
20470                 break;
20471         default:
20472                 break;
20473         }
20474
20475         out_assignments = assignments;
20476 }
20477
20478 /** Get interface of shader
20479  *
20480  * @param ignored
20481  * @param stage            Shader stage
20482  * @param out_interface    Set to ""
20483  **/
20484 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20485                                                                                                                 std::string& out_interface)
20486 {
20487         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out;\n"
20488                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs;\n"
20489                                                           "\n"
20490                                                           "layout(binding    = 0) uniform gs_block {\n"
20491                                                           "    vec4 uni_gs;\n"
20492                                                           "};\n";
20493         static const GLchar* fs = "in  vec4 gs_fs;\n"
20494                                                           "out vec4 fs_out;\n";
20495
20496         switch (stage)
20497         {
20498         case Utils::Shader::FRAGMENT:
20499                 out_interface = fs;
20500                 break;
20501         case Utils::Shader::GEOMETRY:
20502                 out_interface = gs;
20503                 break;
20504         default:
20505                 out_interface = "";
20506                 return;
20507         }
20508 }
20509
20510 /** Returns buffer details in human readable form.
20511  *
20512  * @param test_case_index Index of test case
20513  *
20514  * @return Case description
20515  **/
20516 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20517 {
20518         std::string result;
20519
20520         switch (test_case_index)
20521         {
20522         case VALID:
20523                 result = "Valid case";
20524                 break;
20525         case FIRST_MISSING:
20526                 result = "Missing xfb at index 0";
20527                 break;
20528         case SECOND_MISSING:
20529                 result = "Missing xfb at index 1";
20530                 break;
20531         default:
20532                 TCU_FAIL("Invalid enum");
20533         }
20534
20535         return result;
20536 }
20537
20538 /** Get number of test cases
20539  *
20540  * @return 2
20541  **/
20542 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20543 {
20544         return 3;
20545 }
20546
20547 /** Constructor
20548  *
20549  * @param context Test framework context
20550  **/
20551 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20552         : NegativeTestBase(context, "xfb_too_small_stride",
20553                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20554 {
20555 }
20556
20557 /** Source for given test case and stage
20558  *
20559  * @param test_case_index Index of test case
20560  * @param stage           Shader stage
20561  *
20562  * @return Shader source
20563  **/
20564 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20565 {
20566         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20567                                                                                                 "\n"
20568                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20569         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20570                                                                                                 "\n"
20571                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20572                                                                                                 "    vec4 gohan;\n"
20573                                                                                                 "    vec4 goten;\n"
20574                                                                                                 "    vec4 chichi;\n"
20575                                                                                                 "} gokuARRAY;\n";
20576         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20577                                                                                                  "\n"
20578                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20579         // 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;"
20580         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20581         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20582                                                                                                  "\n"
20583                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20584         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20585                                                                          "    gohanINDEX[1] = result / 4;\n"
20586                                                                          "    gohanINDEX[2] = result / 6;\n"
20587                                                                          "    gohanINDEX[3] = result / 8;\n";
20588         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20589                                                                          "    gokuINDEX.goten  = result / 4;\n"
20590                                                                          "    gokuINDEX.chichi = result / 6;\n";
20591         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20592         static const GLchar* fs                 = "#version 430 core\n"
20593                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20594                                                           "\n"
20595                                                           "in  vec4 gs_fs;\n"
20596                                                           "out vec4 fs_out;\n"
20597                                                           "\n"
20598                                                           "void main()\n"
20599                                                           "{\n"
20600                                                           "    fs_out = gs_fs;\n"
20601                                                           "}\n"
20602                                                           "\n";
20603         static const GLchar* gs_tested = "#version 430 core\n"
20604                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20605                                                                          "\n"
20606                                                                          "layout(points)                           in;\n"
20607                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20608                                                                          "\n"
20609                                                                          "VAR_DEFINITION"
20610                                                                          "\n"
20611                                                                          "in  vec4 tes_gs[];\n"
20612                                                                          "out vec4 gs_fs;\n"
20613                                                                          "\n"
20614                                                                          "void main()\n"
20615                                                                          "{\n"
20616                                                                          "    vec4 result = tes_gs[0];\n"
20617                                                                          "\n"
20618                                                                          "VARIABLE_USE"
20619                                                                          "\n"
20620                                                                          "    gs_fs = result;\n"
20621                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20622                                                                          "    EmitVertex();\n"
20623                                                                          "    gs_fs = result;\n"
20624                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20625                                                                          "    EmitVertex();\n"
20626                                                                          "    gs_fs = result;\n"
20627                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20628                                                                          "    EmitVertex();\n"
20629                                                                          "    gs_fs = result;\n"
20630                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20631                                                                          "    EmitVertex();\n"
20632                                                                          "}\n"
20633                                                                          "\n";
20634         static const GLchar* tcs = "#version 430 core\n"
20635                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20636                                                            "\n"
20637                                                            "layout(vertices = 1) out;\n"
20638                                                            "\n"
20639                                                            "in  vec4 vs_tcs[];\n"
20640                                                            "out vec4 tcs_tes[];\n"
20641                                                            "\n"
20642                                                            "void main()\n"
20643                                                            "{\n"
20644                                                            "\n"
20645                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20646                                                            "\n"
20647                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20648                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20649                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20650                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20651                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20652                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20653                                                            "}\n"
20654                                                            "\n";
20655         static const GLchar* tcs_tested = "#version 430 core\n"
20656                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20657                                                                           "\n"
20658                                                                           "layout(vertices = 1) out;\n"
20659                                                                           "\n"
20660                                                                           "VAR_DEFINITION"
20661                                                                           "\n"
20662                                                                           "in  vec4 vs_tcs[];\n"
20663                                                                           "out vec4 tcs_tes[];\n"
20664                                                                           "\n"
20665                                                                           "void main()\n"
20666                                                                           "{\n"
20667                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20668                                                                           "\n"
20669                                                                           "VARIABLE_USE"
20670                                                                           "\n"
20671                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20672                                                                           "\n"
20673                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20674                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20675                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20676                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20677                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20678                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20679                                                                           "}\n"
20680                                                                           "\n";
20681         static const GLchar* tes_tested = "#version 430 core\n"
20682                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20683                                                                           "\n"
20684                                                                           "layout(isolines, point_mode) in;\n"
20685                                                                           "\n"
20686                                                                           "VAR_DEFINITION"
20687                                                                           "\n"
20688                                                                           "in  vec4 tcs_tes[];\n"
20689                                                                           "out vec4 tes_gs;\n"
20690                                                                           "\n"
20691                                                                           "void main()\n"
20692                                                                           "{\n"
20693                                                                           "    vec4 result = tcs_tes[0];\n"
20694                                                                           "\n"
20695                                                                           "VARIABLE_USE"
20696                                                                           "\n"
20697                                                                           "    tes_gs += result;\n"
20698                                                                           "}\n"
20699                                                                           "\n";
20700         static const GLchar* vs = "#version 430 core\n"
20701                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20702                                                           "\n"
20703                                                           "in  vec4 in_vs;\n"
20704                                                           "out vec4 vs_tcs;\n"
20705                                                           "\n"
20706                                                           "void main()\n"
20707                                                           "{\n"
20708                                                           "    vs_tcs = in_vs;\n"
20709                                                           "}\n"
20710                                                           "\n";
20711         static const GLchar* vs_tested = "#version 430 core\n"
20712                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20713                                                                          "\n"
20714                                                                          "VAR_DEFINITION"
20715                                                                          "\n"
20716                                                                          "in  vec4 in_vs;\n"
20717                                                                          "out vec4 vs_tcs;\n"
20718                                                                          "\n"
20719                                                                          "void main()\n"
20720                                                                          "{\n"
20721                                                                          "    vec4 result = in_vs;\n"
20722                                                                          "\n"
20723                                                                          "VARIABLE_USE"
20724                                                                          "\n"
20725                                                                          "    vs_tcs += result;\n"
20726                                                                          "}\n"
20727                                                                          "\n";
20728
20729         std::string source;
20730         testCase&   test_case = m_test_cases[test_case_index];
20731
20732         if (test_case.m_stage == stage)
20733         {
20734                 const GLchar* array     = "";
20735                 const GLchar* index     = "";
20736                 size_t            position = 0;
20737                 size_t            temp;
20738                 const GLchar* var_definition = 0;
20739                 const GLchar* var_use            = 0;
20740
20741                 switch (test_case.m_case)
20742                 {
20743                 case OFFSET:
20744                         var_definition = offset_var_definition;
20745                         var_use            = output_use;
20746                         break;
20747                 case STRIDE:
20748                         var_definition = stride_var_definition;
20749                         var_use            = output_use;
20750                         break;
20751                 case BLOCK:
20752                         var_definition = block_var_definition;
20753                         var_use            = block_use;
20754                         break;
20755                 case ARRAY:
20756                         var_definition = array_var_definition;
20757                         var_use            = array_use;
20758                         break;
20759                 default:
20760                         TCU_FAIL("Invalid enum");
20761                 }
20762
20763                 switch (stage)
20764                 {
20765                 case Utils::Shader::GEOMETRY:
20766                         source = gs_tested;
20767                         array  = "[]";
20768                         index  = "[0]";
20769                         break;
20770                 case Utils::Shader::TESS_CTRL:
20771                         source = tcs_tested;
20772                         array  = "[]";
20773                         index  = "[gl_InvocationID]";
20774                         break;
20775                 case Utils::Shader::TESS_EVAL:
20776                         source = tes_tested;
20777                         array  = "[]";
20778                         index  = "[0]";
20779                         break;
20780                 case Utils::Shader::VERTEX:
20781                         source = vs_tested;
20782                         break;
20783                 default:
20784                         TCU_FAIL("Invalid enum");
20785                 }
20786
20787                 temp = position;
20788                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20789                 position = temp;
20790                 Utils::replaceToken("ARRAY", position, array, source);
20791                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20792
20793                 Utils::replaceAllTokens("INDEX", index, source);
20794         }
20795         else
20796         {
20797                 switch (test_case.m_stage)
20798                 {
20799                 case Utils::Shader::GEOMETRY:
20800                         switch (stage)
20801                         {
20802                         case Utils::Shader::FRAGMENT:
20803                                 source = fs;
20804                                 break;
20805                         case Utils::Shader::VERTEX:
20806                                 source = vs;
20807                                 break;
20808                         default:
20809                                 source = "";
20810                         }
20811                         break;
20812                 case Utils::Shader::TESS_CTRL:
20813                         switch (stage)
20814                         {
20815                         case Utils::Shader::FRAGMENT:
20816                                 source = fs;
20817                                 break;
20818                         case Utils::Shader::VERTEX:
20819                                 source = vs;
20820                                 break;
20821                         default:
20822                                 source = "";
20823                         }
20824                         break;
20825                 case Utils::Shader::TESS_EVAL:
20826                         switch (stage)
20827                         {
20828                         case Utils::Shader::FRAGMENT:
20829                                 source = fs;
20830                                 break;
20831                         case Utils::Shader::TESS_CTRL:
20832                                 source = tcs;
20833                                 break;
20834                         case Utils::Shader::VERTEX:
20835                                 source = vs;
20836                                 break;
20837                         default:
20838                                 source = "";
20839                         }
20840                         break;
20841                 case Utils::Shader::VERTEX:
20842                         switch (stage)
20843                         {
20844                         case Utils::Shader::FRAGMENT:
20845                                 source = fs;
20846                                 break;
20847                         default:
20848                                 source = "";
20849                         }
20850                         break;
20851                 default:
20852                         TCU_FAIL("Invalid enum");
20853                         break;
20854                 }
20855         }
20856
20857         return source;
20858 }
20859
20860 /** Get description of test case
20861  *
20862  * @param test_case_index Index of test case
20863  *
20864  * @return Test case description
20865  **/
20866 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20867 {
20868         std::stringstream stream;
20869         testCase&                 test_case = m_test_cases[test_case_index];
20870
20871         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20872
20873         switch (test_case.m_case)
20874         {
20875         case OFFSET:
20876                 stream << "buffer stride: 40, vec4 offset: 32";
20877                 break;
20878         case STRIDE:
20879                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20880                 break;
20881         case BLOCK:
20882                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20883                 break;
20884         case ARRAY:
20885                 stream << "buffer stride: 32, vec4[4] offset 16";
20886                 break;
20887         default:
20888                 TCU_FAIL("Invalid enum");
20889         }
20890
20891         return stream.str();
20892 }
20893
20894 /** Get number of test cases
20895  *
20896  * @return Number of test cases
20897  **/
20898 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20899 {
20900         return static_cast<GLuint>(m_test_cases.size());
20901 }
20902
20903 /** Selects if "compute" stage is relevant for test
20904  *
20905  * @param ignored
20906  *
20907  * @return false
20908  **/
20909 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20910 {
20911         return false;
20912 }
20913
20914 /** Prepare all test cases
20915  *
20916  **/
20917 void XFBTooSmallStrideTest::testInit()
20918 {
20919         for (GLuint c = 0; c < CASE_MAX; ++c)
20920         {
20921                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20922                 {
20923                         /*
20924                          It is invalid to define transform feedback output in TCS, according to spec:
20925                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20926                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20927                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20928                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20929                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20930                          each primitive processed by the vertex shader.
20931                          */
20932                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20933                                 (Utils::Shader::FRAGMENT == stage))
20934                         {
20935                                 continue;
20936                         }
20937
20938                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20939
20940                         m_test_cases.push_back(test_case);
20941                 }
20942         }
20943 }
20944
20945 /** Constructor
20946  *
20947  * @param context Test framework context
20948  **/
20949 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
20950         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
20951 {
20952 }
20953
20954 /** Source for given test case and stage
20955  *
20956  * @param test_case_index Index of test case
20957  * @param stage           Shader stage
20958  *
20959  * @return Shader source
20960  **/
20961 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20962 {
20963         static const GLchar* invalid_var_definition =
20964                 "const uint type_size = SIZE;\n"
20965                 "\n"
20966                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
20967                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
20968         static const GLchar* valid_var_definition =
20969                 "const uint type_size = SIZE;\n"
20970                 "\n"
20971                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
20972         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
20973                                                                            "    vegetaINDEX = TYPE(0);\n"
20974                                                                            "    if (vec4(0) == result)\n"
20975                                                                            "    {\n"
20976                                                                            "        gokuINDEX   = TYPE(0);\n"
20977                                                                            "        vegetaINDEX = TYPE(1);\n"
20978                                                                            "    }\n";
20979         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
20980                                                                          "    if (vec4(0) == result)\n"
20981                                                                          "    {\n"
20982                                                                          "        gokuINDEX   = TYPE(0);\n"
20983                                                                          "    }\n";
20984         static const GLchar* fs = "#version 430 core\n"
20985                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20986                                                           "\n"
20987                                                           "in  vec4 any_fs;\n"
20988                                                           "out vec4 fs_out;\n"
20989                                                           "\n"
20990                                                           "void main()\n"
20991                                                           "{\n"
20992                                                           "    fs_out = any_fs;\n"
20993                                                           "}\n"
20994                                                           "\n";
20995         static const GLchar* gs_tested = "#version 430 core\n"
20996                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20997                                                                          "\n"
20998                                                                          "layout(points)                           in;\n"
20999                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21000                                                                          "\n"
21001                                                                          "VAR_DEFINITION"
21002                                                                          "\n"
21003                                                                          "in  vec4 vs_any[];\n"
21004                                                                          "out vec4 any_fs;\n"
21005                                                                          "\n"
21006                                                                          "void main()\n"
21007                                                                          "{\n"
21008                                                                          "    vec4 result = vs_any[0];\n"
21009                                                                          "\n"
21010                                                                          "VARIABLE_USE"
21011                                                                          "\n"
21012                                                                          "    any_fs = result;\n"
21013                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21014                                                                          "    EmitVertex();\n"
21015                                                                          "    any_fs = result;\n"
21016                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21017                                                                          "    EmitVertex();\n"
21018                                                                          "    any_fs = result;\n"
21019                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21020                                                                          "    EmitVertex();\n"
21021                                                                          "    any_fs = result;\n"
21022                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21023                                                                          "    EmitVertex();\n"
21024                                                                          "}\n"
21025                                                                          "\n";
21026         static const GLchar* tcs = "#version 430 core\n"
21027                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21028                                                            "\n"
21029                                                            "layout(vertices = 1) out;\n"
21030                                                            "\n"
21031                                                            "in  vec4 vs_any[];\n"
21032                                                            "out vec4 tcs_tes[];\n"
21033                                                            "\n"
21034                                                            "void main()\n"
21035                                                            "{\n"
21036                                                            "\n"
21037                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21038                                                            "\n"
21039                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21040                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21041                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21042                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21043                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21044                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21045                                                            "}\n"
21046                                                            "\n";
21047         static const GLchar* tcs_tested = "#version 430 core\n"
21048                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21049                                                                           "\n"
21050                                                                           "layout(vertices = 1) out;\n"
21051                                                                           "\n"
21052                                                                           "VAR_DEFINITION"
21053                                                                           "\n"
21054                                                                           "in  vec4 vs_any[];\n"
21055                                                                           "out vec4 any_fs[];\n"
21056                                                                           "\n"
21057                                                                           "void main()\n"
21058                                                                           "{\n"
21059                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21060                                                                           "\n"
21061                                                                           "VARIABLE_USE"
21062                                                                           "\n"
21063                                                                           "    any_fs[gl_InvocationID] = result;\n"
21064                                                                           "\n"
21065                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21066                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21067                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21068                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21069                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21070                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21071                                                                           "}\n"
21072                                                                           "\n";
21073         static const GLchar* tes_tested = "#version 430 core\n"
21074                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21075                                                                           "\n"
21076                                                                           "layout(isolines, point_mode) in;\n"
21077                                                                           "\n"
21078                                                                           "VAR_DEFINITION"
21079                                                                           "\n"
21080                                                                           "in  vec4 tcs_tes[];\n"
21081                                                                           "out vec4 any_fs;\n"
21082                                                                           "\n"
21083                                                                           "void main()\n"
21084                                                                           "{\n"
21085                                                                           "    vec4 result = tcs_tes[0];\n"
21086                                                                           "\n"
21087                                                                           "VARIABLE_USE"
21088                                                                           "\n"
21089                                                                           "    any_fs = result;\n"
21090                                                                           "}\n"
21091                                                                           "\n";
21092         static const GLchar* vs = "#version 430 core\n"
21093                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21094                                                           "\n"
21095                                                           "in  vec4 in_vs;\n"
21096                                                           "out vec4 vs_any;\n"
21097                                                           "\n"
21098                                                           "void main()\n"
21099                                                           "{\n"
21100                                                           "    vs_any = in_vs;\n"
21101                                                           "}\n"
21102                                                           "\n";
21103         static const GLchar* vs_tested = "#version 430 core\n"
21104                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21105                                                                          "\n"
21106                                                                          "VAR_DEFINITION"
21107                                                                          "\n"
21108                                                                          "in  vec4 in_vs;\n"
21109                                                                          "out vec4 any_fs;\n"
21110                                                                          "\n"
21111                                                                          "void main()\n"
21112                                                                          "{\n"
21113                                                                          "    vec4 result = in_vs;\n"
21114                                                                          "\n"
21115                                                                          "VARIABLE_USE"
21116                                                                          "\n"
21117                                                                          "    any_fs = result;\n"
21118                                                                          "}\n"
21119                                                                          "\n";
21120
21121         std::string source;
21122         testCase&   test_case = m_test_cases[test_case_index];
21123
21124         if (test_case.m_stage == stage)
21125         {
21126                 const GLchar* array = "";
21127                 GLchar            buffer[16];
21128                 const GLchar* index     = "";
21129                 size_t            position = 0;
21130                 size_t            temp;
21131                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21132                 const GLchar* var_definition = 0;
21133                 const GLchar* var_use            = 0;
21134
21135                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21136
21137                 switch (test_case.m_case)
21138                 {
21139                 case VALID:
21140                         var_definition = valid_var_definition;
21141                         var_use            = valid_use;
21142                         break;
21143                 case INVALID:
21144                         var_definition = invalid_var_definition;
21145                         var_use            = invalid_use;
21146                         break;
21147                 default:
21148                         TCU_FAIL("Invalid enum");
21149                 }
21150
21151                 switch (stage)
21152                 {
21153                 case Utils::Shader::GEOMETRY:
21154                         source = gs_tested;
21155                         array  = "[1]";
21156                         index  = "[0]";
21157                         break;
21158                 case Utils::Shader::TESS_CTRL:
21159                         source = tcs_tested;
21160                         array  = "[1]";
21161                         index  = "[gl_InvocationID]";
21162                         break;
21163                 case Utils::Shader::TESS_EVAL:
21164                         source = tes_tested;
21165                         array  = "[1]";
21166                         index  = "[0]";
21167                         break;
21168                 case Utils::Shader::VERTEX:
21169                         source = vs_tested;
21170                         break;
21171                 default:
21172                         TCU_FAIL("Invalid enum");
21173                 }
21174
21175                 temp = position;
21176                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21177                 position = temp;
21178                 Utils::replaceToken("SIZE", position, buffer, source);
21179                 Utils::replaceToken("ARRAY", position, array, source);
21180                 if (INVALID == test_case.m_case)
21181                 {
21182                         Utils::replaceToken("ARRAY", position, array, source);
21183                 }
21184                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21185
21186                 Utils::replaceAllTokens("TYPE", type_name, source);
21187                 Utils::replaceAllTokens("INDEX", index, source);
21188         }
21189         else
21190         {
21191                 switch (test_case.m_stage)
21192                 {
21193                 case Utils::Shader::GEOMETRY:
21194                         switch (stage)
21195                         {
21196                         case Utils::Shader::FRAGMENT:
21197                                 source = fs;
21198                                 break;
21199                         case Utils::Shader::VERTEX:
21200                                 source = vs;
21201                                 break;
21202                         default:
21203                                 source = "";
21204                         }
21205                         break;
21206                 case Utils::Shader::TESS_CTRL:
21207                         switch (stage)
21208                         {
21209                         case Utils::Shader::FRAGMENT:
21210                                 source = fs;
21211                                 break;
21212                         case Utils::Shader::VERTEX:
21213                                 source = vs;
21214                                 break;
21215                         default:
21216                                 source = "";
21217                         }
21218                         break;
21219                 case Utils::Shader::TESS_EVAL:
21220                         switch (stage)
21221                         {
21222                         case Utils::Shader::FRAGMENT:
21223                                 source = fs;
21224                                 break;
21225                         case Utils::Shader::TESS_CTRL:
21226                                 source = tcs;
21227                                 break;
21228                         case Utils::Shader::VERTEX:
21229                                 source = vs;
21230                                 break;
21231                         default:
21232                                 source = "";
21233                         }
21234                         break;
21235                 case Utils::Shader::VERTEX:
21236                         switch (stage)
21237                         {
21238                         case Utils::Shader::FRAGMENT:
21239                                 source = fs;
21240                                 break;
21241                         default:
21242                                 source = "";
21243                         }
21244                         break;
21245                 default:
21246                         TCU_FAIL("Invalid enum");
21247                         break;
21248                 }
21249         }
21250
21251         return source;
21252 }
21253
21254 /** Get description of test case
21255  *
21256  * @param test_case_index Index of test case
21257  *
21258  * @return Test case description
21259  **/
21260 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21261 {
21262         std::stringstream stream;
21263         testCase&                 test_case = m_test_cases[test_case_index];
21264
21265         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21266                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21267
21268         switch (test_case.m_case)
21269         {
21270         case VALID:
21271                 stream << "valid";
21272                 break;
21273         case INVALID:
21274                 stream << "invalid";
21275                 break;
21276         default:
21277                 TCU_FAIL("Invalid enum");
21278         }
21279
21280         return stream.str();
21281 }
21282
21283 /** Get number of test cases
21284  *
21285  * @return Number of test cases
21286  **/
21287 GLuint XFBVariableStrideTest::getTestCaseNumber()
21288 {
21289         return static_cast<GLuint>(m_test_cases.size());
21290 }
21291
21292 /** Selects if "compute" stage is relevant for test
21293  *
21294  * @param ignored
21295  *
21296  * @return false
21297  **/
21298 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21299 {
21300         return false;
21301 }
21302
21303 /** Selects if compilation failure is expected result
21304  *
21305  * @param test_case_index Index of test case
21306  *
21307  * @return true
21308  **/
21309 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21310 {
21311         testCase& test_case = m_test_cases[test_case_index];
21312
21313         return (INVALID == test_case.m_case);
21314 }
21315
21316 /** Prepare all test cases
21317  *
21318  **/
21319 void XFBVariableStrideTest::testInit()
21320 {
21321         const GLuint n_types = getTypesNumber();
21322
21323         for (GLuint i = 0; i < n_types; ++i)
21324         {
21325                 const Utils::Type& type = getType(i);
21326
21327                 /*
21328                  Some of the cases are declared as following are considered as invalid,
21329                  but accoring to spec, the following declaration is valid: shaders in the
21330                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21331                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21332                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21333                  the stride.
21334
21335                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21336                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21337                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21338                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21339
21340                  int type_size = 8;
21341                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21342                  layout (xfb_offset = type_size)                     out double vegeta;
21343                  */
21344                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21345                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21346                 {
21347                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21348                         {
21349                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21350                                         (Utils::Shader::FRAGMENT == stage))
21351                                 {
21352                                         continue;
21353                                 }
21354
21355                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21356
21357                                 m_test_cases.push_back(test_case);
21358                         }
21359                 }
21360         }
21361 }
21362
21363 /** Constructor
21364  *
21365  * @param context Test framework context
21366  **/
21367 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21368         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21369 {
21370 }
21371
21372 /** Source for given test case and stage
21373  *
21374  * @param test_case_index Index of test case
21375  * @param stage           Shader stage
21376  *
21377  * @return Shader source
21378  **/
21379 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21380 {
21381         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21382                                                                                   "    vec4 gohan;\n"
21383                                                                                   "    vec4 goten;\n"
21384                                                                                   "    vec4 chichi;\n"
21385                                                                                   "} gokuARRAY;\n";
21386         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21387                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21388                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21389                                                                    "    if (vec4(0) == result)\n"
21390                                                                    "    {\n"
21391                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21392                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21393                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21394                                                                    "    }\n";
21395         static const GLchar* gs_tested =
21396                 "#version 430 core\n"
21397                 "#extension GL_ARB_enhanced_layouts : require\n"
21398                 "\n"
21399                 "layout(points)                           in;\n"
21400                 "layout(triangle_strip, max_vertices = 4) out;\n"
21401                 "\n"
21402                 "VAR_DEFINITION"
21403                 "\n"
21404                 "out gl_PerVertex \n"
21405                 "{ \n"
21406                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21407                 "}; \n"
21408                 "in  vec4 tes_gs[];\n"
21409                 "out vec4 gs_fs;\n"
21410                 "\n"
21411                 "void main()\n"
21412                 "{\n"
21413                 "    vec4 result = tes_gs[0];\n"
21414                 "\n"
21415                 "VARIABLE_USE"
21416                 "\n"
21417                 "    gs_fs = result;\n"
21418                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21419                 "    EmitVertex();\n"
21420                 "    gs_fs = result;\n"
21421                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21422                 "    EmitVertex();\n"
21423                 "    gs_fs = result;\n"
21424                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21425                 "    EmitVertex();\n"
21426                 "    gs_fs = result;\n"
21427                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21428                 "    EmitVertex();\n"
21429                 "}\n"
21430                 "\n";
21431         static const GLchar* tcs = "#version 430 core\n"
21432                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21433                                                            "\n"
21434                                                            "layout(vertices = 1) out;\n"
21435                                                            "\n"
21436                                                            "in  vec4 vs_tcs[];\n"
21437                                                            "out vec4 tcs_tes[];\n"
21438                                                            "\n"
21439                                                            "void main()\n"
21440                                                            "{\n"
21441                                                            "\n"
21442                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21443                                                            "\n"
21444                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21445                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21446                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21447                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21448                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21449                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21450                                                            "}\n"
21451                                                            "\n";
21452 #if 0
21453         static const GLchar* tcs_tested =
21454                 "#version 430 core\n"
21455                 "#extension GL_ARB_enhanced_layouts : require\n"
21456                 "\n"
21457                 "layout(vertices = 1) out;\n"
21458                 "\n"
21459                 "VAR_DEFINITION"
21460                 "\n"
21461                 "in  vec4 vs_tcs[];\n"
21462                 "out vec4 tcs_tes[];\n"
21463                 "\n"
21464                 "void main()\n"
21465                 "{\n"
21466                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21467                 "\n"
21468                 "VARIABLE_USE"
21469                 "\n"
21470                 "    tcs_tes[gl_InvocationID] = result;\n"
21471                 "\n"
21472                 "    gl_TessLevelOuter[0] = 1.0;\n"
21473                 "    gl_TessLevelOuter[1] = 1.0;\n"
21474                 "    gl_TessLevelOuter[2] = 1.0;\n"
21475                 "    gl_TessLevelOuter[3] = 1.0;\n"
21476                 "    gl_TessLevelInner[0] = 1.0;\n"
21477                 "    gl_TessLevelInner[1] = 1.0;\n"
21478                 "}\n"
21479                 "\n";
21480 #endif
21481         static const GLchar* tes_tested = "#version 430 core\n"
21482                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21483                                                                           "\n"
21484                                                                           "layout(isolines, point_mode) in;\n"
21485                                                                           "\n"
21486                                                                           "VAR_DEFINITION"
21487                                                                           "\n"
21488                                                                           "in  vec4 tcs_tes[];\n"
21489                                                                           "out vec4 tes_gs;\n"
21490                                                                           "\n"
21491                                                                           "void main()\n"
21492                                                                           "{\n"
21493                                                                           "    vec4 result = tcs_tes[0];\n"
21494                                                                           "\n"
21495                                                                           "VARIABLE_USE"
21496                                                                           "\n"
21497                                                                           "    tes_gs += result;\n"
21498                                                                           "}\n"
21499                                                                           "\n";
21500         static const GLchar* vs = "#version 430 core\n"
21501                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21502                                                           "\n"
21503                                                           "in  vec4 in_vs;\n"
21504                                                           "out vec4 vs_tcs;\n"
21505                                                           "\n"
21506                                                           "void main()\n"
21507                                                           "{\n"
21508                                                           "    vs_tcs = in_vs;\n"
21509                                                           "}\n"
21510                                                           "\n";
21511         static const GLchar* vs_tested = "#version 430 core\n"
21512                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21513                                                                          "\n"
21514                                                                          "VAR_DEFINITION"
21515                                                                          "\n"
21516                                                                          "in  vec4 in_vs;\n"
21517                                                                          "out vec4 vs_tcs;\n"
21518                                                                          "\n"
21519                                                                          "void main()\n"
21520                                                                          "{\n"
21521                                                                          "    vec4 result = in_vs;\n"
21522                                                                          "\n"
21523                                                                          "VARIABLE_USE"
21524                                                                          "\n"
21525                                                                          "    vs_tcs += result;\n"
21526                                                                          "}\n"
21527                                                                          "\n";
21528
21529         std::string                       source;
21530         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21531
21532         if (test_case == stage)
21533         {
21534                 const GLchar* array     = "";
21535                 const GLchar* index     = "";
21536                 size_t            position = 0;
21537                 size_t            temp;
21538                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21539                 // change array = "[]" to "[1]"
21540                 switch (stage)
21541                 {
21542                 case Utils::Shader::GEOMETRY:
21543                         source = gs_tested;
21544                         array  = "[1]";
21545                         index  = "[0]";
21546                         break;
21547 /*
21548                          It is invalid to define transform feedback output in HS
21549                          */
21550 #if 0
21551                         case Utils::Shader::TESS_CTRL:
21552                         source = tcs_tested;
21553                         array = "[]";
21554                         index = "[gl_InvocationID]";
21555                         break;
21556 #endif
21557                 case Utils::Shader::TESS_EVAL:
21558                         source = tes_tested;
21559                         array  = "[1]";
21560                         index  = "[0]";
21561                         break;
21562                 case Utils::Shader::VERTEX:
21563                         source = vs_tested;
21564                         break;
21565                 default:
21566                         TCU_FAIL("Invalid enum");
21567                 }
21568
21569                 temp = position;
21570                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21571                 position = temp;
21572                 Utils::replaceToken("ARRAY", position, array, source);
21573                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21574
21575                 Utils::replaceAllTokens("INDEX", index, source);
21576         }
21577         else
21578         {
21579                 switch (test_case)
21580                 {
21581                 case Utils::Shader::GEOMETRY:
21582                         switch (stage)
21583                         {
21584                         case Utils::Shader::VERTEX:
21585                                 source = vs;
21586                                 break;
21587                         default:
21588                                 source = "";
21589                         }
21590                         break;
21591                 case Utils::Shader::TESS_CTRL:
21592                         switch (stage)
21593                         {
21594                         case Utils::Shader::VERTEX:
21595                                 source = vs;
21596                                 break;
21597                         default:
21598                                 source = "";
21599                         }
21600                         break;
21601                 case Utils::Shader::TESS_EVAL:
21602                         switch (stage)
21603                         {
21604                         case Utils::Shader::TESS_CTRL:
21605                                 source = tcs;
21606                                 break;
21607                         case Utils::Shader::VERTEX:
21608                                 source = vs;
21609                                 break;
21610                         default:
21611                                 source = "";
21612                         }
21613                         break;
21614                 case Utils::Shader::VERTEX:
21615                         source = "";
21616                         break;
21617                 default:
21618                         TCU_FAIL("Invalid enum");
21619                         break;
21620                 }
21621         }
21622
21623         return source;
21624 }
21625
21626 /** Get description of test case
21627  *
21628  * @param test_case_index Index of test case
21629  *
21630  * @return Test case description
21631  **/
21632 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21633 {
21634         std::stringstream stream;
21635
21636         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21637
21638         return stream.str();
21639 }
21640
21641 /** Get number of test cases
21642  *
21643  * @return Number of test cases
21644  **/
21645 GLuint XFBBlockStrideTest::getTestCaseNumber()
21646 {
21647         return static_cast<GLuint>(m_test_cases.size());
21648 }
21649
21650 /** Inspects program for xfb stride
21651  *
21652  * @param program Program to query
21653  *
21654  * @return true if query results match expected values, false otherwise
21655  **/
21656 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21657 {
21658         GLint stride = 0;
21659
21660         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21661                                                 1 /* buf_size */, &stride);
21662
21663         return (128 == stride);
21664 }
21665
21666 /** Runs test case
21667  *
21668  * @param test_case_index Id of test case
21669  *
21670  * @return true if test case pass, false otherwise
21671  **/
21672 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21673 {
21674         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21675         Utils::Program   program(m_context);
21676         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21677         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21678         bool                       test_case_result = true;
21679         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21680
21681         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21682
21683         test_case_result = inspectProgram(program);
21684
21685         return test_case_result;
21686 }
21687
21688 /** Prepare all test cases
21689  *
21690  **/
21691 void XFBBlockStrideTest::testInit()
21692 {
21693         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21694         {
21695                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21696                         (Utils::Shader::FRAGMENT == stage))
21697                 {
21698                         continue;
21699                 }
21700
21701                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21702         }
21703 }
21704
21705 /** Constructor
21706  *
21707  * @param context Test context
21708  **/
21709 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21710         : BufferTestBase(context, "xfb_block_member_stride",
21711                                          "Test verifies that xfb_stride qualifier is respected for block member")
21712 {
21713         /* Nothing to be done here */
21714 }
21715
21716 /** Get descriptors of buffers necessary for test
21717  *
21718  * @param ignored
21719  * @param out_descriptors Descriptors of buffers used by test
21720  **/
21721 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21722                                                                                                         bufferDescriptor::Vector& out_descriptors)
21723 {
21724         const Utils::Type& vec4 = Utils::Type::vec4;
21725
21726         /* Test needs single uniform and xfb */
21727         out_descriptors.resize(2);
21728
21729         /* Get references */
21730         bufferDescriptor& uniform = out_descriptors[0];
21731         bufferDescriptor& xfb    = out_descriptors[1];
21732
21733         /* Index */
21734         uniform.m_index = 0;
21735         xfb.m_index             = 0;
21736
21737         /* Target */
21738         uniform.m_target = Utils::Buffer::Uniform;
21739         xfb.m_target     = Utils::Buffer::Transform_feedback;
21740
21741         /* Data */
21742         static const GLuint                     vec4_size   = 16;
21743         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21744         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21745         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21746
21747         /* Uniform data */
21748         uniform.m_initial_data.resize(3 * vec4_size);
21749         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21750         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21751         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21752
21753         /* XFB data */
21754         xfb.m_initial_data.resize(4 * vec4_size);
21755         xfb.m_expected_data.resize(4 * vec4_size);
21756
21757         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21758         {
21759                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21760                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21761         }
21762
21763         // the xfb_offset of "chichi" should be 32
21764         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21765         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21766         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21767 }
21768
21769 /** Get body of main function for given shader stage
21770  *
21771  * @param ignored
21772  * @param stage            Shader stage
21773  * @param out_assignments  Set to empty
21774  * @param out_calculations Set to empty
21775  **/
21776 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21777                                                                                          std::string& out_assignments, std::string& out_calculations)
21778 {
21779         out_calculations = "";
21780
21781         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21782                                                           "    goten  = uni_goten;\n"
21783                                                           "    chichi = uni_chichi;\n";
21784         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21785
21786         const GLchar* assignments = "";
21787         switch (stage)
21788         {
21789         case Utils::Shader::FRAGMENT:
21790                 assignments = fs;
21791                 break;
21792         case Utils::Shader::GEOMETRY:
21793                 assignments = gs;
21794                 break;
21795         default:
21796                 break;
21797         }
21798
21799         out_assignments = assignments;
21800 }
21801
21802 /** Get interface of shader
21803  *
21804  * @param ignored
21805  * @param stage            Shader stage
21806  * @param out_interface    Set to ""
21807  **/
21808 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21809                                                                                                   std::string& out_interface)
21810 {
21811         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21812                                                           "                             vec4 gohan;\n"
21813                                                           "    layout (xfb_stride = 48) vec4 goten;\n"
21814                                                           "                             vec4 chichi;\n"
21815                                                           "};\n"
21816                                                           "layout(binding = 0) uniform gs_block {\n"
21817                                                           "    vec4 uni_gohan;\n"
21818                                                           "    vec4 uni_goten;\n"
21819                                                           "    vec4 uni_chichi;\n"
21820                                                           "};\n";
21821         static const GLchar* fs = "in Goku {\n"
21822                                                           "    vec4 gohan;\n"
21823                                                           "    vec4 goten;\n"
21824                                                           "    vec4 chichi;\n"
21825                                                           "};\n"
21826                                                           "out vec4 fs_out;\n";
21827
21828         switch (stage)
21829         {
21830         case Utils::Shader::FRAGMENT:
21831                 out_interface = fs;
21832                 break;
21833         case Utils::Shader::GEOMETRY:
21834                 out_interface = gs;
21835                 break;
21836         default:
21837                 out_interface = "";
21838                 return;
21839         }
21840 }
21841
21842 /** Inspects program to check if all resources are as expected
21843  *
21844  * @param ignored
21845  * @param program    Program instance
21846  * @param out_stream Error message
21847  *
21848  * @return true if everything is ok, false otherwise
21849  **/
21850 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21851                                                                                           std::stringstream& out_stream)
21852 {
21853         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21854         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21855         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21856
21857         GLint gohan_offset  = 0;
21858         GLint goten_offset  = 0;
21859         GLint chichi_offset = 0;
21860
21861         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21862         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21863         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21864
21865         // the xfb_offset of "chichi" should be 32
21866         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21867         {
21868                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21869                                    << "] expected: [0, 16, 32]";
21870                 return false;
21871         }
21872
21873         return true;
21874 }
21875
21876 /** Constructor
21877  *
21878  * @param context Test framework context
21879  **/
21880 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21881         : NegativeTestBase(context, "xfb_duplicated_stride",
21882                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21883 {
21884 }
21885
21886 /** Source for given test case and stage
21887  *
21888  * @param test_case_index Index of test case
21889  * @param stage           Shader stage
21890  *
21891  * @return Shader source
21892  **/
21893 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21894 {
21895         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21896                                                                                                   "const uint conflicting_stride = 128;\n"
21897                                                                                                   "\n"
21898                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21899                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21900         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21901                                                                                                 "\n"
21902                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21903                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21904         static const GLchar* fs = "#version 430 core\n"
21905                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21906                                                           "\n"
21907                                                           "in  vec4 any_fs;\n"
21908                                                           "out vec4 fs_out;\n"
21909                                                           "\n"
21910                                                           "void main()\n"
21911                                                           "{\n"
21912                                                           "    fs_out = any_fs;\n"
21913                                                           "}\n"
21914                                                           "\n";
21915         static const GLchar* gs_tested = "#version 430 core\n"
21916                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21917                                                                          "\n"
21918                                                                          "layout(points)                           in;\n"
21919                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21920                                                                          "\n"
21921                                                                          "VAR_DEFINITION"
21922                                                                          "\n"
21923                                                                          "in  vec4 vs_any[];\n"
21924                                                                          "out vec4 any_fs;\n"
21925                                                                          "\n"
21926                                                                          "void main()\n"
21927                                                                          "{\n"
21928                                                                          "    vec4 result = vs_any[0];\n"
21929                                                                          "\n"
21930                                                                          "VARIABLE_USE"
21931                                                                          "\n"
21932                                                                          "    any_fs = result;\n"
21933                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21934                                                                          "    EmitVertex();\n"
21935                                                                          "    any_fs = result;\n"
21936                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21937                                                                          "    EmitVertex();\n"
21938                                                                          "    any_fs = result;\n"
21939                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21940                                                                          "    EmitVertex();\n"
21941                                                                          "    any_fs = result;\n"
21942                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21943                                                                          "    EmitVertex();\n"
21944                                                                          "}\n"
21945                                                                          "\n";
21946         static const GLchar* tcs = "#version 430 core\n"
21947                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21948                                                            "\n"
21949                                                            "layout(vertices = 1) out;\n"
21950                                                            "\n"
21951                                                            "in  vec4 vs_any[];\n"
21952                                                            "out vec4 tcs_tes[];\n"
21953                                                            "\n"
21954                                                            "void main()\n"
21955                                                            "{\n"
21956                                                            "\n"
21957                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21958                                                            "\n"
21959                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21960                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21961                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21962                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21963                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21964                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21965                                                            "}\n"
21966                                                            "\n";
21967         static const GLchar* tcs_tested = "#version 430 core\n"
21968                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21969                                                                           "\n"
21970                                                                           "layout(vertices = 1) out;\n"
21971                                                                           "\n"
21972                                                                           "VAR_DEFINITION"
21973                                                                           "\n"
21974                                                                           "in  vec4 vs_any[];\n"
21975                                                                           "out vec4 any_fs[];\n"
21976                                                                           "\n"
21977                                                                           "void main()\n"
21978                                                                           "{\n"
21979                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21980                                                                           "\n"
21981                                                                           "VARIABLE_USE"
21982                                                                           "\n"
21983                                                                           "    any_fs[gl_InvocationID] = result;\n"
21984                                                                           "\n"
21985                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21986                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21987                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21988                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21989                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21990                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21991                                                                           "}\n"
21992                                                                           "\n";
21993         static const GLchar* tes_tested = "#version 430 core\n"
21994                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21995                                                                           "\n"
21996                                                                           "layout(isolines, point_mode) in;\n"
21997                                                                           "\n"
21998                                                                           "VAR_DEFINITION"
21999                                                                           "\n"
22000                                                                           "in  vec4 tcs_tes[];\n"
22001                                                                           "out vec4 any_fs;\n"
22002                                                                           "\n"
22003                                                                           "void main()\n"
22004                                                                           "{\n"
22005                                                                           "    vec4 result = tcs_tes[0];\n"
22006                                                                           "\n"
22007                                                                           "VARIABLE_USE"
22008                                                                           "\n"
22009                                                                           "    any_fs = result;\n"
22010                                                                           "}\n"
22011                                                                           "\n";
22012         static const GLchar* vs = "#version 430 core\n"
22013                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22014                                                           "\n"
22015                                                           "in  vec4 in_vs;\n"
22016                                                           "out vec4 vs_any;\n"
22017                                                           "\n"
22018                                                           "void main()\n"
22019                                                           "{\n"
22020                                                           "    vs_any = in_vs;\n"
22021                                                           "}\n"
22022                                                           "\n";
22023         static const GLchar* vs_tested = "#version 430 core\n"
22024                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22025                                                                          "\n"
22026                                                                          "VAR_DEFINITION"
22027                                                                          "\n"
22028                                                                          "in  vec4 in_vs;\n"
22029                                                                          "out vec4 any_fs;\n"
22030                                                                          "\n"
22031                                                                          "void main()\n"
22032                                                                          "{\n"
22033                                                                          "    vec4 result = in_vs;\n"
22034                                                                          "\n"
22035                                                                          "VARIABLE_USE"
22036                                                                          "\n"
22037                                                                          "    any_fs += result;\n"
22038                                                                          "}\n"
22039                                                                          "\n";
22040
22041         std::string source;
22042         testCase&   test_case = m_test_cases[test_case_index];
22043
22044         if (test_case.m_stage == stage)
22045         {
22046                 size_t            position               = 0;
22047                 const GLchar* var_definition = 0;
22048                 const GLchar* var_use            = "";
22049
22050                 switch (test_case.m_case)
22051                 {
22052                 case VALID:
22053                         var_definition = valid_var_definition;
22054                         break;
22055                 case INVALID:
22056                         var_definition = invalid_var_definition;
22057                         break;
22058                 default:
22059                         TCU_FAIL("Invalid enum");
22060                 }
22061
22062                 switch (stage)
22063                 {
22064                 case Utils::Shader::GEOMETRY:
22065                         source = gs_tested;
22066                         break;
22067                 case Utils::Shader::TESS_CTRL:
22068                         source = tcs_tested;
22069                         break;
22070                 case Utils::Shader::TESS_EVAL:
22071                         source = tes_tested;
22072                         break;
22073                 case Utils::Shader::VERTEX:
22074                         source = vs_tested;
22075                         break;
22076                 default:
22077                         TCU_FAIL("Invalid enum");
22078                 }
22079
22080                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22081                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22082         }
22083         else
22084         {
22085                 switch (test_case.m_stage)
22086                 {
22087                 case Utils::Shader::GEOMETRY:
22088                         switch (stage)
22089                         {
22090                         case Utils::Shader::FRAGMENT:
22091                                 source = fs;
22092                                 break;
22093                         case Utils::Shader::VERTEX:
22094                                 source = vs;
22095                                 break;
22096                         default:
22097                                 source = "";
22098                         }
22099                         break;
22100                 case Utils::Shader::TESS_CTRL:
22101                         switch (stage)
22102                         {
22103                         case Utils::Shader::FRAGMENT:
22104                                 source = fs;
22105                                 break;
22106                         case Utils::Shader::VERTEX:
22107                                 source = vs;
22108                                 break;
22109                         default:
22110                                 source = "";
22111                         }
22112                         break;
22113                 case Utils::Shader::TESS_EVAL:
22114                         switch (stage)
22115                         {
22116                         case Utils::Shader::FRAGMENT:
22117                                 source = fs;
22118                                 break;
22119                         case Utils::Shader::TESS_CTRL:
22120                                 source = tcs;
22121                                 break;
22122                         case Utils::Shader::VERTEX:
22123                                 source = vs;
22124                                 break;
22125                         default:
22126                                 source = "";
22127                         }
22128                         break;
22129                 case Utils::Shader::VERTEX:
22130                         switch (stage)
22131                         {
22132                         case Utils::Shader::FRAGMENT:
22133                                 source = fs;
22134                                 break;
22135                         default:
22136                                 source = "";
22137                         }
22138                         break;
22139                 default:
22140                         TCU_FAIL("Invalid enum");
22141                         break;
22142                 }
22143         }
22144
22145         return source;
22146 }
22147
22148 /** Get description of test case
22149  *
22150  * @param test_case_index Index of test case
22151  *
22152  * @return Test case description
22153  **/
22154 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22155 {
22156         std::stringstream stream;
22157         testCase&                 test_case = m_test_cases[test_case_index];
22158
22159         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22160
22161         switch (test_case.m_case)
22162         {
22163         case VALID:
22164                 stream << "valid";
22165                 break;
22166         case INVALID:
22167                 stream << "invalid";
22168                 break;
22169         default:
22170                 TCU_FAIL("Invalid enum");
22171         }
22172
22173         return stream.str();
22174 }
22175
22176 /** Get number of test cases
22177  *
22178  * @return Number of test cases
22179  **/
22180 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22181 {
22182         return static_cast<GLuint>(m_test_cases.size());
22183 }
22184
22185 /** Selects if "compute" stage is relevant for test
22186  *
22187  * @param ignored
22188  *
22189  * @return false
22190  **/
22191 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22192 {
22193         return false;
22194 }
22195
22196 /** Selects if compilation failure is expected result
22197  *
22198  * @param test_case_index Index of test case
22199  *
22200  * @return true
22201  **/
22202 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22203 {
22204         testCase& test_case = m_test_cases[test_case_index];
22205
22206         return (INVALID == test_case.m_case);
22207 }
22208
22209 /** Prepare all test cases
22210  *
22211  **/
22212 void XFBDuplicatedStrideTest::testInit()
22213 {
22214         for (GLuint c = 0; c < CASE_MAX; ++c)
22215         {
22216                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22217                 {
22218                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22219                                 (Utils::Shader::FRAGMENT == stage))
22220                         {
22221                                 continue;
22222                         }
22223
22224                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22225
22226                         m_test_cases.push_back(test_case);
22227                 }
22228         }
22229 }
22230
22231 /** Constructor
22232  *
22233  * @param context Test framework context
22234  **/
22235 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22236         : TestBase(context, "xfb_get_program_resource_api",
22237                            "Test verifies that get program resource reports correct results for XFB")
22238 {
22239 }
22240
22241 /** Source for given test case and stage
22242  *
22243  * @param test_case_index Index of test case
22244  * @param stage           Shader stage
22245  *
22246  * @return Shader source
22247  **/
22248 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22249 {
22250         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22251                                                                                           "out TYPE b1_v1ARRAY;\n"
22252                                                                                           "out TYPE b0_v3ARRAY;\n"
22253                                                                                           "out TYPE b0_v0ARRAY;\n";
22254         static const GLchar* xfb_var_definition =
22255                 "const uint type_size = SIZE;\n"
22256                 "\n"
22257                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22258                 "\n"
22259                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22260                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22261                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22262                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22263         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22264                                                                    "    b1_v1INDEX = TYPE(1);\n"
22265                                                                    "    b0_v3INDEX = TYPE(0);\n"
22266                                                                    "    b0_v0INDEX = TYPE(1);\n"
22267                                                                    "    if (vec4(0) == result)\n"
22268                                                                    "    {\n"
22269                                                                    "        b0_v1INDEX = TYPE(1);\n"
22270                                                                    "        b1_v1INDEX = TYPE(0);\n"
22271                                                                    "        b0_v3INDEX = TYPE(1);\n"
22272                                                                    "        b0_v0INDEX = TYPE(0);\n"
22273                                                                    "    }\n";
22274         static const GLchar* gs_tested =
22275                 "#version 430 core\n"
22276                 "#extension GL_ARB_enhanced_layouts : require\n"
22277                 "\n"
22278                 "layout(points)                           in;\n"
22279                 "layout(triangle_strip, max_vertices = 4) out;\n"
22280                 "\n"
22281                 "VAR_DEFINITION"
22282                 "\n"
22283                 "out gl_PerVertex \n"
22284                 "{ \n"
22285                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22286                 "}; \n"
22287                 "in  vec4 tes_gs[];\n"
22288                 "out vec4 gs_fs;\n"
22289                 "\n"
22290                 "void main()\n"
22291                 "{\n"
22292                 "    vec4 result = tes_gs[0];\n"
22293                 "\n"
22294                 "VARIABLE_USE"
22295                 "\n"
22296                 "    gs_fs = result;\n"
22297                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22298                 "    EmitVertex();\n"
22299                 "    gs_fs = result;\n"
22300                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22301                 "    EmitVertex();\n"
22302                 "    gs_fs = result;\n"
22303                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22304                 "    EmitVertex();\n"
22305                 "    gs_fs = result;\n"
22306                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22307                 "    EmitVertex();\n"
22308                 "}\n"
22309                 "\n";
22310 #if 0
22311         static const GLchar* tcs_tested =
22312                 "#version 430 core\n"
22313                 "#extension GL_ARB_enhanced_layouts : require\n"
22314                 "\n"
22315                 "layout(vertices = 1) out;\n"
22316                 "\n"
22317                 "VAR_DEFINITION"
22318                 "\n"
22319                 "in  vec4 vs_tcs[];\n"
22320                 "out vec4 tcs_tes[];\n"
22321                 "\n"
22322                 "void main()\n"
22323                 "{\n"
22324                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22325                 "\n"
22326                 "VARIABLE_USE"
22327                 "\n"
22328                 "    tcs_tes[gl_InvocationID] = result;\n"
22329                 "\n"
22330                 "    gl_TessLevelOuter[0] = 1.0;\n"
22331                 "    gl_TessLevelOuter[1] = 1.0;\n"
22332                 "    gl_TessLevelOuter[2] = 1.0;\n"
22333                 "    gl_TessLevelOuter[3] = 1.0;\n"
22334                 "    gl_TessLevelInner[0] = 1.0;\n"
22335                 "    gl_TessLevelInner[1] = 1.0;\n"
22336                 "}\n"
22337                 "\n";
22338 #endif
22339         static const GLchar* tes_tested = "#version 430 core\n"
22340                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22341                                                                           "\n"
22342                                                                           "layout(isolines, point_mode) in;\n"
22343                                                                           "\n"
22344                                                                           "VAR_DEFINITION"
22345                                                                           "\n"
22346                                                                           "in  vec4 tcs_tes[];\n"
22347                                                                           "out vec4 tes_gs;\n"
22348                                                                           "\n"
22349                                                                           "void main()\n"
22350                                                                           "{\n"
22351                                                                           "    vec4 result = tcs_tes[0];\n"
22352                                                                           "\n"
22353                                                                           "VARIABLE_USE"
22354                                                                           "\n"
22355                                                                           "    tes_gs = result;\n"
22356                                                                           "}\n"
22357                                                                           "\n";
22358         static const GLchar* vs_tested = "#version 430 core\n"
22359                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22360                                                                          "\n"
22361                                                                          "VAR_DEFINITION"
22362                                                                          "\n"
22363                                                                          "in  vec4 in_vs;\n"
22364                                                                          "out vec4 vs_tcs;\n"
22365                                                                          "\n"
22366                                                                          "void main()\n"
22367                                                                          "{\n"
22368                                                                          "    vec4 result = in_vs;\n"
22369                                                                          "\n"
22370                                                                          "VARIABLE_USE"
22371                                                                          "\n"
22372                                                                          "    vs_tcs = result;\n"
22373                                                                          "}\n"
22374                                                                          "\n";
22375
22376         std::string              source;
22377         const test_Case& test_case = m_test_cases[test_case_index];
22378
22379         if (test_case.m_stage == stage)
22380         {
22381                 const GLchar* array = "";
22382                 GLchar            buffer[16];
22383                 const GLchar* index     = "";
22384                 size_t            position = 0;
22385                 size_t            temp;
22386                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22387                 const GLchar* var_definition = 0;
22388
22389                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22390
22391                 if (XFB == test_case.m_case)
22392                 {
22393                         var_definition = xfb_var_definition;
22394                 }
22395                 else
22396                 {
22397                         var_definition = api_var_definition;
22398                 }
22399
22400                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22401                 // change array = "[]" to "[1]"
22402                 switch (stage)
22403                 {
22404                 case Utils::Shader::GEOMETRY:
22405                         source = gs_tested;
22406                         array  = "[1]";
22407                         index  = "[0]";
22408                         break;
22409 // It is invalid to output transform feedback varyings in tessellation control shader
22410 #if 0
22411                 case Utils::Shader::TESS_CTRL:
22412                         source = tcs_tested;
22413                         array = "[]";
22414                         index = "[gl_InvocationID]";
22415                         break;
22416 #endif
22417                 case Utils::Shader::TESS_EVAL:
22418                         source = tes_tested;
22419                         array  = "[1]";
22420                         index  = "[0]";
22421                         break;
22422                 case Utils::Shader::VERTEX:
22423                         source = vs_tested;
22424                         break;
22425                 default:
22426                         TCU_FAIL("Invalid enum");
22427                 }
22428
22429                 temp = position;
22430                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22431                 if (XFB == test_case.m_case)
22432                 {
22433                         position = temp;
22434                         Utils::replaceToken("SIZE", position, buffer, source);
22435                 }
22436                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22437
22438                 Utils::replaceAllTokens("ARRAY", array, source);
22439                 Utils::replaceAllTokens("INDEX", index, source);
22440                 Utils::replaceAllTokens("TYPE", type_name, source);
22441         }
22442         else
22443         {
22444                 source = "";
22445         }
22446
22447         return source;
22448 }
22449
22450 /** Get description of test case
22451  *
22452  * @param test_case_index Index of test case
22453  *
22454  * @return Test case description
22455  **/
22456 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22457 {
22458         std::stringstream stream;
22459         const test_Case&  test_case = m_test_cases[test_case_index];
22460
22461         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22462                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22463
22464         switch (test_case.m_case)
22465         {
22466         case INTERLEAVED:
22467                 stream << "interleaved";
22468                 break;
22469         case SEPARATED:
22470                 stream << "separated";
22471                 break;
22472         case XFB:
22473                 stream << "xfb";
22474                 break;
22475         default:
22476                 TCU_FAIL("Invalid enum");
22477         }
22478
22479         return stream.str();
22480 }
22481
22482 /** Get number of test cases
22483  *
22484  * @return Number of test cases
22485  **/
22486 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22487 {
22488         return static_cast<GLuint>(m_test_cases.size());
22489 }
22490
22491 /** Inspects program for offset, buffer index, buffer stride and type
22492  *
22493  * @param test_case_index Index of test case
22494  * @param program         Program to query
22495  *
22496  * @return true if query results match expected values, false otherwise
22497  **/
22498 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22499 {
22500         GLint                    b0_stride      = 0;
22501         GLint                    b1_stride      = 0;
22502         GLint                    b0_v0_buf      = 0;
22503         GLint                    b0_v0_offset = 0;
22504         GLint                    b0_v0_type   = 0;
22505         GLint                    b0_v1_buf      = 0;
22506         GLint                    b0_v1_offset = 0;
22507         GLint                    b0_v1_type   = 0;
22508         GLint                    b0_v3_buf      = 0;
22509         GLint                    b0_v3_offset = 0;
22510         GLint                    b0_v3_type   = 0;
22511         GLint                    b1_v1_buf      = 0;
22512         GLint                    b1_v1_offset = 0;
22513         GLint                    b1_v1_type   = 0;
22514         const test_Case& test_case      = m_test_cases[test_case_index];
22515         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22516         const GLint              type_size      = test_case.m_type.GetSize();
22517
22518         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22519         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22520         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22521         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22522
22523         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22524         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22525         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22526         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22527
22528         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22529         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22530         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22531         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22532
22533         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22534                                                 1 /* buf_size */, &b0_v0_buf);
22535         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22536                                                 1 /* buf_size */, &b0_v1_buf);
22537         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22538                                                 1 /* buf_size */, &b0_v3_buf);
22539         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22540                                                 1 /* buf_size */, &b1_v1_buf);
22541
22542         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22543                                                 &b0_stride);
22544         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22545                                                 &b1_stride);
22546
22547         if (SEPARATED != test_case.m_case)
22548         {
22549                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22550                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22551                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22552                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22553                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22554                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22555                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22556         }
22557         else
22558         {
22559                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22560                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22561                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22562                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22563                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22564         }
22565 }
22566
22567 /** Insert gl_SkipComponents
22568  *
22569  * @param num_components How many gl_SkipComponents1 need to be inserted
22570  * @param varyings The transform feedback varyings string vector
22571  *
22572  **/
22573 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22574 {
22575         int num_component_4 = num_components / 4;
22576         int num_component_1 = num_components % 4;
22577         for (int i = 0; i < num_component_4; i++)
22578         {
22579                 varyings.push_back("gl_SkipComponents4");
22580         }
22581         switch (num_component_1)
22582         {
22583         case 1:
22584                 varyings.push_back("gl_SkipComponents1");
22585                 break;
22586         case 2:
22587                 varyings.push_back("gl_SkipComponents2");
22588                 break;
22589         case 3:
22590                 varyings.push_back("gl_SkipComponents3");
22591                 break;
22592         default:
22593                 break;
22594         }
22595 }
22596
22597 /** Runs test case
22598  *
22599  * @param test_case_index Id of test case
22600  *
22601  * @return true if test case pass, false otherwise
22602  **/
22603 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22604 {
22605         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22606         Utils::Program   program(m_context);
22607         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22608         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22609         const test_Case&   test_case            = m_test_cases[test_case_index];
22610         bool                       test_case_result = true;
22611         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22612
22613         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22614         // 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.
22615
22616         if (INTERLEAVED == test_case.m_case)
22617         {
22618                 /*
22619                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22620                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22621                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22622                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22623
22624                  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,
22625                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22626                  */
22627                 Utils::Program::NameVector captured_varyings;
22628                 captured_varyings.push_back("b0_v0");
22629                 captured_varyings.push_back("b0_v1");
22630                 // Compute how many gl_SkipComponents to be inserted
22631                 int numComponents = test_case.m_type.GetSize() / 4;
22632                 insertSkipComponents(numComponents, captured_varyings);
22633                 captured_varyings.push_back("b0_v3");
22634                 captured_varyings.push_back("gl_NextBuffer");
22635                 insertSkipComponents(numComponents, captured_varyings);
22636                 captured_varyings.push_back("b1_v1");
22637                 insertSkipComponents(numComponents * 2, captured_varyings);
22638
22639                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22640                                          true /* separable */);
22641         }
22642         else if (SEPARATED == test_case.m_case)
22643         {
22644                 Utils::Program::NameVector captured_varyings;
22645
22646                 captured_varyings.push_back("b0_v0");
22647                 captured_varyings.push_back("b0_v1");
22648                 captured_varyings.push_back("b0_v3");
22649                 captured_varyings.push_back("b1_v1");
22650
22651                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22652                                          true /* separable */);
22653         }
22654         else
22655         {
22656
22657                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22658         }
22659
22660         test_case_result = inspectProgram(test_case_index, program);
22661
22662         return test_case_result;
22663 }
22664
22665 /** Prepare all test cases
22666  *
22667  **/
22668 void XFBGetProgramResourceAPITest::testInit()
22669 {
22670         const Functions& gl              = m_context.getRenderContext().getFunctions();
22671         const GLuint     n_types = getTypesNumber();
22672         GLint                    max_xfb_int;
22673         GLint                    max_xfb_sep;
22674
22675         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22676         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22677
22678         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22679         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22680
22681         GLint max_varyings;
22682         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22683
22684         for (GLuint i = 0; i < n_types; ++i)
22685         {
22686                 // 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,
22687                 // 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
22688                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22689                 // to guarantee the number of varying not exceeded.
22690                 /*
22691                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22692                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22693                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22694                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22695                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22696                  in  vec4 in_vs;
22697                  out vec4 vs_tcs;
22698                  */
22699                 if (i == 7 || i == 9)
22700                         continue;
22701                 const Utils::Type& type = getType(i);
22702                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22703                 {
22704                         continue;
22705                 }
22706                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22707                 {
22708                         /*
22709                          It is invalid to define transform feedback output in HS
22710                          */
22711                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22712                                 (Utils::Shader::FRAGMENT == stage))
22713                         {
22714                                 continue;
22715                         }
22716
22717                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22718                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22719                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22720
22721                         if ((int)type.GetSize() <= max_xfb_int)
22722                         {
22723                                 m_test_cases.push_back(test_case_xfb);
22724                                 m_test_cases.push_back(test_case_int);
22725                         }
22726
22727                         if ((int)type.GetSize() <= max_xfb_sep)
22728                         {
22729                                 m_test_cases.push_back(test_case_sep);
22730                         }
22731                 }
22732         }
22733 }
22734
22735 /** Constructor
22736  *
22737  * @param context Test context
22738  **/
22739 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22740         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22741                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22742 {
22743         /* Nothing to be done here */
22744 }
22745
22746 /** Get descriptors of buffers necessary for test
22747  *
22748  * @param test_case_index Index of test case
22749  * @param out_descriptors Descriptors of buffers used by test
22750  **/
22751 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22752                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22753 {
22754         const Utils::Type& type = getType(test_case_index);
22755
22756         /* Test needs single uniform and xfb */
22757         out_descriptors.resize(2);
22758
22759         /* Get references */
22760         bufferDescriptor& uniform = out_descriptors[0];
22761         bufferDescriptor& xfb    = out_descriptors[1];
22762
22763         /* Index */
22764         uniform.m_index = 0;
22765         xfb.m_index             = 0;
22766
22767         /* Target */
22768         uniform.m_target = Utils::Buffer::Uniform;
22769         xfb.m_target     = Utils::Buffer::Transform_feedback;
22770
22771         /* Data */
22772         const GLuint                            gen_start   = Utils::s_rand;
22773         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22774         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22775         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22776
22777         Utils::s_rand                                                           = gen_start;
22778         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22779         type.GenerateDataPacked(); // generate the data for trunks
22780         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22781
22782         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22783         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22784
22785         /* Uniform data */
22786         uniform.m_initial_data.resize(3 * type_size);
22787         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22788         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22789         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22790
22791         /* XFB data */
22792         xfb.m_initial_data.resize(3 * type_size_pck);
22793         xfb.m_expected_data.resize(3 * type_size_pck);
22794
22795         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
22796         {
22797                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22798                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22799         }
22800
22801         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22802         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22803 }
22804
22805 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22806  *
22807  * @param ignored
22808  * @param captured_varyings List of names
22809  **/
22810 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
22811                                                                                                                    Utils::Program::NameVector& captured_varyings)
22812 {
22813         captured_varyings.resize(1);
22814
22815         captured_varyings[0] = "trunks";
22816 }
22817
22818 /** Get body of main function for given shader stage
22819  *
22820  * @param test_case_index  Index of test case
22821  * @param stage            Shader stage
22822  * @param out_assignments  Set to empty
22823  * @param out_calculations Set to empty
22824  **/
22825 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22826                                                                                                          std::string& out_assignments, std::string& out_calculations)
22827 {
22828         out_calculations = "";
22829
22830         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22831                                                           "    trunks = uni_trunks;\n"
22832                                                           "    goku   = uni_goku;\n";
22833         static const GLchar* fs = "    fs_out = vec4(0);\n"
22834                                                           "    if (TYPE(1) == goku + trunks + vegeta)\n"
22835                                                           "    {\n"
22836                                                           "        fs_out = vec4(1);\n"
22837                                                           "    }\n";
22838
22839         const GLchar* assignments = "";
22840         switch (stage)
22841         {
22842         case Utils::Shader::FRAGMENT:
22843                 assignments = fs;
22844                 break;
22845         case Utils::Shader::GEOMETRY:
22846                 assignments = gs;
22847                 break;
22848         default:
22849                 break;
22850         }
22851
22852         out_assignments = assignments;
22853
22854         if (Utils::Shader::FRAGMENT == stage)
22855         {
22856                 const Utils::Type& type = getType(test_case_index);
22857
22858                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22859         }
22860 }
22861
22862 /** Get interface of shader
22863  *
22864  * @param test_case_index  Index of test case
22865  * @param stage            Shader stage
22866  * @param out_interface    Set to ""
22867  **/
22868 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22869                                                                                                                   std::string& out_interface)
22870 {
22871         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22872                                                           "\n"
22873                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22874                                                           "                                      flat out TYPE trunks;\n"
22875                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22876                                                           "\n"
22877                                                           /*
22878                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22879                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22880                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22881                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22882                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22883                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22884                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22885                  */
22886                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22887                                                           "    TYPE uni_vegeta;\n"
22888                                                           "    TYPE uni_trunks;\n"
22889                                                           "    TYPE uni_goku;\n"
22890                                                           "};\n";
22891         static const GLchar* fs = "flat in TYPE vegeta;\n"
22892                                                           "flat in TYPE trunks;\n"
22893                                                           "flat in TYPE goku;\n"
22894                                                           "\n"
22895                                                           "out vec4 fs_out;\n";
22896
22897         const Utils::Type& type = getType(test_case_index);
22898
22899         switch (stage)
22900         {
22901         case Utils::Shader::FRAGMENT:
22902                 out_interface = fs;
22903                 break;
22904         case Utils::Shader::GEOMETRY:
22905                 out_interface = gs;
22906                 break;
22907         default:
22908                 out_interface = "";
22909                 return;
22910         }
22911
22912         if (Utils::Shader::GEOMETRY == stage)
22913         {
22914                 GLchar           buffer[16];
22915                 size_t           position  = 0;
22916                 const GLuint type_size = type.GetSize();
22917
22918                 sprintf(buffer, "%d", type_size);
22919
22920                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22921         }
22922
22923         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22924 }
22925
22926 /** Get type name
22927  *
22928  * @param test_case_index Index of test case
22929  *
22930  * @return Name of type test in test_case_index
22931  **/
22932 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22933 {
22934         return getTypeName(test_case_index);
22935 }
22936
22937 /** Returns number of types to test
22938  *
22939  * @return Number of types, 34
22940  **/
22941 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
22942 {
22943         return getTypesNumber();
22944 }
22945
22946 /** Inspects program to check if all resources are as expected
22947  *
22948  * @param test_case_index Index of test case
22949  * @param program         Program instance
22950  * @param out_stream      Error message
22951  *
22952  * @return true if everything is ok, false otherwise
22953  **/
22954 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
22955                                                                                                           std::stringstream& out_stream)
22956 {
22957         GLint                      stride       = 0;
22958         const Utils::Type& type          = getType(test_case_index);
22959         const GLuint       type_size = type.GetSize(false);
22960
22961         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
22962                                                 1 /* buf_size */, &stride);
22963
22964         if ((GLint)(3 * type_size) != stride)
22965         {
22966                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
22967
22968                 return false;
22969         }
22970
22971         return true;
22972 }
22973
22974 /** Constructor
22975  *
22976  * @param context Test context
22977  **/
22978 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
22979         : BufferTestBase(context, "xfb_vertex_streams",
22980                                          "Test verifies that xfb qualifier works with multiple output streams")
22981 {
22982         /* Nothing to be done here */
22983 }
22984
22985 /** Get descriptors of buffers necessary for test
22986  *
22987  * @param ignored
22988  * @param out_descriptors Descriptors of buffers used by test
22989  **/
22990 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
22991                                                                                                 bufferDescriptor::Vector& out_descriptors)
22992 {
22993         const Utils::Type& type = Utils::Type::vec4;
22994
22995         /* Test needs single uniform and three xfbs */
22996         out_descriptors.resize(4);
22997
22998         /* Get references */
22999         bufferDescriptor& uniform = out_descriptors[0];
23000         bufferDescriptor& xfb_1   = out_descriptors[1];
23001         bufferDescriptor& xfb_2   = out_descriptors[2];
23002         bufferDescriptor& xfb_3   = out_descriptors[3];
23003
23004         /* Index */
23005         uniform.m_index = 0;
23006         xfb_1.m_index   = 1;
23007         xfb_2.m_index   = 2;
23008         xfb_3.m_index   = 3;
23009
23010         /* Target */
23011         uniform.m_target = Utils::Buffer::Uniform;
23012         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
23013         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
23014         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
23015
23016         /* Data */
23017         const std::vector<GLubyte>& goku_data   = type.GenerateData();
23018         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
23019         const std::vector<GLubyte>& goten_data  = type.GenerateData();
23020         const std::vector<GLubyte>& picolo_data = type.GenerateData();
23021         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
23022         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
23023
23024         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
23025
23026         /* Uniform data */
23027         uniform.m_initial_data.resize(6 * type_size);
23028         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
23029         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
23030         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
23031         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
23032         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
23033         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
23034
23035         /* XFB data */
23036         static const GLuint xfb_stride = 64;
23037         xfb_1.m_initial_data.resize(xfb_stride);
23038         xfb_1.m_expected_data.resize(xfb_stride);
23039         xfb_2.m_initial_data.resize(xfb_stride);
23040         xfb_2.m_expected_data.resize(xfb_stride);
23041         xfb_3.m_initial_data.resize(xfb_stride);
23042         xfb_3.m_expected_data.resize(xfb_stride);
23043
23044         for (GLuint i = 0; i < xfb_stride; ++i)
23045         {
23046                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
23047                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
23048                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
23049                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
23050                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
23051                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
23052         }
23053
23054         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
23055         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
23056         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23057         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23058         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23059         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23060 }
23061
23062 /** Get body of main function for given shader stage
23063  *
23064  * @param ignored
23065  * @param stage            Shader stage
23066  * @param out_assignments  Set to empty
23067  * @param out_calculations Set to empty
23068  **/
23069 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23070                                                                                  std::string& out_assignments, std::string& out_calculations)
23071 {
23072         out_calculations = "";
23073
23074         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23075         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23076         // by the GS is assigned to specific stream.
23077         static const GLchar* gs = "    goku   = uni_goku;\n"
23078                                                           "    gohan  = uni_gohan;\n"
23079                                                           "    goten  = uni_goten;\n"
23080                                                           "    EmitStreamVertex(0);\n"
23081                                                           "    EndStreamPrimitive(0);\n"
23082                                                           "    picolo = uni_picolo;\n"
23083                                                           "    vegeta = uni_vegeta;\n"
23084                                                           "    EmitStreamVertex(1);\n"
23085                                                           "    EndStreamPrimitive(1);\n"
23086                                                           "    bulma  = uni_bulma;\n"
23087                                                           "    EmitStreamVertex(2);\n"
23088                                                           "    EndStreamPrimitive(2);\n";
23089
23090         static const GLchar* fs = "    fs_out = gohan + goku + goten;\n";
23091
23092         const GLchar* assignments = "";
23093         switch (stage)
23094         {
23095         case Utils::Shader::FRAGMENT:
23096                 assignments = fs;
23097                 break;
23098         case Utils::Shader::GEOMETRY:
23099                 assignments = gs;
23100                 break;
23101         default:
23102                 break;
23103         }
23104
23105         out_assignments = assignments;
23106 }
23107
23108 /** Get interface of shader
23109  *
23110  * @param ignored
23111  * @param stage            Shader stage
23112  * @param out_interface    Set to ""
23113  **/
23114 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23115                                                                                           std::string& out_interface)
23116 {
23117         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23118                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23119                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23120                                                           "\n"
23121                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23122                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23123                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23124                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23125                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23126                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23127                                                           "\n"
23128                                                           "layout(binding = 0) uniform gs_block {\n"
23129                                                           "    vec4 uni_goku;\n"
23130                                                           "    vec4 uni_gohan;\n"
23131                                                           "    vec4 uni_goten;\n"
23132                                                           "    vec4 uni_picolo;\n"
23133                                                           "    vec4 uni_vegeta;\n"
23134                                                           "    vec4 uni_bulma;\n"
23135                                                           "};\n";
23136         /*
23137          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23138          */
23139         static const GLchar* fs = "in vec4 goku;\n"
23140                                                           "in vec4 gohan;\n"
23141                                                           "in vec4 goten;\n"
23142                                                           "\n"
23143                                                           "out vec4 fs_out;\n";
23144
23145         switch (stage)
23146         {
23147         case Utils::Shader::FRAGMENT:
23148                 out_interface = fs;
23149                 break;
23150         case Utils::Shader::GEOMETRY:
23151                 out_interface = gs;
23152                 break;
23153         default:
23154                 out_interface = "";
23155                 return;
23156         }
23157 }
23158
23159 /** Constructor
23160  *
23161  * @param context Test framework context
23162  **/
23163 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23164         : NegativeTestBase(
23165                   context, "xfb_multiple_vertex_streams",
23166                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23167 {
23168 }
23169
23170 /** Source for given test case and stage
23171  *
23172  * @param ignored
23173  * @param stage           Shader stage
23174  *
23175  * @return Shader source
23176  **/
23177 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23178 {
23179         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23180                                                                                   "\n"
23181                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23182                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23183                                                                                   "\n"
23184                                                                                   "\n"
23185                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23186                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23187                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23188         static const GLchar* var_use = "    goku  = result / 2;\n"
23189                                                                    "    gohan = result / 4;\n"
23190                                                                    "    goten = result / 6;\n";
23191         static const GLchar* fs = "#version 430 core\n"
23192                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23193                                                           "\n"
23194                                                           "in  vec4 gs_fs;\n"
23195                                                           "in  vec4 goku;\n"
23196                                                           "out vec4 fs_out;\n"
23197                                                           "\n"
23198                                                           "void main()\n"
23199                                                           "{\n"
23200                                                           "    fs_out = gs_fs + goku;\n"
23201                                                           "}\n"
23202                                                           "\n";
23203         static const GLchar* gs = "#version 430 core\n"
23204                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23205                                                           "\n"
23206                                                           "layout(points)                           in;\n"
23207                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23208                                                           "\n"
23209                                                           "VAR_DEFINITION"
23210                                                           "\n"
23211                                                           "in  vec4 tes_gs[];\n"
23212                                                           "out vec4 gs_fs;\n"
23213                                                           "\n"
23214                                                           "void main()\n"
23215                                                           "{\n"
23216                                                           "    vec4 result = tes_gs[0];\n"
23217                                                           "\n"
23218                                                           "VARIABLE_USE"
23219                                                           "\n"
23220                                                           "    gs_fs = result;\n"
23221                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23222                                                           "    EmitVertex();\n"
23223                                                           "    gs_fs = result;\n"
23224                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23225                                                           "    EmitVertex();\n"
23226                                                           "    gs_fs = result;\n"
23227                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23228                                                           "    EmitVertex();\n"
23229                                                           "    gs_fs = result;\n"
23230                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23231                                                           "    EmitVertex();\n"
23232                                                           "}\n"
23233                                                           "\n";
23234         static const GLchar* vs = "#version 430 core\n"
23235                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23236                                                           "\n"
23237                                                           "in  vec4 in_vs;\n"
23238                                                           "out vec4 vs_tcs;\n"
23239                                                           "\n"
23240                                                           "void main()\n"
23241                                                           "{\n"
23242                                                           "    vs_tcs = in_vs;\n"
23243                                                           "}\n"
23244                                                           "\n";
23245
23246         std::string source;
23247
23248         if (Utils::Shader::GEOMETRY == stage)
23249         {
23250                 size_t position = 0;
23251
23252                 source = gs;
23253
23254                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23255                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23256         }
23257         else
23258         {
23259                 switch (stage)
23260                 {
23261                 case Utils::Shader::FRAGMENT:
23262                         source = fs;
23263                         break;
23264                 case Utils::Shader::VERTEX:
23265                         source = vs;
23266                         break;
23267                 default:
23268                         source = "";
23269                 }
23270         }
23271
23272         return source;
23273 }
23274
23275 /** Selects if "compute" stage is relevant for test
23276  *
23277  * @param ignored
23278  *
23279  * @return false
23280  **/
23281 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23282 {
23283         return false;
23284 }
23285
23286 /** Constructor
23287  *
23288  * @param context Test framework context
23289  **/
23290 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23291         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23292                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23293 {
23294 }
23295
23296 /** Source for given test case and stage
23297  *
23298  * @param test_case_index Index of test case
23299  * @param stage           Shader stage
23300  *
23301  * @return Shader source
23302  **/
23303 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23304 {
23305         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23306                                                                                                 "\n"
23307                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23308                                                                                                 "    vec4 member;\n"
23309                                                                                                 "} gokuARRAY;\n";
23310         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23311                                                                                                  "\n"
23312                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23313         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23314                                                                                                  "\n"
23315                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23316         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23317         static const GLchar* global_use = "";
23318         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23319         static const GLchar* fs                 = "#version 430 core\n"
23320                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23321                                                           "\n"
23322                                                           "in  vec4 gs_fs;\n"
23323                                                           "out vec4 fs_out;\n"
23324                                                           "\n"
23325                                                           "void main()\n"
23326                                                           "{\n"
23327                                                           "    fs_out = gs_fs;\n"
23328                                                           "}\n"
23329                                                           "\n";
23330         static const GLchar* gs_tested = "#version 430 core\n"
23331                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23332                                                                          "\n"
23333                                                                          "layout(points)                           in;\n"
23334                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23335                                                                          "\n"
23336                                                                          "VAR_DEFINITION"
23337                                                                          "\n"
23338                                                                          "in  vec4 tes_gs[];\n"
23339                                                                          "out vec4 gs_fs;\n"
23340                                                                          "\n"
23341                                                                          "void main()\n"
23342                                                                          "{\n"
23343                                                                          "    vec4 result = tes_gs[0];\n"
23344                                                                          "\n"
23345                                                                          "VARIABLE_USE"
23346                                                                          "\n"
23347                                                                          "    gs_fs = result;\n"
23348                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23349                                                                          "    EmitVertex();\n"
23350                                                                          "    gs_fs = result;\n"
23351                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23352                                                                          "    EmitVertex();\n"
23353                                                                          "    gs_fs = result;\n"
23354                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23355                                                                          "    EmitVertex();\n"
23356                                                                          "    gs_fs = result;\n"
23357                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23358                                                                          "    EmitVertex();\n"
23359                                                                          "}\n"
23360                                                                          "\n";
23361         static const GLchar* tcs = "#version 430 core\n"
23362                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23363                                                            "\n"
23364                                                            "layout(vertices = 1) out;\n"
23365                                                            "\n"
23366                                                            "in  vec4 vs_tcs[];\n"
23367                                                            "out vec4 tcs_tes[];\n"
23368                                                            "\n"
23369                                                            "void main()\n"
23370                                                            "{\n"
23371                                                            "\n"
23372                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23373                                                            "\n"
23374                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23375                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23376                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23377                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23378                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23379                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23380                                                            "}\n"
23381                                                            "\n";
23382         static const GLchar* tcs_tested = "#version 430 core\n"
23383                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23384                                                                           "\n"
23385                                                                           "layout(vertices = 1) out;\n"
23386                                                                           "\n"
23387                                                                           "VAR_DEFINITION"
23388                                                                           "\n"
23389                                                                           "in  vec4 vs_tcs[];\n"
23390                                                                           "out vec4 tcs_tes[];\n"
23391                                                                           "\n"
23392                                                                           "void main()\n"
23393                                                                           "{\n"
23394                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23395                                                                           "\n"
23396                                                                           "VARIABLE_USE"
23397                                                                           "\n"
23398                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23399                                                                           "\n"
23400                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23401                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23402                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23403                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23404                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23405                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23406                                                                           "}\n"
23407                                                                           "\n";
23408         static const GLchar* tes_tested = "#version 430 core\n"
23409                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23410                                                                           "\n"
23411                                                                           "layout(isolines, point_mode) in;\n"
23412                                                                           "\n"
23413                                                                           "VAR_DEFINITION"
23414                                                                           "\n"
23415                                                                           "in  vec4 tcs_tes[];\n"
23416                                                                           "out vec4 tes_gs;\n"
23417                                                                           "\n"
23418                                                                           "void main()\n"
23419                                                                           "{\n"
23420                                                                           "    vec4 result = tcs_tes[0];\n"
23421                                                                           "\n"
23422                                                                           "VARIABLE_USE"
23423                                                                           "\n"
23424                                                                           "    tes_gs += result;\n"
23425                                                                           "}\n"
23426                                                                           "\n";
23427         static const GLchar* vs = "#version 430 core\n"
23428                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23429                                                           "\n"
23430                                                           "in  vec4 in_vs;\n"
23431                                                           "out vec4 vs_tcs;\n"
23432                                                           "\n"
23433                                                           "void main()\n"
23434                                                           "{\n"
23435                                                           "    vs_tcs = in_vs;\n"
23436                                                           "}\n"
23437                                                           "\n";
23438         static const GLchar* vs_tested = "#version 430 core\n"
23439                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23440                                                                          "\n"
23441                                                                          "VAR_DEFINITION"
23442                                                                          "\n"
23443                                                                          "in  vec4 in_vs;\n"
23444                                                                          "out vec4 vs_tcs;\n"
23445                                                                          "\n"
23446                                                                          "void main()\n"
23447                                                                          "{\n"
23448                                                                          "    vec4 result = in_vs;\n"
23449                                                                          "\n"
23450                                                                          "VARIABLE_USE"
23451                                                                          "\n"
23452                                                                          "    vs_tcs = result;\n"
23453                                                                          "}\n"
23454                                                                          "\n";
23455
23456         std::string source;
23457         testCase&   test_case = m_test_cases[test_case_index];
23458
23459         if (test_case.m_stage == stage)
23460         {
23461                 const GLchar*   array = "";
23462                 GLchar                   buffer[16];
23463                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23464                 const GLchar*   index    = "";
23465                 GLint                    max_n_xfb = 0;
23466                 size_t                   position  = 0;
23467                 size_t                   temp;
23468                 const GLchar*   var_definition = 0;
23469                 const GLchar*   var_use         = 0;
23470
23471                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23472                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23473
23474                 sprintf(buffer, "%d", max_n_xfb);
23475
23476                 switch (test_case.m_case)
23477                 {
23478                 case BLOCK:
23479                         var_definition = block_var_definition;
23480                         var_use            = block_use;
23481                         break;
23482                 case GLOBAL:
23483                         var_definition = global_var_definition;
23484                         var_use            = global_use;
23485                         break;
23486                 case VECTOR:
23487                         var_definition = vector_var_definition;
23488                         var_use            = vector_use;
23489                         break;
23490                 default:
23491                         TCU_FAIL("Invalid enum");
23492                 }
23493
23494                 switch (stage)
23495                 {
23496                 case Utils::Shader::GEOMETRY:
23497                         source = gs_tested;
23498                         array  = "[]";
23499                         index  = "[0]";
23500                         break;
23501                 case Utils::Shader::TESS_CTRL:
23502                         source = tcs_tested;
23503                         array  = "[]";
23504                         index  = "[gl_InvocationID]";
23505                         break;
23506                 case Utils::Shader::TESS_EVAL:
23507                         source = tes_tested;
23508                         array  = "[]";
23509                         index  = "[0]";
23510                         break;
23511                 case Utils::Shader::VERTEX:
23512                         source = vs_tested;
23513                         break;
23514                 default:
23515                         TCU_FAIL("Invalid enum");
23516                 }
23517
23518                 temp = position;
23519                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23520                 position = temp;
23521                 Utils::replaceToken("BUFFER", position, buffer, source);
23522                 if (GLOBAL != test_case.m_case)
23523                 {
23524                         Utils::replaceToken("ARRAY", position, array, source);
23525                 }
23526                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23527
23528                 Utils::replaceAllTokens("INDEX", index, source);
23529         }
23530         else
23531         {
23532                 switch (test_case.m_stage)
23533                 {
23534                 case Utils::Shader::GEOMETRY:
23535                         switch (stage)
23536                         {
23537                         case Utils::Shader::FRAGMENT:
23538                                 source = fs;
23539                                 break;
23540                         case Utils::Shader::VERTEX:
23541                                 source = vs;
23542                                 break;
23543                         default:
23544                                 source = "";
23545                         }
23546                         break;
23547                 case Utils::Shader::TESS_CTRL:
23548                         switch (stage)
23549                         {
23550                         case Utils::Shader::FRAGMENT:
23551                                 source = fs;
23552                                 break;
23553                         case Utils::Shader::VERTEX:
23554                                 source = vs;
23555                                 break;
23556                         default:
23557                                 source = "";
23558                         }
23559                         break;
23560                 case Utils::Shader::TESS_EVAL:
23561                         switch (stage)
23562                         {
23563                         case Utils::Shader::FRAGMENT:
23564                                 source = fs;
23565                                 break;
23566                         case Utils::Shader::TESS_CTRL:
23567                                 source = tcs;
23568                                 break;
23569                         case Utils::Shader::VERTEX:
23570                                 source = vs;
23571                                 break;
23572                         default:
23573                                 source = "";
23574                         }
23575                         break;
23576                 case Utils::Shader::VERTEX:
23577                         switch (stage)
23578                         {
23579                         case Utils::Shader::FRAGMENT:
23580                                 source = fs;
23581                                 break;
23582                         default:
23583                                 source = "";
23584                         }
23585                         break;
23586                 default:
23587                         TCU_FAIL("Invalid enum");
23588                         break;
23589                 }
23590         }
23591
23592         return source;
23593 }
23594
23595 /** Get description of test case
23596  *
23597  * @param test_case_index Index of test case
23598  *
23599  * @return Test case description
23600  **/
23601 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23602 {
23603         std::stringstream stream;
23604         testCase&                 test_case = m_test_cases[test_case_index];
23605
23606         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23607
23608         switch (test_case.m_case)
23609         {
23610         case BLOCK:
23611                 stream << "BLOCK";
23612                 break;
23613         case GLOBAL:
23614                 stream << "GLOBAL";
23615                 break;
23616         case VECTOR:
23617                 stream << "VECTOR";
23618                 break;
23619         default:
23620                 TCU_FAIL("Invalid enum");
23621         }
23622
23623         return stream.str();
23624 }
23625
23626 /** Get number of test cases
23627  *
23628  * @return Number of test cases
23629  **/
23630 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23631 {
23632         return static_cast<GLuint>(m_test_cases.size());
23633 }
23634
23635 /** Selects if "compute" stage is relevant for test
23636  *
23637  * @param ignored
23638  *
23639  * @return false
23640  **/
23641 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23642 {
23643         return false;
23644 }
23645
23646 /** Prepare all test cases
23647  *
23648  **/
23649 void XFBExceedBufferLimitTest::testInit()
23650 {
23651         for (GLuint c = 0; c < CASE_MAX; ++c)
23652         {
23653                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23654                 {
23655                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23656                                 (Utils::Shader::FRAGMENT == stage))
23657                         {
23658                                 continue;
23659                         }
23660
23661                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23662
23663                         m_test_cases.push_back(test_case);
23664                 }
23665         }
23666 }
23667
23668 /** Constructor
23669  *
23670  * @param context Test framework context
23671  **/
23672 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23673         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23674                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23675 {
23676 }
23677
23678 /** Source for given test case and stage
23679  *
23680  * @param test_case_index Index of test case
23681  * @param stage           Shader stage
23682  *
23683  * @return Shader source
23684  **/
23685 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23686 {
23687         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23688                                                                                                 "\n"
23689                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23690                                                                                                 "    vec4 member;\n"
23691                                                                                                 "} gokuARRAY;\n";
23692         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23693                                                                                                  "\n"
23694                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23695         static const GLchar* vector_var_definition =
23696                 "const uint max_size = SIZE;\n"
23697                 "\n"
23698                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23699         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23700         static const GLchar* global_use = "";
23701         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23702         static const GLchar* fs                 = "#version 430 core\n"
23703                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23704                                                           "\n"
23705                                                           "in  vec4 gs_fs;\n"
23706                                                           "out vec4 fs_out;\n"
23707                                                           "\n"
23708                                                           "void main()\n"
23709                                                           "{\n"
23710                                                           "    fs_out = gs_fs;\n"
23711                                                           "}\n"
23712                                                           "\n";
23713         static const GLchar* gs_tested = "#version 430 core\n"
23714                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23715                                                                          "\n"
23716                                                                          "layout(points)                           in;\n"
23717                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23718                                                                          "\n"
23719                                                                          "VAR_DEFINITION"
23720                                                                          "\n"
23721                                                                          "in  vec4 tes_gs[];\n"
23722                                                                          "out vec4 gs_fs;\n"
23723                                                                          "\n"
23724                                                                          "void main()\n"
23725                                                                          "{\n"
23726                                                                          "    vec4 result = tes_gs[0];\n"
23727                                                                          "\n"
23728                                                                          "VARIABLE_USE"
23729                                                                          "\n"
23730                                                                          "    gs_fs = result;\n"
23731                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23732                                                                          "    EmitVertex();\n"
23733                                                                          "    gs_fs = result;\n"
23734                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23735                                                                          "    EmitVertex();\n"
23736                                                                          "    gs_fs = result;\n"
23737                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23738                                                                          "    EmitVertex();\n"
23739                                                                          "    gs_fs = result;\n"
23740                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23741                                                                          "    EmitVertex();\n"
23742                                                                          "}\n"
23743                                                                          "\n";
23744         static const GLchar* tcs = "#version 430 core\n"
23745                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23746                                                            "\n"
23747                                                            "layout(vertices = 1) out;\n"
23748                                                            "\n"
23749                                                            "in  vec4 vs_tcs[];\n"
23750                                                            "out vec4 tcs_tes[];\n"
23751                                                            "\n"
23752                                                            "void main()\n"
23753                                                            "{\n"
23754                                                            "\n"
23755                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23756                                                            "\n"
23757                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23758                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23759                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23760                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23761                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23762                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23763                                                            "}\n"
23764                                                            "\n";
23765         static const GLchar* tcs_tested = "#version 430 core\n"
23766                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23767                                                                           "\n"
23768                                                                           "layout(vertices = 1) out;\n"
23769                                                                           "\n"
23770                                                                           "VAR_DEFINITION"
23771                                                                           "\n"
23772                                                                           "in  vec4 vs_tcs[];\n"
23773                                                                           "out vec4 tcs_tes[];\n"
23774                                                                           "\n"
23775                                                                           "void main()\n"
23776                                                                           "{\n"
23777                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23778                                                                           "\n"
23779                                                                           "VARIABLE_USE"
23780                                                                           "\n"
23781                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23782                                                                           "\n"
23783                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23784                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23785                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23786                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23787                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23788                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23789                                                                           "}\n"
23790                                                                           "\n";
23791         static const GLchar* tes_tested = "#version 430 core\n"
23792                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23793                                                                           "\n"
23794                                                                           "layout(isolines, point_mode) in;\n"
23795                                                                           "\n"
23796                                                                           "VAR_DEFINITION"
23797                                                                           "\n"
23798                                                                           "in  vec4 tcs_tes[];\n"
23799                                                                           "out vec4 tes_gs;\n"
23800                                                                           "\n"
23801                                                                           "void main()\n"
23802                                                                           "{\n"
23803                                                                           "    vec4 result = tcs_tes[0];\n"
23804                                                                           "\n"
23805                                                                           "VARIABLE_USE"
23806                                                                           "\n"
23807                                                                           "    tes_gs += result;\n"
23808                                                                           "}\n"
23809                                                                           "\n";
23810         static const GLchar* vs = "#version 430 core\n"
23811                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23812                                                           "\n"
23813                                                           "in  vec4 in_vs;\n"
23814                                                           "out vec4 vs_tcs;\n"
23815                                                           "\n"
23816                                                           "void main()\n"
23817                                                           "{\n"
23818                                                           "    vs_tcs = in_vs;\n"
23819                                                           "}\n"
23820                                                           "\n";
23821         static const GLchar* vs_tested = "#version 430 core\n"
23822                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23823                                                                          "\n"
23824                                                                          "VAR_DEFINITION"
23825                                                                          "\n"
23826                                                                          "in  vec4 in_vs;\n"
23827                                                                          "out vec4 vs_tcs;\n"
23828                                                                          "\n"
23829                                                                          "void main()\n"
23830                                                                          "{\n"
23831                                                                          "    vec4 result = in_vs;\n"
23832                                                                          "\n"
23833                                                                          "VARIABLE_USE"
23834                                                                          "\n"
23835                                                                          "    vs_tcs = result;\n"
23836                                                                          "}\n"
23837                                                                          "\n";
23838
23839         std::string source;
23840         testCase&   test_case = m_test_cases[test_case_index];
23841
23842         if (test_case.m_stage == stage)
23843         {
23844                 const GLchar*   array = "";
23845                 GLchar                   buffer[16];
23846                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23847                 const GLchar*   index                    = "";
23848                 GLint                    max_n_xfb_comp  = 0;
23849                 GLint                    max_n_xfb_bytes = 0;
23850                 size_t                   position                = 0;
23851                 size_t                   temp;
23852                 const GLchar*   var_definition = 0;
23853                 const GLchar*   var_use         = 0;
23854
23855                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23856                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23857
23858                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23859
23860                 sprintf(buffer, "%d", max_n_xfb_bytes);
23861
23862                 switch (test_case.m_case)
23863                 {
23864                 case BLOCK:
23865                         var_definition = block_var_definition;
23866                         var_use            = block_use;
23867                         break;
23868                 case GLOBAL:
23869                         var_definition = global_var_definition;
23870                         var_use            = global_use;
23871                         break;
23872                 case VECTOR:
23873                         var_definition = vector_var_definition;
23874                         var_use            = vector_use;
23875                         break;
23876                 default:
23877                         TCU_FAIL("Invalid enum");
23878                 }
23879                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23880                 // change array = "[]" to "[1]"
23881                 switch (stage)
23882                 {
23883                 case Utils::Shader::GEOMETRY:
23884                         source = gs_tested;
23885                         array  = "[1]";
23886                         index  = "[0]";
23887                         break;
23888                 case Utils::Shader::TESS_CTRL:
23889                         source = tcs_tested;
23890                         array  = "[1]";
23891                         index  = "[gl_InvocationID]";
23892                         break;
23893                 case Utils::Shader::TESS_EVAL:
23894                         source = tes_tested;
23895                         array  = "[1]";
23896                         index  = "[0]";
23897                         break;
23898                 case Utils::Shader::VERTEX:
23899                         source = vs_tested;
23900                         break;
23901                 default:
23902                         TCU_FAIL("Invalid enum");
23903                 }
23904
23905                 temp = position;
23906                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23907                 position = temp;
23908                 Utils::replaceToken("SIZE", position, buffer, source);
23909                 if (GLOBAL != test_case.m_case)
23910                 {
23911                         Utils::replaceToken("ARRAY", position, array, source);
23912                 }
23913                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23914
23915                 Utils::replaceAllTokens("INDEX", index, source);
23916         }
23917         else
23918         {
23919                 switch (test_case.m_stage)
23920                 {
23921                 case Utils::Shader::GEOMETRY:
23922                         switch (stage)
23923                         {
23924                         case Utils::Shader::FRAGMENT:
23925                                 source = fs;
23926                                 break;
23927                         case Utils::Shader::VERTEX:
23928                                 source = vs;
23929                                 break;
23930                         default:
23931                                 source = "";
23932                         }
23933                         break;
23934                 case Utils::Shader::TESS_CTRL:
23935                         switch (stage)
23936                         {
23937                         case Utils::Shader::FRAGMENT:
23938                                 source = fs;
23939                                 break;
23940                         case Utils::Shader::VERTEX:
23941                                 source = vs;
23942                                 break;
23943                         default:
23944                                 source = "";
23945                         }
23946                         break;
23947                 case Utils::Shader::TESS_EVAL:
23948                         switch (stage)
23949                         {
23950                         case Utils::Shader::FRAGMENT:
23951                                 source = fs;
23952                                 break;
23953                         case Utils::Shader::TESS_CTRL:
23954                                 source = tcs;
23955                                 break;
23956                         case Utils::Shader::VERTEX:
23957                                 source = vs;
23958                                 break;
23959                         default:
23960                                 source = "";
23961                         }
23962                         break;
23963                 case Utils::Shader::VERTEX:
23964                         switch (stage)
23965                         {
23966                         case Utils::Shader::FRAGMENT:
23967                                 source = fs;
23968                                 break;
23969                         default:
23970                                 source = "";
23971                         }
23972                         break;
23973                 default:
23974                         TCU_FAIL("Invalid enum");
23975                         break;
23976                 }
23977         }
23978
23979         return source;
23980 }
23981
23982 /** Get description of test case
23983  *
23984  * @param test_case_index Index of test case
23985  *
23986  * @return Test case description
23987  **/
23988 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
23989 {
23990         std::stringstream stream;
23991         testCase&                 test_case = m_test_cases[test_case_index];
23992
23993         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23994
23995         switch (test_case.m_case)
23996         {
23997         case BLOCK:
23998                 stream << "BLOCK";
23999                 break;
24000         case GLOBAL:
24001                 stream << "GLOBAL";
24002                 break;
24003         case VECTOR:
24004                 stream << "VECTOR";
24005                 break;
24006         default:
24007                 TCU_FAIL("Invalid enum");
24008         }
24009
24010         return stream.str();
24011 }
24012
24013 /** Get number of test cases
24014  *
24015  * @return Number of test cases
24016  **/
24017 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
24018 {
24019         return static_cast<GLuint>(m_test_cases.size());
24020 }
24021
24022 /** Selects if "compute" stage is relevant for test
24023  *
24024  * @param ignored
24025  *
24026  * @return false
24027  **/
24028 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
24029 {
24030         return false;
24031 }
24032
24033 /** Prepare all test cases
24034  *
24035  **/
24036 void XFBExceedOffsetLimitTest::testInit()
24037 {
24038         for (GLuint c = 0; c < CASE_MAX; ++c)
24039         {
24040                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24041                 {
24042                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
24043                                 (Utils::Shader::FRAGMENT == stage))
24044                         {
24045                                 continue;
24046                         }
24047
24048                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
24049
24050                         m_test_cases.push_back(test_case);
24051                 }
24052         }
24053 }
24054
24055 /** Constructor
24056  *
24057  * @param context Test context
24058  **/
24059 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24060         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24061 {
24062         /* Nothing to be done here */
24063 }
24064
24065 /** Get descriptors of buffers necessary for test
24066  *
24067  * @param test_case_index Index of test case
24068  * @param out_descriptors Descriptors of buffers used by test
24069  **/
24070 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24071 {
24072         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24073         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24074
24075         /* Test needs single uniform and two xfbs */
24076         out_descriptors.resize(3);
24077
24078         /* Get references */
24079         bufferDescriptor& uniform = out_descriptors[0];
24080         bufferDescriptor& xfb_1   = out_descriptors[1];
24081         bufferDescriptor& xfb_3   = out_descriptors[2];
24082
24083         /* Index */
24084         uniform.m_index = 0;
24085         xfb_1.m_index   = 1;
24086         xfb_3.m_index   = 3;
24087
24088         /* Target */
24089         uniform.m_target = Utils::Buffer::Uniform;
24090         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24091         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24092
24093         /* Data */
24094         const GLuint                            gen_start   = Utils::s_rand;
24095         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24096         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24097         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24098         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24099         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24100         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24101
24102         Utils::s_rand                                                           = gen_start;
24103         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24104         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24105         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24106         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24107         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24108         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24109
24110         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24111         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24112
24113         /* Uniform data */
24114         uniform.m_initial_data.resize(6 * type_size);
24115         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24116         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24117         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24118         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24119         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24120         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24121
24122         /* XFB data */
24123         xfb_1.m_initial_data.resize(3 * type_size_pck);
24124         xfb_1.m_expected_data.resize(3 * type_size_pck);
24125         xfb_3.m_initial_data.resize(3 * type_size_pck);
24126         xfb_3.m_expected_data.resize(3 * type_size_pck);
24127
24128         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24129         {
24130                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24131                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24132                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24133                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24134         }
24135
24136         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24137         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24138         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24139         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24140         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24141         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24142 }
24143
24144 /** Source for given test case and stage
24145  *
24146  * @param test_case_index Index of test case
24147  * @param stage           Shader stage
24148  *
24149  * @return Shader source
24150  **/
24151 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24152 {
24153         static const GLchar* fs =
24154                 "#version 430 core\n"
24155                 "#extension GL_ARB_enhanced_layouts : require\n"
24156                 "\n"
24157                 "flat in TYPE chichi;\n"
24158                 "flat in TYPE bulma;\n"
24159                 "in Vegeta {\n"
24160                 "    flat TYPE trunk;\n"
24161                 "    flat TYPE bra;\n"
24162                 "} vegeta;\n"
24163                 "in Goku {\n"
24164                 "    flat TYPE gohan;\n"
24165                 "    flat TYPE goten;\n"
24166                 "} goku;\n"
24167                 "\n"
24168                 "out vec4 fs_out;\n"
24169                 "\n"
24170                 "void main()\n"
24171                 "{\n"
24172                 "    fs_out = vec4(1);\n"
24173                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24174                 "    {\n"
24175                 "        fs_out = vec4(0);\n"
24176                 "    }\n"
24177                 "}\n"
24178                 "\n";
24179
24180         static const GLchar* gs = "#version 430 core\n"
24181                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24182                                                           "\n"
24183                                                           "layout(points)                   in;\n"
24184                                                           "layout(points, max_vertices = 1) out;\n"
24185                                                           "\n"
24186                                                           "INTERFACE"
24187                                                           "\n"
24188                                                           "void main()\n"
24189                                                           "{\n"
24190                                                           "ASSIGNMENTS"
24191                                                           "    EmitVertex();\n"
24192                                                           "}\n"
24193                                                           "\n";
24194
24195         static const GLchar* tcs = "#version 430 core\n"
24196                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24197                                                            "\n"
24198                                                            "layout(vertices = 1) out;\n"
24199                                                            "\n"
24200                                                            "\n"
24201                                                            "void main()\n"
24202                                                            "{\n"
24203                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24204                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24205                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24206                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24207                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24208                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24209                                                            "}\n"
24210                                                            "\n";
24211
24212         static const GLchar* tes = "#version 430 core\n"
24213                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24214                                                            "\n"
24215                                                            "layout(isolines, point_mode) in;\n"
24216                                                            "\n"
24217                                                            "INTERFACE"
24218                                                            "\n"
24219                                                            "void main()\n"
24220                                                            "{\n"
24221                                                            "ASSIGNMENTS"
24222                                                            "}\n"
24223                                                            "\n";
24224
24225         static const GLchar* vs = "#version 430 core\n"
24226                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24227                                                           "\n"
24228                                                           "void main()\n"
24229                                                           "{\n"
24230                                                           "}\n"
24231                                                           "\n";
24232
24233         static const GLchar* vs_tested = "#version 430 core\n"
24234                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24235                                                                          "\n"
24236                                                                          "INTERFACE"
24237                                                                          "\n"
24238                                                                          "void main()\n"
24239                                                                          "{\n"
24240                                                                          "ASSIGNMENTS"
24241                                                                          "}\n"
24242                                                                          "\n";
24243
24244         std::string              source;
24245         const _testCase& test_case = m_test_cases[test_case_index];
24246         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24247
24248         if (test_case.m_stage == stage)
24249         {
24250                 std::string assignments = "    chichi       = uni_chichi;\n"
24251                                                                   "    bulma        = uni_bulma;\n"
24252                                                                   "    vegeta.trunk = uni_trunk;\n"
24253                                                                   "    vegeta.bra   = uni_bra;\n"
24254                                                                   "    goku.gohan   = uni_gohan;\n"
24255                                                                   "    goku.goten   = uni_goten;\n";
24256
24257                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24258                                                                 "\n"
24259                                                                 "const uint type_size = SIZE;\n"
24260                                                                 "\n"
24261                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24262                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24263                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24264                                                                 "    flat TYPE trunk;\n"
24265                                                                 "    flat TYPE bra;\n"
24266                                                                 "} vegeta;\n"
24267                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24268                                                                 "    flat TYPE gohan;\n"
24269                                                                 "    flat TYPE goten;\n"
24270                                                                 "} goku;\n"
24271                                                                 "\n"
24272                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24273                                                                 "layout(binding = 0, std140) uniform block {\n"
24274                                                                 "    TYPE uni_chichi;\n"
24275                                                                 "    TYPE uni_bulma;\n"
24276                                                                 "    TYPE uni_trunk;\n"
24277                                                                 "    TYPE uni_bra;\n"
24278                                                                 "    TYPE uni_gohan;\n"
24279                                                                 "    TYPE uni_goten;\n"
24280                                                                 "};\n";
24281
24282                 /* Prepare interface string */
24283                 {
24284                         GLchar           buffer[16];
24285                         size_t           position  = 0;
24286                         const GLuint type_size = test_case.m_type.GetSize();
24287
24288                         sprintf(buffer, "%d", type_size);
24289
24290                         Utils::replaceToken("SIZE", position, buffer, interface);
24291                         Utils::replaceAllTokens("TYPE", type_name, interface);
24292                 }
24293
24294                 switch (stage)
24295                 {
24296                 case Utils::Shader::GEOMETRY:
24297                         source = gs;
24298                         break;
24299                 case Utils::Shader::TESS_EVAL:
24300                         source = tes;
24301                         break;
24302                 case Utils::Shader::VERTEX:
24303                         source = vs_tested;
24304                         break;
24305                 default:
24306                         TCU_FAIL("Invalid enum");
24307                 }
24308
24309                 /* Replace tokens */
24310                 {
24311                         size_t position = 0;
24312
24313                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24314                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24315                 }
24316         }
24317         else
24318         {
24319                 switch (test_case.m_stage)
24320                 {
24321                 case Utils::Shader::GEOMETRY:
24322                         switch (stage)
24323                         {
24324                         case Utils::Shader::FRAGMENT:
24325                                 source = fs;
24326                                 Utils::replaceAllTokens("TYPE", type_name, source);
24327                                 break;
24328                         case Utils::Shader::VERTEX:
24329                                 source = vs;
24330                                 break;
24331                         default:
24332                                 source = "";
24333                         }
24334                         break;
24335                 case Utils::Shader::TESS_EVAL:
24336                         switch (stage)
24337                         {
24338                         case Utils::Shader::FRAGMENT:
24339                                 source = fs;
24340                                 Utils::replaceAllTokens("TYPE", type_name, source);
24341                                 break;
24342                         case Utils::Shader::TESS_CTRL:
24343                                 source = tcs;
24344                                 break;
24345                         case Utils::Shader::VERTEX:
24346                                 source = vs;
24347                                 break;
24348                         default:
24349                                 source = "";
24350                         }
24351                         break;
24352                 case Utils::Shader::VERTEX:
24353                         switch (stage)
24354                         {
24355                         case Utils::Shader::FRAGMENT:
24356                                 source = fs;
24357                                 Utils::replaceAllTokens("TYPE", type_name, source);
24358                                 break;
24359                         default:
24360                                 source = "";
24361                         }
24362                         break;
24363                 default:
24364                         TCU_FAIL("Invalid enum");
24365                         break;
24366                 }
24367         }
24368
24369         return source;
24370 }
24371
24372 /** Get name of test case
24373  *
24374  * @param test_case_index Index of test case
24375  *
24376  * @return Name of case
24377  **/
24378 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24379 {
24380         std::string              name;
24381         const _testCase& test_case = m_test_cases[test_case_index];
24382
24383         name = "Tested stage: ";
24384         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24385         name.append(". Tested type: ");
24386         name.append(test_case.m_type.GetGLSLTypeName());
24387
24388         return name;
24389 }
24390
24391 /** Get number of cases
24392  *
24393  * @return Number of test cases
24394  **/
24395 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24396 {
24397         return static_cast<GLuint>(m_test_cases.size());
24398 }
24399
24400 /** Prepare set of test cases
24401  *
24402  **/
24403 void XFBGlobalBufferTest::testInit()
24404 {
24405         GLuint n_types = getTypesNumber();
24406
24407         for (GLuint i = 0; i < n_types; ++i)
24408         {
24409                 const Utils::Type& type = getType(i);
24410                 /*
24411                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24412                  cause a link time error.
24413                  */
24414                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24415                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24416                 {
24417                         continue;
24418                 }
24419                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24420                                                                                  { Utils::Shader::GEOMETRY, type },
24421                                                                                  { Utils::Shader::TESS_EVAL, type } };
24422
24423                 m_test_cases.push_back(test_cases[0]);
24424                 m_test_cases.push_back(test_cases[1]);
24425                 m_test_cases.push_back(test_cases[2]);
24426         }
24427 }
24428
24429 /** Constructor
24430  *
24431  * @param context Test context
24432  **/
24433 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24434         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24435 {
24436         /* Nothing to be done here */
24437 }
24438
24439 /** Execute drawArrays for single vertex
24440  *
24441  * @param test_case_index
24442  *
24443  * @return true
24444  **/
24445 bool XFBStrideTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
24446 {
24447         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24448         GLenum                   primitive_type = GL_PATCHES;
24449         const testCase&  test_case              = m_test_cases[test_case_index];
24450
24451         if (Utils::Shader::VERTEX == test_case.m_stage)
24452         {
24453                 primitive_type = GL_POINTS;
24454         }
24455
24456         gl.disable(GL_RASTERIZER_DISCARD);
24457         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24458
24459         gl.beginTransformFeedback(GL_POINTS);
24460         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24461
24462         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24463         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24464
24465         gl.endTransformFeedback();
24466         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24467
24468         return true;
24469 }
24470
24471 /** Get descriptors of buffers necessary for test
24472  *
24473  * @param test_case_index Index of test case
24474  * @param out_descriptors Descriptors of buffers used by test
24475  **/
24476 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24477 {
24478         const testCase& test_case = m_test_cases[test_case_index];
24479         const Utils::Type& type          = test_case.m_type;
24480
24481         /* Test needs single uniform and xfb */
24482         out_descriptors.resize(2);
24483
24484         /* Get references */
24485         bufferDescriptor& uniform = out_descriptors[0];
24486         bufferDescriptor& xfb    = out_descriptors[1];
24487
24488         /* Index */
24489         uniform.m_index = 0;
24490         xfb.m_index             = 0;
24491
24492         /* Target */
24493         uniform.m_target = Utils::Buffer::Uniform;
24494         xfb.m_target     = Utils::Buffer::Transform_feedback;
24495
24496         /* Data */
24497         const GLuint                            rand_start   = Utils::s_rand;
24498         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24499
24500         Utils::s_rand                                            = rand_start;
24501         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24502
24503         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24504         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24505         /*
24506          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24507          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24508          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24509          only one valid data should be initialized in xfb.m_expected_data
24510          */
24511         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24512         /* Uniform data */
24513         uniform.m_initial_data.resize(uni_type_size);
24514         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24515
24516         /* XFB data */
24517         xfb.m_initial_data.resize(xfb_data_size);
24518         xfb.m_expected_data.resize(xfb_data_size);
24519
24520         for (GLuint i = 0; i < xfb_data_size; ++i)
24521         {
24522                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24523                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24524         }
24525
24526         if (test_case.m_stage == Utils::Shader::VERTEX)
24527         {
24528                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24529         }
24530         else
24531         {
24532                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24533                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24534         }
24535 }
24536
24537 /** Get body of main function for given shader stage
24538  *
24539  * @param test_case_index  Index of test case
24540  * @param stage            Shader stage
24541  * @param out_assignments  Set to empty
24542  * @param out_calculations Set to empty
24543  **/
24544 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24545                                                                   std::string& out_calculations)
24546 {
24547         const testCase& test_case = m_test_cases[test_case_index];
24548
24549         out_calculations = "";
24550
24551         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24552         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24553                                                           "    if (TYPE(0) == goku)\n"
24554                                                           "    {\n"
24555                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24556                                                           "    }\n";
24557
24558         const GLchar* assignments = "";
24559
24560         if (test_case.m_stage == stage)
24561         {
24562                 switch (stage)
24563                 {
24564                 case Utils::Shader::GEOMETRY:
24565                         assignments = vs_tes_gs;
24566                         break;
24567                 case Utils::Shader::TESS_EVAL:
24568                         assignments = vs_tes_gs;
24569                         break;
24570                 case Utils::Shader::VERTEX:
24571                         assignments = vs_tes_gs;
24572                         break;
24573                 default:
24574                         TCU_FAIL("Invalid enum");
24575                 }
24576         }
24577         else
24578         {
24579                 switch (stage)
24580                 {
24581                 case Utils::Shader::FRAGMENT:
24582                         assignments = fs;
24583                         break;
24584                 case Utils::Shader::GEOMETRY:
24585                 case Utils::Shader::TESS_CTRL:
24586                 case Utils::Shader::TESS_EVAL:
24587                 case Utils::Shader::VERTEX:
24588                         break;
24589                 default:
24590                         TCU_FAIL("Invalid enum");
24591                 }
24592         }
24593
24594         out_assignments = assignments;
24595
24596         if (Utils::Shader::FRAGMENT == stage)
24597         {
24598                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24599         }
24600 }
24601
24602 /** Get interface of shader
24603  *
24604  * @param test_case_index  Index of test case
24605  * @param stage            Shader stage
24606  * @param out_interface    Set to ""
24607  **/
24608 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24609 {
24610         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24611                                                                          "\n"
24612                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24613                                                                          "    TYPE uni_goku;\n"
24614                                                                          "};\n";
24615         static const GLchar* fs = "FLAT in TYPE goku;\n"
24616                                                           "\n"
24617                                                           "out vec4 fs_out;\n";
24618
24619         const testCase& test_case = m_test_cases[test_case_index];
24620         const GLchar*   interface = "";
24621         const GLchar*   flat      = "";
24622
24623         if (test_case.m_stage == stage)
24624         {
24625                 switch (stage)
24626                 {
24627                 case Utils::Shader::GEOMETRY:
24628                         interface = vs_tes_gs;
24629                         break;
24630                 case Utils::Shader::TESS_EVAL:
24631                         interface = vs_tes_gs;
24632                         break;
24633                 case Utils::Shader::VERTEX:
24634                         interface = vs_tes_gs;
24635                         break;
24636                 default:
24637                         TCU_FAIL("Invalid enum");
24638                 }
24639         }
24640         else
24641         {
24642                 switch (stage)
24643                 {
24644                 case Utils::Shader::FRAGMENT:
24645                         interface = fs;
24646                         break;
24647                 case Utils::Shader::GEOMETRY:
24648                 case Utils::Shader::TESS_CTRL:
24649                 case Utils::Shader::TESS_EVAL:
24650                 case Utils::Shader::VERTEX:
24651                         break;
24652                 default:
24653                         TCU_FAIL("Invalid enum");
24654                 }
24655         }
24656
24657         out_interface = interface;
24658
24659         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24660         {
24661                 flat = "flat";
24662         }
24663
24664         Utils::replaceAllTokens("FLAT", flat, out_interface);
24665         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24666 }
24667
24668 /** Get source code of shader
24669  *
24670  * @param test_case_index Index of test case
24671  * @param stage           Shader stage
24672  *
24673  * @return Source
24674  **/
24675 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24676 {
24677         std::string             source;
24678         const testCase& test_case = m_test_cases[test_case_index];
24679
24680         switch (test_case.m_stage)
24681         {
24682         case Utils::Shader::VERTEX:
24683                 switch (stage)
24684                 {
24685                 case Utils::Shader::FRAGMENT:
24686                 case Utils::Shader::VERTEX:
24687                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24688                         break;
24689                 default:
24690                         break;
24691                 }
24692                 break;
24693
24694         case Utils::Shader::TESS_EVAL:
24695                 switch (stage)
24696                 {
24697                 case Utils::Shader::FRAGMENT:
24698                 case Utils::Shader::TESS_CTRL:
24699                 case Utils::Shader::TESS_EVAL:
24700                 case Utils::Shader::VERTEX:
24701                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24702                         break;
24703                 default:
24704                         break;
24705                 }
24706                 break;
24707
24708         case Utils::Shader::GEOMETRY:
24709                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24710                 break;
24711
24712         default:
24713                 TCU_FAIL("Invalid enum");
24714                 break;
24715         }
24716
24717         /* */
24718         return source;
24719 }
24720
24721 /** Get name of test case
24722  *
24723  * @param test_case_index Index of test case
24724  *
24725  * @return Name of tested stage
24726  **/
24727 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24728 {
24729         std::stringstream stream;
24730         const testCase&   test_case = m_test_cases[test_case_index];
24731
24732         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24733                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24734
24735         return stream.str();
24736 }
24737
24738 /** Returns number of test cases
24739  *
24740  * @return TEST_MAX
24741  **/
24742 glw::GLuint XFBStrideTest::getTestCaseNumber()
24743 {
24744         return static_cast<GLuint>(m_test_cases.size());
24745 }
24746
24747 /** Prepare all test cases
24748  *
24749  **/
24750 void XFBStrideTest::testInit()
24751 {
24752         const GLuint n_types = getTypesNumber();
24753
24754         for (GLuint i = 0; i < n_types; ++i)
24755         {
24756                 const Utils::Type& type = getType(i);
24757
24758                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24759                 {
24760                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24761                                 (Utils::Shader::TESS_CTRL == stage))
24762                         {
24763                                 continue;
24764                         }
24765
24766                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24767
24768                         m_test_cases.push_back(test_case);
24769                 }
24770         }
24771 }
24772
24773 /** Constructor
24774  *
24775  * @param context Test framework context
24776  **/
24777 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24778         : NegativeTestBase(
24779                   context, "xfb_block_member_buffer",
24780                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24781 {
24782 }
24783
24784 /** Source for given test case and stage
24785  *
24786  * @param test_case_index Index of test case
24787  * @param stage           Shader stage
24788  *
24789  * @return Shader source
24790  **/
24791 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24792 {
24793         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24794                                                                                   "                            vec4 gohan;\n"
24795                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24796                                                                                   "} gokuARRAY;\n";
24797         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24798                                                                    "    gokuINDEX.goten = result / 4;\n";
24799         static const GLchar* fs = "#version 430 core\n"
24800                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24801                                                           "\n"
24802                                                           "in  vec4 gs_fs;\n"
24803                                                           "out vec4 fs_out;\n"
24804                                                           "\n"
24805                                                           "void main()\n"
24806                                                           "{\n"
24807                                                           "    fs_out = gs_fs;\n"
24808                                                           "}\n"
24809                                                           "\n";
24810         static const GLchar* gs_tested = "#version 430 core\n"
24811                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24812                                                                          "\n"
24813                                                                          "layout(points)                           in;\n"
24814                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24815                                                                          "\n"
24816                                                                          "VAR_DEFINITION"
24817                                                                          "\n"
24818                                                                          "in  vec4 tes_gs[];\n"
24819                                                                          "out vec4 gs_fs;\n"
24820                                                                          "\n"
24821                                                                          "void main()\n"
24822                                                                          "{\n"
24823                                                                          "    vec4 result = tes_gs[0];\n"
24824                                                                          "\n"
24825                                                                          "VARIABLE_USE"
24826                                                                          "\n"
24827                                                                          "    gs_fs = result;\n"
24828                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24829                                                                          "    EmitVertex();\n"
24830                                                                          "    gs_fs = result;\n"
24831                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24832                                                                          "    EmitVertex();\n"
24833                                                                          "    gs_fs = result;\n"
24834                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24835                                                                          "    EmitVertex();\n"
24836                                                                          "    gs_fs = result;\n"
24837                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24838                                                                          "    EmitVertex();\n"
24839                                                                          "}\n"
24840                                                                          "\n";
24841         static const GLchar* tcs = "#version 430 core\n"
24842                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24843                                                            "\n"
24844                                                            "layout(vertices = 1) out;\n"
24845                                                            "\n"
24846                                                            "in  vec4 vs_tcs[];\n"
24847                                                            "out vec4 tcs_tes[];\n"
24848                                                            "\n"
24849                                                            "void main()\n"
24850                                                            "{\n"
24851                                                            "\n"
24852                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24853                                                            "\n"
24854                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24855                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24856                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24857                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24858                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24859                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24860                                                            "}\n"
24861                                                            "\n";
24862         static const GLchar* tcs_tested = "#version 430 core\n"
24863                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24864                                                                           "\n"
24865                                                                           "layout(vertices = 1) out;\n"
24866                                                                           "\n"
24867                                                                           "VAR_DEFINITION"
24868                                                                           "\n"
24869                                                                           "in  vec4 vs_tcs[];\n"
24870                                                                           "out vec4 tcs_tes[];\n"
24871                                                                           "\n"
24872                                                                           "void main()\n"
24873                                                                           "{\n"
24874                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24875                                                                           "\n"
24876                                                                           "VARIABLE_USE"
24877                                                                           "\n"
24878                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24879                                                                           "\n"
24880                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24881                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24882                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24883                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24884                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24885                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24886                                                                           "}\n"
24887                                                                           "\n";
24888         static const GLchar* tes_tested = "#version 430 core\n"
24889                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24890                                                                           "\n"
24891                                                                           "layout(isolines, point_mode) in;\n"
24892                                                                           "\n"
24893                                                                           "VAR_DEFINITION"
24894                                                                           "\n"
24895                                                                           "in  vec4 tcs_tes[];\n"
24896                                                                           "out vec4 tes_gs;\n"
24897                                                                           "\n"
24898                                                                           "void main()\n"
24899                                                                           "{\n"
24900                                                                           "    vec4 result = tcs_tes[0];\n"
24901                                                                           "\n"
24902                                                                           "VARIABLE_USE"
24903                                                                           "\n"
24904                                                                           "    tes_gs += result;\n"
24905                                                                           "}\n"
24906                                                                           "\n";
24907         static const GLchar* vs = "#version 430 core\n"
24908                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24909                                                           "\n"
24910                                                           "in  vec4 in_vs;\n"
24911                                                           "out vec4 vs_tcs;\n"
24912                                                           "\n"
24913                                                           "void main()\n"
24914                                                           "{\n"
24915                                                           "    vs_tcs = in_vs;\n"
24916                                                           "}\n"
24917                                                           "\n";
24918         static const GLchar* vs_tested = "#version 430 core\n"
24919                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24920                                                                          "\n"
24921                                                                          "VAR_DEFINITION"
24922                                                                          "\n"
24923                                                                          "in  vec4 in_vs;\n"
24924                                                                          "out vec4 vs_tcs;\n"
24925                                                                          "\n"
24926                                                                          "void main()\n"
24927                                                                          "{\n"
24928                                                                          "    vec4 result = in_vs;\n"
24929                                                                          "\n"
24930                                                                          "VARIABLE_USE"
24931                                                                          "\n"
24932                                                                          "    vs_tcs = result;\n"
24933                                                                          "}\n"
24934                                                                          "\n";
24935
24936         std::string source;
24937         testCase&   test_case = m_test_cases[test_case_index];
24938
24939         if (test_case.m_stage == stage)
24940         {
24941                 const GLchar* array     = "";
24942                 const GLchar* index     = "";
24943                 size_t            position = 0;
24944
24945                 switch (stage)
24946                 {
24947                 case Utils::Shader::GEOMETRY:
24948                         source = gs_tested;
24949                         array  = "[]";
24950                         index  = "[0]";
24951                         break;
24952                 case Utils::Shader::TESS_CTRL:
24953                         source = tcs_tested;
24954                         array  = "[]";
24955                         index  = "[gl_InvocationID]";
24956                         break;
24957                 case Utils::Shader::TESS_EVAL:
24958                         source = tes_tested;
24959                         array  = "[]";
24960                         index  = "[0]";
24961                         break;
24962                 case Utils::Shader::VERTEX:
24963                         source = vs_tested;
24964                         break;
24965                 default:
24966                         TCU_FAIL("Invalid enum");
24967                 }
24968
24969                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
24970                 position = 0;
24971                 Utils::replaceToken("ARRAY", position, array, source);
24972                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
24973
24974                 Utils::replaceAllTokens("INDEX", index, source);
24975         }
24976         else
24977         {
24978                 switch (test_case.m_stage)
24979                 {
24980                 case Utils::Shader::GEOMETRY:
24981                         switch (stage)
24982                         {
24983                         case Utils::Shader::FRAGMENT:
24984                                 source = fs;
24985                                 break;
24986                         case Utils::Shader::VERTEX:
24987                                 source = vs;
24988                                 break;
24989                         default:
24990                                 source = "";
24991                         }
24992                         break;
24993                 case Utils::Shader::TESS_CTRL:
24994                         switch (stage)
24995                         {
24996                         case Utils::Shader::FRAGMENT:
24997                                 source = fs;
24998                                 break;
24999                         case Utils::Shader::VERTEX:
25000                                 source = vs;
25001                                 break;
25002                         default:
25003                                 source = "";
25004                         }
25005                         break;
25006                 case Utils::Shader::TESS_EVAL:
25007                         switch (stage)
25008                         {
25009                         case Utils::Shader::FRAGMENT:
25010                                 source = fs;
25011                                 break;
25012                         case Utils::Shader::TESS_CTRL:
25013                                 source = tcs;
25014                                 break;
25015                         case Utils::Shader::VERTEX:
25016                                 source = vs;
25017                                 break;
25018                         default:
25019                                 source = "";
25020                         }
25021                         break;
25022                 case Utils::Shader::VERTEX:
25023                         switch (stage)
25024                         {
25025                         case Utils::Shader::FRAGMENT:
25026                                 source = fs;
25027                                 break;
25028                         default:
25029                                 source = "";
25030                         }
25031                         break;
25032                 default:
25033                         TCU_FAIL("Invalid enum");
25034                         break;
25035                 }
25036         }
25037
25038         return source;
25039 }
25040
25041 /** Get description of test case
25042  *
25043  * @param test_case_index Index of test case
25044  *
25045  * @return Test case description
25046  **/
25047 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
25048 {
25049         std::stringstream stream;
25050         testCase&                 test_case = m_test_cases[test_case_index];
25051
25052         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
25053
25054         return stream.str();
25055 }
25056
25057 /** Get number of test cases
25058  *
25059  * @return Number of test cases
25060  **/
25061 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25062 {
25063         return static_cast<GLuint>(m_test_cases.size());
25064 }
25065
25066 /** Selects if "compute" stage is relevant for test
25067  *
25068  * @param ignored
25069  *
25070  * @return false
25071  **/
25072 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25073 {
25074         return false;
25075 }
25076
25077 /** Prepare all test cases
25078  *
25079  **/
25080 void XFBBlockMemberBufferTest::testInit()
25081 {
25082         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25083         {
25084                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25085                         (Utils::Shader::FRAGMENT == stage))
25086                 {
25087                         continue;
25088                 }
25089
25090                 testCase test_case = { (Utils::Shader::STAGES)stage };
25091
25092                 m_test_cases.push_back(test_case);
25093         }
25094 }
25095
25096 /** Constructor
25097  *
25098  * @param context Test framework context
25099  **/
25100 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25101         : NegativeTestBase(context, "xfb_output_overlapping",
25102                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25103 {
25104 }
25105
25106 /** Source for given test case and stage
25107  *
25108  * @param test_case_index Index of test case
25109  * @param stage           Shader stage
25110  *
25111  * @return Shader source
25112  **/
25113 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25114 {
25115         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25116                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25117         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25118                                                                    "    gotenINDEX = TYPE(1);\n"
25119                                                                    "    if (vec4(0) == result)\n"
25120                                                                    "    {\n"
25121                                                                    "        gohanINDEX = TYPE(1);\n"
25122                                                                    "        gotenINDEX = TYPE(0);\n"
25123                                                                    "    }\n";
25124         static const GLchar* fs = "#version 430 core\n"
25125                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25126                                                           "\n"
25127                                                           "in  vec4 gs_fs;\n"
25128                                                           "out vec4 fs_out;\n"
25129                                                           "\n"
25130                                                           "void main()\n"
25131                                                           "{\n"
25132                                                           "    fs_out = gs_fs;\n"
25133                                                           "}\n"
25134                                                           "\n";
25135         static const GLchar* gs_tested = "#version 430 core\n"
25136                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25137                                                                          "\n"
25138                                                                          "layout(points)                           in;\n"
25139                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25140                                                                          "\n"
25141                                                                          "VAR_DEFINITION"
25142                                                                          "\n"
25143                                                                          "in  vec4 tes_gs[];\n"
25144                                                                          "out vec4 gs_fs;\n"
25145                                                                          "\n"
25146                                                                          "void main()\n"
25147                                                                          "{\n"
25148                                                                          "    vec4 result = tes_gs[0];\n"
25149                                                                          "\n"
25150                                                                          "VARIABLE_USE"
25151                                                                          "\n"
25152                                                                          "    gs_fs = result;\n"
25153                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25154                                                                          "    EmitVertex();\n"
25155                                                                          "    gs_fs = result;\n"
25156                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25157                                                                          "    EmitVertex();\n"
25158                                                                          "    gs_fs = result;\n"
25159                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25160                                                                          "    EmitVertex();\n"
25161                                                                          "    gs_fs = result;\n"
25162                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25163                                                                          "    EmitVertex();\n"
25164                                                                          "}\n"
25165                                                                          "\n";
25166         static const GLchar* tcs = "#version 430 core\n"
25167                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25168                                                            "\n"
25169                                                            "layout(vertices = 1) out;\n"
25170                                                            "\n"
25171                                                            "in  vec4 vs_tcs[];\n"
25172                                                            "out vec4 tcs_tes[];\n"
25173                                                            "\n"
25174                                                            "void main()\n"
25175                                                            "{\n"
25176                                                            "\n"
25177                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25178                                                            "\n"
25179                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25180                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25181                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25182                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25183                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25184                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25185                                                            "}\n"
25186                                                            "\n";
25187         static const GLchar* tcs_tested = "#version 430 core\n"
25188                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25189                                                                           "\n"
25190                                                                           "layout(vertices = 1) out;\n"
25191                                                                           "\n"
25192                                                                           "VAR_DEFINITION"
25193                                                                           "\n"
25194                                                                           "in  vec4 vs_tcs[];\n"
25195                                                                           "out vec4 tcs_tes[];\n"
25196                                                                           "\n"
25197                                                                           "void main()\n"
25198                                                                           "{\n"
25199                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25200                                                                           "\n"
25201                                                                           "VARIABLE_USE"
25202                                                                           "\n"
25203                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25204                                                                           "\n"
25205                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25206                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25207                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25208                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25209                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25210                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25211                                                                           "}\n"
25212                                                                           "\n";
25213         static const GLchar* tes_tested = "#version 430 core\n"
25214                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25215                                                                           "\n"
25216                                                                           "layout(isolines, point_mode) in;\n"
25217                                                                           "\n"
25218                                                                           "VAR_DEFINITION"
25219                                                                           "\n"
25220                                                                           "in  vec4 tcs_tes[];\n"
25221                                                                           "out vec4 tes_gs;\n"
25222                                                                           "\n"
25223                                                                           "void main()\n"
25224                                                                           "{\n"
25225                                                                           "    vec4 result = tcs_tes[0];\n"
25226                                                                           "\n"
25227                                                                           "VARIABLE_USE"
25228                                                                           "\n"
25229                                                                           "    tes_gs += result;\n"
25230                                                                           "}\n"
25231                                                                           "\n";
25232         static const GLchar* vs = "#version 430 core\n"
25233                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25234                                                           "\n"
25235                                                           "in  vec4 in_vs;\n"
25236                                                           "out vec4 vs_tcs;\n"
25237                                                           "\n"
25238                                                           "void main()\n"
25239                                                           "{\n"
25240                                                           "    vs_tcs = in_vs;\n"
25241                                                           "}\n"
25242                                                           "\n";
25243         static const GLchar* vs_tested = "#version 430 core\n"
25244                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25245                                                                          "\n"
25246                                                                          "VAR_DEFINITION"
25247                                                                          "\n"
25248                                                                          "in  vec4 in_vs;\n"
25249                                                                          "out vec4 vs_tcs;\n"
25250                                                                          "\n"
25251                                                                          "void main()\n"
25252                                                                          "{\n"
25253                                                                          "    vec4 result = in_vs;\n"
25254                                                                          "\n"
25255                                                                          "VARIABLE_USE"
25256                                                                          "\n"
25257                                                                          "    vs_tcs = result;\n"
25258                                                                          "}\n"
25259                                                                          "\n";
25260
25261         std::string source;
25262         testCase&   test_case = m_test_cases[test_case_index];
25263
25264         if (test_case.m_stage == stage)
25265         {
25266                 const GLchar* array = "";
25267                 GLchar            buffer_gohan[16];
25268                 GLchar            buffer_goten[16];
25269                 const GLchar* index                      = "";
25270                 size_t            position               = 0;
25271                 size_t            position_start = 0;
25272                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25273
25274                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25275                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25276
25277                 switch (stage)
25278                 {
25279                 case Utils::Shader::GEOMETRY:
25280                         source = gs_tested;
25281                         array  = "[]";
25282                         index  = "[0]";
25283                         break;
25284                 case Utils::Shader::TESS_CTRL:
25285                         source = tcs_tested;
25286                         array  = "[]";
25287                         index  = "[gl_InvocationID]";
25288                         break;
25289                 case Utils::Shader::TESS_EVAL:
25290                         source = tes_tested;
25291                         array  = "[]";
25292                         index  = "[0]";
25293                         break;
25294                 case Utils::Shader::VERTEX:
25295                         source = vs_tested;
25296                         break;
25297                 default:
25298                         TCU_FAIL("Invalid enum");
25299                 }
25300
25301                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25302                 position = 0;
25303                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25304                 Utils::replaceToken("TYPE", position, type_name, source);
25305                 Utils::replaceToken("ARRAY", position, array, source);
25306                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25307                 Utils::replaceToken("TYPE", position, type_name, source);
25308                 Utils::replaceToken("ARRAY", position, array, source);
25309                 position_start = position;
25310                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25311                 position = position_start;
25312                 Utils::replaceToken("INDEX", position, index, source);
25313                 Utils::replaceToken("TYPE", position, type_name, source);
25314                 Utils::replaceToken("INDEX", position, index, source);
25315                 Utils::replaceToken("TYPE", position, type_name, source);
25316                 Utils::replaceToken("INDEX", position, index, source);
25317                 Utils::replaceToken("TYPE", position, type_name, source);
25318                 Utils::replaceToken("INDEX", position, index, source);
25319                 Utils::replaceToken("TYPE", position, type_name, source);
25320         }
25321         else
25322         {
25323                 switch (test_case.m_stage)
25324                 {
25325                 case Utils::Shader::GEOMETRY:
25326                         switch (stage)
25327                         {
25328                         case Utils::Shader::FRAGMENT:
25329                                 source = fs;
25330                                 break;
25331                         case Utils::Shader::VERTEX:
25332                                 source = vs;
25333                                 break;
25334                         default:
25335                                 source = "";
25336                         }
25337                         break;
25338                 case Utils::Shader::TESS_CTRL:
25339                         switch (stage)
25340                         {
25341                         case Utils::Shader::FRAGMENT:
25342                                 source = fs;
25343                                 break;
25344                         case Utils::Shader::VERTEX:
25345                                 source = vs;
25346                                 break;
25347                         default:
25348                                 source = "";
25349                         }
25350                         break;
25351                 case Utils::Shader::TESS_EVAL:
25352                         switch (stage)
25353                         {
25354                         case Utils::Shader::FRAGMENT:
25355                                 source = fs;
25356                                 break;
25357                         case Utils::Shader::TESS_CTRL:
25358                                 source = tcs;
25359                                 break;
25360                         case Utils::Shader::VERTEX:
25361                                 source = vs;
25362                                 break;
25363                         default:
25364                                 source = "";
25365                         }
25366                         break;
25367                 case Utils::Shader::VERTEX:
25368                         switch (stage)
25369                         {
25370                         case Utils::Shader::FRAGMENT:
25371                                 source = fs;
25372                                 break;
25373                         default:
25374                                 source = "";
25375                         }
25376                         break;
25377                 default:
25378                         TCU_FAIL("Invalid enum");
25379                         break;
25380                 }
25381         }
25382
25383         return source;
25384 }
25385
25386 /** Get description of test case
25387  *
25388  * @param test_case_index Index of test case
25389  *
25390  * @return Test case description
25391  **/
25392 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25393 {
25394         std::stringstream stream;
25395         testCase&                 test_case = m_test_cases[test_case_index];
25396
25397         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25398                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25399                    << test_case.m_offset_goten;
25400
25401         return stream.str();
25402 }
25403
25404 /** Get number of test cases
25405  *
25406  * @return Number of test cases
25407  **/
25408 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25409 {
25410         return static_cast<GLuint>(m_test_cases.size());
25411 }
25412
25413 /** Selects if "compute" stage is relevant for test
25414  *
25415  * @param ignored
25416  *
25417  * @return false
25418  **/
25419 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25420 {
25421         return false;
25422 }
25423
25424 /** Prepare all test cases
25425  *
25426  **/
25427 void XFBOutputOverlappingTest::testInit()
25428 {
25429         const GLuint n_types = getTypesNumber();
25430
25431         for (GLuint i = 0; i < n_types; ++i)
25432         {
25433                 const Utils::Type& type                   = getType(i);
25434                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25435
25436                 /* Skip scalars, not applicable as:
25437                  *
25438                  *     The offset must be a multiple of the size of the first component of the first
25439                  *     qualified variable or block member, or a compile-time error results.
25440                  */
25441                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25442                 {
25443                         continue;
25444                 }
25445
25446                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25447                 {
25448                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25449                                 (Utils::Shader::FRAGMENT == stage))
25450                         {
25451                                 continue;
25452                         }
25453
25454                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25455                                                                    (Utils::Shader::STAGES)stage, type };
25456
25457                         m_test_cases.push_back(test_case);
25458                 }
25459         }
25460 }
25461
25462 /** Constructor
25463  *
25464  * @param context Test framework context
25465  **/
25466 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25467         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25468                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25469 {
25470 }
25471
25472 /** Source for given test case and stage
25473  *
25474  * @param test_case_index Index of test case
25475  * @param stage           Shader stage
25476  *
25477  * @return Shader source
25478  **/
25479 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25480 {
25481         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25482         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25483                                                                    "    if (vec4(0) == result)\n"
25484                                                                    "    {\n"
25485                                                                    "        gohanINDEX = TYPE(1);\n"
25486                                                                    "    }\n";
25487         static const GLchar* fs = "#version 430 core\n"
25488                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25489                                                           "\n"
25490                                                           "in  vec4 gs_fs;\n"
25491                                                           "out vec4 fs_out;\n"
25492                                                           "\n"
25493                                                           "void main()\n"
25494                                                           "{\n"
25495                                                           "    fs_out = gs_fs;\n"
25496                                                           "}\n"
25497                                                           "\n";
25498         static const GLchar* gs_tested = "#version 430 core\n"
25499                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25500                                                                          "\n"
25501                                                                          "layout(points)                           in;\n"
25502                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25503                                                                          "\n"
25504                                                                          "VAR_DEFINITION"
25505                                                                          "\n"
25506                                                                          "in  vec4 tes_gs[];\n"
25507                                                                          "out vec4 gs_fs;\n"
25508                                                                          "\n"
25509                                                                          "void main()\n"
25510                                                                          "{\n"
25511                                                                          "    vec4 result = tes_gs[0];\n"
25512                                                                          "\n"
25513                                                                          "VARIABLE_USE"
25514                                                                          "\n"
25515                                                                          "    gs_fs = result;\n"
25516                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25517                                                                          "    EmitVertex();\n"
25518                                                                          "    gs_fs = result;\n"
25519                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25520                                                                          "    EmitVertex();\n"
25521                                                                          "    gs_fs = result;\n"
25522                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25523                                                                          "    EmitVertex();\n"
25524                                                                          "    gs_fs = result;\n"
25525                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25526                                                                          "    EmitVertex();\n"
25527                                                                          "}\n"
25528                                                                          "\n";
25529         static const GLchar* tcs = "#version 430 core\n"
25530                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25531                                                            "\n"
25532                                                            "layout(vertices = 1) out;\n"
25533                                                            "\n"
25534                                                            "in  vec4 vs_tcs[];\n"
25535                                                            "out vec4 tcs_tes[];\n"
25536                                                            "\n"
25537                                                            "void main()\n"
25538                                                            "{\n"
25539                                                            "\n"
25540                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25541                                                            "\n"
25542                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25543                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25544                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25545                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25546                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25547                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25548                                                            "}\n"
25549                                                            "\n";
25550         static const GLchar* tcs_tested = "#version 430 core\n"
25551                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25552                                                                           "\n"
25553                                                                           "layout(vertices = 1) out;\n"
25554                                                                           "\n"
25555                                                                           "VAR_DEFINITION"
25556                                                                           "\n"
25557                                                                           "in  vec4 vs_tcs[];\n"
25558                                                                           "out vec4 tcs_tes[];\n"
25559                                                                           "\n"
25560                                                                           "void main()\n"
25561                                                                           "{\n"
25562                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25563                                                                           "\n"
25564                                                                           "VARIABLE_USE"
25565                                                                           "\n"
25566                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25567                                                                           "\n"
25568                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25569                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25570                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25571                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25572                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25573                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25574                                                                           "}\n"
25575                                                                           "\n";
25576         static const GLchar* tes_tested = "#version 430 core\n"
25577                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25578                                                                           "\n"
25579                                                                           "layout(isolines, point_mode) in;\n"
25580                                                                           "\n"
25581                                                                           "VAR_DEFINITION"
25582                                                                           "\n"
25583                                                                           "in  vec4 tcs_tes[];\n"
25584                                                                           "out vec4 tes_gs;\n"
25585                                                                           "\n"
25586                                                                           "void main()\n"
25587                                                                           "{\n"
25588                                                                           "    vec4 result = tcs_tes[0];\n"
25589                                                                           "\n"
25590                                                                           "VARIABLE_USE"
25591                                                                           "\n"
25592                                                                           "    tes_gs += result;\n"
25593                                                                           "}\n"
25594                                                                           "\n";
25595         static const GLchar* vs = "#version 430 core\n"
25596                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25597                                                           "\n"
25598                                                           "in  vec4 in_vs;\n"
25599                                                           "out vec4 vs_tcs;\n"
25600                                                           "\n"
25601                                                           "void main()\n"
25602                                                           "{\n"
25603                                                           "    vs_tcs = in_vs;\n"
25604                                                           "}\n"
25605                                                           "\n";
25606         static const GLchar* vs_tested = "#version 430 core\n"
25607                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25608                                                                          "\n"
25609                                                                          "VAR_DEFINITION"
25610                                                                          "\n"
25611                                                                          "in  vec4 in_vs;\n"
25612                                                                          "out vec4 vs_tcs;\n"
25613                                                                          "\n"
25614                                                                          "void main()\n"
25615                                                                          "{\n"
25616                                                                          "    vec4 result = in_vs;\n"
25617                                                                          "\n"
25618                                                                          "VARIABLE_USE"
25619                                                                          "\n"
25620                                                                          "    vs_tcs = result;\n"
25621                                                                          "}\n"
25622                                                                          "\n";
25623
25624         std::string source;
25625         testCase&   test_case = m_test_cases[test_case_index];
25626
25627         if (test_case.m_stage == stage)
25628         {
25629                 const GLchar* array = "";
25630                 GLchar            buffer[16];
25631                 const GLchar* index                      = "";
25632                 size_t            position               = 0;
25633                 size_t            position_start = 0;
25634                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25635
25636                 sprintf(buffer, "%d", test_case.m_offset);
25637
25638                 switch (stage)
25639                 {
25640                 case Utils::Shader::GEOMETRY:
25641                         source = gs_tested;
25642                         array  = "[]";
25643                         index  = "[0]";
25644                         break;
25645                 case Utils::Shader::TESS_CTRL:
25646                         source = tcs_tested;
25647                         array  = "[]";
25648                         index  = "[gl_InvocationID]";
25649                         break;
25650                 case Utils::Shader::TESS_EVAL:
25651                         source = tes_tested;
25652                         array  = "[]";
25653                         index  = "[0]";
25654                         break;
25655                 case Utils::Shader::VERTEX:
25656                         source = vs_tested;
25657                         break;
25658                 default:
25659                         TCU_FAIL("Invalid enum");
25660                 }
25661
25662                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25663                 position = 0;
25664                 Utils::replaceToken("OFFSET", position, buffer, source);
25665                 Utils::replaceToken("TYPE", position, type_name, source);
25666                 Utils::replaceToken("ARRAY", position, array, source);
25667                 position_start = position;
25668                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25669                 position = position_start;
25670                 Utils::replaceToken("INDEX", position, index, source);
25671                 Utils::replaceToken("TYPE", position, type_name, source);
25672                 Utils::replaceToken("INDEX", position, index, source);
25673                 Utils::replaceToken("TYPE", position, type_name, source);
25674         }
25675         else
25676         {
25677                 switch (test_case.m_stage)
25678                 {
25679                 case Utils::Shader::GEOMETRY:
25680                         switch (stage)
25681                         {
25682                         case Utils::Shader::FRAGMENT:
25683                                 source = fs;
25684                                 break;
25685                         case Utils::Shader::VERTEX:
25686                                 source = vs;
25687                                 break;
25688                         default:
25689                                 source = "";
25690                         }
25691                         break;
25692                 case Utils::Shader::TESS_CTRL:
25693                         switch (stage)
25694                         {
25695                         case Utils::Shader::FRAGMENT:
25696                                 source = fs;
25697                                 break;
25698                         case Utils::Shader::VERTEX:
25699                                 source = vs;
25700                                 break;
25701                         default:
25702                                 source = "";
25703                         }
25704                         break;
25705                 case Utils::Shader::TESS_EVAL:
25706                         switch (stage)
25707                         {
25708                         case Utils::Shader::FRAGMENT:
25709                                 source = fs;
25710                                 break;
25711                         case Utils::Shader::TESS_CTRL:
25712                                 source = tcs;
25713                                 break;
25714                         case Utils::Shader::VERTEX:
25715                                 source = vs;
25716                                 break;
25717                         default:
25718                                 source = "";
25719                         }
25720                         break;
25721                 case Utils::Shader::VERTEX:
25722                         switch (stage)
25723                         {
25724                         case Utils::Shader::FRAGMENT:
25725                                 source = fs;
25726                                 break;
25727                         default:
25728                                 source = "";
25729                         }
25730                         break;
25731                 default:
25732                         TCU_FAIL("Invalid enum");
25733                         break;
25734                 }
25735         }
25736
25737         return source;
25738 }
25739
25740 /** Get description of test case
25741  *
25742  * @param test_case_index Index of test case
25743  *
25744  * @return Test case description
25745  **/
25746 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25747 {
25748         std::stringstream stream;
25749         testCase&                 test_case = m_test_cases[test_case_index];
25750
25751         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25752                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25753
25754         return stream.str();
25755 }
25756
25757 /** Get number of test cases
25758  *
25759  * @return Number of test cases
25760  **/
25761 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25762 {
25763         return static_cast<GLuint>(m_test_cases.size());
25764 }
25765
25766 /** Selects if "compute" stage is relevant for test
25767  *
25768  * @param ignored
25769  *
25770  * @return false
25771  **/
25772 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25773 {
25774         return false;
25775 }
25776
25777 /** Prepare all test cases
25778  *
25779  **/
25780 void XFBInvalidOffsetAlignmentTest::testInit()
25781 {
25782         const GLuint n_types = getTypesNumber();
25783
25784         for (GLuint i = 0; i < n_types; ++i)
25785         {
25786                 const Utils::Type& type                   = getType(i);
25787                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25788
25789                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25790                 {
25791                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25792                                 (Utils::Shader::FRAGMENT == stage))
25793                         {
25794                                 continue;
25795                         }
25796
25797                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25798                         {
25799                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25800
25801                                 m_test_cases.push_back(test_case);
25802                         }
25803                 }
25804         }
25805 }
25806
25807 /** Constructor
25808  *
25809  * @param context Test context
25810  **/
25811 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25812         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25813                                          "Test verifies that inactive variables are captured")
25814 {
25815         /* Nothing to be done here */
25816 }
25817
25818 /** Execute drawArrays for single vertex
25819  *
25820  * @param test_case_index
25821  *
25822  * @return true
25823  **/
25824 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
25825 {
25826         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25827         GLenum                   primitive_type = GL_PATCHES;
25828
25829         if (TEST_VS == test_case_index)
25830         {
25831                 primitive_type = GL_POINTS;
25832         }
25833
25834         gl.disable(GL_RASTERIZER_DISCARD);
25835         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25836
25837         gl.beginTransformFeedback(GL_POINTS);
25838         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25839
25840         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25841         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25842
25843         gl.endTransformFeedback();
25844         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25845
25846         return true;
25847 }
25848
25849 /** Get descriptors of buffers necessary for test
25850  *
25851  * @param ignored
25852  * @param out_descriptors Descriptors of buffers used by test
25853  **/
25854 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25855                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25856 {
25857         const Utils::Type& type = Utils::Type::vec4;
25858
25859         /* Test needs single uniform and xfb */
25860         out_descriptors.resize(2);
25861
25862         /* Get references */
25863         bufferDescriptor& uniform = out_descriptors[0];
25864         bufferDescriptor& xfb    = out_descriptors[1];
25865
25866         /* Index */
25867         uniform.m_index = 0;
25868         xfb.m_index             = 0;
25869
25870         /* Target */
25871         uniform.m_target = Utils::Buffer::Uniform;
25872         xfb.m_target     = Utils::Buffer::Transform_feedback;
25873
25874         /* Data */
25875         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25876         const std::vector<GLubyte>& goten_data = type.GenerateData();
25877
25878         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25879
25880         /* Uniform data */
25881         uniform.m_initial_data.resize(2 * type_size);
25882         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25883         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25884
25885         /* XFB data */
25886         xfb.m_initial_data.resize(3 * type_size);
25887         xfb.m_expected_data.resize(3 * type_size);
25888
25889         for (GLuint i = 0; i < 3 * type_size; ++i)
25890         {
25891                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25892                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25893         }
25894
25895         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25896         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25897 }
25898
25899 /** Get body of main function for given shader stage
25900  *
25901  * @param test_case_index  Index of test case
25902  * @param stage            Shader stage
25903  * @param out_assignments  Set to empty
25904  * @param out_calculations Set to empty
25905  **/
25906 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25907                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25908 {
25909         out_calculations = "";
25910
25911         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25912                                                                          "    gohan = uni_gohan;\n";
25913         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25914
25915         const GLchar* assignments = "";
25916
25917         switch (stage)
25918         {
25919         case Utils::Shader::FRAGMENT:
25920                 assignments = fs;
25921                 break;
25922
25923         case Utils::Shader::GEOMETRY:
25924                 if (TEST_GS == test_case_index)
25925                 {
25926                         assignments = vs_tes_gs;
25927                 }
25928                 break;
25929
25930         case Utils::Shader::TESS_CTRL:
25931                 break;
25932
25933         case Utils::Shader::TESS_EVAL:
25934                 if (TEST_TES == test_case_index)
25935                 {
25936                         assignments = vs_tes_gs;
25937                 }
25938                 break;
25939
25940         case Utils::Shader::VERTEX:
25941                 if (TEST_VS == test_case_index)
25942                 {
25943                         assignments = vs_tes_gs;
25944                 }
25945                 break;
25946
25947         default:
25948                 TCU_FAIL("Invalid enum");
25949         }
25950
25951         out_assignments = assignments;
25952 }
25953
25954 /** Get interface of shader
25955  *
25956  * @param test_case_index  Index of test case
25957  * @param stage            Shader stage
25958  * @param out_interface    Set to ""
25959  **/
25960 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
25961                                                                                                                           std::string& out_interface)
25962 {
25963         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
25964                                                                          "\n"
25965                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
25966                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
25967                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
25968                                                                          "\n"
25969                                                                          "layout(binding = 0) uniform block {\n"
25970                                                                          "    vec4 uni_gohan;\n"
25971                                                                          "    vec4 uni_goten;\n"
25972                                                                          "};\n";
25973         static const GLchar* fs = "in vec4 goku;\n"
25974                                                           "in vec4 gohan;\n"
25975                                                           "in vec4 goten;\n"
25976                                                           "out vec4 fs_out;\n";
25977
25978         const GLchar* interface = "";
25979
25980         switch (stage)
25981         {
25982         case Utils::Shader::FRAGMENT:
25983                 interface = fs;
25984                 break;
25985
25986         case Utils::Shader::GEOMETRY:
25987                 if (TEST_GS == test_case_index)
25988                 {
25989                         interface = vs_tes_gs;
25990                 }
25991                 break;
25992
25993         case Utils::Shader::TESS_CTRL:
25994                 break;
25995
25996         case Utils::Shader::TESS_EVAL:
25997                 if (TEST_TES == test_case_index)
25998                 {
25999                         interface = vs_tes_gs;
26000                 }
26001                 break;
26002
26003         case Utils::Shader::VERTEX:
26004                 if (TEST_VS == test_case_index)
26005                 {
26006                         interface = vs_tes_gs;
26007                 }
26008                 break;
26009
26010         default:
26011                 TCU_FAIL("Invalid enum");
26012         }
26013
26014         out_interface = interface;
26015 }
26016
26017 /** Get source code of shader
26018  *
26019  * @param test_case_index Index of test case
26020  * @param stage           Shader stage
26021  *
26022  * @return Source
26023  **/
26024 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26025 {
26026         std::string source;
26027
26028         switch (test_case_index)
26029         {
26030         case TEST_VS:
26031                 switch (stage)
26032                 {
26033                 case Utils::Shader::FRAGMENT:
26034                 case Utils::Shader::VERTEX:
26035                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26036                         break;
26037                 default:
26038                         break;
26039                 }
26040                 break;
26041
26042         case TEST_TES:
26043                 switch (stage)
26044                 {
26045                 case Utils::Shader::FRAGMENT:
26046                 case Utils::Shader::TESS_CTRL:
26047                 case Utils::Shader::TESS_EVAL:
26048                 case Utils::Shader::VERTEX:
26049                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26050                         break;
26051                 default:
26052                         break;
26053                 }
26054                 break;
26055
26056         case TEST_GS:
26057                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26058                 break;
26059
26060         default:
26061                 TCU_FAIL("Invalid enum");
26062                 break;
26063         }
26064
26065         /* */
26066         return source;
26067 }
26068
26069 /** Get name of test case
26070  *
26071  * @param test_case_index Index of test case
26072  *
26073  * @return Name of tested stage
26074  **/
26075 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26076 {
26077         const GLchar* name = 0;
26078
26079         switch (test_case_index)
26080         {
26081         case TEST_VS:
26082                 name = "vertex";
26083                 break;
26084         case TEST_TES:
26085                 name = "tessellation evaluation";
26086                 break;
26087         case TEST_GS:
26088                 name = "geometry";
26089                 break;
26090         default:
26091                 TCU_FAIL("Invalid enum");
26092         }
26093
26094         return name;
26095 }
26096
26097 /** Returns number of test cases
26098  *
26099  * @return TEST_MAX
26100  **/
26101 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26102 {
26103         return TEST_MAX;
26104 }
26105
26106 /** Inspects program to check if all resources are as expected
26107  *
26108  * @param ignored
26109  * @param program         Program instance
26110  * @param out_stream      Error message
26111  *
26112  * @return true if everything is ok, false otherwise
26113  **/
26114 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26115                                                                                                                   std::stringstream& out_stream)
26116 {
26117         GLint                      stride       = 0;
26118         const Utils::Type& type          = Utils::Type::vec4;
26119         const GLuint       type_size = type.GetSize();
26120
26121         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26122                                                 1 /* buf_size */, &stride);
26123
26124         if ((GLint)(3 * type_size) != stride)
26125         {
26126                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26127
26128                 return false;
26129         }
26130
26131         return true;
26132 }
26133
26134 /** Verify contents of buffers
26135  *
26136  * @param buffers Collection of buffers to be verified
26137  *
26138  * @return true if everything is as expected, false otherwise
26139  **/
26140 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26141 {
26142         bool result = true;
26143
26144         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26145         Utils::Buffer*                  buffer   = pair.m_buffer;
26146         bufferDescriptor*               descriptor = pair.m_descriptor;
26147
26148         /* Get pointer to contents of buffer */
26149         buffer->Bind();
26150         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26151
26152         /* Get pointer to expected data */
26153         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26154
26155         /* Compare */
26156         static const GLuint vec4_size = 16;
26157
26158         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26159         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26160
26161         if ((0 != res_gohan) || (0 != res_goten))
26162         {
26163                 m_context.getTestContext().getLog()
26164                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26165                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26166
26167                 result = false;
26168         }
26169
26170         /* Release buffer mapping */
26171         buffer->UnMap();
26172
26173         return result;
26174 }
26175
26176 /** Constructor
26177  *
26178  * @param context Test context
26179  **/
26180 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26181         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26182                                          "Test verifies that inactive components are not modified")
26183 {
26184         /* Nothing to be done here */
26185 }
26186
26187 /** Execute drawArrays for single vertex
26188  *
26189  * @param test_case_index
26190  *
26191  * @return true
26192  **/
26193 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26194 {
26195         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26196         GLenum                   primitive_type = GL_PATCHES;
26197
26198         if (TEST_VS == test_case_index)
26199         {
26200                 primitive_type = GL_POINTS;
26201         }
26202
26203         gl.disable(GL_RASTERIZER_DISCARD);
26204         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26205
26206         gl.beginTransformFeedback(GL_POINTS);
26207         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26208
26209         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26210         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26211
26212         gl.endTransformFeedback();
26213         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26214
26215         return true;
26216 }
26217
26218 /** Get descriptors of buffers necessary for test
26219  *
26220  * @param ignored
26221  * @param out_descriptors Descriptors of buffers used by test
26222  **/
26223 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26224                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26225 {
26226         const Utils::Type& type = Utils::Type::vec4;
26227
26228         /* Test needs single uniform and xfb */
26229         out_descriptors.resize(2);
26230
26231         /* Get references */
26232         bufferDescriptor& uniform = out_descriptors[0];
26233         bufferDescriptor& xfb    = out_descriptors[1];
26234
26235         /* Index */
26236         uniform.m_index = 0;
26237         xfb.m_index             = 0;
26238
26239         /* Target */
26240         uniform.m_target = Utils::Buffer::Uniform;
26241         xfb.m_target     = Utils::Buffer::Transform_feedback;
26242
26243         /* Data */
26244         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26245         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26246         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26247         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26248         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26249         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26250         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26251         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26252
26253         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26254         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26255
26256         /* Uniform data */
26257         uniform.m_initial_data.resize(8 * type_size);
26258         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26259         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26260         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26261         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26262         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26263         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26264         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26265         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26266
26267         /* XFB data */
26268         xfb.m_initial_data.resize(8 * type_size);
26269         xfb.m_expected_data.resize(8 * type_size);
26270
26271         for (GLuint i = 0; i < 8 * type_size; ++i)
26272         {
26273                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26274                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26275         }
26276
26277         /* goku - x, z - 32 */
26278         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26279         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26280
26281         /* gohan - y, w - 0 */
26282         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26283         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26284
26285         /* goten - x, y - 16 */
26286         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26287         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26288
26289         /* chichi - z, w - 48 */
26290         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26291         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26292
26293         /* vegeta - x - 112 */
26294         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26295
26296         /* trunks - y - 96 */
26297         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26298
26299         /* bra - z - 80 */
26300         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26301
26302         /* bulma - w - 64 */
26303         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26304 }
26305
26306 /** Get body of main function for given shader stage
26307  *
26308  * @param test_case_index  Index of test case
26309  * @param stage            Shader stage
26310  * @param out_assignments  Set to empty
26311  * @param out_calculations Set to empty
26312  **/
26313 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26314                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26315 {
26316         out_calculations = "";
26317
26318         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26319                                                                          "    goku.z    = uni_goku.z   ;\n"
26320                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26321                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26322                                                                          "    goten.x   = uni_goten.x  ;\n"
26323                                                                          "    goten.y   = uni_goten.y  ;\n"
26324                                                                          "    chichi.z  = uni_chichi.z ;\n"
26325                                                                          "    chichi.w  = uni_chichi.w ;\n"
26326                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26327                                                                          "    trunks.y  = uni_trunks.y ;\n"
26328                                                                          "    bra.z     = uni_bra.z    ;\n"
26329                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26330         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26331
26332         const GLchar* assignments = "";
26333
26334         switch (stage)
26335         {
26336         case Utils::Shader::FRAGMENT:
26337                 assignments = fs;
26338                 break;
26339
26340         case Utils::Shader::GEOMETRY:
26341                 if (TEST_GS == test_case_index)
26342                 {
26343                         assignments = vs_tes_gs;
26344                 }
26345                 break;
26346
26347         case Utils::Shader::TESS_CTRL:
26348                 break;
26349
26350         case Utils::Shader::TESS_EVAL:
26351                 if (TEST_TES == test_case_index)
26352                 {
26353                         assignments = vs_tes_gs;
26354                 }
26355                 break;
26356
26357         case Utils::Shader::VERTEX:
26358                 if (TEST_VS == test_case_index)
26359                 {
26360                         assignments = vs_tes_gs;
26361                 }
26362                 break;
26363
26364         default:
26365                 TCU_FAIL("Invalid enum");
26366         }
26367
26368         out_assignments = assignments;
26369 }
26370
26371 /** Get interface of shader
26372  *
26373  * @param test_case_index  Index of test case
26374  * @param stage            Shader stage
26375  * @param out_interface    Set to ""
26376  **/
26377 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26378                                                                                                                            std::string& out_interface)
26379 {
26380         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26381                                                                          "\n"
26382                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26383                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26384                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26385                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26386                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26387                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26388                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26389                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26390                                                                          "\n"
26391                                                                          "layout(binding = 0) uniform block {\n"
26392                                                                          "    vec4 uni_goku;\n"
26393                                                                          "    vec4 uni_gohan;\n"
26394                                                                          "    vec4 uni_goten;\n"
26395                                                                          "    vec4 uni_chichi;\n"
26396                                                                          "    vec4 uni_vegeta;\n"
26397                                                                          "    vec4 uni_trunks;\n"
26398                                                                          "    vec4 uni_bra;\n"
26399                                                                          "    vec4 uni_bulma;\n"
26400                                                                          "};\n";
26401         static const GLchar* fs = "in vec4 vegeta;\n"
26402                                                           "in vec4 trunks;\n"
26403                                                           "in vec4 bra;\n"
26404                                                           "in vec4 bulma;\n"
26405                                                           "in vec4 goku;\n"
26406                                                           "in vec4 gohan;\n"
26407                                                           "in vec4 goten;\n"
26408                                                           "in vec4 chichi;\n"
26409                                                           "\n"
26410                                                           "out vec4 fs_out;\n";
26411
26412         const GLchar* interface = "";
26413
26414         switch (stage)
26415         {
26416         case Utils::Shader::FRAGMENT:
26417                 interface = fs;
26418                 break;
26419
26420         case Utils::Shader::GEOMETRY:
26421                 if (TEST_GS == test_case_index)
26422                 {
26423                         interface = vs_tes_gs;
26424                 }
26425                 break;
26426
26427         case Utils::Shader::TESS_CTRL:
26428                 break;
26429
26430         case Utils::Shader::TESS_EVAL:
26431                 if (TEST_TES == test_case_index)
26432                 {
26433                         interface = vs_tes_gs;
26434                 }
26435                 break;
26436
26437         case Utils::Shader::VERTEX:
26438                 if (TEST_VS == test_case_index)
26439                 {
26440                         interface = vs_tes_gs;
26441                 }
26442                 break;
26443
26444         default:
26445                 TCU_FAIL("Invalid enum");
26446         }
26447
26448         out_interface = interface;
26449 }
26450
26451 /** Get source code of shader
26452  *
26453  * @param test_case_index Index of test case
26454  * @param stage           Shader stage
26455  *
26456  * @return Source
26457  **/
26458 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26459 {
26460         std::string source;
26461
26462         switch (test_case_index)
26463         {
26464         case TEST_VS:
26465                 switch (stage)
26466                 {
26467                 case Utils::Shader::FRAGMENT:
26468                 case Utils::Shader::VERTEX:
26469                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26470                         break;
26471                 default:
26472                         break;
26473                 }
26474                 break;
26475
26476         case TEST_TES:
26477                 switch (stage)
26478                 {
26479                 case Utils::Shader::FRAGMENT:
26480                 case Utils::Shader::TESS_CTRL:
26481                 case Utils::Shader::TESS_EVAL:
26482                 case Utils::Shader::VERTEX:
26483                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26484                         break;
26485                 default:
26486                         break;
26487                 }
26488                 break;
26489
26490         case TEST_GS:
26491                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26492                 break;
26493
26494         default:
26495                 TCU_FAIL("Invalid enum");
26496                 break;
26497         }
26498
26499         /* */
26500         return source;
26501 }
26502
26503 /** Get name of test case
26504  *
26505  * @param test_case_index Index of test case
26506  *
26507  * @return Name of tested stage
26508  **/
26509 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26510 {
26511         const GLchar* name = 0;
26512
26513         switch (test_case_index)
26514         {
26515         case TEST_VS:
26516                 name = "vertex";
26517                 break;
26518         case TEST_TES:
26519                 name = "tessellation evaluation";
26520                 break;
26521         case TEST_GS:
26522                 name = "geometry";
26523                 break;
26524         default:
26525                 TCU_FAIL("Invalid enum");
26526         }
26527
26528         return name;
26529 }
26530
26531 /** Returns number of test cases
26532  *
26533  * @return TEST_MAX
26534  **/
26535 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26536 {
26537         return TEST_MAX;
26538 }
26539
26540 /** Verify contents of buffers
26541  *
26542  * @param buffers Collection of buffers to be verified
26543  *
26544  * @return true if everything is as expected, false otherwise
26545  **/
26546 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26547 {
26548         bool result = true;
26549
26550         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26551         Utils::Buffer*                  buffer   = pair.m_buffer;
26552         bufferDescriptor*               descriptor = pair.m_descriptor;
26553
26554         /* Get pointer to contents of buffer */
26555         buffer->Bind();
26556         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26557
26558         /* Get pointer to expected data */
26559         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26560
26561         /* Compare */
26562         static const GLuint comp_size = 4;
26563         static const GLuint vec4_size = 16;
26564
26565         int res_goku_x =
26566                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26567         int res_goku_z =
26568                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26569
26570         int res_gohan_y =
26571                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26572         int res_gohan_w =
26573                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26574
26575         int res_goten_x =
26576                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26577         int res_goten_y =
26578                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26579
26580         int res_chichi_z =
26581                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26582         int res_chichi_w =
26583                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26584
26585         int res_vegeta_x =
26586                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26587
26588         int res_trunks_y =
26589                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26590
26591         int res_bra_z =
26592                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26593
26594         int res_bulma_w =
26595                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26596
26597         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26598                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26599                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26600         {
26601                 m_context.getTestContext().getLog()
26602                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26603                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26604
26605                 result = false;
26606         }
26607
26608         /* Release buffer mapping */
26609         buffer->UnMap();
26610
26611         return result;
26612 }
26613
26614 /** Constructor
26615  *
26616  * @param context Test context
26617  **/
26618 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26619         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26620                                          "Test verifies that inactive block members are captured")
26621 {
26622         /* Nothing to be done here */
26623 }
26624
26625 /** Execute drawArrays for single vertex
26626  *
26627  * @param test_case_index
26628  *
26629  * @return true
26630  **/
26631 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26632 {
26633         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26634         GLenum                   primitive_type = GL_PATCHES;
26635
26636         if (TEST_VS == test_case_index)
26637         {
26638                 primitive_type = GL_POINTS;
26639         }
26640
26641         gl.disable(GL_RASTERIZER_DISCARD);
26642         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26643
26644         gl.beginTransformFeedback(GL_POINTS);
26645         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26646
26647         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26648         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26649
26650         gl.endTransformFeedback();
26651         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26652
26653         return true;
26654 }
26655
26656 /** Get descriptors of buffers necessary for test
26657  *
26658  * @param ignored
26659  * @param out_descriptors Descriptors of buffers used by test
26660  **/
26661 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26662                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26663 {
26664         const Utils::Type& type = Utils::Type::vec4;
26665
26666         /* Test needs single uniform and xfb */
26667         out_descriptors.resize(2);
26668
26669         /* Get references */
26670         bufferDescriptor& uniform = out_descriptors[0];
26671         bufferDescriptor& xfb    = out_descriptors[1];
26672
26673         /* Index */
26674         uniform.m_index = 0;
26675         xfb.m_index             = 0;
26676
26677         /* Target */
26678         uniform.m_target = Utils::Buffer::Uniform;
26679         xfb.m_target     = Utils::Buffer::Transform_feedback;
26680
26681         /* Data */
26682         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26683         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26684
26685         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26686
26687         /* Uniform data */
26688         uniform.m_initial_data.resize(2 * type_size);
26689         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26690         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26691
26692         /* XFB data */
26693         xfb.m_initial_data.resize(4 * type_size);
26694         xfb.m_expected_data.resize(4 * type_size);
26695
26696         for (GLuint i = 0; i < 4 * type_size; ++i)
26697         {
26698                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26699                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26700         }
26701
26702         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26703         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26704 }
26705
26706 /** Get body of main function for given shader stage
26707  *
26708  * @param test_case_index  Index of test case
26709  * @param stage            Shader stage
26710  * @param out_assignments  Set to empty
26711  * @param out_calculations Set to empty
26712  **/
26713 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26714                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26715 {
26716         out_calculations = "";
26717
26718         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26719                                                                          "    gohan  = uni_gohan;\n";
26720         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26721
26722         const GLchar* assignments = "";
26723
26724         switch (stage)
26725         {
26726         case Utils::Shader::FRAGMENT:
26727                 assignments = fs;
26728                 break;
26729
26730         case Utils::Shader::GEOMETRY:
26731                 if (TEST_GS == test_case_index)
26732                 {
26733                         assignments = vs_tes_gs;
26734                 }
26735                 break;
26736
26737         case Utils::Shader::TESS_CTRL:
26738                 break;
26739
26740         case Utils::Shader::TESS_EVAL:
26741                 if (TEST_TES == test_case_index)
26742                 {
26743                         assignments = vs_tes_gs;
26744                 }
26745                 break;
26746
26747         case Utils::Shader::VERTEX:
26748                 if (TEST_VS == test_case_index)
26749                 {
26750                         assignments = vs_tes_gs;
26751                 }
26752                 break;
26753
26754         default:
26755                 TCU_FAIL("Invalid enum");
26756         }
26757
26758         out_assignments = assignments;
26759 }
26760
26761 /** Get interface of shader
26762  *
26763  * @param test_case_index  Index of test case
26764  * @param stage            Shader stage
26765  * @param out_interface    Set to ""
26766  **/
26767 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26768                                                                                                                                  std::string& out_interface)
26769 {
26770         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26771                                                                          "\n"
26772                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26773                                                                          "    vec4 gohan;\n"
26774                                                                          "    vec4 goten;\n"
26775                                                                          "    vec4 chichi;\n"
26776                                                                          "};\n"
26777                                                                          "\n"
26778                                                                          "layout(binding = 0) uniform block {\n"
26779                                                                          "    vec4 uni_gohan;\n"
26780                                                                          "    vec4 uni_chichi;\n"
26781                                                                          "};\n";
26782         static const GLchar* fs = "in Goku {\n"
26783                                                           "    vec4 gohan;\n"
26784                                                           "    vec4 goten;\n"
26785                                                           "    vec4 chichi;\n"
26786                                                           "};\n"
26787                                                           "out vec4 fs_out;\n";
26788
26789         const GLchar* interface = "";
26790
26791         switch (stage)
26792         {
26793         case Utils::Shader::FRAGMENT:
26794                 interface = fs;
26795                 break;
26796
26797         case Utils::Shader::GEOMETRY:
26798                 if (TEST_GS == test_case_index)
26799                 {
26800                         interface = vs_tes_gs;
26801                 }
26802                 break;
26803
26804         case Utils::Shader::TESS_CTRL:
26805                 break;
26806
26807         case Utils::Shader::TESS_EVAL:
26808                 if (TEST_TES == test_case_index)
26809                 {
26810                         interface = vs_tes_gs;
26811                 }
26812                 break;
26813
26814         case Utils::Shader::VERTEX:
26815                 if (TEST_VS == test_case_index)
26816                 {
26817                         interface = vs_tes_gs;
26818                 }
26819                 break;
26820
26821         default:
26822                 TCU_FAIL("Invalid enum");
26823         }
26824
26825         out_interface = interface;
26826 }
26827
26828 /** Get source code of shader
26829  *
26830  * @param test_case_index Index of test case
26831  * @param stage           Shader stage
26832  *
26833  * @return Source
26834  **/
26835 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26836                                                                                                                                          Utils::Shader::STAGES stage)
26837 {
26838         std::string source;
26839
26840         switch (test_case_index)
26841         {
26842         case TEST_VS:
26843                 switch (stage)
26844                 {
26845                 case Utils::Shader::FRAGMENT:
26846                 case Utils::Shader::VERTEX:
26847                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26848                         break;
26849                 default:
26850                         break;
26851                 }
26852                 break;
26853
26854         case TEST_TES:
26855                 switch (stage)
26856                 {
26857                 case Utils::Shader::FRAGMENT:
26858                 case Utils::Shader::TESS_CTRL:
26859                 case Utils::Shader::TESS_EVAL:
26860                 case Utils::Shader::VERTEX:
26861                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26862                         break;
26863                 default:
26864                         break;
26865                 }
26866                 break;
26867
26868         case TEST_GS:
26869                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26870                 break;
26871
26872         default:
26873                 TCU_FAIL("Invalid enum");
26874                 break;
26875         }
26876
26877         /* */
26878         return source;
26879 }
26880
26881 /** Get name of test case
26882  *
26883  * @param test_case_index Index of test case
26884  *
26885  * @return Name of tested stage
26886  **/
26887 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26888 {
26889         const GLchar* name = 0;
26890
26891         switch (test_case_index)
26892         {
26893         case TEST_VS:
26894                 name = "vertex";
26895                 break;
26896         case TEST_TES:
26897                 name = "tessellation evaluation";
26898                 break;
26899         case TEST_GS:
26900                 name = "geometry";
26901                 break;
26902         default:
26903                 TCU_FAIL("Invalid enum");
26904         }
26905
26906         return name;
26907 }
26908
26909 /** Returns number of test cases
26910  *
26911  * @return TEST_MAX
26912  **/
26913 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26914 {
26915         return TEST_MAX;
26916 }
26917
26918 /** Verify contents of buffers
26919  *
26920  * @param buffers Collection of buffers to be verified
26921  *
26922  * @return true if everything is as expected, false otherwise
26923  **/
26924 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26925 {
26926         bool result = true;
26927
26928         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26929         Utils::Buffer*                  buffer   = pair.m_buffer;
26930         bufferDescriptor*               descriptor = pair.m_descriptor;
26931
26932         /* Get pointer to contents of buffer */
26933         buffer->Bind();
26934         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26935
26936         /* Get pointer to expected data */
26937         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26938
26939         /* Compare */
26940         static const GLuint vec4_size = 16;
26941
26942         int res_before = memcmp(buffer_data, expected_data, vec4_size);
26943         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
26944         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
26945
26946         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
26947         {
26948                 m_context.getTestContext().getLog()
26949                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26950                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26951
26952                 result = false;
26953         }
26954
26955         /* Release buffer mapping */
26956         buffer->UnMap();
26957
26958         return result;
26959 }
26960
26961 /** Constructor
26962  *
26963  * @param context Test context
26964  **/
26965 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
26966         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
26967 {
26968         /* Nothing to be done here */
26969 }
26970
26971 /** Execute drawArrays for single vertex
26972  *
26973  * @param test_case_index
26974  *
26975  * @return true
26976  **/
26977 bool XFBCaptureStructTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26978 {
26979         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26980         GLenum                   primitive_type = GL_PATCHES;
26981
26982         if (TEST_VS == test_case_index)
26983         {
26984                 primitive_type = GL_POINTS;
26985         }
26986
26987         gl.disable(GL_RASTERIZER_DISCARD);
26988         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26989
26990         gl.beginTransformFeedback(GL_POINTS);
26991         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26992
26993         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26994         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26995
26996         gl.endTransformFeedback();
26997         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26998
26999         return true;
27000 }
27001
27002 /** Get descriptors of buffers necessary for test
27003  *
27004  * @param ignored
27005  * @param out_descriptors Descriptors of buffers used by test
27006  **/
27007 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
27008                                                                                                 bufferDescriptor::Vector& out_descriptors)
27009 {
27010         const Utils::Type& type = Utils::Type::vec4;
27011
27012         /* Test needs single uniform and xfb */
27013         out_descriptors.resize(2);
27014
27015         /* Get references */
27016         bufferDescriptor& uniform = out_descriptors[0];
27017         bufferDescriptor& xfb    = out_descriptors[1];
27018
27019         /* Index */
27020         uniform.m_index = 0;
27021         xfb.m_index             = 0;
27022
27023         /* Target */
27024         uniform.m_target = Utils::Buffer::Uniform;
27025         xfb.m_target     = Utils::Buffer::Transform_feedback;
27026
27027         /* Data */
27028         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
27029         const std::vector<GLubyte>& chichi_data = type.GenerateData();
27030
27031         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
27032
27033         /* Uniform data */
27034         uniform.m_initial_data.resize(2 * type_size);
27035         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
27036         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
27037
27038         /* XFB data */
27039         xfb.m_initial_data.resize(4 * type_size);
27040         xfb.m_expected_data.resize(4 * type_size);
27041
27042         for (GLuint i = 0; i < 4 * type_size; ++i)
27043         {
27044                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
27045                 xfb.m_expected_data[i] = (glw::GLubyte)i;
27046         }
27047
27048         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
27049         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
27050 }
27051
27052 /** Get body of main function for given shader stage
27053  *
27054  * @param test_case_index  Index of test case
27055  * @param stage            Shader stage
27056  * @param out_assignments  Set to empty
27057  * @param out_calculations Set to empty
27058  **/
27059 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27060                                                                                  std::string& out_assignments, std::string& out_calculations)
27061 {
27062         out_calculations = "";
27063
27064         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27065                                                                          "    goku.gohan  = uni_gohan;\n";
27066         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27067
27068         const GLchar* assignments = "";
27069
27070         switch (stage)
27071         {
27072         case Utils::Shader::FRAGMENT:
27073                 assignments = fs;
27074                 break;
27075
27076         case Utils::Shader::GEOMETRY:
27077                 if (TEST_GS == test_case_index)
27078                 {
27079                         assignments = vs_tes_gs;
27080                 }
27081                 break;
27082
27083         case Utils::Shader::TESS_CTRL:
27084                 break;
27085
27086         case Utils::Shader::TESS_EVAL:
27087                 if (TEST_TES == test_case_index)
27088                 {
27089                         assignments = vs_tes_gs;
27090                 }
27091                 break;
27092
27093         case Utils::Shader::VERTEX:
27094                 if (TEST_VS == test_case_index)
27095                 {
27096                         assignments = vs_tes_gs;
27097                 }
27098                 break;
27099
27100         default:
27101                 TCU_FAIL("Invalid enum");
27102         }
27103
27104         out_assignments = assignments;
27105 }
27106
27107 /** Get interface of shader
27108  *
27109  * @param test_case_index  Index of test case
27110  * @param stage            Shader stage
27111  * @param out_interface    Set to ""
27112  **/
27113 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27114                                                                                           std::string& out_interface)
27115 {
27116         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27117                                                                          "\n"
27118                                                                          "struct Goku {\n"
27119                                                                          "    vec4 gohan;\n"
27120                                                                          "    vec4 goten;\n"
27121                                                                          "    vec4 chichi;\n"
27122                                                                          "};\n"
27123                                                                          "\n"
27124                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27125                                                                          "\n"
27126                                                                          "layout(binding = 0, std140) uniform block {\n"
27127                                                                          "    vec4 uni_gohan;\n"
27128                                                                          "    vec4 uni_chichi;\n"
27129                                                                          "};\n";
27130         static const GLchar* fs = "struct Goku {\n"
27131                                                           "    vec4 gohan;\n"
27132                                                           "    vec4 goten;\n"
27133                                                           "    vec4 chichi;\n"
27134                                                           "};\n"
27135                                                           "\n"
27136                                                           "in Goku goku;\n"
27137                                                           "\n"
27138                                                           "out vec4 fs_out;\n";
27139
27140         const GLchar* interface = "";
27141
27142         switch (stage)
27143         {
27144         case Utils::Shader::FRAGMENT:
27145                 interface = fs;
27146                 break;
27147
27148         case Utils::Shader::GEOMETRY:
27149                 if (TEST_GS == test_case_index)
27150                 {
27151                         interface = vs_tes_gs;
27152                 }
27153                 break;
27154
27155         case Utils::Shader::TESS_CTRL:
27156                 break;
27157
27158         case Utils::Shader::TESS_EVAL:
27159                 if (TEST_TES == test_case_index)
27160                 {
27161                         interface = vs_tes_gs;
27162                 }
27163                 break;
27164
27165         case Utils::Shader::VERTEX:
27166                 if (TEST_VS == test_case_index)
27167                 {
27168                         interface = vs_tes_gs;
27169                 }
27170                 break;
27171
27172         default:
27173                 TCU_FAIL("Invalid enum");
27174         }
27175
27176         out_interface = interface;
27177 }
27178
27179 /** Get source code of shader
27180  *
27181  * @param test_case_index Index of test case
27182  * @param stage           Shader stage
27183  *
27184  * @return Source
27185  **/
27186 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27187 {
27188         std::string source;
27189
27190         switch (test_case_index)
27191         {
27192         case TEST_VS:
27193                 switch (stage)
27194                 {
27195                 case Utils::Shader::FRAGMENT:
27196                 case Utils::Shader::VERTEX:
27197                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27198                         break;
27199                 default:
27200                         break;
27201                 }
27202                 break;
27203
27204         case TEST_TES:
27205                 switch (stage)
27206                 {
27207                 case Utils::Shader::FRAGMENT:
27208                 case Utils::Shader::TESS_CTRL:
27209                 case Utils::Shader::TESS_EVAL:
27210                 case Utils::Shader::VERTEX:
27211                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27212                         break;
27213                 default:
27214                         break;
27215                 }
27216                 break;
27217
27218         case TEST_GS:
27219                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27220                 break;
27221
27222         default:
27223                 TCU_FAIL("Invalid enum");
27224                 break;
27225         }
27226
27227         /* */
27228         return source;
27229 }
27230
27231 /** Get name of test case
27232  *
27233  * @param test_case_index Index of test case
27234  *
27235  * @return Name of tested stage
27236  **/
27237 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27238 {
27239         const GLchar* name = 0;
27240
27241         switch (test_case_index)
27242         {
27243         case TEST_VS:
27244                 name = "vertex";
27245                 break;
27246         case TEST_TES:
27247                 name = "tessellation evaluation";
27248                 break;
27249         case TEST_GS:
27250                 name = "geometry";
27251                 break;
27252         default:
27253                 TCU_FAIL("Invalid enum");
27254         }
27255
27256         return name;
27257 }
27258
27259 /** Returns number of test cases
27260  *
27261  * @return TEST_MAX
27262  **/
27263 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27264 {
27265         return TEST_MAX;
27266 }
27267
27268 /** Verify contents of buffers
27269  *
27270  * @param buffers Collection of buffers to be verified
27271  *
27272  * @return true if everything is as expected, false otherwise
27273  **/
27274 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27275 {
27276         bool result = true;
27277
27278         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27279         Utils::Buffer*                  buffer   = pair.m_buffer;
27280         bufferDescriptor*               descriptor = pair.m_descriptor;
27281
27282         /* Get pointer to contents of buffer */
27283         buffer->Bind();
27284         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27285
27286         /* Get pointer to expected data */
27287         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27288
27289         /* Compare */
27290         static const GLuint vec4_size = 16;
27291
27292         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27293         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27294         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27295
27296         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27297         {
27298                 m_context.getTestContext().getLog()
27299                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27300                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27301
27302                 result = false;
27303         }
27304
27305         /* Release buffer mapping */
27306         buffer->UnMap();
27307
27308         return result;
27309 }
27310
27311 /** Constructor
27312  *
27313  * @param context Test framework context
27314  **/
27315 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27316         : NegativeTestBase(context, "xfb_capture_unsized_array",
27317                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27318 {
27319 }
27320
27321 /** Source for given test case and stage
27322  *
27323  * @param test_case_index Index of test case
27324  * @param stage           Shader stage
27325  *
27326  * @return Shader source
27327  **/
27328 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27329 {
27330         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27331         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27332         static const GLchar* fs                         = "#version 430 core\n"
27333                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27334                                                           "\n"
27335                                                           "in  vec4 gs_fs;\n"
27336                                                           "out vec4 fs_out;\n"
27337                                                           "\n"
27338                                                           "void main()\n"
27339                                                           "{\n"
27340                                                           "    fs_out = gs_fs;\n"
27341                                                           "}\n"
27342                                                           "\n";
27343         static const GLchar* gs_tested = "#version 430 core\n"
27344                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27345                                                                          "\n"
27346                                                                          "layout(points)                           in;\n"
27347                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27348                                                                          "\n"
27349                                                                          "VAR_DEFINITION"
27350                                                                          "\n"
27351                                                                          "in  vec4 tes_gs[];\n"
27352                                                                          "out vec4 gs_fs;\n"
27353                                                                          "\n"
27354                                                                          "void main()\n"
27355                                                                          "{\n"
27356                                                                          "    vec4 result = tes_gs[0];\n"
27357                                                                          "\n"
27358                                                                          "VARIABLE_USE"
27359                                                                          "\n"
27360                                                                          "    gs_fs = result;\n"
27361                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27362                                                                          "    EmitVertex();\n"
27363                                                                          "    gs_fs = result;\n"
27364                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27365                                                                          "    EmitVertex();\n"
27366                                                                          "    gs_fs = result;\n"
27367                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27368                                                                          "    EmitVertex();\n"
27369                                                                          "    gs_fs = result;\n"
27370                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27371                                                                          "    EmitVertex();\n"
27372                                                                          "}\n"
27373                                                                          "\n";
27374         static const GLchar* tcs = "#version 430 core\n"
27375                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27376                                                            "\n"
27377                                                            "layout(vertices = 1) out;\n"
27378                                                            "\n"
27379                                                            "in  vec4 vs_tcs[];\n"
27380                                                            "out vec4 tcs_tes[];\n"
27381                                                            "\n"
27382                                                            "void main()\n"
27383                                                            "{\n"
27384                                                            "\n"
27385                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27386                                                            "\n"
27387                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27388                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27389                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27390                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27391                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27392                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27393                                                            "}\n"
27394                                                            "\n";
27395         static const GLchar* tcs_tested = "#version 430 core\n"
27396                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27397                                                                           "\n"
27398                                                                           "layout(vertices = 1) out;\n"
27399                                                                           "\n"
27400                                                                           "VAR_DEFINITION"
27401                                                                           "\n"
27402                                                                           "in  vec4 vs_tcs[];\n"
27403                                                                           "out vec4 tcs_tes[];\n"
27404                                                                           "\n"
27405                                                                           "void main()\n"
27406                                                                           "{\n"
27407                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27408                                                                           "\n"
27409                                                                           "VARIABLE_USE"
27410                                                                           "\n"
27411                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27412                                                                           "\n"
27413                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27414                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27415                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27416                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27417                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27418                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27419                                                                           "}\n"
27420                                                                           "\n";
27421         static const GLchar* tes_tested = "#version 430 core\n"
27422                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27423                                                                           "\n"
27424                                                                           "layout(isolines, point_mode) in;\n"
27425                                                                           "\n"
27426                                                                           "VAR_DEFINITION"
27427                                                                           "\n"
27428                                                                           "in  vec4 tcs_tes[];\n"
27429                                                                           "out vec4 tes_gs;\n"
27430                                                                           "\n"
27431                                                                           "void main()\n"
27432                                                                           "{\n"
27433                                                                           "    vec4 result = tcs_tes[0];\n"
27434                                                                           "\n"
27435                                                                           "VARIABLE_USE"
27436                                                                           "\n"
27437                                                                           "    tes_gs += result;\n"
27438                                                                           "}\n"
27439                                                                           "\n";
27440         static const GLchar* vs = "#version 430 core\n"
27441                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27442                                                           "\n"
27443                                                           "in  vec4 in_vs;\n"
27444                                                           "out vec4 vs_tcs;\n"
27445                                                           "\n"
27446                                                           "void main()\n"
27447                                                           "{\n"
27448                                                           "    vs_tcs = in_vs;\n"
27449                                                           "}\n"
27450                                                           "\n";
27451         static const GLchar* vs_tested = "#version 430 core\n"
27452                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27453                                                                          "\n"
27454                                                                          "VAR_DEFINITION"
27455                                                                          "\n"
27456                                                                          "in  vec4 in_vs;\n"
27457                                                                          "out vec4 vs_tcs;\n"
27458                                                                          "\n"
27459                                                                          "void main()\n"
27460                                                                          "{\n"
27461                                                                          "    vec4 result = in_vs;\n"
27462                                                                          "\n"
27463                                                                          "VARIABLE_USE"
27464                                                                          "\n"
27465                                                                          "    vs_tcs = result;\n"
27466                                                                          "}\n"
27467                                                                          "\n";
27468
27469         std::string source;
27470         testCase&   test_case = m_test_cases[test_case_index];
27471
27472         if (test_case.m_stage == stage)
27473         {
27474                 const GLchar* array     = "";
27475                 const GLchar* index     = "";
27476                 size_t            position = 0;
27477
27478                 switch (stage)
27479                 {
27480                 case Utils::Shader::GEOMETRY:
27481                         source = gs_tested;
27482                         array  = "[]";
27483                         index  = "[0]";
27484                         break;
27485                 case Utils::Shader::TESS_CTRL:
27486                         source = tcs_tested;
27487                         array  = "[]";
27488                         index  = "[gl_InvocationID]";
27489                         break;
27490                 case Utils::Shader::TESS_EVAL:
27491                         source = tes_tested;
27492                         array  = "[]";
27493                         index  = "[0]";
27494                         break;
27495                 case Utils::Shader::VERTEX:
27496                         source = vs_tested;
27497                         break;
27498                 default:
27499                         TCU_FAIL("Invalid enum");
27500                 }
27501
27502                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27503                 position = 0;
27504                 Utils::replaceToken("ARRAY", position, array, source);
27505                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27506
27507                 Utils::replaceAllTokens("INDEX", index, source);
27508         }
27509         else
27510         {
27511                 switch (test_case.m_stage)
27512                 {
27513                 case Utils::Shader::GEOMETRY:
27514                         switch (stage)
27515                         {
27516                         case Utils::Shader::FRAGMENT:
27517                                 source = fs;
27518                                 break;
27519                         case Utils::Shader::VERTEX:
27520                                 source = vs;
27521                                 break;
27522                         default:
27523                                 source = "";
27524                         }
27525                         break;
27526                 case Utils::Shader::TESS_CTRL:
27527                         switch (stage)
27528                         {
27529                         case Utils::Shader::FRAGMENT:
27530                                 source = fs;
27531                                 break;
27532                         case Utils::Shader::VERTEX:
27533                                 source = vs;
27534                                 break;
27535                         default:
27536                                 source = "";
27537                         }
27538                         break;
27539                 case Utils::Shader::TESS_EVAL:
27540                         switch (stage)
27541                         {
27542                         case Utils::Shader::FRAGMENT:
27543                                 source = fs;
27544                                 break;
27545                         case Utils::Shader::TESS_CTRL:
27546                                 source = tcs;
27547                                 break;
27548                         case Utils::Shader::VERTEX:
27549                                 source = vs;
27550                                 break;
27551                         default:
27552                                 source = "";
27553                         }
27554                         break;
27555                 case Utils::Shader::VERTEX:
27556                         switch (stage)
27557                         {
27558                         case Utils::Shader::FRAGMENT:
27559                                 source = fs;
27560                                 break;
27561                         default:
27562                                 source = "";
27563                         }
27564                         break;
27565                 default:
27566                         TCU_FAIL("Invalid enum");
27567                         break;
27568                 }
27569         }
27570
27571         return source;
27572 }
27573
27574 /** Get description of test case
27575  *
27576  * @param test_case_index Index of test case
27577  *
27578  * @return Test case description
27579  **/
27580 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27581 {
27582         std::stringstream stream;
27583         testCase&                 test_case = m_test_cases[test_case_index];
27584
27585         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27586
27587         return stream.str();
27588 }
27589
27590 /** Get number of test cases
27591  *
27592  * @return Number of test cases
27593  **/
27594 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27595 {
27596         return static_cast<GLuint>(m_test_cases.size());
27597 }
27598
27599 /** Selects if "compute" stage is relevant for test
27600  *
27601  * @param ignored
27602  *
27603  * @return false
27604  **/
27605 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27606 {
27607         return false;
27608 }
27609
27610 /** Prepare all test cases
27611  *
27612  **/
27613 void XFBCaptureUnsizedArrayTest::testInit()
27614 {
27615         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27616         {
27617                 /* Not aplicable for */
27618                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27619                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27620                 {
27621                         continue;
27622                 }
27623
27624                 testCase test_case = { (Utils::Shader::STAGES)stage };
27625
27626                 m_test_cases.push_back(test_case);
27627         }
27628 }
27629 } /* EnhancedLayouts namespace */
27630
27631 /** Constructor.
27632  *
27633  *  @param context Rendering context.
27634  **/
27635 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27636         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27637 {
27638         /* Left blank on purpose */
27639 }
27640
27641 /** Initializes a texture_storage_multisample test group.
27642  *
27643  **/
27644 void EnhancedLayoutsTests::init(void)
27645 {
27646         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27647         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27648         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27649         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27650         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27651         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27652         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27653         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27654         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27655         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27656         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27657         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27658         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27659         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27660         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27661         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27662         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27663         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27664
27665         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27666         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27667         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27668         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27669         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27670         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27671         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27672         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27673         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27674         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27675         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27676         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27677         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27678         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27679         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27680         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27681         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27682         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27683         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27684         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27685         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27686         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27687         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27688         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27689         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27690         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27691         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27692         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27693         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27694         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27695         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27696         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27697         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27698         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27699         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27700         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27701         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27702         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27703         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27704         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27705         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27706         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27707         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27708         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27709         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27710 }
27711
27712 } /* gl4cts namespace */