1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2014-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 gl4cShadingLanguage420PackTests.cpp
26 * \brief Implements conformance tests for "Shading Language 420Pack" functionality.
27 */ /*-------------------------------------------------------------------*/
28
29 #include "gl4cShadingLanguage420PackTests.hpp"
30
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestLog.hpp"
36
37 #include <algorithm>
38 #include <iomanip>
39 #include <stdio.h>
40 #include <string.h>
41 #include <string>
42 #include <vector>
43
44 #define IS_DEBUG 0
45
46 using namespace glw;
47
48 namespace gl4cts
49 {
50
51 namespace GLSL420Pack
52 {
53 /** Check binding of uniform
54 *
55 * @param program Program object
56 * @param name Array name
57 * @param expected_binding Expected binding value
58 *
59 * @return true if binding is as expected, false otherwise
60 **/
checkUniformBinding(Utils::program & program,const glw::GLchar * name,glw::GLint expected_binding)61 bool Utils::checkUniformBinding(Utils::program &program, const glw::GLchar *name, glw::GLint expected_binding)
62 {
63 const GLint uniform_location = program.getUniformLocation(name);
64 if (-1 == uniform_location)
65 {
66 TCU_FAIL("Uniform is inactive");
67 }
68
69 GLint binding = program.getUniform1i(uniform_location);
70
71 return (expected_binding == binding);
72 }
73 /** Check binding of uniform array element at <index>
74 *
75 * @param program Program object
76 * @param name Array name
77 * @param index Index
78 * @param expected_binding Expected binding value
79 *
80 * @return true if binding is as expected, false otherwise
81 **/
checkUniformArrayBinding(Utils::program & program,const glw::GLchar * name,glw::GLuint index,glw::GLint expected_binding)82 bool Utils::checkUniformArrayBinding(Utils::program &program, const glw::GLchar *name, glw::GLuint index,
83 glw::GLint expected_binding)
84 {
85 GLchar buffer[64];
86 sprintf(buffer, "%s[%d]", name, index);
87
88 const GLint uniform_location = program.getUniformLocation(buffer);
89 if (-1 == uniform_location)
90 {
91 TCU_FAIL("Uniform is inactive");
92 }
93
94 GLint binding = program.getUniform1i(uniform_location);
95
96 return (expected_binding == binding);
97 }
98
99 /** Check if given qualifier is present in set
100 *
101 * @param qualifier Specific qualifier
102 * @param qualifiers Qualifiers' set
103 *
104 * @return true if qualifier is present, false otherwise
105 **/
doesContainQualifier(Utils::QUALIFIERS qualifier,const Utils::qualifierSet & qualifiers)106 bool Utils::doesContainQualifier(Utils::QUALIFIERS qualifier, const Utils::qualifierSet &qualifiers)
107 {
108 for (GLuint i = 0; i < qualifiers.size(); ++i)
109 {
110 if (qualifiers[i] == qualifier)
111 {
112 return true;
113 }
114 }
115
116 return false;
117 }
118
119 /** Check if given stage supports specific qualifier
120 *
121 * @param stage Shader stage
122 * @param storage Storage of variable
123 * @param qualifier Qualifier
124 *
125 * @return true if qualifier can be used in given stage, false otherwise
126 **/
doesStageSupportQualifier(Utils::SHADER_STAGES stage,Utils::VARIABLE_STORAGE storage,Utils::QUALIFIERS qualifier)127 bool Utils::doesStageSupportQualifier(Utils::SHADER_STAGES stage, Utils::VARIABLE_STORAGE storage,
128 Utils::QUALIFIERS qualifier)
129 {
130 bool result = true;
131
132 switch (stage)
133 {
134 case COMPUTE_SHADER:
135 switch (qualifier)
136 {
137 case QUAL_NONE:
138 case QUAL_UNIFORM:
139 case QUAL_LOWP:
140 case QUAL_MEDIUMP:
141 case QUAL_HIGHP:
142 case QUAL_INVARIANT:
143 result = true;
144 break;
145 default:
146 result = false;
147 break;
148 }
149 break;
150 case FRAGMENT_SHADER:
151 if (QUAL_PATCH == qualifier)
152 {
153 result = false;
154 }
155 else if ((OUTPUT == storage) &&
156 ((QUAL_SMOOTH == qualifier) || (QUAL_NOPERSPECTIVE == qualifier) || (QUAL_FLAT == qualifier)))
157 {
158 result = false;
159 }
160 break;
161 case VERTEX_SHADER:
162 if (QUAL_PATCH == qualifier)
163 {
164 result = false;
165 }
166 else if ((INPUT == storage) &&
167 ((QUAL_SMOOTH == qualifier) || (QUAL_NOPERSPECTIVE == qualifier) || (QUAL_FLAT == qualifier) ||
168 (QUAL_INVARIANT == qualifier) || (QUAL_CENTROID == qualifier) || (QUAL_SAMPLE == qualifier)))
169 {
170 result = false;
171 }
172 break;
173 case GEOMETRY_SHADER:
174 if (QUAL_PATCH == qualifier)
175 {
176 result = false;
177 }
178 break;
179 case TESS_CTRL_SHADER:
180 if ((INPUT == storage) && (QUAL_PATCH == qualifier))
181 {
182 result = false;
183 }
184 break;
185 case TESS_EVAL_SHADER:
186 if ((OUTPUT == storage) && (QUAL_PATCH == qualifier))
187 {
188 result = false;
189 }
190 break;
191 default:
192 break;
193 }
194
195 return result;
196 }
197
198 /** Get string for qualifier
199 *
200 * @param qualifier Qualifier
201 *
202 * @return A string for given qualifier
203 **/
getQualifierString(Utils::QUALIFIERS qualifier)204 const GLchar *Utils::getQualifierString(Utils::QUALIFIERS qualifier)
205 {
206 const GLchar *result = 0;
207 switch (qualifier)
208 {
209 case QUAL_NONE:
210 result = "";
211 break;
212 case QUAL_CONST:
213 result = "const";
214 break;
215 case QUAL_IN:
216 result = "in";
217 break;
218 case QUAL_OUT:
219 result = "out";
220 break;
221 case QUAL_INOUT:
222 result = "inout";
223 break;
224 case QUAL_UNIFORM:
225 result = "uniform";
226 break;
227 case QUAL_PATCH:
228 result = "patch";
229 break;
230 case QUAL_CENTROID:
231 result = "centroid";
232 break;
233 case QUAL_SAMPLE:
234 result = "sample";
235 break;
236 case QUAL_FLAT:
237 result = "flat";
238 break;
239 case QUAL_NOPERSPECTIVE:
240 result = "noperspective";
241 break;
242 case QUAL_SMOOTH:
243 result = "smooth";
244 break;
245 case QUAL_LOCATION:
246 result = "layout (location = LOC_VALUE)";
247 break;
248 case QUAL_LOWP:
249 result = "lowp";
250 break;
251 case QUAL_MEDIUMP:
252 result = "mediump";
253 break;
254 case QUAL_HIGHP:
255 result = "highp";
256 break;
257 case QUAL_PRECISE:
258 result = "precise";
259 break;
260 case QUAL_INVARIANT:
261 result = "invariant";
262 break;
263 default:
264 TCU_FAIL("Invalid enum");
265 }
266
267 return result;
268 }
269
270 /** Returns a string with set of qualifiers.
271 *
272 * @param qualifiers Set of qualifiers
273 *
274 * @return String
275 **/
getQualifiersListString(const qualifierSet & qualifiers)276 std::string Utils::getQualifiersListString(const qualifierSet &qualifiers)
277 {
278 static const GLchar *qualifier_list = "QUALIFIER QUALIFIER_LIST";
279 const GLuint qualifier_list_length = static_cast<GLuint>(strlen(qualifier_list));
280
281 /* Tokens */
282 static const GLchar *token_qualifier = "QUALIFIER";
283 static const GLchar *token_qual_list = "QUALIFIER_LIST";
284
285 /* Variables */
286 std::string list = token_qual_list;
287 size_t position = 0;
288
289 /* Replace tokens */
290 for (GLuint i = 0; i < qualifiers.size(); ++i)
291 {
292 Utils::replaceToken(token_qual_list, position, qualifier_list, list);
293 position -= qualifier_list_length;
294
295 const GLchar *qualifier_str = getQualifierString(qualifiers[i]);
296
297 Utils::replaceToken(token_qualifier, position, qualifier_str, list);
298 }
299
300 Utils::replaceToken(token_qual_list, position, "", list);
301
302 return list;
303 }
304
305 /** Prepare a set of qualifiers for given shader stage and variable storage.
306 * Filters out not supported qualifiers from in_qualifiers
307 *
308 * @param in_qualifiers Origiranl set of qualifiers
309 * @param stage Shader stage
310 * @param storage Variable storage
311 *
312 * @return Set of qualifiers
313 **/
prepareQualifiersSet(const qualifierSet & in_qualifiers,SHADER_STAGES stage,VARIABLE_STORAGE storage)314 Utils::qualifierSet Utils::prepareQualifiersSet(const qualifierSet &in_qualifiers, SHADER_STAGES stage,
315 VARIABLE_STORAGE storage)
316 {
317 qualifierSet result;
318
319 for (GLuint i = 0; i < in_qualifiers.size(); ++i)
320 {
321 Utils::QUALIFIERS qualifier = in_qualifiers[i];
322
323 if (false == doesStageSupportQualifier(stage, storage, qualifier))
324 {
325 continue;
326 }
327
328 /* Replace wrong storage qualifiers */
329 if ((Utils::INPUT == storage) && ((Utils::QUAL_UNIFORM == qualifier) || (Utils::QUAL_OUT == qualifier)))
330 {
331 qualifier = QUAL_IN;
332 }
333 else if ((Utils::OUTPUT == storage) && ((Utils::QUAL_IN == qualifier) || (Utils::QUAL_UNIFORM == qualifier)))
334 {
335 qualifier = QUAL_OUT;
336 }
337 else if ((Utils::UNIFORM == storage) && ((Utils::QUAL_IN == qualifier) || (Utils::QUAL_OUT == qualifier)))
338 {
339 qualifier = QUAL_UNIFORM;
340 }
341
342 result.push_back(qualifier);
343 }
344
345 return result;
346 }
347
348 /** Get image type for given texture type
349 *
350 * @param type Texture type
351 *
352 * @return String representing sampler type
353 **/
getImageType(Utils::TEXTURE_TYPES type)354 const GLchar *Utils::getImageType(Utils::TEXTURE_TYPES type)
355 {
356 const GLchar *result = 0;
357
358 switch (type)
359 {
360 case TEX_BUFFER:
361 result = "imageBuffer";
362 break;
363 case TEX_2D:
364 result = "image2D";
365 break;
366 case TEX_2D_RECT:
367 result = "image2DRect";
368 break;
369 case TEX_2D_ARRAY:
370 result = "image2DArray";
371 break;
372 case TEX_3D:
373 result = "image3D";
374 break;
375 case TEX_CUBE:
376 result = "imageCube";
377 break;
378 case TEX_1D:
379 result = "image1D";
380 break;
381 case TEX_1D_ARRAY:
382 result = "image1DArray";
383 break;
384 default:
385 TCU_FAIL("Invalid enum");
386 }
387
388 return result;
389 }
390
391 /** Get number of coordinates required to address texture of given type
392 *
393 * @param type Type of texture
394 *
395 * @return Number of coordinates
396 **/
getNumberOfCoordinates(Utils::TEXTURE_TYPES type)397 GLuint Utils::getNumberOfCoordinates(Utils::TEXTURE_TYPES type)
398 {
399 GLuint result = 0;
400
401 switch (type)
402 {
403 case TEX_BUFFER:
404 result = 1;
405 break;
406 case TEX_2D:
407 result = 2;
408 break;
409 case TEX_2D_RECT:
410 result = 2;
411 break;
412 case TEX_2D_ARRAY:
413 result = 3;
414 break;
415 case TEX_3D:
416 result = 3;
417 break;
418 case TEX_CUBE:
419 result = 3;
420 break;
421 case TEX_1D:
422 result = 1;
423 break;
424 case TEX_1D_ARRAY:
425 result = 2;
426 break;
427 default:
428 TCU_FAIL("Invalid enum");
429 }
430
431 return result;
432 }
433
434 /** Get sampler type for given texture type
435 *
436 * @param type Texture type
437 *
438 * @return String representing sampler type
439 **/
getSamplerType(Utils::TEXTURE_TYPES type)440 const GLchar *Utils::getSamplerType(Utils::TEXTURE_TYPES type)
441 {
442 const GLchar *result = 0;
443
444 switch (type)
445 {
446 case TEX_BUFFER:
447 result = "samplerBuffer";
448 break;
449 case TEX_2D:
450 result = "sampler2D";
451 break;
452 case TEX_2D_RECT:
453 result = "sampler2DRect";
454 break;
455 case TEX_2D_ARRAY:
456 result = "sampler2DArray";
457 break;
458 case TEX_3D:
459 result = "sampler3D";
460 break;
461 case TEX_CUBE:
462 result = "samplerCube";
463 break;
464 case TEX_1D:
465 result = "sampler1D";
466 break;
467 case TEX_1D_ARRAY:
468 result = "sampler1DArray";
469 break;
470 default:
471 TCU_FAIL("Invalid enum");
472 }
473
474 return result;
475 }
476
477 /** Get target for given texture type
478 *
479 * @param type Type of texture
480 *
481 * @return Target
482 **/
getTextureTartet(Utils::TEXTURE_TYPES type)483 GLenum Utils::getTextureTartet(Utils::TEXTURE_TYPES type)
484 {
485 GLenum result = 0;
486
487 switch (type)
488 {
489 case TEX_BUFFER:
490 result = GL_TEXTURE_BUFFER;
491 break;
492 case TEX_2D:
493 result = GL_TEXTURE_2D;
494 break;
495 case TEX_2D_RECT:
496 result = GL_TEXTURE_RECTANGLE;
497 break;
498 case TEX_2D_ARRAY:
499 result = GL_TEXTURE_2D_ARRAY;
500 break;
501 case TEX_3D:
502 result = GL_TEXTURE_3D;
503 break;
504 case TEX_CUBE:
505 result = GL_TEXTURE_CUBE_MAP;
506 break;
507 case TEX_1D:
508 result = GL_TEXTURE_1D;
509 break;
510 case TEX_1D_ARRAY:
511 result = GL_TEXTURE_1D_ARRAY;
512 break;
513 default:
514 TCU_FAIL("Invalid enum");
515 }
516
517 return result;
518 }
519
520 /** Get name of given texture type
521 *
522 * @param type Texture type
523 *
524 * @return String representing name of texture type
525 **/
getTextureTypeName(Utils::TEXTURE_TYPES type)526 const GLchar *Utils::getTextureTypeName(Utils::TEXTURE_TYPES type)
527 {
528 const GLchar *result = 0;
529
530 switch (type)
531 {
532 case TEX_BUFFER:
533 result = "buffer";
534 break;
535 case TEX_2D:
536 result = "2D";
537 break;
538 case TEX_2D_RECT:
539 result = "2D_rectangle";
540 break;
541 case TEX_2D_ARRAY:
542 result = "2D_array";
543 break;
544 case TEX_3D:
545 result = "3D";
546 break;
547 case TEX_CUBE:
548 result = "cube";
549 break;
550 case TEX_1D:
551 result = "1D";
552 break;
553 case TEX_1D_ARRAY:
554 result = "1D_array";
555 break;
556 default:
557 TCU_FAIL("Invalid enum");
558 }
559
560 return result;
561 }
562
563 /** Check if glsl support matrices for specific basic type
564 *
565 * @param type Basic type
566 *
567 * @return true if matrices of <type> are supported, false otherwise
568 **/
doesTypeSupportMatrix(TYPES type)569 bool Utils::doesTypeSupportMatrix(TYPES type)
570 {
571 bool result = false;
572
573 switch (type)
574 {
575 case FLOAT:
576 case DOUBLE:
577 result = true;
578 break;
579 case INT:
580 case UINT:
581 result = false;
582 break;
583 default:
584 TCU_FAIL("Invliad enum");
585 }
586
587 return result;
588 }
589
590 /** Get string representing name of shader stage
591 *
592 * @param stage Shader stage
593 *
594 * @return String with name of shader stage
595 **/
getShaderStageName(Utils::SHADER_STAGES stage)596 const glw::GLchar *Utils::getShaderStageName(Utils::SHADER_STAGES stage)
597 {
598 const GLchar *result = 0;
599
600 switch (stage)
601 {
602 case COMPUTE_SHADER:
603 result = "compute";
604 break;
605 case VERTEX_SHADER:
606 result = "vertex";
607 break;
608 case TESS_CTRL_SHADER:
609 result = "tesselation_control";
610 break;
611 case TESS_EVAL_SHADER:
612 result = "tesselation_evaluation";
613 break;
614 case GEOMETRY_SHADER:
615 result = "geometry";
616 break;
617 case FRAGMENT_SHADER:
618 result = "fragment";
619 break;
620 default:
621 TCU_FAIL("Invalid enum");
622 }
623
624 return result;
625 }
626
627 /** Get glsl name of specified type
628 *
629 * @param type Basic type
630 * @param n_columns Number of columns
631 * @param n_rows Number of rows
632 *
633 * @return Name of glsl type
634 **/
getTypeName(TYPES type,glw::GLuint n_columns,glw::GLuint n_rows)635 const glw::GLchar *Utils::getTypeName(TYPES type, glw::GLuint n_columns, glw::GLuint n_rows)
636 {
637 static const GLchar *float_lut[4][4] = {
638 {"float", "vec2", "vec3", "vec4"},
639 {0, "mat2", "mat2x3", "mat2x4"},
640 {0, "mat3x2", "mat3", "mat3x4"},
641 {0, "mat4x2", "mat4x3", "mat4"},
642 };
643
644 static const GLchar *double_lut[4][4] = {
645 {"double", "dvec2", "dvec3", "dvec4"},
646 {0, "dmat2", "dmat2x3", "dmat2x4"},
647 {0, "dmat3x2", "dmat3", "dmat3x4"},
648 {0, "dmat4x2", "dmat4x3", "dmat4"},
649 };
650
651 static const GLchar *int_lut[4] = {"int", "ivec2", "ivec3", "ivec4"};
652
653 static const GLchar *uint_lut[4] = {"uint", "uvec2", "uvec3", "uvec4"};
654
655 const GLchar *result = 0;
656
657 if ((1 > n_columns) || (1 > n_rows) || (4 < n_columns) || (4 < n_rows))
658 {
659 return 0;
660 }
661
662 switch (type)
663 {
664 case FLOAT:
665 result = float_lut[n_columns - 1][n_rows - 1];
666 break;
667 case DOUBLE:
668 result = double_lut[n_columns - 1][n_rows - 1];
669 break;
670 case INT:
671 result = int_lut[n_rows - 1];
672 break;
673 case UINT:
674 result = uint_lut[n_rows - 1];
675 break;
676 default:
677 TCU_FAIL("Invliad enum");
678 }
679
680 return result;
681 }
682
683 /** Get proper glUniformNdv routine for vectors with specified number of rows
684 *
685 * @param gl GL functions
686 * @param n_rows Number of rows
687 *
688 * @return Function address
689 **/
getUniformNdv(const glw::Functions & gl,glw::GLuint n_rows)690 Utils::uniformNdv Utils::getUniformNdv(const glw::Functions &gl, glw::GLuint n_rows)
691 {
692 uniformNdv result = 0;
693
694 switch (n_rows)
695 {
696 case 1:
697 result = gl.uniform1dv;
698 break;
699 case 2:
700 result = gl.uniform2dv;
701 break;
702 case 3:
703 result = gl.uniform3dv;
704 break;
705 case 4:
706 result = gl.uniform4dv;
707 break;
708 default:
709 TCU_FAIL("Invalid number of rows");
710 }
711
712 return result;
713 }
714
715 /** Get proper glUniformNfv routine for vectors with specified number of rows
716 *
717 * @param gl GL functions
718 * @param n_rows Number of rows
719 *
720 * @return Function address
721 **/
getUniformNfv(const glw::Functions & gl,glw::GLuint n_rows)722 Utils::uniformNfv Utils::getUniformNfv(const glw::Functions &gl, glw::GLuint n_rows)
723 {
724 uniformNfv result = 0;
725
726 switch (n_rows)
727 {
728 case 1:
729 result = gl.uniform1fv;
730 break;
731 case 2:
732 result = gl.uniform2fv;
733 break;
734 case 3:
735 result = gl.uniform3fv;
736 break;
737 case 4:
738 result = gl.uniform4fv;
739 break;
740 default:
741 TCU_FAIL("Invalid number of rows");
742 }
743
744 return result;
745 }
746
747 /** Get proper glUniformNiv routine for vectors with specified number of rows
748 *
749 * @param gl GL functions
750 * @param n_rows Number of rows
751 *
752 * @return Function address
753 **/
getUniformNiv(const glw::Functions & gl,glw::GLuint n_rows)754 Utils::uniformNiv Utils::getUniformNiv(const glw::Functions &gl, glw::GLuint n_rows)
755 {
756 uniformNiv result = 0;
757
758 switch (n_rows)
759 {
760 case 1:
761 result = gl.uniform1iv;
762 break;
763 case 2:
764 result = gl.uniform2iv;
765 break;
766 case 3:
767 result = gl.uniform3iv;
768 break;
769 case 4:
770 result = gl.uniform4iv;
771 break;
772 default:
773 TCU_FAIL("Invalid number of rows");
774 }
775
776 return result;
777 }
778
779 /** Get proper glUniformNuiv routine for vectors with specified number of rows
780 *
781 * @param gl GL functions
782 * @param n_rows Number of rows
783 *
784 * @return Function address
785 **/
getUniformNuiv(const glw::Functions & gl,glw::GLuint n_rows)786 Utils::uniformNuiv Utils::getUniformNuiv(const glw::Functions &gl, glw::GLuint n_rows)
787 {
788 uniformNuiv result = 0;
789
790 switch (n_rows)
791 {
792 case 1:
793 result = gl.uniform1uiv;
794 break;
795 case 2:
796 result = gl.uniform2uiv;
797 break;
798 case 3:
799 result = gl.uniform3uiv;
800 break;
801 case 4:
802 result = gl.uniform4uiv;
803 break;
804 default:
805 TCU_FAIL("Invalid number of rows");
806 }
807
808 return result;
809 }
810
811 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
812 *
813 * @param gl GL functions
814 * @param n_rows Number of rows
815 *
816 * @return Function address
817 **/
getUniformMatrixNdv(const glw::Functions & gl,glw::GLuint n_columns,glw::GLuint n_rows)818 Utils::uniformMatrixNdv Utils::getUniformMatrixNdv(const glw::Functions &gl, glw::GLuint n_columns, glw::GLuint n_rows)
819 {
820 uniformMatrixNdv result = 0;
821
822 switch (n_columns)
823 {
824 case 2:
825 switch (n_rows)
826 {
827 case 2:
828 result = gl.uniformMatrix2dv;
829 break;
830 case 3:
831 result = gl.uniformMatrix2x3dv;
832 break;
833 case 4:
834 result = gl.uniformMatrix2x4dv;
835 break;
836 default:
837 TCU_FAIL("Invalid number of rows");
838 }
839 break;
840 case 3:
841 switch (n_rows)
842 {
843 case 2:
844 result = gl.uniformMatrix3x2dv;
845 break;
846 case 3:
847 result = gl.uniformMatrix3dv;
848 break;
849 case 4:
850 result = gl.uniformMatrix3x4dv;
851 break;
852 default:
853 TCU_FAIL("Invalid number of rows");
854 }
855 break;
856 case 4:
857 switch (n_rows)
858 {
859 case 2:
860 result = gl.uniformMatrix4x2dv;
861 break;
862 case 3:
863 result = gl.uniformMatrix4x3dv;
864 break;
865 case 4:
866 result = gl.uniformMatrix4dv;
867 break;
868 default:
869 TCU_FAIL("Invalid number of rows");
870 }
871 break;
872 default:
873 TCU_FAIL("Invalid number of columns");
874 }
875
876 return result;
877 }
878
879 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
880 *
881 * @param gl GL functions
882 * @param n_rows Number of rows
883 *
884 * @return Function address
885 **/
getUniformMatrixNfv(const glw::Functions & gl,glw::GLuint n_columns,glw::GLuint n_rows)886 Utils::uniformMatrixNfv Utils::getUniformMatrixNfv(const glw::Functions &gl, glw::GLuint n_columns, glw::GLuint n_rows)
887 {
888 uniformMatrixNfv result = 0;
889
890 switch (n_columns)
891 {
892 case 2:
893 switch (n_rows)
894 {
895 case 2:
896 result = gl.uniformMatrix2fv;
897 break;
898 case 3:
899 result = gl.uniformMatrix2x3fv;
900 break;
901 case 4:
902 result = gl.uniformMatrix2x4fv;
903 break;
904 default:
905 TCU_FAIL("Invalid number of rows");
906 }
907 break;
908 case 3:
909 switch (n_rows)
910 {
911 case 2:
912 result = gl.uniformMatrix3x2fv;
913 break;
914 case 3:
915 result = gl.uniformMatrix3fv;
916 break;
917 case 4:
918 result = gl.uniformMatrix3x4fv;
919 break;
920 default:
921 TCU_FAIL("Invalid number of rows");
922 }
923 break;
924 case 4:
925 switch (n_rows)
926 {
927 case 2:
928 result = gl.uniformMatrix4x2fv;
929 break;
930 case 3:
931 result = gl.uniformMatrix4x3fv;
932 break;
933 case 4:
934 result = gl.uniformMatrix4fv;
935 break;
936 default:
937 TCU_FAIL("Invalid number of rows");
938 }
939 break;
940 default:
941 TCU_FAIL("Invalid number of columns");
942 }
943
944 return result;
945 }
946
947 /** Prepare definition of input or output block's variable
948 *
949 * @param qualifiers Set of qualifiers
950 * @param type_name Name of type
951 * @param variable_name Meaningful part of variable name, eg. tex_coord
952 *
953 * @return Definition of variable
954 **/
getBlockVariableDefinition(const qualifierSet & qualifiers,const glw::GLchar * type_name,const glw::GLchar * variable_name)955 std::string Utils::getBlockVariableDefinition(const qualifierSet &qualifiers, const glw::GLchar *type_name,
956 const glw::GLchar *variable_name)
957 {
958 /* Templates */
959 static const GLchar *def_template = "QUALIFIER_LISTTYPE VARIABLE_NAME";
960
961 /* Tokens */
962 static const GLchar *token_type = "TYPE";
963 static const GLchar *token_variable_name = "VARIABLE_NAME";
964 static const GLchar *token_qual_list = "QUALIFIER_LIST";
965
966 /* Variables */
967 std::string variable_definition = def_template;
968 size_t position = 0;
969
970 /* Get qualifiers list */
971 const std::string &list = getQualifiersListString(qualifiers);
972
973 /* Replace tokens */
974 Utils::replaceToken(token_qual_list, position, list.c_str(), variable_definition);
975 Utils::replaceToken(token_type, position, type_name, variable_definition);
976 Utils::replaceToken(token_variable_name, position, variable_name, variable_definition);
977
978 /* Done */
979 return variable_definition;
980 }
981
982 /** Prepare reference to input or output variable
983 *
984 * @param flavour "Flavour" of variable
985 * @param variable_name Meaningful part of variable name, eg. tex_coord
986 * @param block_name Name of block
987 *
988 * @return Reference to variable
989 **/
getBlockVariableReference(VARIABLE_FLAVOUR flavour,const glw::GLchar * variable_name,const glw::GLchar * block_name)990 std::string Utils::getBlockVariableReference(VARIABLE_FLAVOUR flavour, const glw::GLchar *variable_name,
991 const glw::GLchar *block_name)
992 {
993 /* Templates */
994 static const GLchar *ref_template = "BLOCK_NAME.VARIABLE_NAME";
995 static const GLchar *array_ref_template = "BLOCK_NAME[0].VARIABLE_NAME";
996 static const GLchar *tcs_ref_template = "BLOCK_NAME[gl_InvocationID].VARIABLE_NAME";
997
998 /* Token */
999 static const GLchar *token_block_name = "BLOCK_NAME";
1000 static const GLchar *token_variable_name = "VARIABLE_NAME";
1001
1002 /* Variables */
1003 std::string variable_definition;
1004 size_t position = 0;
1005
1006 /* Select variable reference template */
1007 switch (flavour)
1008 {
1009 case BASIC:
1010 variable_definition = ref_template;
1011 break;
1012 case ARRAY:
1013 variable_definition = array_ref_template;
1014 break;
1015 case INDEXED_BY_INVOCATION_ID:
1016 variable_definition = tcs_ref_template;
1017 break;
1018 default:
1019 variable_definition = ref_template;
1020 break;
1021 }
1022
1023 /* Replace tokens */
1024 replaceAllTokens(token_block_name, block_name, variable_definition);
1025 replaceToken(token_variable_name, position, variable_name, variable_definition);
1026
1027 /* Done */
1028 return variable_definition;
1029 }
1030
1031 /** Prepare definition of input or output variable
1032 *
1033 * @param flavour "Flavour" of variable
1034 * @param qualifiers Set of qualifiers
1035 * @param type_name Name of type
1036 * @param variable_name Meaningful part of variable name, eg. tex_coord
1037 *
1038 * @return Definition of variable
1039 **/
getVariableDefinition(VARIABLE_FLAVOUR flavour,const qualifierSet & qualifiers,const glw::GLchar * type_name,const glw::GLchar * variable_name)1040 std::string Utils::getVariableDefinition(VARIABLE_FLAVOUR flavour, const qualifierSet &qualifiers,
1041 const glw::GLchar *type_name, const glw::GLchar *variable_name)
1042 {
1043 /* Templates */
1044 static const GLchar *def_template = "QUALIFIER_LISTTYPE VARIABLE_NAME";
1045 static const GLchar *def_array_template = "QUALIFIER_LISTTYPE VARIABLE_NAME[]";
1046
1047 /* Tokens */
1048 static const GLchar *token_type = "TYPE";
1049 static const GLchar *token_variable_name = "VARIABLE_NAME";
1050 static const GLchar *token_qual_list = "QUALIFIER_LIST";
1051
1052 /* Variables */
1053 std::string variable_definition;
1054 size_t position = 0;
1055
1056 /* Select variable definition template */
1057 switch (flavour)
1058 {
1059 case BASIC:
1060 variable_definition = def_template;
1061 break;
1062 case ARRAY:
1063 case INDEXED_BY_INVOCATION_ID:
1064 variable_definition = def_array_template;
1065 break;
1066 default:
1067 TCU_FAIL("Invliad enum");
1068 }
1069
1070 /* Get qualifiers list */
1071 const std::string &list = getQualifiersListString(qualifiers);
1072
1073 /* Replace tokens */
1074 replaceToken(token_qual_list, position, list.c_str(), variable_definition);
1075 replaceToken(token_type, position, type_name, variable_definition);
1076 replaceToken(token_variable_name, position, variable_name, variable_definition);
1077
1078 /* Done */
1079 return variable_definition;
1080 }
1081
1082 /** Get "flavour" of variable
1083 *
1084 * @param stage Shader stage
1085 * @param storage Storage of variable
1086 * @param qualifiers Set of qualifiers for variable
1087 *
1088 * @return "Flavour" of variable
1089 **/
getVariableFlavour(SHADER_STAGES stage,VARIABLE_STORAGE storage,const qualifierSet & qualifiers)1090 Utils::VARIABLE_FLAVOUR Utils::getVariableFlavour(SHADER_STAGES stage, VARIABLE_STORAGE storage,
1091 const qualifierSet &qualifiers)
1092 {
1093 VARIABLE_FLAVOUR result;
1094
1095 if (UNIFORM == storage)
1096 {
1097 result = BASIC;
1098 }
1099 else
1100 {
1101 switch (stage)
1102 {
1103 case Utils::GEOMETRY_SHADER:
1104 if (Utils::INPUT == storage)
1105 {
1106 result = ARRAY;
1107 }
1108 else /* OUTPUT */
1109 {
1110 result = BASIC;
1111 }
1112 break;
1113 case Utils::TESS_EVAL_SHADER:
1114 if ((false == Utils::doesContainQualifier(Utils::QUAL_PATCH, qualifiers)) && (Utils::INPUT == storage))
1115 {
1116 result = ARRAY;
1117 }
1118 else /* OUTPUT */
1119 {
1120 result = BASIC;
1121 }
1122 break;
1123 case Utils::TESS_CTRL_SHADER:
1124 if ((true == Utils::doesContainQualifier(Utils::QUAL_PATCH, qualifiers)) && (Utils::OUTPUT == storage))
1125 {
1126 result = BASIC;
1127 }
1128 else
1129 {
1130 result = INDEXED_BY_INVOCATION_ID;
1131 }
1132 break;
1133 case Utils::VERTEX_SHADER:
1134 case Utils::FRAGMENT_SHADER:
1135 result = BASIC;
1136 break;
1137 default:
1138 TCU_FAIL("Invliad enum");
1139 }
1140 }
1141
1142 return result;
1143 }
1144
1145 /** Prepare name of input or output variable
1146 *
1147 * @param stage Shader stage
1148 * @param storage Storage of variable
1149 * @param variable_name Meaningful part of variable name, eg. tex_coord
1150 *
1151 * @return Name of variable
1152 **/
getVariableName(SHADER_STAGES stage,VARIABLE_STORAGE storage,const glw::GLchar * variable_name)1153 std::string Utils::getVariableName(SHADER_STAGES stage, VARIABLE_STORAGE storage, const glw::GLchar *variable_name)
1154 {
1155 /* Variable name template */
1156 static const GLchar *variable_name_template = "PRECEEDING_PREFIX_VARIABLE_NAME";
1157
1158 /* Tokens */
1159 static const GLchar *token_preceeding = "PRECEEDING";
1160 static const GLchar *token_prefix = "PREFIX";
1161 static const GLchar *token_variable_name = "VARIABLE_NAME";
1162
1163 static const GLchar *prefixes[Utils::STORAGE_MAX][Utils::SHADER_STAGES_MAX][2] = {
1164 /* COMPUTE, VERTEX, TCS, TES, GEOMETRY, FRAGMENT */
1165 {{"", ""}, {"in", "vs"}, {"vs", "tcs"}, {"tcs", "tes"}, {"tes", "gs"}, {"gs", "fs"}}, /* INPUT */
1166 {{"", ""}, {"vs", "tcs"}, {"tcs", "tes"}, {"tes", "gs"}, {"gs", "fs"}, {"fs", "out"}}, /* OUTPUT */
1167 {{"uni", "comp"}, {"uni", "vs"}, {"uni", "tcs"}, {"uni", "tes"}, {"uni", "gs"}, {"uni", "fs"}} /* UNIFORM */
1168 };
1169
1170 /* Variables */
1171 const GLchar *preceeding = prefixes[storage][stage][0];
1172 const GLchar *prefix = prefixes[storage][stage][1];
1173 std::string name = variable_name_template;
1174 size_t position = 0;
1175
1176 /* Replace tokens */
1177 Utils::replaceToken(token_preceeding, position, preceeding, name);
1178 Utils::replaceToken(token_prefix, position, prefix, name);
1179 Utils::replaceToken(token_variable_name, position, variable_name, name);
1180
1181 /* Done */
1182 return name;
1183 }
1184
1185 /** Prepare reference to input or output variable
1186 *
1187 * @param flavour "Flavour" of variable
1188 * @param variable_name Meaningful part of variable name, eg. tex_coord
1189 *
1190 * @return Reference to variable
1191 **/
getVariableReference(VARIABLE_FLAVOUR flavour,const glw::GLchar * variable_name)1192 std::string Utils::getVariableReference(VARIABLE_FLAVOUR flavour, const glw::GLchar *variable_name)
1193 {
1194 /* Templates */
1195 static const GLchar *ref_template = "VARIABLE_NAME";
1196 static const GLchar *array_ref_template = "VARIABLE_NAME[0]";
1197 static const GLchar *tcs_ref_template = "VARIABLE_NAME[gl_InvocationID]";
1198
1199 /* Token */
1200 static const GLchar *token_variable_name = "VARIABLE_NAME";
1201
1202 /* Variables */
1203 std::string variable_definition;
1204 size_t position = 0;
1205
1206 /* Select variable reference template */
1207 switch (flavour)
1208 {
1209 case BASIC:
1210 variable_definition = ref_template;
1211 break;
1212 case ARRAY:
1213 variable_definition = array_ref_template;
1214 break;
1215 case INDEXED_BY_INVOCATION_ID:
1216 variable_definition = tcs_ref_template;
1217 break;
1218 default:
1219 variable_definition = ref_template;
1220 break;
1221 }
1222
1223 /* Replace token */
1224 Utils::replaceToken(token_variable_name, position, variable_name, variable_definition);
1225
1226 /* Done */
1227 return variable_definition;
1228 }
1229
1230 /** Prepare definition and reference string for block varaible
1231 *
1232 * @param in_stage Shader stage
1233 * @param in_storage Storage of variable
1234 * @param in_qualifiers Set of qualifiers
1235 * @param in_type_name Type name
1236 * @param in_variable_name Meaningful part of variable name, like "color"
1237 * @param in_block_name Name of block, like "input"
1238 * @param out_definition Definition string
1239 * @param out_reference Reference string
1240 **/
prepareBlockVariableStrings(Utils::SHADER_STAGES in_stage,Utils::VARIABLE_STORAGE in_storage,const Utils::qualifierSet & in_qualifiers,const glw::GLchar * in_type_name,const glw::GLchar * in_variable_name,const glw::GLchar * in_block_name,std::string & out_definition,std::string & out_reference)1241 void Utils::prepareBlockVariableStrings(Utils::SHADER_STAGES in_stage, Utils::VARIABLE_STORAGE in_storage,
1242 const Utils::qualifierSet &in_qualifiers, const glw::GLchar *in_type_name,
1243 const glw::GLchar *in_variable_name, const glw::GLchar *in_block_name,
1244 std::string &out_definition, std::string &out_reference)
1245 {
1246 VARIABLE_FLAVOUR flavour = getVariableFlavour(in_stage, in_storage, in_qualifiers);
1247 const qualifierSet &qualifiers = prepareQualifiersSet(in_qualifiers, in_stage, in_storage);
1248 const std::string &name = getVariableName(in_stage, in_storage, in_variable_name);
1249
1250 out_definition = getBlockVariableDefinition(qualifiers, in_type_name, name.c_str());
1251 out_reference = getBlockVariableReference(flavour, name.c_str(), in_block_name);
1252 }
1253
1254 /** Prepare definition and reference string for block varaible
1255 *
1256 * @param in_stage Shader stage
1257 * @param in_storage Storage of variable
1258 * @param in_qualifiers Set of qualifiers
1259 * @param in_type_name Type name
1260 * @param in_variable_name Meaningful part of variable name, like "color"
1261 * @param out_definition Definition string
1262 * @param out_reference Reference string
1263 **/
prepareVariableStrings(Utils::SHADER_STAGES in_stage,Utils::VARIABLE_STORAGE in_storage,const Utils::qualifierSet & in_qualifiers,const glw::GLchar * in_type_name,const glw::GLchar * in_variable_name,std::string & out_definition,std::string & out_reference)1264 void Utils::prepareVariableStrings(Utils::SHADER_STAGES in_stage, Utils::VARIABLE_STORAGE in_storage,
1265 const Utils::qualifierSet &in_qualifiers, const glw::GLchar *in_type_name,
1266 const glw::GLchar *in_variable_name, std::string &out_definition,
1267 std::string &out_reference)
1268 {
1269 VARIABLE_FLAVOUR flavour = getVariableFlavour(in_stage, in_storage, in_qualifiers);
1270 const qualifierSet &qualifiers = prepareQualifiersSet(in_qualifiers, in_stage, in_storage);
1271 const std::string &name = getVariableName(in_stage, in_storage, in_variable_name);
1272
1273 out_definition = getVariableDefinition(flavour, qualifiers, in_type_name, name.c_str());
1274 out_reference = getVariableReference(flavour, name.c_str());
1275 }
1276
1277 /** Returns string with UTF8 character for current test case
1278 *
1279 * @return String with UTF8 character
1280 **/
getUtf8Character(Utils::UTF8_CHARACTERS character)1281 const GLchar *Utils::getUtf8Character(Utils::UTF8_CHARACTERS character)
1282 {
1283 static const unsigned char two_bytes[] = {0xd7, 0x84, 0x00};
1284 static const unsigned char three_bytes[] = {0xe3, 0x82, 0x81, 0x00};
1285 static const unsigned char four_bytes[] = {0xf0, 0x93, 0x83, 0x93, 0x00};
1286 static const unsigned char five_bytes[] = {0xfa, 0x82, 0x82, 0x82, 0x82, 0x00};
1287 static const unsigned char six_bytes[] = {0xfd, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00};
1288 static const unsigned char redundant_bytes[] = {0xf2, 0x80, 0x80, 0x5e, 0x00};
1289
1290 const GLchar *result = 0;
1291
1292 switch (character)
1293 {
1294 case TWO_BYTES:
1295 result = (const GLchar *)two_bytes;
1296 break;
1297 case THREE_BYTES:
1298 result = (const GLchar *)three_bytes;
1299 break;
1300 case FOUR_BYTES:
1301 result = (const GLchar *)four_bytes;
1302 break;
1303 case FIVE_BYTES:
1304 result = (const GLchar *)five_bytes;
1305 break;
1306 case SIX_BYTES:
1307 result = (const GLchar *)six_bytes;
1308 break;
1309 case REDUNDANT_ASCII:
1310 result = (const GLchar *)redundant_bytes;
1311 break;
1312 case EMPTY:
1313 result = "";
1314 break;
1315 default:
1316 TCU_FAIL("Invalid enum");
1317 }
1318
1319 return result;
1320 }
1321 /** Check if extension is supported
1322 *
1323 * @param context Test context
1324 * @param extension_name Name of extension
1325 *
1326 * @return true if extension is supported, false otherwise
1327 **/
isExtensionSupported(deqp::Context & context,const GLchar * extension_name)1328 bool Utils::isExtensionSupported(deqp::Context &context, const GLchar *extension_name)
1329 {
1330 const std::vector<std::string> &extensions = context.getContextInfo().getExtensions();
1331
1332 if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1333 {
1334 return false;
1335 }
1336
1337 return true;
1338 }
1339
1340 /** Check if GL context meets version requirements
1341 *
1342 * @param gl Functions
1343 * @param required_major Minimum required MAJOR_VERSION
1344 * @param required_minor Minimum required MINOR_VERSION
1345 *
1346 * @return true if GL context version is at least as requested, false otherwise
1347 **/
isGLVersionAtLeast(const glw::Functions & gl,glw::GLint required_major,glw::GLint required_minor)1348 bool Utils::isGLVersionAtLeast(const glw::Functions &gl, glw::GLint required_major, glw::GLint required_minor)
1349 {
1350 glw::GLint major = 0;
1351 glw::GLint minor = 0;
1352
1353 gl.getIntegerv(GL_MAJOR_VERSION, &major);
1354 gl.getIntegerv(GL_MINOR_VERSION, &minor);
1355
1356 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1357
1358 if (major > required_major)
1359 {
1360 /* Major is higher than required one */
1361 return true;
1362 }
1363 else if (major == required_major)
1364 {
1365 if (minor >= required_minor)
1366 {
1367 /* Major is equal to required one */
1368 /* Minor is higher than or equal to required one */
1369 return true;
1370 }
1371 else
1372 {
1373 /* Major is equal to required one */
1374 /* Minor is lower than required one */
1375 return false;
1376 }
1377 }
1378 else
1379 {
1380 /* Major is lower than required one */
1381 return false;
1382 }
1383 }
1384
1385 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1386 *
1387 * @param token Token string
1388 * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1389 * @param text String that will be used as replacement for <token>
1390 * @param string String to work on
1391 **/
replaceToken(const glw::GLchar * token,size_t & search_position,const glw::GLchar * text,std::string & string)1392 void Utils::replaceToken(const glw::GLchar *token, size_t &search_position, const glw::GLchar *text,
1393 std::string &string)
1394 {
1395 const size_t text_length = strlen(text);
1396 const size_t token_length = strlen(token);
1397 const size_t token_position = string.find(token, search_position);
1398
1399 string.replace(token_position, token_length, text, text_length);
1400
1401 search_position = token_position + text_length;
1402 }
1403
1404 /** Replace all occurances of <token> with <text> in <string>
1405 *
1406 * @param token Token string
1407 * @param text String that will be used as replacement for <token>
1408 * @param string String to work on
1409 **/
replaceAllTokens(const glw::GLchar * token,const glw::GLchar * text,std::string & string)1410 void Utils::replaceAllTokens(const glw::GLchar *token, const glw::GLchar *text, std::string &string)
1411 {
1412 const size_t text_length = strlen(text);
1413 const size_t token_length = strlen(token);
1414
1415 size_t search_position = 0;
1416
1417 while (1)
1418 {
1419 const size_t token_position = string.find(token, search_position);
1420
1421 if (std::string::npos == token_position)
1422 {
1423 break;
1424 }
1425
1426 search_position = token_position + text_length;
1427
1428 string.replace(token_position, token_length, text, text_length);
1429 }
1430 }
1431
1432 /** Constructor
1433 *
1434 * @param context Test context
1435 * @param test_name Test name
1436 * @param test_description Test description
1437 **/
TestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1438 TestBase::TestBase(deqp::Context &context, const glw::GLchar *test_name, const glw::GLchar *test_description)
1439 : TestCase(context, test_name, test_description)
1440 , m_is_compute_shader_supported(false)
1441 , m_is_explicit_uniform_location(false)
1442 , m_is_shader_language_420pack(false)
1443 {
1444 /* Nothing to be done here */
1445 }
1446
1447 /** Execute test
1448 *
1449 * @return tcu::TestNode::CONTINUE after executing test case, tcu::TestNode::STOP otherwise
1450 **/
iterate()1451 tcu::TestNode::IterateResult TestBase::iterate()
1452 {
1453 /* GL entry points */
1454 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1455
1456 /* Check extension support and version */
1457 m_is_explicit_uniform_location = Utils::isExtensionSupported(m_context, "GL_ARB_explicit_uniform_location");
1458 m_is_shader_language_420pack = Utils::isExtensionSupported(m_context, "GL_ARB_shading_language_420pack");
1459 m_is_compute_shader_supported = Utils::isGLVersionAtLeast(gl, 4, 3);
1460
1461 /* Execute test */
1462 bool test_result = test();
1463
1464 /* Set result */
1465 if (true == test_result)
1466 {
1467 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
1468 }
1469 else
1470 {
1471 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1472 }
1473
1474 /* Done */
1475 return tcu::TestNode::STOP;
1476 }
1477
1478 /** Basic implementation of getShaderSourceConfig method.
1479 *
1480 * @param out_n_parts Number of source parts used by this test case
1481 * @param out_use_lengths If source lengths shall be provided to compiler
1482 **/
getShaderSourceConfig(glw::GLuint & out_n_parts,bool & out_use_lengths)1483 void TestBase::getShaderSourceConfig(glw::GLuint &out_n_parts, bool &out_use_lengths)
1484 {
1485 out_n_parts = 1;
1486 out_use_lengths = false;
1487 }
1488
1489 /** Basic implementation of prepareNextTestCase method.
1490 *
1491 * @param test_case_index Index of test case
1492 *
1493 * @return true if index is -1 or 0, false otherwise
1494 **/
prepareNextTestCase(GLuint test_case_index)1495 bool TestBase::prepareNextTestCase(GLuint test_case_index)
1496 {
1497 if (((GLuint)-1 == test_case_index) || (0 == test_case_index))
1498 {
1499 return true;
1500 }
1501 else
1502 {
1503 return false;
1504 }
1505 }
1506
1507 /** Basic implementation of prepareUniforms method
1508 *
1509 * @param ignored
1510 **/
prepareUniforms(Utils::program &)1511 void TestBase::prepareUniforms(Utils::program & /* program */)
1512 {
1513 /* Nothing to be done */
1514 }
1515
1516 /** Basic implementation of testInit method
1517 *
1518 * @return true if test can be executed, false otherwise
1519 **/
testInit()1520 bool TestBase::testInit()
1521 {
1522 return true;
1523 }
1524
1525 /** Get layout specific for given stage
1526 *
1527 * @param stage Shader stage
1528 *
1529 * @return Stage specific part
1530 **/
getStageSpecificLayout(Utils::SHADER_STAGES stage) const1531 const GLchar *TestBase::getStageSpecificLayout(Utils::SHADER_STAGES stage) const
1532 {
1533 static const GLchar *stage_layout_geometry = "layout(points) in;\n"
1534 "layout(triangle_strip, max_vertices = 4) out;\n";
1535 static const GLchar *stage_layout_tess_ctrl = "layout(vertices = 1) out;\n";
1536 static const GLchar *stage_layout_tess_eval = "layout(isolines, point_mode) in;\n";
1537
1538 const GLchar *result = "";
1539
1540 switch (stage)
1541 {
1542 case Utils::GEOMETRY_SHADER:
1543 result = stage_layout_geometry;
1544 break;
1545 case Utils::TESS_CTRL_SHADER:
1546 result = stage_layout_tess_ctrl;
1547 break;
1548 case Utils::TESS_EVAL_SHADER:
1549 result = stage_layout_tess_eval;
1550 break;
1551 case Utils::VERTEX_SHADER:
1552 case Utils::FRAGMENT_SHADER:
1553 default:
1554 break;
1555 }
1556
1557 return result;
1558 }
1559
1560 /** Get "version" string
1561 *
1562 * @param stage Shader stage, compute shader will use 430
1563 * @param use_version_400 Select if 400 or 420 should be used
1564 *
1565 * @return Version string
1566 **/
getVersionString(Utils::SHADER_STAGES stage,bool use_version_400) const1567 const GLchar *TestBase::getVersionString(Utils::SHADER_STAGES stage, bool use_version_400) const
1568 {
1569 static const GLchar *version_400 = "#version 400\n"
1570 "#extension GL_ARB_shading_language_420pack : require\n"
1571 "#extension GL_ARB_separate_shader_objects : enable";
1572 static const GLchar *version_420 = "#version 420";
1573 static const GLchar *version_430 = "#version 430";
1574
1575 const GLchar *result = "";
1576
1577 if (Utils::COMPUTE_SHADER == stage)
1578 {
1579 result = version_430;
1580 }
1581 else if (true == use_version_400)
1582 {
1583 result = version_400;
1584 }
1585 else
1586 {
1587 result = version_420;
1588 }
1589
1590 return result;
1591 }
1592
1593 /** Initialize shaderSource instance, reserve storage and prepare shader source
1594 *
1595 * @param in_stage Shader stage
1596 * @param in_use_version_400 If version 400 or 420 should be used
1597 * @param out_source Shader source instance
1598 **/
initShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)1599 void TestBase::initShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400, Utils::shaderSource &out_source)
1600 {
1601 /* Shader source configuration */
1602 glw::GLuint n_parts = 0;
1603 bool use_lengths = false;
1604
1605 getShaderSourceConfig(n_parts, use_lengths);
1606
1607 out_source.m_parts.resize(n_parts);
1608 out_source.m_use_lengths = use_lengths;
1609
1610 /* Request child class to prepare shader sources */
1611 prepareShaderSource(in_stage, in_use_version_400, out_source);
1612
1613 /* Prepare source lengths */
1614 if (true == use_lengths)
1615 {
1616 for (GLuint i = 0; i < n_parts; ++i)
1617 {
1618 out_source.m_parts[i].m_length = static_cast<glw::GLint>(out_source.m_parts[i].m_code.length());
1619
1620 out_source.m_parts[i].m_code.append("This should be ignored by compiler, as source length is provided");
1621 }
1622 }
1623 else
1624 {
1625 for (GLuint i = 0; i < n_parts; ++i)
1626 {
1627 out_source.m_parts[i].m_length = 0;
1628 }
1629 }
1630 }
1631
1632 /** Execute test
1633 *
1634 * @return true if test pass, false otherwise
1635 **/
test()1636 bool TestBase::test()
1637 {
1638 bool result = true;
1639 GLuint test_case_index = 0;
1640
1641 /* Prepare test cases */
1642 testInit();
1643
1644 /* GL entry points */
1645 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1646
1647 /* Tesselation patch set up */
1648 gl.patchParameteri(GL_PATCH_VERTICES, 1);
1649 GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
1650
1651 while (true == prepareNextTestCase(test_case_index))
1652 {
1653 bool case_result = true;
1654
1655 /* Execute drawing case */
1656 if (false == testDrawArray(false))
1657 {
1658 case_result = false;
1659 }
1660
1661 if (true == m_is_shader_language_420pack)
1662 {
1663 if (false == testDrawArray(true))
1664 {
1665 case_result = false;
1666 }
1667 }
1668
1669 /* Execute compute shader case */
1670 if (true == m_is_compute_shader_supported)
1671 {
1672 if (false == testCompute())
1673 {
1674 case_result = false;
1675 }
1676 }
1677
1678 /* Log failure */
1679 if (false == case_result)
1680 {
1681 m_context.getTestContext().getLog()
1682 << tcu::TestLog::Message << "Test case failed." << tcu::TestLog::EndMessage;
1683
1684 result = false;
1685 }
1686
1687 /* Go to next test case */
1688 test_case_index += 1;
1689 }
1690
1691 /* Done */
1692 return result;
1693 }
1694
maxImageUniforms(Utils::SHADER_STAGES stage) const1695 int TestBase::maxImageUniforms(Utils::SHADER_STAGES stage) const
1696 {
1697 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1698 GLint max_image_uniforms;
1699
1700 switch (stage)
1701 {
1702 case Utils::COMPUTE_SHADER:
1703 gl.getIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &max_image_uniforms);
1704 break;
1705 case Utils::FRAGMENT_SHADER:
1706 gl.getIntegerv(GL_MAX_FRAGMENT_IMAGE_UNIFORMS, &max_image_uniforms);
1707 break;
1708 case Utils::GEOMETRY_SHADER:
1709 gl.getIntegerv(GL_MAX_GEOMETRY_IMAGE_UNIFORMS, &max_image_uniforms);
1710 break;
1711 case Utils::TESS_CTRL_SHADER:
1712 gl.getIntegerv(GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS, &max_image_uniforms);
1713 break;
1714 case Utils::TESS_EVAL_SHADER:
1715 gl.getIntegerv(GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS, &max_image_uniforms);
1716 break;
1717 case Utils::VERTEX_SHADER:
1718 gl.getIntegerv(GL_MAX_VERTEX_IMAGE_UNIFORMS, &max_image_uniforms);
1719 break;
1720 default:
1721 TCU_FAIL("Invalid enum");
1722 }
1723 return max_image_uniforms;
1724 }
1725
1726 /** Constructor
1727 *
1728 * @param context Test context
1729 * @param test_name Name of test
1730 * @param test_description Description of test
1731 **/
APITestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1732 APITestBase::APITestBase(deqp::Context &context, const glw::GLchar *test_name, const glw::GLchar *test_description)
1733 : TestBase(context, test_name, test_description)
1734 {
1735 /* Nothing to be done here */
1736 }
1737
1738 /** Execute test with compute shader
1739 *
1740 * @return true if test pass, false otherwise
1741 **/
testCompute()1742 bool APITestBase::testCompute()
1743 {
1744 /* GL objects */
1745 Utils::program program(m_context);
1746
1747 /* Shaders */
1748 Utils::shaderSource compute_shader;
1749 initShaderSource(Utils::COMPUTE_SHADER, false, compute_shader);
1750
1751 /* Check if test support compute shaders */
1752 if (true == compute_shader.m_parts[0].m_code.empty())
1753 {
1754 return true;
1755 }
1756
1757 /* Build program */
1758 try
1759 {
1760 program.build(compute_shader, 0 /* fragment shader */, 0 /* geometry shader */,
1761 0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
1762 0 /* varying names */, 0 /* n varying names */, false);
1763 }
1764 catch (Utils::shaderCompilationException &exc)
1765 {
1766 /* Something wrong with compilation, test case failed */
1767 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
1768
1769 message << "Shader compilation failed. Error message: " << exc.m_error_message;
1770
1771 Utils::program::printShaderSource(exc.m_shader_source, message);
1772
1773 message << tcu::TestLog::EndMessage;
1774
1775 return false;
1776 }
1777 catch (Utils::programLinkageException &exc)
1778 {
1779 /* Something wrong with linking, test case failed */
1780 m_context.getTestContext().getLog()
1781 << tcu::TestLog::Message << "Program linking failed. Error message: " << exc.m_error_message
1782 << tcu::TestLog::EndMessage;
1783 return false;
1784 }
1785
1786 /* Set current program */
1787 program.use();
1788
1789 /* Return result of verification */
1790 return checkResults(program);
1791 }
1792
1793 /** Execute test with VS, TCS, TES, GS and FS
1794 *
1795 * @param use_version_400 Select if 400 or 420 should be used
1796 *
1797 * @return true if test pass, false otherwise
1798 **/
testDrawArray(bool use_version_400)1799 bool APITestBase::testDrawArray(bool use_version_400)
1800 {
1801 /* GL objects */
1802 Utils::program program(m_context);
1803
1804 /* Shaders */
1805 Utils::shaderSource fragment_data;
1806 Utils::shaderSource geometry_data;
1807 Utils::shaderSource tess_ctrl_data;
1808 Utils::shaderSource tess_eval_data;
1809 Utils::shaderSource vertex_data;
1810
1811 initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
1812 initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
1813 initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
1814 initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
1815 initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
1816
1817 /* Build program */
1818 try
1819 {
1820 program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
1821 0 /* varying names */, 0 /* n varying names */, false);
1822 }
1823 catch (Utils::shaderCompilationException &exc)
1824 {
1825 /* Something wrong with compilation, test case failed */
1826 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
1827
1828 message << "Shader compilation failed. Error message: " << exc.m_error_message;
1829
1830 Utils::program::printShaderSource(exc.m_shader_source, message);
1831
1832 message << tcu::TestLog::EndMessage;
1833
1834 return false;
1835 }
1836 catch (Utils::programLinkageException &exc)
1837 {
1838 /* Something wrong with linking, test case failed */
1839 m_context.getTestContext().getLog()
1840 << tcu::TestLog::Message << "Program linking failed. Error message: " << exc.m_error_message
1841 << tcu::TestLog::EndMessage;
1842 return false;
1843 }
1844
1845 /* Set current program */
1846 program.use();
1847
1848 /* Return result of verification */
1849 return checkResults(program);
1850 }
1851
1852 /* Constants used by GLSLTestBase */
1853 const glw::GLenum GLSLTestBase::m_color_texture_internal_format = GL_RGBA8;
1854 const glw::GLenum GLSLTestBase::m_color_texture_format = GL_RGBA;
1855 const glw::GLenum GLSLTestBase::m_color_texture_type = GL_UNSIGNED_BYTE;
1856 const glw::GLuint GLSLTestBase::m_color_texture_width = 16;
1857 const glw::GLuint GLSLTestBase::m_color_texture_height = 16;
1858
1859 /** Constructor
1860 *
1861 * @param context Test context
1862 * @param test_name Test name
1863 * @param test_description Test description
1864 **/
GLSLTestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1865 GLSLTestBase::GLSLTestBase(deqp::Context &context, const glw::GLchar *test_name, const glw::GLchar *test_description)
1866 : TestBase(context, test_name, test_description)
1867 {
1868 /* Nothing to be done here */
1869 }
1870
1871 /** Basic implementation of prepareSourceTexture method.
1872 *
1873 * @param ignored Texture instance
1874 *
1875 * @return 0
1876 **/
prepareSourceTexture(Utils::texture &)1877 const GLchar *GLSLTestBase::prepareSourceTexture(Utils::texture &)
1878 {
1879 return 0;
1880 }
1881
1882 /** Basic implementation of prepareVertexBuffer method.
1883 *
1884 * @param ignored Program instance
1885 * @param ignored Buffer instance
1886 * @param vao VertexArray instance
1887 *
1888 * @return 0
1889 **/
prepareVertexBuffer(const Utils::program &,Utils::buffer &,Utils::vertexArray & vao)1890 void GLSLTestBase::prepareVertexBuffer(const Utils::program &, Utils::buffer &, Utils::vertexArray &vao)
1891 {
1892 vao.generate();
1893 vao.bind();
1894 }
1895
1896 /** Basic implementation of verifyAdditionalResults
1897 *
1898 * @return true
1899 **/
verifyAdditionalResults() const1900 bool GLSLTestBase::verifyAdditionalResults() const
1901 {
1902 return true;
1903 }
1904
1905 /** Basic implementation of releaseResource method
1906 *
1907 * @param ignored
1908 **/
releaseResource()1909 void GLSLTestBase::releaseResource()
1910 {
1911 /* Nothing to be done */
1912 }
1913
1914 /** Bind texture to first image unit and set image uniform to that unit
1915 *
1916 * @param program Program object
1917 * @param texture Texture object
1918 * @param uniform_name Name of image uniform
1919 **/
bindTextureToimage(Utils::program & program,Utils::texture & texture,const glw::GLchar * uniform_name) const1920 void GLSLTestBase::bindTextureToimage(Utils::program &program, Utils::texture &texture,
1921 const glw::GLchar *uniform_name) const
1922 {
1923 /* GL entry points */
1924 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1925
1926 gl.bindImageTexture(0 /* unit */, texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* layer */, GL_WRITE_ONLY,
1927 GL_RGBA8);
1928 GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
1929
1930 GLint location = program.getUniformLocation(uniform_name);
1931 gl.uniform1i(location, 0);
1932 GLU_EXPECT_NO_ERROR(gl.getError(), "Uniform1i");
1933 }
1934
1935 /** Bind texture to first texture unit and set sampler uniform to that unit
1936 *
1937 * @param program Program object
1938 * @param texture Texture object
1939 * @param uniform_name Name of sampler uniform
1940 **/
bindTextureToSampler(Utils::program & program,Utils::texture & texture,const glw::GLchar * uniform_name) const1941 void GLSLTestBase::bindTextureToSampler(Utils::program &program, Utils::texture &texture,
1942 const glw::GLchar *uniform_name) const
1943 {
1944 /* GL entry points */
1945 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1946
1947 gl.activeTexture(GL_TEXTURE0);
1948 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
1949
1950 texture.bind();
1951
1952 GLint location = program.getUniformLocation(uniform_name);
1953 gl.uniform1i(location, 0);
1954 GLU_EXPECT_NO_ERROR(gl.getError(), "Uniform1i");
1955 }
1956
1957 /** Check contents of texture. It is expected that it will be filled with green color
1958 *
1959 * @param color_texture Texture that will be verified
1960 *
1961 * @return true if texture is all green, false otherwise
1962 **/
checkResults(Utils::texture & color_texture) const1963 bool GLSLTestBase::checkResults(Utils::texture &color_texture) const
1964 {
1965 static const GLuint green_color = 0xff00ff00;
1966 const GLuint texture_data_size = m_color_texture_width * m_color_texture_height;
1967 std::vector<glw::GLuint> texture_data;
1968
1969 texture_data.resize(texture_data_size);
1970
1971 color_texture.get(m_color_texture_format, m_color_texture_type, &texture_data[0]);
1972
1973 for (GLuint i = 0; i < texture_data_size; ++i)
1974 {
1975 if (green_color != texture_data[i])
1976 {
1977 m_context.getTestContext().getLog()
1978 << tcu::TestLog::Message << "Invalid texel: " << std::setbase(16) << std::setfill('0') << std::setw(8)
1979 << texture_data[i] << " at index: " << i << tcu::TestLog::EndMessage;
1980
1981 return false;
1982 }
1983 }
1984
1985 return verifyAdditionalResults();
1986 }
1987
1988 /** Prepare framebuffer with texture used as attachment
1989 *
1990 * @param framebuffer Framebuffer
1991 * @param color_texture Textue used as color attachment 0
1992 **/
prepareFramebuffer(Utils::framebuffer & framebuffer,Utils::texture & color_texture) const1993 void GLSLTestBase::prepareFramebuffer(Utils::framebuffer &framebuffer, Utils::texture &color_texture) const
1994 {
1995 framebuffer.generate();
1996
1997 color_texture.create(m_color_texture_width, m_color_texture_height, m_color_texture_internal_format);
1998
1999 framebuffer.attachTexture(GL_COLOR_ATTACHMENT0, color_texture.m_id, m_color_texture_width, m_color_texture_height);
2000
2001 framebuffer.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2002 framebuffer.clear(GL_COLOR_BUFFER_BIT);
2003 }
2004
2005 /** Prepare texture and bind it to image uniform
2006 *
2007 * @param framebuffer Framebuffer
2008 * @param color_texture Textue used as color attachment 0
2009 **/
prepareImage(Utils::program & program,Utils::texture & color_texture) const2010 void GLSLTestBase::prepareImage(Utils::program &program, Utils::texture &color_texture) const
2011 {
2012 color_texture.create(m_color_texture_width, m_color_texture_height, m_color_texture_internal_format);
2013
2014 bindTextureToimage(program, color_texture, "uni_image");
2015 }
2016
2017 /** Execute test with compute shader
2018 *
2019 * @return true if test pass, false otherwise
2020 **/
testCompute()2021 bool GLSLTestBase::testCompute()
2022 {
2023 /* Test Result */
2024 bool result = true;
2025
2026 /* GL objects */
2027 Utils::texture color_tex(m_context);
2028 Utils::program program(m_context);
2029 Utils::texture source_tex(m_context);
2030
2031 /* Shaders */
2032 Utils::shaderSource compute_shader;
2033 initShaderSource(Utils::COMPUTE_SHADER, false, compute_shader);
2034
2035 /* Check if test support compute shaders */
2036 if (true == compute_shader.m_parts[0].m_code.empty())
2037 {
2038 return true;
2039 }
2040
2041 /* Build program */
2042 try
2043 {
2044 program.build(compute_shader, 0 /* fragment shader */, 0 /* geometry shader */,
2045 0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
2046 0 /* varying names */, 0 /* n varying names */, false);
2047 }
2048 catch (Utils::shaderCompilationException &exc)
2049 {
2050 /* Something wrong with compilation, test case failed */
2051 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2052
2053 message << "Shader compilation failed. Error message: " << exc.m_error_message;
2054
2055 Utils::program::printShaderSource(exc.m_shader_source, message);
2056
2057 message << tcu::TestLog::EndMessage;
2058
2059 return false;
2060 }
2061 catch (Utils::programLinkageException &exc)
2062 {
2063 /* Something wrong with linking, test case failed */
2064 m_context.getTestContext().getLog()
2065 << tcu::TestLog::Message << "Program linking failed. Error message: " << exc.m_error_message
2066 << tcu::TestLog::EndMessage;
2067 return false;
2068 }
2069
2070 /* Log shaders, for debugging */
2071 #if IS_DEBUG
2072 {
2073 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2074
2075 Utils::program::printShaderSource(compute_shader, message);
2076
2077 message << tcu::TestLog::EndMessage;
2078 }
2079 #endif /* IS_DEBUG */
2080
2081 /* Set current program */
2082 program.use();
2083
2084 /* Prepare image unit */
2085 prepareImage(program, color_tex);
2086
2087 /* Test specific preparation of source texture */
2088 const GLchar *sampler_name = prepareSourceTexture(source_tex);
2089 if (0 != sampler_name)
2090 {
2091 bindTextureToSampler(program, source_tex, sampler_name);
2092 }
2093
2094 /* Set up uniforms */
2095 prepareUniforms(program);
2096
2097 /* GL entry points */
2098 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2099
2100 /* Draw */
2101 gl.dispatchCompute(m_color_texture_width, m_color_texture_height, 1);
2102 GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
2103
2104 /* Return result of verification */
2105 result = checkResults(color_tex);
2106
2107 /* Release extra resource for the test */
2108 releaseResource();
2109
2110 return result;
2111 }
2112
2113 /** Execute test with draw array operation
2114 *
2115 * @param use_version_400 Select if 400 or 420 should be used
2116 *
2117 * @return true if test pass, false otherwise
2118 **/
testDrawArray(bool use_version_400)2119 bool GLSLTestBase::testDrawArray(bool use_version_400)
2120 {
2121 /* Test Result */
2122 bool result = true;
2123
2124 /* GL objects */
2125 Utils::texture color_tex(m_context);
2126 Utils::framebuffer framebuffer(m_context);
2127 Utils::program program(m_context);
2128 Utils::texture source_tex(m_context);
2129 Utils::vertexArray vao(m_context);
2130 Utils::buffer vertex_buffer(m_context);
2131
2132 /* Shaders */
2133 Utils::shaderSource fragment_data;
2134 Utils::shaderSource geometry_data;
2135 Utils::shaderSource tess_ctrl_data;
2136 Utils::shaderSource tess_eval_data;
2137 Utils::shaderSource vertex_data;
2138
2139 initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
2140 initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
2141 initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
2142 initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
2143 initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
2144
2145 /* Build program */
2146 try
2147 {
2148 program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
2149 0 /* varying names */, 0 /* n varying names */, false);
2150 }
2151 catch (Utils::shaderCompilationException &exc)
2152 {
2153 /* Something wrong with compilation, test case failed */
2154 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2155
2156 message << "Shader compilation failed. Error message: " << exc.m_error_message;
2157
2158 Utils::program::printShaderSource(exc.m_shader_source, message);
2159
2160 message << tcu::TestLog::EndMessage;
2161
2162 return false;
2163 }
2164 catch (Utils::programLinkageException &exc)
2165 {
2166 /* Something wrong with linking, test case failed */
2167 m_context.getTestContext().getLog()
2168 << tcu::TestLog::Message << "Program linking failed. Error message: " << exc.m_error_message
2169 << tcu::TestLog::EndMessage;
2170 return false;
2171 }
2172
2173 /* Log shaders, for debugging */
2174 #if IS_DEBUG
2175 {
2176 const Utils::shaderSource *data[] = {&vertex_data, &tess_ctrl_data, &tess_eval_data, &geometry_data,
2177 &fragment_data};
2178
2179 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2180
2181 for (GLuint i = 0; i < 5; ++i)
2182 {
2183 Utils::program::printShaderSource(*data[i], message);
2184 }
2185
2186 message << tcu::TestLog::EndMessage;
2187 }
2188 #endif /* IS_DEBUG */
2189
2190 /* Test specific preparation of vertex buffer and vao*/
2191 prepareVertexBuffer(program, vertex_buffer, vao);
2192
2193 /* Set current program */
2194 program.use();
2195
2196 /* Prepare framebuffer */
2197 prepareFramebuffer(framebuffer, color_tex);
2198
2199 /* Test specific preparation of source texture */
2200 const GLchar *sampler_name = prepareSourceTexture(source_tex);
2201 if (0 != sampler_name)
2202 {
2203 bindTextureToSampler(program, source_tex, sampler_name);
2204 }
2205
2206 /* Set up uniforms */
2207 prepareUniforms(program);
2208
2209 /* GL entry points */
2210 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2211
2212 /* Draw */
2213 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
2214 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
2215
2216 /* Return result of verification */
2217 result = checkResults(color_tex);
2218
2219 /* Release extra resource for the test */
2220 releaseResource();
2221
2222 return result;
2223 }
2224
2225 /** Constructor
2226 *
2227 * @param context Test context
2228 * @param test_name Test name
2229 * @param test_description Test description
2230 **/
NegativeTestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)2231 NegativeTestBase::NegativeTestBase(deqp::Context &context, const glw::GLchar *test_name,
2232 const glw::GLchar *test_description)
2233 : TestBase(context, test_name, test_description)
2234 {
2235 /* Nothing to be done here */
2236 }
2237
2238 /** Execute test with compute shader
2239 *
2240 * @return true if test pass, false otherwise
2241 **/
testCompute()2242 bool NegativeTestBase::testCompute()
2243 {
2244 /* GL objects */
2245 Utils::program program(m_context);
2246
2247 /* Shaders */
2248 Utils::shaderSource conmpute_data;
2249 initShaderSource(Utils::COMPUTE_SHADER, false, conmpute_data);
2250
2251 /* Build program */
2252 try
2253 {
2254 program.build(conmpute_data /* compute shader */, 0 /* fragment shader */, 0 /* geometry shader */,
2255 0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
2256 0 /* varying names */, 0 /* n varying names */, false);
2257 }
2258 catch (Utils::shaderCompilationException &exc)
2259 {
2260 /* Compilation failed, as expected. Verify that reason of failure is as expected */
2261 m_context.getTestContext().getLog()
2262 << tcu::TestLog::Message << "Shader compilation error message: " << exc.m_error_message
2263 << tcu::TestLog::EndMessage;
2264 return true;
2265 }
2266 catch (Utils::programLinkageException &exc)
2267 {
2268 /* Something wrong with linking, test case failed */
2269 m_context.getTestContext().getLog()
2270 << tcu::TestLog::Message << "Program linking failed. Error message: " << exc.m_error_message
2271 << tcu::TestLog::EndMessage;
2272 return true;
2273 }
2274
2275 /* Build process succeded */
2276 return false;
2277 }
2278
2279 /** Execute test with draw array operation
2280 *
2281 * @param use_version_400 Select if 400 or 420 should be used
2282 *
2283 * @return true if test pass, false otherwise
2284 **/
testDrawArray(bool use_version_400)2285 bool NegativeTestBase::testDrawArray(bool use_version_400)
2286 {
2287 /* GL objects */
2288 Utils::program program(m_context);
2289
2290 /* Shaders */
2291 Utils::shaderSource fragment_data;
2292 Utils::shaderSource geometry_data;
2293 Utils::shaderSource tess_ctrl_data;
2294 Utils::shaderSource tess_eval_data;
2295 Utils::shaderSource vertex_data;
2296
2297 initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
2298 initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
2299 initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
2300 initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
2301 initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
2302
2303 /* Build program */
2304 try
2305 {
2306 program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
2307 0 /* varying names */, 0 /* n varying names */, false);
2308 }
2309 catch (Utils::shaderCompilationException &exc)
2310 {
2311 /* Compilation failed, as expected. Verify that reason of failure is as expected */
2312 m_context.getTestContext().getLog()
2313 << tcu::TestLog::Message << "Shader compilation error message: " << exc.m_error_message
2314 << tcu::TestLog::EndMessage;
2315 return true;
2316 }
2317 catch (Utils::programLinkageException &exc)
2318 {
2319 /* Something wrong with linking, test case failed */
2320 m_context.getTestContext().getLog()
2321 << tcu::TestLog::Message << "Program linking failed. Error message: " << exc.m_error_message
2322 << tcu::TestLog::EndMessage;
2323 return true;
2324 }
2325
2326 /* Build process succeded */
2327 return false;
2328 }
2329
2330 /* Constants used by BindingImageTest */
2331 const GLuint BindingImageTest::m_width = 16;
2332 const GLuint BindingImageTest::m_green_color = 0xff00ff00;
2333 const GLuint BindingImageTest::m_height = 16;
2334 const GLuint BindingImageTest::m_depth = 6;
2335
2336 /** Constructor
2337 *
2338 * @param context Test context
2339 **/
BindingImageTest(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)2340 BindingImageTest::BindingImageTest(deqp::Context &context, const glw::GLchar *test_name,
2341 const glw::GLchar *test_description)
2342 : GLSLTestBase(context, test_name, test_description)
2343 {
2344 /* Nothing to be done */
2345 }
2346
2347 /** Prepare buffer, filled with given color
2348 *
2349 * @param buffer Buffer object
2350 * @param color Color
2351 **/
prepareBuffer(Utils::buffer & buffer,GLuint color)2352 void BindingImageTest::prepareBuffer(Utils::buffer &buffer, GLuint color)
2353 {
2354 std::vector<GLuint> texture_data;
2355 texture_data.resize(m_width);
2356
2357 buffer.generate(GL_TEXTURE_BUFFER);
2358
2359 for (GLuint i = 0; i < texture_data.size(); ++i)
2360 {
2361 texture_data[i] = color;
2362 }
2363
2364 buffer.update(m_width * sizeof(GLuint), &texture_data[0], GL_STATIC_DRAW);
2365 }
2366
2367 /** Prepare texture of given type filled with given color and bind to specified image unit
2368 *
2369 * @param texture Texture
2370 * @param buffer Buffer
2371 * @param texture_type Type of texture
2372 * @param color Color
2373 **/
prepareTexture(Utils::texture & texture,const Utils::buffer & buffer,Utils::TEXTURE_TYPES texture_type,GLuint color,GLuint unit)2374 void BindingImageTest::prepareTexture(Utils::texture &texture, const Utils::buffer &buffer,
2375 Utils::TEXTURE_TYPES texture_type, GLuint color, GLuint unit)
2376 {
2377 std::vector<GLuint> texture_data;
2378 texture_data.resize(m_width * m_height * m_depth);
2379
2380 GLboolean is_layered = GL_FALSE;
2381
2382 for (GLuint i = 0; i < texture_data.size(); ++i)
2383 {
2384 texture_data[i] = color;
2385 }
2386
2387 if (Utils::TEX_BUFFER != texture_type)
2388 {
2389 texture.create(m_width, m_height, m_depth, GL_RGBA8, texture_type);
2390
2391 texture.update(m_width, m_height, m_depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
2392 }
2393 else
2394 {
2395 buffer.bind();
2396
2397 texture.createBuffer(GL_RGBA8, buffer.m_id);
2398 }
2399
2400 switch (texture_type)
2401 {
2402 case Utils::TEX_1D_ARRAY:
2403 case Utils::TEX_2D_ARRAY:
2404 case Utils::TEX_3D:
2405 case Utils::TEX_CUBE:
2406 is_layered = GL_TRUE;
2407 break;
2408 default:
2409 break;
2410 }
2411
2412 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2413
2414 gl.bindImageTexture(unit, texture.m_id, 0 /* level */, is_layered /* layered */, 0 /* layer */, GL_READ_WRITE,
2415 GL_RGBA8);
2416 GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
2417 }
2418
2419 /** Verifies that texel at offset 0 is green
2420 *
2421 * @param buffer Buffer object
2422 *
2423 * @return true if texel at offset 0 is green, false otherwise
2424 **/
verifyBuffer(const Utils::buffer & buffer) const2425 bool BindingImageTest::verifyBuffer(const Utils::buffer &buffer) const
2426 {
2427 GLuint *data = (GLuint *)buffer.map(GL_READ_ONLY);
2428
2429 GLuint color = data[0];
2430
2431 buffer.unmap();
2432
2433 return (m_green_color == color);
2434 }
2435
2436 /** Verifies that texel at offset 0 is green
2437 *
2438 * @param buffer Buffer object
2439 *
2440 * @return true if texel at offset 0 is green, false otherwise
2441 **/
verifyTexture(const Utils::texture & texture) const2442 bool BindingImageTest::verifyTexture(const Utils::texture &texture) const
2443 {
2444 static const GLuint texture_data_size = m_width * m_height * m_depth;
2445
2446 std::vector<glw::GLuint> texture_data;
2447 texture_data.resize(texture_data_size);
2448
2449 texture.get(GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
2450
2451 GLuint color = texture_data[0];
2452
2453 return (m_green_color == color);
2454 }
2455
2456 /* Constants used by LineContinuationTest */
2457 const GLuint LineContinuationTest::m_n_repetitions = 20;
2458 const GLchar *LineContinuationTest::m_texture_coordinates_name = "texture_coordinates";
2459
2460 /** Constructor
2461 *
2462 * @param context Test context
2463 **/
LineContinuationTest(deqp::Context & context,testCase test_case)2464 LineContinuationTest::LineContinuationTest(deqp::Context &context, testCase test_case)
2465 : GLSLTestBase(context, "line_continuation", "desc")
2466 , m_test_case(test_case)
2467 {
2468 std::string name = "line_continuation_case_" + std::string(casesToStr(static_cast<CASES>(m_test_case.m_case))) +
2469 "_repetition_" +
2470 std::string(repetitionsToStr(static_cast<REPETITIONS>(m_test_case.m_repetitions))) + "_ending_" +
2471 std::string(lineEndingsToStr(static_cast<LINE_ENDINGS>(m_test_case.m_line_endings)));
2472
2473 TestCase::m_name = name;
2474 }
2475
2476 /** Overwrite getShaderSourceConfig method
2477 *
2478 * @param out_n_parts Number of source parts used by this test case
2479 * @param out_use_lengths If source lengths shall be provided to compiler
2480 **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)2481 void LineContinuationTest::getShaderSourceConfig(GLuint &out_n_parts, bool &out_use_lengths)
2482 {
2483 out_n_parts = (true == isShaderMultipart()) ? 2 : 1;
2484 out_use_lengths = useSourceLengths();
2485 }
2486
2487 /** Set up next test case
2488 *
2489 * @param test_case_index Index of next test case
2490 *
2491 * @return false if there is no more test cases, true otherwise
2492 **/
prepareNextTestCase(glw::GLuint test_case_index)2493 bool LineContinuationTest::prepareNextTestCase(glw::GLuint test_case_index)
2494 {
2495 if ((GLuint)-1 == test_case_index)
2496 {
2497 m_test_case.m_case = DEBUG_CASE;
2498 }
2499 if (test_case_index > 0)
2500 {
2501 return false;
2502 }
2503
2504 m_context.getTestContext().getLog() << tcu::TestLog::Message
2505 << "Test case: " << repetitionsToStr((REPETITIONS)m_test_case.m_repetitions)
2506 << " line continuation, with "
2507 << lineEndingsToStr((LINE_ENDINGS)m_test_case.m_line_endings)
2508 << " line endings, is placed " << casesToStr((CASES)m_test_case.m_case)
2509 << tcu::TestLog::EndMessage;
2510
2511 return true;
2512 }
2513
2514 /** Prepare source for given shader stage
2515 *
2516 * @param in_stage Shader stage, compute shader will use 430
2517 * @param in_use_version_400 Select if 400 or 420 should be used
2518 * @param out_source Prepared shader source instance
2519 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)2520 void LineContinuationTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
2521 Utils::shaderSource &out_source)
2522 {
2523 if (Utils::COMPUTE_SHADER == in_stage)
2524 {
2525 prepareComputShaderSource(out_source);
2526 }
2527 else
2528 {
2529 prepareShaderSourceForDraw(in_stage, in_use_version_400, out_source);
2530 }
2531 }
2532
2533 /** Prepare compute shader source
2534 *
2535 * @param source Result shader source
2536 **/
prepareComputShaderSource(Utils::shaderSource & source)2537 void LineContinuationTest::prepareComputShaderSource(Utils::shaderSource &source)
2538 {
2539 static const GLchar *shader_template_part_0 =
2540 "#version 430\n"
2541 "\n"
2542 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2543 "\n"
2544 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
2545 "\n"
2546 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2547 "\n"
2548 "writeonly uniform image2D uni_image;\n"
2549 " uniform sampler2D uni_sampler;\n"
2550 "\n"
2551 "void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2552 "{\n"
2553 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), inVARIABLE_CASE_value);\n"
2554 "}\n"
2555 "\n"
2556 "#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2557 "PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2558 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2559
2560 static const GLchar *shader_template_part_1 =
2561 "void main()\n"
2562 "{\n"
2563 " ivec2 coordinates ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE "
2564 "ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
2565 " vec4 sampled_color = texelFetch(uni_sampler, coordinates, 0 /* lod */);\n"
2566 " vec4 result = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2567 "\n"
2568 " if (vec4(0, 0, 1, 1) == sampled_color)\n"
2569 " {\n"
2570 " result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2571 " }\n"
2572 " else\n"
2573 " {\n"
2574 " result = vec4(coordinates.xy, sampled_color.rg);\n"
2575 " }\n"
2576 "\n"
2577 " SET_RESULT(result);"
2578 "}\n";
2579
2580 /* Init strings with templates and replace all CASE tokens */
2581 if (true == isShaderMultipart())
2582 {
2583 source.m_parts[0].m_code = shader_template_part_0;
2584 source.m_parts[1].m_code = shader_template_part_1;
2585
2586 replaceAllCaseTokens(source.m_parts[0].m_code);
2587 replaceAllCaseTokens(source.m_parts[1].m_code);
2588 }
2589 else
2590 {
2591 source.m_parts[0].m_code = shader_template_part_0;
2592 source.m_parts[0].m_code.append(shader_template_part_1);
2593
2594 replaceAllCaseTokens(source.m_parts[0].m_code);
2595 }
2596 }
2597
2598 /** Prepare source for given shader stage
2599 *
2600 * @param stage Shader stage, compute shader will use 430
2601 * @param use_version_400 Select if 400 or 420 should be used
2602 * @param source Result shader sources
2603 **/
prepareShaderSourceForDraw(Utils::SHADER_STAGES stage,bool use_version_400,Utils::shaderSource & source)2604 void LineContinuationTest::prepareShaderSourceForDraw(Utils::SHADER_STAGES stage, bool use_version_400,
2605 Utils::shaderSource &source)
2606 {
2607 /* Templates */
2608 static const GLchar *shader_template_part_0 =
2609 "VERSION\n"
2610 "\n"
2611 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2612 "\n"
2613 "STAGE_SPECIFIC\n"
2614 "\n"
2615 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2616 "\n"
2617 "IN_COLOR_DEFINITION\n"
2618 "IN_TEXTURE_COORDINATES_DEFINITION\n"
2619 "OUT_COLOR_DEFINITION\n"
2620 "OUT_TEXTURE_COORDINATES_DEFINITION\n"
2621 "uniform sampler2D uni_sampler;\n"
2622 "\n"
2623 "void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2624 "{\n"
2625 " OUT_COLOR ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE inVARIABLE_CASE_value;\n"
2626 "}\n"
2627 "\n"
2628 "#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2629 "PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2630 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2631
2632 static const GLchar *shader_template_part_1 =
2633 "void main()\n"
2634 "{\n"
2635 " vec2 coordinates = TEXTURE_COORDINATES;\n"
2636 " vec4 sampled_color = texture(uni_sampler, coordinates);\n"
2637 " vec4 result = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2638 "\n"
2639 " if (PASS_CONDITION)\n"
2640 " {\n"
2641 " result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2642 " }\n"
2643 " else\n"
2644 " {\n"
2645 " result = vec4(coordinates.xy, sampled_color.rg);\n"
2646 " }\n"
2647 "\n"
2648 "STORE_RESULTS"
2649 "}\n"
2650 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2651
2652 static const GLchar *store_results_template = " SET_RESULT(result);\n"
2653 " TEXTURE_COORDINATES = coordinates;\n";
2654
2655 static const GLchar *store_results_tcs_template = " SET_RESULT(result);\n"
2656 " TEXTURE_COORDINATES = coordinates;\n"
2657 " gl_TessLevelOuter[0] = 1.0;\n"
2658 " gl_TessLevelOuter[1] = 1.0;\n"
2659 " gl_TessLevelOuter[2] = 1.0;\n"
2660 " gl_TessLevelOuter[3] = 1.0;\n"
2661 " gl_TessLevelInner[0] = 1.0;\n"
2662 " gl_TessLevelInner[1] = 1.0;\n";
2663
2664 static const GLchar *store_results_fs_template = " SET_RESULT(result);\n";
2665
2666 static const GLchar *store_results_gs_template = " gl_Position = vec4(-1, -1, 0, 1);\n"
2667 " SET_RESULT(result);\n"
2668 " TEXTURE_COORDINATES = coordinates + vec2(-0.25, -0.25);\n"
2669 " EmitVertex();\n"
2670 " gl_Position = vec4(-1, 1, 0, 1);\n"
2671 " SET_RESULT(result);\n"
2672 " TEXTURE_COORDINATES = coordinates + vec2(-0.25, 0.25);\n"
2673 " EmitVertex();\n"
2674 " gl_Position = vec4(1, -1, 0, 1);\n"
2675 " SET_RESULT(result);\n"
2676 " TEXTURE_COORDINATES = coordinates + vec2(0.25, -0.25);\n"
2677 " EmitVertex();\n"
2678 " gl_Position = vec4(1, 1, 0, 1);\n"
2679 " SET_RESULT(result);\n"
2680 " TEXTURE_COORDINATES = coordinates + vec2(0.25, 0.25);\n"
2681 " EmitVertex();\n";
2682
2683 static const GLchar *pass_condition_template = "(EXPECTED_VALUE == sampled_color) &&\n"
2684 " (vec4(0, 1, 0, 1) == IN_COLOR) ";
2685
2686 static const GLchar *pass_condition_vs_template = "EXPECTED_VALUE == sampled_color";
2687
2688 /* Tokens to be replaced with GLSL stuff */
2689 static const GLchar *token_version = "VERSION";
2690 static const GLchar *token_stage_specific = "STAGE_SPECIFIC";
2691
2692 static const GLchar *token_in_color_definition = "IN_COLOR_DEFINITION";
2693 static const GLchar *token_in_tex_coord_definition = "IN_TEXTURE_COORDINATES_DEFINITION";
2694 static const GLchar *token_out_color_definition = "OUT_COLOR_DEFINITION";
2695 static const GLchar *token_out_tex_coord_definition = "OUT_TEXTURE_COORDINATES_DEFINITION";
2696
2697 static const GLchar *token_expected_value = "EXPECTED_VALUE";
2698 static const GLchar *token_texture_coordinates = "TEXTURE_COORDINATES";
2699 static const GLchar *token_in_color = "IN_COLOR";
2700 static const GLchar *token_out_color = "OUT_COLOR";
2701
2702 static const GLchar *token_store_results = "STORE_RESULTS";
2703 static const GLchar *token_pass_condition = "PASS_CONDITION";
2704
2705 /* Name of variable and empty string*/
2706 static const GLchar *color_name = "color";
2707 static const GLchar *empty = "";
2708
2709 /* GLSL stuff */
2710 const GLchar *version = getVersionString(stage, use_version_400);
2711 const GLchar *stage_specific_layout = getStageSpecificLayout(stage);
2712 const GLchar *expected_value = getExpectedValueString();
2713
2714 /* Qualifiers */
2715 Utils::qualifierSet in;
2716 Utils::qualifierSet out;
2717 in.push_back(Utils::QUAL_IN);
2718 out.push_back(Utils::QUAL_OUT);
2719
2720 /* In/Out variables definitions and references */
2721 std::string in_tex_coord_reference;
2722 std::string out_tex_coord_reference;
2723 std::string in_color_reference;
2724 std::string out_color_reference;
2725 std::string in_tex_coord_definition;
2726 std::string out_tex_coord_definition;
2727 std::string in_color_definition;
2728 std::string out_color_definition;
2729
2730 Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec2", m_texture_coordinates_name, in_tex_coord_definition,
2731 in_tex_coord_reference);
2732 Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec2", m_texture_coordinates_name,
2733 out_tex_coord_definition, out_tex_coord_reference);
2734 Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec4", color_name, in_color_definition, in_color_reference);
2735 Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec4", color_name, out_color_definition,
2736 out_color_reference);
2737
2738 in_tex_coord_definition.append(";");
2739 out_tex_coord_definition.append(";");
2740 in_color_definition.append(";");
2741 out_color_definition.append(";");
2742
2743 /* Select pass condition and store results tempaltes */
2744 const GLchar *store_results = store_results_template;
2745 const GLchar *pass_condition = pass_condition_template;
2746
2747 switch (stage)
2748 {
2749 case Utils::FRAGMENT_SHADER:
2750 store_results = store_results_fs_template;
2751 break;
2752 case Utils::GEOMETRY_SHADER:
2753 store_results = store_results_gs_template;
2754 break;
2755 case Utils::TESS_CTRL_SHADER:
2756 store_results = store_results_tcs_template;
2757 break;
2758 case Utils::VERTEX_SHADER:
2759 pass_condition = pass_condition_vs_template;
2760 break;
2761 default:
2762 break;
2763 }
2764 const GLuint store_results_length = static_cast<GLuint>(strlen(store_results));
2765 const GLuint pass_condition_length = static_cast<GLuint>(strlen(pass_condition));
2766
2767 /* Init strings with templates and replace all CASE tokens */
2768 if (true == isShaderMultipart())
2769 {
2770 source.m_parts[0].m_code = shader_template_part_0;
2771 source.m_parts[1].m_code = shader_template_part_1;
2772
2773 replaceAllCaseTokens(source.m_parts[0].m_code);
2774 replaceAllCaseTokens(source.m_parts[1].m_code);
2775 }
2776 else
2777 {
2778 source.m_parts[0].m_code = shader_template_part_0;
2779 source.m_parts[0].m_code.append(shader_template_part_1);
2780
2781 replaceAllCaseTokens(source.m_parts[0].m_code);
2782 }
2783
2784 /* Get memory for shader source parts */
2785 const bool is_multipart = isShaderMultipart();
2786 size_t position = 0;
2787 std::string &shader_source_part_0 = source.m_parts[0].m_code;
2788 std::string &shader_source_part_1 = (true == is_multipart) ? source.m_parts[1].m_code : source.m_parts[0].m_code;
2789
2790 /* Replace tokens */
2791 /* Part 0 */
2792 Utils::replaceToken(token_version, position, version, shader_source_part_0);
2793
2794 Utils::replaceToken(token_stage_specific, position, stage_specific_layout, shader_source_part_0);
2795
2796 if (Utils::VERTEX_SHADER != stage)
2797 {
2798 Utils::replaceToken(token_in_color_definition, position, in_color_definition.c_str(), shader_source_part_0);
2799 }
2800 else
2801 {
2802 Utils::replaceToken(token_in_color_definition, position, empty, shader_source_part_0);
2803 }
2804 Utils::replaceToken(token_in_tex_coord_definition, position, in_tex_coord_definition.c_str(), shader_source_part_0);
2805 Utils::replaceToken(token_out_color_definition, position, out_color_definition.c_str(), shader_source_part_0);
2806 if (Utils::FRAGMENT_SHADER == stage)
2807 {
2808 Utils::replaceToken(token_out_tex_coord_definition, position, empty, shader_source_part_0);
2809 }
2810 else
2811 {
2812 Utils::replaceToken(token_out_tex_coord_definition, position, out_tex_coord_definition.c_str(),
2813 shader_source_part_0);
2814 }
2815
2816 Utils::replaceToken(token_out_color, position, out_color_reference.c_str(), shader_source_part_0);
2817
2818 /* Part 1 */
2819 if (true == is_multipart)
2820 {
2821 position = 0;
2822 }
2823
2824 Utils::replaceToken(token_texture_coordinates, position, in_tex_coord_reference.c_str(), shader_source_part_1);
2825
2826 Utils::replaceToken(token_pass_condition, position, pass_condition, shader_source_part_1);
2827 position -= pass_condition_length;
2828
2829 Utils::replaceToken(token_expected_value, position, expected_value, shader_source_part_1);
2830 if (Utils::VERTEX_SHADER != stage)
2831 {
2832 Utils::replaceToken(token_in_color, position, in_color_reference.c_str(), shader_source_part_1);
2833 }
2834
2835 Utils::replaceToken(token_store_results, position, store_results, shader_source_part_1);
2836 position -= store_results_length;
2837
2838 if (Utils::GEOMETRY_SHADER == stage)
2839 {
2840 for (GLuint i = 0; i < 4; ++i)
2841 {
2842 Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(),
2843 shader_source_part_1);
2844 }
2845 }
2846 else if (Utils::FRAGMENT_SHADER == stage)
2847 {
2848 /* Nothing to be done */
2849 }
2850 else
2851 {
2852 Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(), shader_source_part_1);
2853 }
2854 }
2855
2856 /** Prepare texture
2857 *
2858 * @param texture Texutre to be created and filled with content
2859 *
2860 * @return Name of sampler uniform that should be used for the texture
2861 **/
prepareSourceTexture(Utils::texture & texture)2862 const GLchar *LineContinuationTest::prepareSourceTexture(Utils::texture &texture)
2863 {
2864 std::vector<GLuint> data;
2865 static const GLuint width = 64;
2866 static const GLuint height = 64;
2867 static const GLuint data_size = width * height;
2868 static const GLuint blue_color = 0xffff0000;
2869 static const GLuint grey_color = 0xaaaaaaaa;
2870
2871 data.resize(data_size);
2872
2873 for (GLuint i = 0; i < data_size; ++i)
2874 {
2875 data[i] = grey_color;
2876 }
2877
2878 for (GLuint y = 16; y < 48; ++y)
2879 {
2880 const GLuint line_offset = y * 64;
2881
2882 for (GLuint x = 16; x < 48; ++x)
2883 {
2884 const GLuint pixel_offset = x + line_offset;
2885
2886 data[pixel_offset] = blue_color;
2887 }
2888 }
2889
2890 texture.create(width, height, GL_RGBA8);
2891
2892 texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
2893
2894 return "uni_sampler";
2895 }
2896
2897 /** Prepare vertex buffer, vec2 tex_coord
2898 *
2899 * @param program Program object
2900 * @param buffer Vertex buffer
2901 * @param vao Vertex array object
2902 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)2903 void LineContinuationTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
2904 Utils::vertexArray &vao)
2905 {
2906 std::string tex_coord_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, m_texture_coordinates_name);
2907 GLint tex_coord_loc = program.getAttribLocation(tex_coord_name.c_str());
2908
2909 if (-1 == tex_coord_loc)
2910 {
2911 TCU_FAIL("Vertex attribute location is invalid");
2912 }
2913
2914 vao.generate();
2915 vao.bind();
2916
2917 buffer.generate(GL_ARRAY_BUFFER);
2918
2919 GLfloat data[] = {0.5f, 0.5f, 0.5f, 0.5f};
2920 GLsizeiptr data_size = sizeof(data);
2921
2922 buffer.update(data_size, data, GL_STATIC_DRAW);
2923
2924 /* GL entry points */
2925 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2926
2927 /* Set up vao */
2928 gl.vertexAttribPointer(tex_coord_loc, 2 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
2929 0 /* offset */);
2930 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
2931
2932 /* Enable attribute */
2933 gl.enableVertexAttribArray(tex_coord_loc);
2934 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
2935 }
2936
2937 /** Get string describing test cases
2938 *
2939 * @param cases Test case
2940 *
2941 * @return String describing current test case
2942 **/
casesToStr(CASES cases) const2943 const GLchar *LineContinuationTest::casesToStr(CASES cases) const
2944 {
2945 const GLchar *result = 0;
2946 switch (cases)
2947 {
2948 case ASSIGNMENT_BEFORE_OPERATOR:
2949 result = "just_before_assignment_operator";
2950 break;
2951 case ASSIGNMENT_AFTER_OPERATOR:
2952 result = "just_after_assignment_operator";
2953 break;
2954 case VECTOR_VARIABLE_INITIALIZER:
2955 result = "inside_vector_variable_initializer";
2956 break;
2957 case TOKEN_INSIDE_FUNCTION_NAME:
2958 result = "inside_function_name";
2959 break;
2960 case TOKEN_INSIDE_TYPE_NAME:
2961 result = "inside_type_name";
2962 break;
2963 case TOKEN_INSIDE_VARIABLE_NAME:
2964 result = "inside_variable_name";
2965 break;
2966 case PREPROCESSOR_TOKEN_INSIDE:
2967 result = "inside_preprocessor_token";
2968 break;
2969 case PREPROCESSOR_TOKEN_BETWEEN:
2970 result = "between_preprocessor_token";
2971 break;
2972 case COMMENT:
2973 result = "inside_comment";
2974 break;
2975 case SOURCE_TERMINATION_NULL:
2976 result = "just_before_null_terminating_source";
2977 break;
2978 case SOURCE_TERMINATION_NON_NULL:
2979 result = "as_last_character_in_source_string_without_null_termination";
2980 break;
2981 case PART_TERMINATION_NULL:
2982 result = "just_before_null_terminating_part_of_source";
2983 break;
2984 case PART_NEXT_TO_TERMINATION_NULL:
2985 result = "just_before_last_character_in_part_of_source";
2986 break;
2987 case PART_TERMINATION_NON_NULL:
2988 result = "as_last_character_in_part_string_without_null_termination";
2989 break;
2990 case PART_NEXT_TO_TERMINATION_NON_NULL:
2991 result = "just_before_last_character_in_part_string_without_null_termination";
2992 break;
2993 case DEBUG_CASE: /* intended fall through */
2994 default:
2995 result = "nowhere_at_all_This_is_debug";
2996 break;
2997 }
2998
2999 return result;
3000 }
3001
3002 /** Get expected value, blue color as vec4
3003 *
3004 * @return blue color
3005 **/
getExpectedValueString() const3006 const GLchar *LineContinuationTest::getExpectedValueString() const
3007 {
3008 return "vec4(0, 0, 1, 1)";
3009 }
3010
3011 /** Get line continuation string, single or multiple \
3012 *
3013 * @return String
3014 **/
getLineContinuationString() const3015 std::string LineContinuationTest::getLineContinuationString() const
3016 {
3017 static const GLchar line_continuation_ending_dos[] = {'\\', 0x0d, 0x0a, 0x00};
3018 static const GLchar line_continuation_ending_unix[] = {'\\', 0x0a, 0x00};
3019
3020 std::string result;
3021 const GLchar *selected_string;
3022
3023 if (DOS == m_test_case.m_line_endings)
3024 {
3025 selected_string = line_continuation_ending_dos;
3026 }
3027 else
3028 {
3029 selected_string = line_continuation_ending_unix;
3030 }
3031
3032 GLuint n_repetitions = (ONCE == m_test_case.m_repetitions) ? 1 : m_n_repetitions;
3033
3034 for (GLuint i = 0; i < n_repetitions; ++i)
3035 {
3036 result.append(selected_string);
3037 }
3038
3039 return result;
3040 }
3041
3042 /** Decides if shader should consist of multiple parts for the current test case
3043 *
3044 * @return true if test case requires multiple parts, false otherwise
3045 **/
isShaderMultipart() const3046 bool LineContinuationTest::isShaderMultipart() const
3047 {
3048 bool result;
3049
3050 switch (m_test_case.m_case)
3051 {
3052 case ASSIGNMENT_BEFORE_OPERATOR:
3053 case ASSIGNMENT_AFTER_OPERATOR:
3054 case VECTOR_VARIABLE_INITIALIZER:
3055 case TOKEN_INSIDE_FUNCTION_NAME:
3056 case TOKEN_INSIDE_TYPE_NAME:
3057 case TOKEN_INSIDE_VARIABLE_NAME:
3058 case PREPROCESSOR_TOKEN_INSIDE:
3059 case PREPROCESSOR_TOKEN_BETWEEN:
3060 case COMMENT:
3061 case SOURCE_TERMINATION_NULL:
3062 case SOURCE_TERMINATION_NON_NULL:
3063 default:
3064 result = false;
3065 break;
3066 case PART_TERMINATION_NULL:
3067 case PART_NEXT_TO_TERMINATION_NULL:
3068 case PART_TERMINATION_NON_NULL:
3069 case PART_NEXT_TO_TERMINATION_NON_NULL:
3070 result = true;
3071 break;
3072 }
3073
3074 return result;
3075 }
3076
3077 /** String describing line endings
3078 *
3079 * @param line_ending Line ending enum
3080 *
3081 * @return "unix" or "dos" strings
3082 **/
lineEndingsToStr(LINE_ENDINGS line_ending) const3083 const GLchar *LineContinuationTest::lineEndingsToStr(LINE_ENDINGS line_ending) const
3084 {
3085 const GLchar *result = 0;
3086
3087 if (UNIX == line_ending)
3088 {
3089 result = "unix";
3090 }
3091 else
3092 {
3093 result = "dos";
3094 }
3095
3096 return result;
3097 }
3098
3099 /** String describing number of repetitions
3100 *
3101 * @param repetitions Repetitions enum
3102 *
3103 * @return "single" or "multiple" strings
3104 **/
repetitionsToStr(REPETITIONS repetitions) const3105 const GLchar *LineContinuationTest::repetitionsToStr(REPETITIONS repetitions) const
3106 {
3107 const GLchar *result = 0;
3108
3109 if (ONCE == repetitions)
3110 {
3111 result = "single";
3112 }
3113 else
3114 {
3115 result = "multiple";
3116 }
3117
3118 return result;
3119 }
3120
3121 /** Replace all CASES tokens
3122 *
3123 * @param source String with shader template
3124 **/
replaceAllCaseTokens(std::string & source) const3125 void LineContinuationTest::replaceAllCaseTokens(std::string &source) const
3126 {
3127
3128 /* Tokens to be replaced with line continuation */
3129 static const GLchar *token_assignment_before_operator_case = "ASSIGNMENT_BEFORE_OPERATOR_CASE";
3130 static const GLchar *token_assignment_after_operator_case = "ASSIGNMENT_AFTER_OPERATOR_CASE";
3131 static const GLchar *token_vector_initializer = "VECTOR_VARIABLE_INITIALIZER_CASE";
3132 static const GLchar *token_function_case = "FUNCTION_CASE";
3133 static const GLchar *token_type_case = "TYPE_CASE";
3134 static const GLchar *token_variable_case = "VARIABLE_CASE";
3135 static const GLchar *token_preprocessor_inside_case = "PREPROCESSOR_INSIDE_CASE";
3136 static const GLchar *token_preprocessor_between_case = "PREPROCESSOR_BETWEEN_CASE";
3137 static const GLchar *token_comment = "COMMENT_CASE";
3138 static const GLchar *token_termination = "TERMINATION_CASE";
3139 static const GLchar *token_next_to_termination = "NEXT_TO_TERMINATION_CASE";
3140
3141 /* Line continuation and empty string*/
3142 static const GLchar *empty = "";
3143 const std::string &line_continuation = getLineContinuationString();
3144
3145 /* These strings will used to replace "CASE" tokens */
3146 const GLchar *assignment_before_operator_case = empty;
3147 const GLchar *assignment_after_operator_case = empty;
3148 const GLchar *vector_variable_initializer_case = empty;
3149 const GLchar *function_case = empty;
3150 const GLchar *type_case = empty;
3151 const GLchar *variable_case = empty;
3152 const GLchar *preprocessor_inside_case = empty;
3153 const GLchar *preprocessor_between_case = empty;
3154 const GLchar *comment_case = empty;
3155 const GLchar *source_termination_case = empty;
3156 const GLchar *part_termination_case = empty;
3157 const GLchar *next_to_part_termination_case = empty;
3158
3159 /* Configuration of test case */
3160 switch (m_test_case.m_case)
3161 {
3162 case ASSIGNMENT_BEFORE_OPERATOR:
3163 assignment_before_operator_case = line_continuation.c_str();
3164 break;
3165 case ASSIGNMENT_AFTER_OPERATOR:
3166 assignment_after_operator_case = line_continuation.c_str();
3167 break;
3168 case VECTOR_VARIABLE_INITIALIZER:
3169 vector_variable_initializer_case = line_continuation.c_str();
3170 break;
3171 case TOKEN_INSIDE_FUNCTION_NAME:
3172 function_case = line_continuation.c_str();
3173 break;
3174 case TOKEN_INSIDE_TYPE_NAME:
3175 type_case = line_continuation.c_str();
3176 break;
3177 case TOKEN_INSIDE_VARIABLE_NAME:
3178 variable_case = line_continuation.c_str();
3179 break;
3180 case PREPROCESSOR_TOKEN_INSIDE:
3181 preprocessor_inside_case = line_continuation.c_str();
3182 break;
3183 case PREPROCESSOR_TOKEN_BETWEEN:
3184 preprocessor_between_case = line_continuation.c_str();
3185 break;
3186 case COMMENT:
3187 comment_case = line_continuation.c_str();
3188 break;
3189 case SOURCE_TERMINATION_NULL: /* intended fall through */
3190 case SOURCE_TERMINATION_NON_NULL:
3191 source_termination_case = line_continuation.c_str();
3192 break;
3193 case PART_TERMINATION_NULL: /* intended fall through */
3194 case PART_TERMINATION_NON_NULL:
3195 part_termination_case = line_continuation.c_str();
3196 source_termination_case = line_continuation.c_str();
3197 break;
3198 case PART_NEXT_TO_TERMINATION_NULL: /* intended fall through */
3199 case PART_NEXT_TO_TERMINATION_NON_NULL:
3200 next_to_part_termination_case = line_continuation.c_str();
3201 break;
3202 case DEBUG_CASE: /* intended fall through */
3203 default:
3204 break; /* no line continuations */
3205 }
3206
3207 Utils::replaceAllTokens(token_assignment_after_operator_case, assignment_after_operator_case, source);
3208 Utils::replaceAllTokens(token_assignment_before_operator_case, assignment_before_operator_case, source);
3209 Utils::replaceAllTokens(token_comment, comment_case, source);
3210 Utils::replaceAllTokens(token_function_case, function_case, source);
3211 Utils::replaceAllTokens(token_next_to_termination, next_to_part_termination_case, source);
3212 Utils::replaceAllTokens(token_termination, part_termination_case, source);
3213 Utils::replaceAllTokens(token_preprocessor_between_case, preprocessor_between_case, source);
3214 Utils::replaceAllTokens(token_preprocessor_inside_case, preprocessor_inside_case, source);
3215 Utils::replaceAllTokens(token_termination, source_termination_case, source);
3216 Utils::replaceAllTokens(token_type_case, type_case, source);
3217 Utils::replaceAllTokens(token_variable_case, variable_case, source);
3218 Utils::replaceAllTokens(token_vector_initializer, vector_variable_initializer_case, source);
3219 }
3220
3221 /** Decides if the current test case requires source lengths
3222 *
3223 * @return true if test requires lengths, false otherwise
3224 **/
useSourceLengths() const3225 bool LineContinuationTest::useSourceLengths() const
3226 {
3227 bool result;
3228
3229 switch (m_test_case.m_case)
3230 {
3231 case ASSIGNMENT_BEFORE_OPERATOR:
3232 case ASSIGNMENT_AFTER_OPERATOR:
3233 case VECTOR_VARIABLE_INITIALIZER:
3234 case TOKEN_INSIDE_FUNCTION_NAME:
3235 case TOKEN_INSIDE_TYPE_NAME:
3236 case TOKEN_INSIDE_VARIABLE_NAME:
3237 case PREPROCESSOR_TOKEN_INSIDE:
3238 case PREPROCESSOR_TOKEN_BETWEEN:
3239 case COMMENT:
3240 case SOURCE_TERMINATION_NULL:
3241 case PART_TERMINATION_NULL:
3242 case PART_NEXT_TO_TERMINATION_NULL:
3243 default:
3244 result = false;
3245 break;
3246 case SOURCE_TERMINATION_NON_NULL:
3247 case PART_TERMINATION_NON_NULL:
3248 case PART_NEXT_TO_TERMINATION_NON_NULL:
3249 result = true;
3250 break;
3251 }
3252
3253 return result;
3254 }
3255
3256 /** Constructor
3257 *
3258 * @param context Test context
3259 **/
LineNumberingTest(deqp::Context & context)3260 LineNumberingTest::LineNumberingTest(deqp::Context &context)
3261 : GLSLTestBase(context, "line_numbering", "Verify if line numbering is correct after line continuation")
3262 {
3263 /* Nothing to be done here */
3264 }
3265
3266 /** Prepare source for given shader stage
3267 *
3268 * @param in_stage Shader stage, compute shader will use 430
3269 * @param in_use_version_400 Select if 400 or 420 should be used
3270 * @param out_source Prepared shader source instance
3271 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3272 void LineNumberingTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3273 Utils::shaderSource &out_source)
3274 {
3275 static const GLchar *test_result_snippet_normal[6] = {/* Utils::COMPUTE_SHADER */
3276 "ivec4(11, 1, 2, 3)",
3277 /* Utils::VERTEX_SHADER */
3278 "ivec4(9, 1, 2, 3)",
3279 /* Utils::TESS_CTRL_SHADER */
3280 "ivec4(12, 1, 2, 3)",
3281 /* Utils::TESS_EVAL_SHADER */
3282 "ivec4(12, 1, 2, 3)",
3283 /* Utils::GEOMETRY_SHADER */
3284 "ivec4(13, 1, 2, 3)",
3285 /* Utils::FRAGMENT_SHADER */
3286 "ivec4(10, 1, 2, 3)"};
3287
3288 static const GLchar *test_result_snippet_400[6] = {/* Utils::COMPUTE_SHADER */
3289 "ivec4(13, 1, 2, 3)",
3290 /* Utils::VERTEX_SHADER */
3291 "ivec4(11, 1, 2, 3)",
3292 /* Utils::TESS_CTRL_SHADER */
3293 "ivec4(14, 1, 2, 3)",
3294 /* Utils::TESS_EVAL_SHADER */
3295 "ivec4(14, 1, 2, 3)",
3296 /* Utils::GEOMETRY_SHADER */
3297 "ivec4(15, 1, 2, 3)",
3298 /* Utils::FRAGMENT_SHADER */
3299 "ivec4(12, 1, 2, 3)"};
3300
3301 static const GLchar *line_numbering_snippet = "ivec4 glsl\\\n"
3302 "Test\\\n"
3303 "Function(in ivec3 arg)\n"
3304 "{\n"
3305 " return ivec4(__LINE__, arg.xyz);\n"
3306 "}\n";
3307
3308 static const GLchar *compute_shader_template =
3309 "VERSION\n"
3310 "\n"
3311 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3312 "\n"
3313 "writeonly uniform image2D uni_image;\n"
3314 "\n"
3315 "GLSL_TEST_FUNCTION"
3316 "\n"
3317 "void main()\n"
3318 "{\n"
3319 " vec4 result = vec4(1, 0, 0, 1);\n"
3320 "\n"
3321 " if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3322 " {\n"
3323 " result = vec4(0, 1, 0, 1);\n"
3324 " }\n"
3325 "\n"
3326 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3327 "}\n"
3328 "\n";
3329
3330 static const GLchar *fragment_shader_template =
3331 "VERSION\n"
3332 "\n"
3333 "in vec4 gs_fs_result;\n"
3334 "out vec4 fs_out_result;\n"
3335 "\n"
3336 "GLSL_TEST_FUNCTION"
3337 "\n"
3338 "void main()\n"
3339 "{\n"
3340 " vec4 result = vec4(1, 0, 0, 1);\n"
3341 "\n"
3342 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3343 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3344 " {\n"
3345 " result = vec4(0, 1, 0, 1);\n"
3346 " }\n"
3347 "\n"
3348 " fs_out_result = result;\n"
3349 "}\n"
3350 "\n";
3351
3352 static const GLchar *geometry_shader_template =
3353 "VERSION\n"
3354 "\n"
3355 "layout(points) in;\n"
3356 "layout(triangle_strip, max_vertices = 4) out;\n"
3357 "\n"
3358 "in vec4 tes_gs_result[];\n"
3359 "out vec4 gs_fs_result;\n"
3360 "\n"
3361 "GLSL_TEST_FUNCTION"
3362 "\n"
3363 "void main()\n"
3364 "{\n"
3365 " vec4 result = vec4(1, 0, 0, 1);\n"
3366 "\n"
3367 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3368 " (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3369 " {\n"
3370 " result = vec4(0, 1, 0, 1);\n"
3371 " }\n"
3372 "\n"
3373 " gs_fs_result = result;\n"
3374 " gl_Position = vec4(-1, -1, 0, 1);\n"
3375 " EmitVertex();\n"
3376 " gs_fs_result = result;\n"
3377 " gl_Position = vec4(-1, 1, 0, 1);\n"
3378 " EmitVertex();\n"
3379 " gs_fs_result = result;\n"
3380 " gl_Position = vec4(1, -1, 0, 1);\n"
3381 " EmitVertex();\n"
3382 " gs_fs_result = result;\n"
3383 " gl_Position = vec4(1, 1, 0, 1);\n"
3384 " EmitVertex();\n"
3385 "}\n"
3386 "\n";
3387
3388 static const GLchar *tess_ctrl_shader_template =
3389 "VERSION\n"
3390 "\n"
3391 "layout(vertices = 1) out;\n"
3392 "\n"
3393 "in vec4 vs_tcs_result[];\n"
3394 "out vec4 tcs_tes_result[];\n"
3395 "\n"
3396 "GLSL_TEST_FUNCTION"
3397 "\n"
3398 "void main()\n"
3399 "{\n"
3400 " vec4 result = vec4(1, 0, 0, 1);\n"
3401 "\n"
3402 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3403 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3404 " {\n"
3405 " result = vec4(0, 1, 0, 1);\n"
3406 " }\n"
3407 "\n"
3408 " tcs_tes_result[gl_InvocationID] = result;\n"
3409 "\n"
3410 " gl_TessLevelOuter[0] = 1.0;\n"
3411 " gl_TessLevelOuter[1] = 1.0;\n"
3412 " gl_TessLevelOuter[2] = 1.0;\n"
3413 " gl_TessLevelOuter[3] = 1.0;\n"
3414 " gl_TessLevelInner[0] = 1.0;\n"
3415 " gl_TessLevelInner[1] = 1.0;\n"
3416 "}\n"
3417 "\n";
3418
3419 static const GLchar *tess_eval_shader_template =
3420 "VERSION\n"
3421 "\n"
3422 "layout(isolines, point_mode) in;\n"
3423 "\n"
3424 "in vec4 tcs_tes_result[];\n"
3425 "out vec4 tes_gs_result;\n"
3426 "\n"
3427 "GLSL_TEST_FUNCTION"
3428 "\n"
3429 "void main()\n"
3430 "{\n"
3431 " vec4 result = vec4(1, 0, 0, 1);\n"
3432 "\n"
3433 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3434 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3435 " {\n"
3436 " result = vec4(0, 1, 0, 1);\n"
3437 " }\n"
3438 "\n"
3439 " tes_gs_result = result;\n"
3440 "}\n"
3441 "\n";
3442
3443 static const GLchar *vertex_shader_template = "VERSION\n"
3444 "\n"
3445 "out vec4 vs_tcs_result;\n"
3446 "\n"
3447 "GLSL_TEST_FUNCTION"
3448 "\n"
3449 "void main()\n"
3450 "{\n"
3451 " vec4 result = vec4(1, 0, 0, 1);\n"
3452 "\n"
3453 " if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3454 " {\n"
3455 " result = vec4(0, 1, 0, 1);\n"
3456 " }\n"
3457 "\n"
3458 " vs_tcs_result = result;\n"
3459 "}\n"
3460 "\n";
3461
3462 const GLchar *shader_template = 0;
3463
3464 switch (in_stage)
3465 {
3466 case Utils::COMPUTE_SHADER:
3467 shader_template = compute_shader_template;
3468 break;
3469 case Utils::FRAGMENT_SHADER:
3470 shader_template = fragment_shader_template;
3471 break;
3472 case Utils::GEOMETRY_SHADER:
3473 shader_template = geometry_shader_template;
3474 break;
3475 case Utils::TESS_CTRL_SHADER:
3476 shader_template = tess_ctrl_shader_template;
3477 break;
3478 case Utils::TESS_EVAL_SHADER:
3479 shader_template = tess_eval_shader_template;
3480 break;
3481 case Utils::VERTEX_SHADER:
3482 shader_template = vertex_shader_template;
3483 break;
3484 default:
3485 TCU_FAIL("Invalid enum");
3486 }
3487
3488 out_source.m_parts[0].m_code = shader_template;
3489
3490 size_t position = 0;
3491 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3492 out_source.m_parts[0].m_code);
3493
3494 Utils::replaceToken("GLSL_TEST_FUNCTION", position, line_numbering_snippet, out_source.m_parts[0].m_code);
3495
3496 Utils::replaceToken("GLSL_TEST_RESULT", position,
3497 in_use_version_400 ? test_result_snippet_400[in_stage] : test_result_snippet_normal[in_stage],
3498 out_source.m_parts[0].m_code);
3499 }
3500
3501 /** Constructor
3502 *
3503 * @param context Test context
3504 **/
UTF8CharactersTest(deqp::Context & context,testCase test_case)3505 UTF8CharactersTest::UTF8CharactersTest(deqp::Context &context, testCase test_case)
3506 : GLSLTestBase(context, "utf8_characters", "UTF8 character used in comment or preprocessor")
3507 , m_test_case(test_case)
3508 {
3509 std::string name =
3510 "utf8_characters_case_" + std::string(casesToStr()) + "_character_" + std::string(characterToStr());
3511
3512 TestCase::m_name = name;
3513 }
3514
3515 /** Overwrite getShaderSourceConfig method
3516 *
3517 * @param out_n_parts Number of source parts used by this test case
3518 * @param out_use_lengths If source lengths shall be provided to compiler
3519 **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)3520 void UTF8CharactersTest::getShaderSourceConfig(GLuint &out_n_parts, bool &out_use_lengths)
3521 {
3522 out_n_parts = 1;
3523 out_use_lengths = (AS_LAST_CHARACTER_NON_NULL_TERMINATED == m_test_case.m_case) ? true : false;
3524 }
3525
3526 /** Set up next test case
3527 *
3528 * @param test_case_index Index of next test case
3529 *
3530 * @return false if there is no more test cases, true otherwise
3531 **/
prepareNextTestCase(glw::GLuint test_case_index)3532 bool UTF8CharactersTest::prepareNextTestCase(glw::GLuint test_case_index)
3533 {
3534 if ((GLuint)-1 == test_case_index)
3535 {
3536 m_test_case.m_case = DEBUG_CASE;
3537 m_test_case.m_character = Utils::EMPTY;
3538 }
3539 if (test_case_index > 0)
3540 {
3541 return false;
3542 }
3543
3544 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case: utf8 character: "
3545 << Utils::getUtf8Character(m_test_case.m_character) << " is placed "
3546 << casesToStr() << tcu::TestLog::EndMessage;
3547
3548 return true;
3549 }
3550
3551 /** Prepare source for given shader stage
3552 *
3553 * @param in_stage Shader stage, compute shader will use 430
3554 * @param in_use_version_400 Select if 400 or 420 should be used
3555 * @param out_source Prepared shader source instance
3556 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3557 void UTF8CharactersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3558 Utils::shaderSource &out_source)
3559 {
3560 static const GLchar *compute_shader_template =
3561 "VERSION\n"
3562 "\n"
3563 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3564 "\n"
3565 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3566 "\n"
3567 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3568 "\n"
3569 "writeonly uniform image2D uni_image;\n"
3570 " uniform sampler2D uni_sampler;\n"
3571 "\n"
3572 "#if 0\n"
3573 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3574 "#else\n"
3575 " #define SET_RESULT(XX) result = XX\n"
3576 "#endif\n"
3577 "\n"
3578 "void main()\n"
3579 "{\n"
3580 " ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
3581 " vec4 result = vec4(1, 0, 0, 1);\n"
3582 "\n"
3583 " if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
3584 " {\n"
3585 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3586 " }\n"
3587 "\n"
3588 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3589 "}\n"
3590 "// Lorem ipsum LAST_CHARACTER_CASE";
3591
3592 static const GLchar *fragment_shader_template =
3593 "VERSION\n"
3594 "\n"
3595 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3596 "\n"
3597 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3598 "\n"
3599 "in vec4 gs_fs_result;\n"
3600 "in vec2 gs_fs_tex_coord;\n"
3601 "out vec4 fs_out_result;\n"
3602 "uniform sampler2D uni_sampler;\n"
3603 "\n"
3604 "#if 0\n"
3605 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3606 "#else\n"
3607 " #define SET_RESULT(XX) result = XX\n"
3608 "#endif\n"
3609 "\n"
3610 "void main()\n"
3611 "{\n"
3612 " vec4 result = vec4(1, 0, 0, 1);\n"
3613 "\n"
3614 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
3615 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3616 " {\n"
3617 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3618 " }\n"
3619 "\n"
3620 " fs_out_result = result;\n"
3621 "}\n"
3622 "// Lorem ipsum LAST_CHARACTER_CASE";
3623
3624 static const GLchar *geometry_shader_template =
3625 "VERSION\n"
3626 "\n"
3627 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3628 "\n"
3629 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3630 "\n"
3631 "layout(points) in;\n"
3632 "layout(triangle_strip, max_vertices = 4) out;\n"
3633 "\n"
3634 "in vec4 tes_gs_result[];\n"
3635 "out vec2 gs_fs_tex_coord;\n"
3636 "out vec4 gs_fs_result;\n"
3637 "uniform sampler2D uni_sampler;\n"
3638 "\n"
3639 "#if 0\n"
3640 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3641 "#else\n"
3642 " #define SET_RESULT(XX) result = XX\n"
3643 "#endif\n"
3644 "\n"
3645 "void main()\n"
3646 "{\n"
3647 " vec4 result = vec4(1, 0, 0, 1);\n"
3648 "\n"
3649 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
3650 " (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3651 " {\n"
3652 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3653 " }\n"
3654 "\n"
3655 " gs_fs_tex_coord = vec2(0.25, 0.25);\n"
3656 " gs_fs_result = result;\n"
3657 " gl_Position = vec4(-1, -1, 0, 1);\n"
3658 " EmitVertex();\n"
3659 " gs_fs_tex_coord = vec2(0.25, 0.75);\n"
3660 " gs_fs_result = result;\n"
3661 " gl_Position = vec4(-1, 1, 0, 1);\n"
3662 " EmitVertex();\n"
3663 " gs_fs_tex_coord = vec2(0.75, 0.25);\n"
3664 " gs_fs_result = result;\n"
3665 " gl_Position = vec4(1, -1, 0, 1);\n"
3666 " EmitVertex();\n"
3667 " gs_fs_tex_coord = vec2(0.75, 0.75);\n"
3668 " gs_fs_result = result;\n"
3669 " gl_Position = vec4(1, 1, 0, 1);\n"
3670 " EmitVertex();\n"
3671 "}\n"
3672 "// Lorem ipsum LAST_CHARACTER_CASE";
3673
3674 static const GLchar *tess_ctrl_shader_template =
3675 "VERSION\n"
3676 "\n"
3677 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3678 "\n"
3679 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3680 "\n"
3681 "layout(vertices = 1) out;\n"
3682 "\n"
3683 "in vec4 vs_tcs_result[];\n"
3684 "out vec4 tcs_tes_result[];\n"
3685 "uniform sampler2D uni_sampler;\n"
3686 "\n"
3687 "#if 0\n"
3688 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3689 "#else\n"
3690 " #define SET_RESULT(XX) result = XX\n"
3691 "#endif\n"
3692 "\n"
3693 "void main()\n"
3694 "{\n"
3695 " vec4 result = vec4(1, 0, 0, 1);\n"
3696 "\n"
3697 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
3698 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3699 " {\n"
3700 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3701 " }\n"
3702 "\n"
3703 " tcs_tes_result[gl_InvocationID] = result;\n"
3704 "\n"
3705 " gl_TessLevelOuter[0] = 1.0;\n"
3706 " gl_TessLevelOuter[1] = 1.0;\n"
3707 " gl_TessLevelOuter[2] = 1.0;\n"
3708 " gl_TessLevelOuter[3] = 1.0;\n"
3709 " gl_TessLevelInner[0] = 1.0;\n"
3710 " gl_TessLevelInner[1] = 1.0;\n"
3711 "}\n"
3712 "// Lorem ipsum LAST_CHARACTER_CASE";
3713
3714 static const GLchar *tess_eval_shader_template =
3715 "VERSION\n"
3716 "\n"
3717 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3718 "\n"
3719 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3720 "\n"
3721 "layout(isolines, point_mode) in;\n"
3722 "\n"
3723 "in vec4 tcs_tes_result[];\n"
3724 "out vec4 tes_gs_result;\n"
3725 "uniform sampler2D uni_sampler;\n"
3726 "\n"
3727 "#if 0\n"
3728 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3729 "#else\n"
3730 " #define SET_RESULT(XX) result = XX\n"
3731 "#endif\n"
3732 "\n"
3733 "void main()\n"
3734 "{\n"
3735 " vec4 result = vec4(1, 0, 0, 1);\n"
3736 "\n"
3737 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
3738 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3739 " {\n"
3740 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3741 " }\n"
3742 "\n"
3743 " tes_gs_result = result;\n"
3744 "}\n"
3745 "// Lorem ipsum LAST_CHARACTER_CASE";
3746
3747 static const GLchar *vertex_shader_template =
3748 "VERSION\n"
3749 "\n"
3750 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3751 "\n"
3752 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3753 "\n"
3754 "out vec4 vs_tcs_result;\n"
3755 "uniform sampler2D uni_sampler;\n"
3756 "\n"
3757 "#if 0\n"
3758 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3759 "#else\n"
3760 " #define SET_RESULT(XX) result = XX\n"
3761 "#endif\n"
3762 "\n"
3763 "void main()\n"
3764 "{\n"
3765 " vec4 result = vec4(1, 0, 0, 1);\n"
3766 "\n"
3767 " if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
3768 " {\n"
3769 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3770 " }\n"
3771 "\n"
3772 " vs_tcs_result = result;\n"
3773 "}\n"
3774 "// Lorem ipsum LAST_CHARACTER_CASE";
3775
3776 const GLchar *shader_template = 0;
3777 const GLchar *comment_case = "";
3778 const GLchar *preprocessor_case = "";
3779 const GLchar *last_character_case = "";
3780 const GLchar *utf8_character = Utils::getUtf8Character(m_test_case.m_character);
3781
3782 switch (in_stage)
3783 {
3784 case Utils::COMPUTE_SHADER:
3785 shader_template = compute_shader_template;
3786 break;
3787 case Utils::FRAGMENT_SHADER:
3788 shader_template = fragment_shader_template;
3789 break;
3790 case Utils::GEOMETRY_SHADER:
3791 shader_template = geometry_shader_template;
3792 break;
3793 case Utils::TESS_CTRL_SHADER:
3794 shader_template = tess_ctrl_shader_template;
3795 break;
3796 case Utils::TESS_EVAL_SHADER:
3797 shader_template = tess_eval_shader_template;
3798 break;
3799 case Utils::VERTEX_SHADER:
3800 shader_template = vertex_shader_template;
3801 break;
3802 default:
3803 TCU_FAIL("Invalid enum");
3804 }
3805
3806 switch (m_test_case.m_case)
3807 {
3808 case IN_COMMENT:
3809 comment_case = utf8_character;
3810 break;
3811 case IN_PREPROCESSOR:
3812 preprocessor_case = utf8_character;
3813 break;
3814 case AS_LAST_CHARACTER_NULL_TERMINATED:
3815 last_character_case = utf8_character;
3816 break;
3817 case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
3818 last_character_case = utf8_character;
3819 break;
3820 case DEBUG_CASE:
3821 break;
3822 default:
3823 TCU_FAIL("Invalid enum");
3824 }
3825
3826 out_source.m_parts[0].m_code = shader_template;
3827
3828 size_t position = 0;
3829 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3830 out_source.m_parts[0].m_code);
3831
3832 Utils::replaceAllTokens("COMMENT_CASE", comment_case, out_source.m_parts[0].m_code);
3833
3834 Utils::replaceAllTokens("PREPROCESSOR_CASE", preprocessor_case, out_source.m_parts[0].m_code);
3835
3836 Utils::replaceAllTokens("LAST_CHARACTER_CASE", last_character_case, out_source.m_parts[0].m_code);
3837 }
3838
3839 /** Prepare texture
3840 *
3841 * @param texture Texutre to be created and filled with content
3842 *
3843 * @return Name of sampler uniform that should be used for the texture
3844 **/
prepareSourceTexture(Utils::texture & texture)3845 const GLchar *UTF8CharactersTest::prepareSourceTexture(Utils::texture &texture)
3846 {
3847 std::vector<GLuint> data;
3848 static const GLuint width = 64;
3849 static const GLuint height = 64;
3850 static const GLuint data_size = width * height;
3851 static const GLuint blue_color = 0xffff0000;
3852 static const GLuint grey_color = 0xaaaaaaaa;
3853
3854 data.resize(data_size);
3855
3856 for (GLuint i = 0; i < data_size; ++i)
3857 {
3858 data[i] = grey_color;
3859 }
3860
3861 for (GLuint y = 16; y < 48; ++y)
3862 {
3863 const GLuint line_offset = y * 64;
3864
3865 for (GLuint x = 16; x < 48; ++x)
3866 {
3867 const GLuint pixel_offset = x + line_offset;
3868
3869 data[pixel_offset] = blue_color;
3870 }
3871 }
3872
3873 texture.create(width, height, GL_RGBA8);
3874
3875 texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
3876
3877 return "uni_sampler";
3878 }
3879
3880 /** Returns description of current test case
3881 *
3882 * @return String with description
3883 **/
casesToStr() const3884 const GLchar *UTF8CharactersTest::casesToStr() const
3885 {
3886 const GLchar *result = 0;
3887
3888 switch (m_test_case.m_case)
3889 {
3890 case IN_COMMENT:
3891 result = "in_comment";
3892 break;
3893 case IN_PREPROCESSOR:
3894 result = "in_preprocessor";
3895 break;
3896 case AS_LAST_CHARACTER_NULL_TERMINATED:
3897 result = "just_before_null";
3898 break;
3899 case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
3900 result = "as_last_character";
3901 break;
3902 case DEBUG_CASE:
3903 result = "nowhere. This is debug!";
3904 break;
3905 default:
3906 TCU_FAIL("Invalid enum");
3907 }
3908
3909 return result;
3910 }
3911
characterToStr() const3912 const GLchar *UTF8CharactersTest::characterToStr() const
3913 {
3914 const GLchar *result = 0;
3915
3916 switch (m_test_case.m_character)
3917 {
3918 case Utils::TWO_BYTES:
3919 result = "two_bytes";
3920 break;
3921 case Utils::THREE_BYTES:
3922 result = "three_bytes";
3923 break;
3924 case Utils::FOUR_BYTES:
3925 result = "four_bytes";
3926 break;
3927 case Utils::FIVE_BYTES:
3928 result = "five_bytes";
3929 break;
3930 case Utils::SIX_BYTES:
3931 result = "six_bytes";
3932 break;
3933 case Utils::REDUNDANT_ASCII:
3934 result = "redundant_bytes";
3935 break;
3936 case Utils::EMPTY:
3937 result = "empty";
3938 }
3939
3940 return result;
3941 }
3942
3943 /** Constructor
3944 *
3945 * @param context Test context
3946 **/
UTF8InSourceTest(deqp::Context & context,Utils::UTF8_CHARACTERS character)3947 UTF8InSourceTest::UTF8InSourceTest(deqp::Context &context, Utils::UTF8_CHARACTERS character)
3948 : NegativeTestBase(context, "utf8_in_source", "UTF8 characters used in shader source")
3949 , m_character(character)
3950 {
3951 std::string name = "utf8_in_source_character_" + std::string(characterToStr());
3952
3953 TestCase::m_name = name;
3954 }
3955
characterToStr() const3956 const GLchar *UTF8InSourceTest::characterToStr() const
3957 {
3958 const GLchar *result = 0;
3959
3960 switch (m_character)
3961 {
3962 case Utils::TWO_BYTES:
3963 result = "two_bytes";
3964 break;
3965 case Utils::THREE_BYTES:
3966 result = "three_bytes";
3967 break;
3968 case Utils::FOUR_BYTES:
3969 result = "four_bytes";
3970 break;
3971 case Utils::FIVE_BYTES:
3972 result = "five_bytes";
3973 break;
3974 case Utils::SIX_BYTES:
3975 result = "six_bytes";
3976 break;
3977 case Utils::REDUNDANT_ASCII:
3978 result = "redundant_bytes";
3979 break;
3980 case Utils::EMPTY:
3981 result = "empty";
3982 }
3983
3984 return result;
3985 }
3986
3987 /** Set up next test case
3988 *
3989 * @param test_case_index Index of next test case
3990 *
3991 * @return false if there is no more test cases, true otherwise
3992 **/
prepareNextTestCase(glw::GLuint test_case_index)3993 bool UTF8InSourceTest::prepareNextTestCase(glw::GLuint test_case_index)
3994 {
3995 if ((GLuint)-1 == test_case_index)
3996 {
3997 m_character = Utils::EMPTY;
3998 }
3999 else if (test_case_index > 0)
4000 {
4001 return false;
4002 }
4003
4004 m_context.getTestContext().getLog() << tcu::TestLog::Message
4005 << "Test case: utf8 character: " << Utils::getUtf8Character(m_character)
4006 << tcu::TestLog::EndMessage;
4007
4008 return true;
4009 }
4010
4011 /** Prepare source for given shader stage
4012 *
4013 * @param in_stage Shader stage, compute shader will use 430
4014 * @param in_use_version_400 Select if 400 or 420 should be used
4015 * @param out_source Prepared shader source instance
4016 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4017 void UTF8InSourceTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4018 Utils::shaderSource &out_source)
4019 {
4020 static const GLchar *compute_shader_template =
4021 "VERSION\n"
4022 "\n"
4023 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4024 "\n"
4025 "writeonly uniform image2D uni_image;\n"
4026 " uniform sampler2D uni_sampler;\n"
4027 "\n"
4028 "#define SET_RESULT(XX) resHEREult = XX\n"
4029 "\n"
4030 "void main()\n"
4031 "{\n"
4032 " ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
4033 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4034 "\n"
4035 " if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
4036 " {\n"
4037 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4038 " }\n"
4039 "\n"
4040 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), resHEREult);\n"
4041 "}\n"
4042 "";
4043
4044 static const GLchar *fragment_shader_template =
4045 "VERSION\n"
4046 "\n"
4047 "in vec4 gs_fs_result;\n"
4048 "in vec2 gs_fs_tex_coord;\n"
4049 "out vec4 fs_out_result;\n"
4050 "uniform sampler2D uni_sampler;\n"
4051 "\n"
4052 "#define SET_RESULT(XX) resHEREult = XX\n"
4053 "\n"
4054 "void main()\n"
4055 "{\n"
4056 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4057 "\n"
4058 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
4059 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
4060 " {\n"
4061 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4062 " }\n"
4063 "\n"
4064 " fs_out_result = resHEREult;\n"
4065 "}\n"
4066 "\n";
4067
4068 static const GLchar *geometry_shader_template =
4069 "VERSION\n"
4070 "\n"
4071 "layout(points) in;\n"
4072 "layout(triangle_strip, max_vertices = 4) out;\n"
4073 "\n"
4074 "in vec4 tes_gHEREs_result[];\n"
4075 "out vec2 gs_fs_tex_coord;\n"
4076 "out vec4 gs_fs_result;\n"
4077 "uniform sampler2D uni_sampler;\n"
4078 "\n"
4079 "#define SET_RESULT(XX) result = XX\n"
4080 "\n"
4081 "void main()\n"
4082 "{\n"
4083 " vec4 result = vec4(1, 0, 0, 1);\n"
4084 "\n"
4085 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
4086 " (vec4(0, 1, 0, 1) == tes_gHEREs_result[0]) )\n"
4087 " {\n"
4088 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4089 " }\n"
4090 "\n"
4091 " gs_fs_tex_coord = vec2(0.25, 0.25);\n"
4092 " gs_fs_result = result;\n"
4093 " gl_Position = vec4(-1, -1, 0, 1);\n"
4094 " EmitVertex();\n"
4095 " gs_fs_tex_coord = vec2(0.25, 0.75);\n"
4096 " gs_fs_result = result;\n"
4097 " gl_Position = vec4(-1, 1, 0, 1);\n"
4098 " EmitVertex();\n"
4099 " gs_fs_tex_coord = vec2(0.75, 0.25);\n"
4100 " gs_fs_result = result;\n"
4101 " gl_Position = vec4(1, -1, 0, 1);\n"
4102 " EmitVertex();\n"
4103 " gs_fs_tex_coord = vec2(0.75, 0.75);\n"
4104 " gs_fs_result = result;\n"
4105 " gl_Position = vec4(1, 1, 0, 1);\n"
4106 " EmitVertex();\n"
4107 "}\n"
4108 "\n";
4109
4110 static const GLchar *tess_ctrl_shader_template =
4111 "VERSION\n"
4112 "\n"
4113 "layout(vertices = 1) out;\n"
4114 "\n"
4115 "in vec4 vs_tcs_result[];\n"
4116 "out vec4 tcHEREs_tes_result[];\n"
4117 "uniform sampler2D uni_sampler;\n"
4118 "\n"
4119 "#define SET_RESULT(XX) resulHEREt = XX\n"
4120 "\n"
4121 "void main()\n"
4122 "{\n"
4123 " vec4 resulHEREt = vec4(1, 0, 0, 1);\n"
4124 "\n"
4125 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
4126 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
4127 " {\n"
4128 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4129 " }\n"
4130 "\n"
4131 " tcHEREs_tes_result[gl_InvocationID] = resulHEREt;\n"
4132 "\n"
4133 " gl_TessLevelOuter[0] = 1.0;\n"
4134 " gl_TessLevelOuter[1] = 1.0;\n"
4135 " gl_TessLevelOuter[2] = 1.0;\n"
4136 " gl_TessLevelOuter[3] = 1.0;\n"
4137 " gl_TessLevelInner[0] = 1.0;\n"
4138 " gl_TessLevelInner[1] = 1.0;\n"
4139 "}\n"
4140 "\n";
4141
4142 static const GLchar *tess_eval_shader_template =
4143 "VERSION\n"
4144 "\n"
4145 "layout(isolines, point_mode) in;\n"
4146 "\n"
4147 "in vec4 tcs_tes_result[];\n"
4148 "out vec4 teHEREs_gs_result;\n"
4149 "uniform sampler2D uni_sampler;\n"
4150 "\n"
4151 "#define SET_RESULT(XX) reHEREsult = XX\n"
4152 "\n"
4153 "void main()\n"
4154 "{\n"
4155 " vec4 reHEREsult = vec4(1, 0, 0, 1);\n"
4156 "\n"
4157 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
4158 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
4159 " {\n"
4160 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4161 " }\n"
4162 "\n"
4163 " teHEREs_gs_result = reHEREsult;\n"
4164 "}\n"
4165 "\n";
4166
4167 static const GLchar *vertex_shader_template = "VERSION\n"
4168 "\n"
4169 "out vec4 vs_tcs_HEREresult;\n"
4170 "uniform sampler2D uni_sampler;\n"
4171 "\n"
4172 "#define SET_RHEREESULT(XX) resHEREult = XX\n"
4173 "\n"
4174 "void main()\n"
4175 "{\n"
4176 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4177 "\n"
4178 " if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
4179 " {\n"
4180 " SET_RHEREESULT(vec4(0, 1, 0, 1));\n"
4181 " }\n"
4182 "\n"
4183 " vs_tcs_HEREresult = resHEREult;\n"
4184 "}\n"
4185 "\n";
4186
4187 const GLchar *shader_template = 0;
4188 const GLchar *utf8_character = Utils::getUtf8Character(m_character);
4189
4190 switch (in_stage)
4191 {
4192 case Utils::COMPUTE_SHADER:
4193 shader_template = compute_shader_template;
4194 break;
4195 case Utils::FRAGMENT_SHADER:
4196 shader_template = fragment_shader_template;
4197 break;
4198 case Utils::GEOMETRY_SHADER:
4199 shader_template = geometry_shader_template;
4200 break;
4201 case Utils::TESS_CTRL_SHADER:
4202 shader_template = tess_ctrl_shader_template;
4203 break;
4204 case Utils::TESS_EVAL_SHADER:
4205 shader_template = tess_eval_shader_template;
4206 break;
4207 case Utils::VERTEX_SHADER:
4208 shader_template = vertex_shader_template;
4209 break;
4210 default:
4211 TCU_FAIL("Invalid enum");
4212 }
4213
4214 out_source.m_parts[0].m_code = shader_template;
4215
4216 size_t position = 0;
4217 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4218 out_source.m_parts[0].m_code);
4219
4220 Utils::replaceAllTokens("HERE", utf8_character, out_source.m_parts[0].m_code);
4221 }
4222
4223 /** Constructor
4224 *
4225 * @param context Test context
4226 **/
ImplicitConversionsValidTest(deqp::Context & context,testCase test_case)4227 ImplicitConversionsValidTest::ImplicitConversionsValidTest(deqp::Context &context, testCase test_case)
4228 : GLSLTestBase(context, "implicit_conversions", "Verifies that implicit conversions are allowed")
4229 {
4230 m_debug_test_case.m_types.m_t1 = Utils::FLOAT;
4231 m_debug_test_case.m_types.m_t2 = Utils::FLOAT;
4232 m_debug_test_case.m_n_cols = 4;
4233 m_debug_test_case.m_n_rows = 4;
4234
4235 m_test_cases.push_back(test_case);
4236
4237 std::string name = "implicit_conversions_case_t1_" +
4238 std::string(Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols, test_case.m_n_rows)) +
4239 "_t2_" +
4240 std::string(Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols, test_case.m_n_rows));
4241
4242 TestCase::m_name = name;
4243 }
4244
4245 /** Set up next test case
4246 *
4247 * @param test_case_index Index of next test case
4248 *
4249 * @return false if there is no more test cases, true otherwise
4250 **/
prepareNextTestCase(glw::GLuint test_case_index)4251 bool ImplicitConversionsValidTest::prepareNextTestCase(glw::GLuint test_case_index)
4252 {
4253 m_current_test_case_index = test_case_index;
4254
4255 if ((glw::GLuint)-1 == test_case_index)
4256 {
4257 return true;
4258 }
4259 else if (m_test_cases.size() <= test_case_index)
4260 {
4261 return false;
4262 }
4263
4264 const testCase &test_case = m_test_cases[test_case_index];
4265
4266 m_context.getTestContext().getLog() << tcu::TestLog::Message << "T1:"
4267 << Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols,
4268 test_case.m_n_rows)
4269 << " T2:"
4270 << Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols,
4271 test_case.m_n_rows)
4272 << tcu::TestLog::EndMessage;
4273
4274 return true;
4275 }
4276
4277 /** Prepare source for given shader stage
4278 *
4279 * @param in_stage Shader stage, compute shader will use 430
4280 * @param in_use_version_400 Select if 400 or 420 should be used
4281 * @param out_source Prepared shader source instance
4282 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4283 void ImplicitConversionsValidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4284 Utils::shaderSource &out_source)
4285 {
4286 static const GLchar *function_definition = "T1 function(in T2 left, in T2 right)\n"
4287 "{\n"
4288 " return left + right;\n"
4289 "}\n";
4290
4291 static const GLchar *verification_snippet = " const T2 const_left = T2(VALUE_LIST);\n"
4292 " const T2 const_right = T2(VALUE_LIST);\n"
4293 "\n"
4294 " T1 const_result = function(const_left, const_right);\n"
4295 "\n"
4296 " T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4297 "\n"
4298 " T2 var_left = uni_left;\n"
4299 " T2 var_right = uni_right;\n"
4300 "\n"
4301 " T1 var_result = function(var_left, var_right);\n"
4302 "\n"
4303 " if ((literal_result != const_result) ||\n"
4304 " (const_result != var_result) )\n"
4305 " {\n"
4306 " result = vec4(1, 0, 0, 1);\n"
4307 " }\n";
4308
4309 static const GLchar *compute_shader_template =
4310 "VERSION\n"
4311 "\n"
4312 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4313 "\n"
4314 "writeonly uniform image2D uni_image;\n"
4315 " uniform T2 uni_left;\n"
4316 " uniform T2 uni_right;\n"
4317 "\n"
4318 "FUNCTION_DEFINITION"
4319 "\n"
4320 "void main()\n"
4321 "{\n"
4322 " vec4 result = vec4(0, 1, 0, 1);\n"
4323 "\n"
4324 "VERIFICATION"
4325 "\n"
4326 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4327 "}\n"
4328 "\n";
4329
4330 static const GLchar *fragment_shader_template = "VERSION\n"
4331 "\n"
4332 "in vec4 gs_fs_result;\n"
4333 "out vec4 fs_out_result;\n"
4334 "uniform T2 uni_left;\n"
4335 "uniform T2 uni_right;\n"
4336 "\n"
4337 "FUNCTION_DEFINITION"
4338 "\n"
4339 "void main()\n"
4340 "{\n"
4341 " vec4 result = vec4(0, 1, 0, 1);\n"
4342 "\n"
4343 "VERIFICATION"
4344 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4345 " {\n"
4346 " result = vec4(1, 0, 0, 1);\n"
4347 " }\n"
4348 "\n"
4349 " fs_out_result = result;\n"
4350 "}\n"
4351 "\n";
4352
4353 static const GLchar *geometry_shader_template = "VERSION\n"
4354 "\n"
4355 "layout(points) in;\n"
4356 "layout(triangle_strip, max_vertices = 4) out;\n"
4357 "\n"
4358 "in vec4 tes_gs_result[];\n"
4359 "out vec4 gs_fs_result;\n"
4360 "uniform T2 uni_left;\n"
4361 "uniform T2 uni_right;\n"
4362 "\n"
4363 "FUNCTION_DEFINITION"
4364 "\n"
4365 "void main()\n"
4366 "{\n"
4367 " vec4 result = vec4(0, 1, 0, 1);\n"
4368 "\n"
4369 "VERIFICATION"
4370 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4371 " {\n"
4372 " result = vec4(1, 0, 0, 1);\n"
4373 " }\n"
4374 "\n"
4375 " gs_fs_result = result;\n"
4376 " gl_Position = vec4(-1, -1, 0, 1);\n"
4377 " EmitVertex();\n"
4378 " gs_fs_result = result;\n"
4379 " gl_Position = vec4(-1, 1, 0, 1);\n"
4380 " EmitVertex();\n"
4381 " gs_fs_result = result;\n"
4382 " gl_Position = vec4(1, -1, 0, 1);\n"
4383 " EmitVertex();\n"
4384 " gs_fs_result = result;\n"
4385 " gl_Position = vec4(1, 1, 0, 1);\n"
4386 " EmitVertex();\n"
4387 "}\n"
4388 "\n";
4389
4390 static const GLchar *tess_ctrl_shader_template =
4391 "VERSION\n"
4392 "\n"
4393 "layout(vertices = 1) out;\n"
4394 "\n"
4395 "in vec4 vs_tcs_result[];\n"
4396 "out vec4 tcs_tes_result[];\n"
4397 "uniform T2 uni_left;\n"
4398 "uniform T2 uni_right;\n"
4399 "\n"
4400 "FUNCTION_DEFINITION"
4401 "\n"
4402 "void main()\n"
4403 "{\n"
4404 " vec4 result = vec4(0, 1, 0, 1);\n"
4405 "\n"
4406 "VERIFICATION"
4407 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4408 " {\n"
4409 " result = vec4(1, 0, 0, 1);\n"
4410 " }\n"
4411 "\n"
4412 " tcs_tes_result[gl_InvocationID] = result;\n"
4413 "\n"
4414 " gl_TessLevelOuter[0] = 1.0;\n"
4415 " gl_TessLevelOuter[1] = 1.0;\n"
4416 " gl_TessLevelOuter[2] = 1.0;\n"
4417 " gl_TessLevelOuter[3] = 1.0;\n"
4418 " gl_TessLevelInner[0] = 1.0;\n"
4419 " gl_TessLevelInner[1] = 1.0;\n"
4420 "}\n"
4421 "\n";
4422
4423 static const GLchar *tess_eval_shader_template = "VERSION\n"
4424 "\n"
4425 "layout(isolines, point_mode) in;\n"
4426 "\n"
4427 "in vec4 tcs_tes_result[];\n"
4428 "out vec4 tes_gs_result;\n"
4429 "uniform T2 uni_left;\n"
4430 "uniform T2 uni_right;\n"
4431 "\n"
4432 "FUNCTION_DEFINITION"
4433 "\n"
4434 "void main()\n"
4435 "{\n"
4436 " vec4 result = vec4(0, 1, 0, 1);\n"
4437 "\n"
4438 "VERIFICATION"
4439 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4440 " {\n"
4441 " result = vec4(1, 0, 0, 1);\n"
4442 " }\n"
4443 "\n"
4444 " tes_gs_result = result;\n"
4445 "}\n"
4446 "\n";
4447
4448 static const GLchar *vertex_shader_template = "VERSION\n"
4449 "\n"
4450 "out vec4 vs_tcs_result;\n"
4451 "uniform T2 uni_left;\n"
4452 "uniform T2 uni_right;\n"
4453 "\n"
4454 "FUNCTION_DEFINITION"
4455 "\n"
4456 "void main()\n"
4457 "{\n"
4458 " vec4 result = vec4(0, 1, 0, 1);\n"
4459 "\n"
4460 "VERIFICATION"
4461 "\n"
4462 " vs_tcs_result = result;\n"
4463 "}\n"
4464 "\n";
4465
4466 const testCase &test_case = getCurrentTestCase();
4467 const GLchar *t1 = Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols, test_case.m_n_rows);
4468 const GLchar *t2 = Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols, test_case.m_n_rows);
4469 const std::string &value_list = getValueList(test_case.m_n_cols, test_case.m_n_rows);
4470 const GLchar *shader_template = 0;
4471
4472 switch (in_stage)
4473 {
4474 case Utils::COMPUTE_SHADER:
4475 shader_template = compute_shader_template;
4476 break;
4477 case Utils::FRAGMENT_SHADER:
4478 shader_template = fragment_shader_template;
4479 break;
4480 case Utils::GEOMETRY_SHADER:
4481 shader_template = geometry_shader_template;
4482 break;
4483 case Utils::TESS_CTRL_SHADER:
4484 shader_template = tess_ctrl_shader_template;
4485 break;
4486 case Utils::TESS_EVAL_SHADER:
4487 shader_template = tess_eval_shader_template;
4488 break;
4489 case Utils::VERTEX_SHADER:
4490 shader_template = vertex_shader_template;
4491 break;
4492 default:
4493 TCU_FAIL("Invalid enum");
4494 }
4495
4496 out_source.m_parts[0].m_code = shader_template;
4497
4498 size_t position = 0;
4499 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4500 out_source.m_parts[0].m_code);
4501
4502 Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4503
4504 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4505
4506 Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4507
4508 Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4509
4510 Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4511 }
4512
4513 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
4514 *
4515 * @param program Current program
4516 **/
prepareUniforms(Utils::program & program)4517 void ImplicitConversionsValidTest::prepareUniforms(Utils::program &program)
4518 {
4519 static const GLdouble double_data[16] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
4520 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
4521 static const GLfloat float_data[16] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
4522 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
4523 static const GLint int_data[4] = {1, 1, 1, 1};
4524 static const GLuint uint_data[4] = {1u, 1u, 1u, 1u};
4525
4526 const testCase &test_case = getCurrentTestCase();
4527
4528 switch (test_case.m_types.m_t2)
4529 {
4530 case Utils::DOUBLE:
4531 program.uniform("uni_left", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4532 program.uniform("uni_right", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4533 break;
4534 case Utils::FLOAT:
4535 program.uniform("uni_left", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4536 program.uniform("uni_right", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4537 break;
4538 case Utils::INT:
4539 program.uniform("uni_left", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4540 program.uniform("uni_right", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4541 break;
4542 case Utils::UINT:
4543 program.uniform("uni_left", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4544 program.uniform("uni_right", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4545 break;
4546 default:
4547 TCU_FAIL("Invalid enum");
4548 }
4549 }
4550
4551 /** Returns reference to current test case
4552 *
4553 * @return Reference to testCase
4554 **/
getCurrentTestCase()4555 const ImplicitConversionsValidTest::testCase &ImplicitConversionsValidTest::getCurrentTestCase()
4556 {
4557 if ((glw::GLuint)-1 == m_current_test_case_index)
4558 {
4559 return m_debug_test_case;
4560 }
4561 else
4562 {
4563 return m_test_cases[m_current_test_case_index];
4564 }
4565 }
4566
4567 /** Get list of values to for glsl constants
4568 *
4569 * @param n_columns Number of columns
4570 * @param n_rows Number of rows
4571 *
4572 * @return String with list of values separated with comma
4573 **/
getValueList(glw::GLuint n_columns,glw::GLuint n_rows)4574 std::string ImplicitConversionsValidTest::getValueList(glw::GLuint n_columns, glw::GLuint n_rows)
4575 {
4576 std::string result;
4577
4578 for (GLuint i = 0; i < n_columns * n_rows; ++i)
4579 {
4580 if (i != n_columns * n_rows - 1)
4581 {
4582 result.append("1, ");
4583 }
4584 else
4585 {
4586 result.append("1");
4587 }
4588 }
4589
4590 return result;
4591 }
4592
4593 /** Constructor
4594 *
4595 * @param context Test context
4596 **/
ImplicitConversionsInvalidTest(deqp::Context & context)4597 ImplicitConversionsInvalidTest::ImplicitConversionsInvalidTest(deqp::Context &context)
4598 : NegativeTestBase(context, "implicit_conversions_invalid",
4599 "Verifies that implicit conversions from uint to int are forbidden")
4600 , m_current_test_case_index(0)
4601 {
4602 /* Nothing to be done here */
4603 }
4604
4605 /** Set up next test case
4606 *
4607 * @param test_case_index Index of next test case
4608 *
4609 * @return false if there is no more test cases, true otherwise
4610 **/
prepareNextTestCase(glw::GLuint test_case_index)4611 bool ImplicitConversionsInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
4612 {
4613 m_current_test_case_index = test_case_index;
4614
4615 if ((glw::GLuint)-1 == test_case_index)
4616 {
4617 return false;
4618 }
4619 else if (4 <= test_case_index)
4620 {
4621 return false;
4622 }
4623
4624 m_context.getTestContext().getLog() << tcu::TestLog::Message
4625 << "T1:" << Utils::getTypeName(Utils::UINT, 1, test_case_index + 1)
4626 << " T2:" << Utils::getTypeName(Utils::INT, 1, test_case_index + 1)
4627 << tcu::TestLog::EndMessage;
4628
4629 return true;
4630 }
4631
4632 /** Prepare source for given shader stage
4633 *
4634 * @param in_stage Shader stage, compute shader will use 430
4635 * @param in_use_version_400 Select if 400 or 420 should be used
4636 * @param out_source Prepared shader source instance
4637 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4638 void ImplicitConversionsInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4639 Utils::shaderSource &out_source)
4640 {
4641 static const GLchar *function_definition = "T1 function(in T2 left, in T2 right)\n"
4642 "{\n"
4643 " return left + right;\n"
4644 "}\n";
4645
4646 static const GLchar *verification_snippet = " const T2 const_left = T2(VALUE_LIST);\n"
4647 " const T2 const_right = T2(VALUE_LIST);\n"
4648 "\n"
4649 " T1 const_result = function(const_left, const_right);\n"
4650 "\n"
4651 " T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4652 "\n"
4653 " T2 var_left = uni_left;\n"
4654 " T2 var_right = uni_right;\n"
4655 "\n"
4656 " T1 var_result = function(var_left, var_right);\n"
4657 "\n"
4658 " if ((literal_result != const_result) ||\n"
4659 " (const_result != var_result) )\n"
4660 " {\n"
4661 " result = vec4(1, 0, 0, 1);\n"
4662 " }\n";
4663
4664 static const GLchar *compute_shader_template =
4665 "VERSION\n"
4666 "\n"
4667 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4668 "\n"
4669 "writeonly uniform image2D uni_image;\n"
4670 " uniform T2 uni_left;\n"
4671 " uniform T2 uni_right;\n"
4672 "\n"
4673 "FUNCTION_DEFINITION"
4674 "\n"
4675 "void main()\n"
4676 "{\n"
4677 " vec4 result = vec4(0, 1, 0, 1);\n"
4678 "\n"
4679 "VERIFICATION"
4680 "\n"
4681 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4682 "}\n"
4683 "\n";
4684
4685 static const GLchar *fragment_shader_template = "VERSION\n"
4686 "\n"
4687 "in vec4 gs_fs_result;\n"
4688 "out vec4 fs_out_result;\n"
4689 "uniform T2 uni_left;\n"
4690 "uniform T2 uni_right;\n"
4691 "\n"
4692 "FUNCTION_DEFINITION"
4693 "\n"
4694 "void main()\n"
4695 "{\n"
4696 " vec4 result = vec4(0, 1, 0, 1);\n"
4697 "\n"
4698 "VERIFICATION"
4699 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4700 " {\n"
4701 " result = vec4(1, 0, 0, 1);\n"
4702 " }\n"
4703 "\n"
4704 " fs_out_result = result;\n"
4705 "}\n"
4706 "\n";
4707
4708 static const GLchar *geometry_shader_template = "VERSION\n"
4709 "\n"
4710 "layout(points) in;\n"
4711 "layout(triangle_strip, max_vertices = 4) out;\n"
4712 "\n"
4713 "in vec4 tes_gs_result[];\n"
4714 "out vec4 gs_fs_result;\n"
4715 "uniform T2 uni_left;\n"
4716 "uniform T2 uni_right;\n"
4717 "\n"
4718 "FUNCTION_DEFINITION"
4719 "\n"
4720 "void main()\n"
4721 "{\n"
4722 " vec4 result = vec4(0, 1, 0, 1);\n"
4723 "\n"
4724 "VERIFICATION"
4725 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4726 " {\n"
4727 " result = vec4(1, 0, 0, 1);\n"
4728 " }\n"
4729 "\n"
4730 " gs_fs_result = result;\n"
4731 " gl_Position = vec4(-1, -1, 0, 1);\n"
4732 " EmitVertex();\n"
4733 " gs_fs_result = result;\n"
4734 " gl_Position = vec4(-1, 1, 0, 1);\n"
4735 " EmitVertex();\n"
4736 " gs_fs_result = result;\n"
4737 " gl_Position = vec4(1, -1, 0, 1);\n"
4738 " EmitVertex();\n"
4739 " gs_fs_result = result;\n"
4740 " gl_Position = vec4(1, 1, 0, 1);\n"
4741 " EmitVertex();\n"
4742 "}\n"
4743 "\n";
4744
4745 static const GLchar *tess_ctrl_shader_template =
4746 "VERSION\n"
4747 "\n"
4748 "layout(vertices = 1) out;\n"
4749 "\n"
4750 "in vec4 vs_tcs_result[];\n"
4751 "out vec4 tcs_tes_result[];\n"
4752 "uniform T2 uni_left;\n"
4753 "uniform T2 uni_right;\n"
4754 "\n"
4755 "FUNCTION_DEFINITION"
4756 "\n"
4757 "void main()\n"
4758 "{\n"
4759 " vec4 result = vec4(0, 1, 0, 1);\n"
4760 "\n"
4761 "VERIFICATION"
4762 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4763 " {\n"
4764 " result = vec4(1, 0, 0, 1);\n"
4765 " }\n"
4766 "\n"
4767 " tcs_tes_result[gl_InvocationID] = result;\n"
4768 "\n"
4769 " gl_TessLevelOuter[0] = 1.0;\n"
4770 " gl_TessLevelOuter[1] = 1.0;\n"
4771 " gl_TessLevelOuter[2] = 1.0;\n"
4772 " gl_TessLevelOuter[3] = 1.0;\n"
4773 " gl_TessLevelInner[0] = 1.0;\n"
4774 " gl_TessLevelInner[1] = 1.0;\n"
4775 "}\n"
4776 "\n";
4777
4778 static const GLchar *tess_eval_shader_template = "VERSION\n"
4779 "\n"
4780 "layout(isolines, point_mode) in;\n"
4781 "\n"
4782 "in vec4 tcs_tes_result[];\n"
4783 "out vec4 tes_gs_result;\n"
4784 "uniform T2 uni_left;\n"
4785 "uniform T2 uni_right;\n"
4786 "\n"
4787 "FUNCTION_DEFINITION"
4788 "\n"
4789 "void main()\n"
4790 "{\n"
4791 " vec4 result = vec4(0, 1, 0, 1);\n"
4792 "\n"
4793 "VERIFICATION"
4794 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4795 " {\n"
4796 " result = vec4(1, 0, 0, 1);\n"
4797 " }\n"
4798 "\n"
4799 " tes_gs_result = result;\n"
4800 "}\n"
4801 "\n";
4802
4803 static const GLchar *vertex_shader_template = "VERSION\n"
4804 "\n"
4805 "out vec4 vs_tcs_result;\n"
4806 "uniform T2 uni_left;\n"
4807 "uniform T2 uni_right;\n"
4808 "\n"
4809 "FUNCTION_DEFINITION"
4810 "\n"
4811 "void main()\n"
4812 "{\n"
4813 " vec4 result = vec4(0, 1, 0, 1);\n"
4814 "\n"
4815 "VERIFICATION"
4816 "\n"
4817 " vs_tcs_result = result;\n"
4818 "}\n"
4819 "\n";
4820
4821 GLuint n_rows = m_current_test_case_index + 1;
4822 const GLchar *t1 = Utils::getTypeName(Utils::INT, 1, n_rows);
4823 const GLchar *t2 = Utils::getTypeName(Utils::UINT, 1, n_rows);
4824 const std::string &value_list = getValueList(n_rows);
4825 const GLchar *shader_template = 0;
4826
4827 switch (in_stage)
4828 {
4829 case Utils::COMPUTE_SHADER:
4830 shader_template = compute_shader_template;
4831 break;
4832 case Utils::FRAGMENT_SHADER:
4833 shader_template = fragment_shader_template;
4834 break;
4835 case Utils::GEOMETRY_SHADER:
4836 shader_template = geometry_shader_template;
4837 break;
4838 case Utils::TESS_CTRL_SHADER:
4839 shader_template = tess_ctrl_shader_template;
4840 break;
4841 case Utils::TESS_EVAL_SHADER:
4842 shader_template = tess_eval_shader_template;
4843 break;
4844 case Utils::VERTEX_SHADER:
4845 shader_template = vertex_shader_template;
4846 break;
4847 default:
4848 TCU_FAIL("Invalid enum");
4849 }
4850
4851 out_source.m_parts[0].m_code = shader_template;
4852
4853 size_t position = 0;
4854 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4855 out_source.m_parts[0].m_code);
4856
4857 Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4858
4859 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4860
4861 Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4862
4863 Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4864
4865 Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4866 }
4867
4868 /** Get list of values to for glsl constants
4869 *
4870 * @return String with list of values separated with comma
4871 **/
getValueList(glw::GLuint n_rows)4872 std::string ImplicitConversionsInvalidTest::getValueList(glw::GLuint n_rows)
4873 {
4874 std::string result;
4875
4876 for (GLuint i = 0; i < n_rows; ++i)
4877 {
4878 if (i != n_rows - 1)
4879 {
4880 result.append("1, ");
4881 }
4882 else
4883 {
4884 result.append("1");
4885 }
4886 }
4887
4888 return result;
4889 }
4890
4891 /** Constructor
4892 *
4893 * @param context Test context
4894 **/
ConstDynamicValueTest(deqp::Context & context)4895 ConstDynamicValueTest::ConstDynamicValueTest(deqp::Context &context)
4896 : GLSLTestBase(context, "const_dynamic_value", "Test if constants can be initialized with dynamic values")
4897 {
4898 /* Nothing to be done here */
4899 }
4900
4901 /** Prepare source for given shader stage
4902 *
4903 * @param in_stage Shader stage, compute shader will use 430
4904 * @param in_use_version_400 Select if 400 or 420 should be used
4905 * @param out_source Prepared shader source instance
4906 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4907 void ConstDynamicValueTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4908 Utils::shaderSource &out_source)
4909 {
4910 static const GLchar *struct_definition = "struct S {\n"
4911 " float scalar;\n"
4912 " vec4 vector;\n"
4913 " mat2 matrix;\n"
4914 "};\n";
4915
4916 static const GLchar *verification_snippet = " const float c1 = uni_scalar;\n"
4917 " const vec4 c2 = uni_vector;\n"
4918 " const mat2 c3 = uni_matrix;\n"
4919 " const S c4 = { uni_scalar, uni_vector, uni_matrix };\n"
4920 " const vec4 c5[15] = { uni_vector,\n"
4921 " uni_vector,\n"
4922 " uni_vector,\n"
4923 " uni_vector,\n"
4924 " uni_vector,\n"
4925 " uni_vector,\n"
4926 " uni_vector,\n"
4927 " uni_vector,\n"
4928 " uni_vector,\n"
4929 " uni_vector,\n"
4930 " uni_vector,\n"
4931 " uni_vector,\n"
4932 " uni_vector,\n"
4933 " uni_vector,\n"
4934 " uni_vector };\n"
4935 " if ((SCALAR != c1) ||\n"
4936 " (VECTOR != c2) ||\n"
4937 " (MATRIX != c3) ||\n"
4938 " (SCALAR != c4.scalar) ||\n"
4939 " (VECTOR != c4.vector) ||\n"
4940 " (MATRIX != c4.matrix) ||\n"
4941 " (VECTOR != c5[0]) ||\n"
4942 " (VECTOR != c5[1]) ||\n"
4943 " (VECTOR != c5[2]) ||\n"
4944 " (VECTOR != c5[3]) ||\n"
4945 " (VECTOR != c5[4]) ||\n"
4946 " (VECTOR != c5[5]) ||\n"
4947 " (VECTOR != c5[6]) ||\n"
4948 " (VECTOR != c5[7]) ||\n"
4949 " (VECTOR != c5[8]) ||\n"
4950 " (VECTOR != c5[9]) ||\n"
4951 " (VECTOR != c5[10]) ||\n"
4952 " (VECTOR != c5[11]) ||\n"
4953 " (VECTOR != c5[12]) ||\n"
4954 " (VECTOR != c5[13]) ||\n"
4955 " (VECTOR != c5[14]) )\n"
4956 " {\n"
4957 " result = vec4(1, 0, 0, 1);\n"
4958 " }\n";
4959
4960 static const GLchar *compute_shader_template =
4961 "VERSION\n"
4962 "\n"
4963 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4964 "\n"
4965 "writeonly uniform image2D uni_image;\n"
4966 " uniform float uni_scalar;\n"
4967 " uniform vec4 uni_vector;\n"
4968 " uniform mat2 uni_matrix;\n"
4969 "\n"
4970 "STRUCTURE_DEFINITION"
4971 "\n"
4972 "void main()\n"
4973 "{\n"
4974 " vec4 result = vec4(0, 1, 0, 1);\n"
4975 "\n"
4976 "VERIFICATION"
4977 "\n"
4978 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4979 "}\n"
4980 "\n";
4981
4982 static const GLchar *fragment_shader_template = "VERSION\n"
4983 "\n"
4984 "in vec4 gs_fs_result;\n"
4985 "out vec4 fs_out_result;\n"
4986 "uniform float uni_scalar;\n"
4987 "uniform vec4 uni_vector;\n"
4988 "uniform mat2 uni_matrix;\n"
4989 "\n"
4990 "STRUCTURE_DEFINITION"
4991 "\n"
4992 "void main()\n"
4993 "{\n"
4994 " vec4 result = vec4(0, 1, 0, 1);\n"
4995 "\n"
4996 "VERIFICATION"
4997 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4998 " {\n"
4999 " result = vec4(1, 0, 0, 1);\n"
5000 " }\n"
5001 "\n"
5002 " fs_out_result = result;\n"
5003 "}\n"
5004 "\n";
5005
5006 static const GLchar *geometry_shader_template = "VERSION\n"
5007 "\n"
5008 "layout(points) in;\n"
5009 "layout(triangle_strip, max_vertices = 4) out;\n"
5010 "\n"
5011 "in vec4 tes_gs_result[];\n"
5012 "out vec4 gs_fs_result;\n"
5013 "uniform float uni_scalar;\n"
5014 "uniform vec4 uni_vector;\n"
5015 "uniform mat2 uni_matrix;\n"
5016 "\n"
5017 "STRUCTURE_DEFINITION"
5018 "\n"
5019 "void main()\n"
5020 "{\n"
5021 " vec4 result = vec4(0, 1, 0, 1);\n"
5022 "\n"
5023 "VERIFICATION"
5024 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5025 " {\n"
5026 " result = vec4(1, 0, 0, 1);\n"
5027 " }\n"
5028 "\n"
5029 " gs_fs_result = result;\n"
5030 " gl_Position = vec4(-1, -1, 0, 1);\n"
5031 " EmitVertex();\n"
5032 " gs_fs_result = result;\n"
5033 " gl_Position = vec4(-1, 1, 0, 1);\n"
5034 " EmitVertex();\n"
5035 " gs_fs_result = result;\n"
5036 " gl_Position = vec4(1, -1, 0, 1);\n"
5037 " EmitVertex();\n"
5038 " gs_fs_result = result;\n"
5039 " gl_Position = vec4(1, 1, 0, 1);\n"
5040 " EmitVertex();\n"
5041 "}\n"
5042 "\n";
5043
5044 static const GLchar *tess_ctrl_shader_template =
5045 "VERSION\n"
5046 "\n"
5047 "layout(vertices = 1) out;\n"
5048 "\n"
5049 "in vec4 vs_tcs_result[];\n"
5050 "out vec4 tcs_tes_result[];\n"
5051 "uniform float uni_scalar;\n"
5052 "uniform vec4 uni_vector;\n"
5053 "uniform mat2 uni_matrix;\n"
5054 "\n"
5055 "STRUCTURE_DEFINITION"
5056 "\n"
5057 "void main()\n"
5058 "{\n"
5059 " vec4 result = vec4(0, 1, 0, 1);\n"
5060 "\n"
5061 "VERIFICATION"
5062 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5063 " {\n"
5064 " result = vec4(1, 0, 0, 1);\n"
5065 " }\n"
5066 "\n"
5067 " tcs_tes_result[gl_InvocationID] = result;\n"
5068 "\n"
5069 " gl_TessLevelOuter[0] = 1.0;\n"
5070 " gl_TessLevelOuter[1] = 1.0;\n"
5071 " gl_TessLevelOuter[2] = 1.0;\n"
5072 " gl_TessLevelOuter[3] = 1.0;\n"
5073 " gl_TessLevelInner[0] = 1.0;\n"
5074 " gl_TessLevelInner[1] = 1.0;\n"
5075 "}\n"
5076 "\n";
5077
5078 static const GLchar *tess_eval_shader_template = "VERSION\n"
5079 "\n"
5080 "layout(isolines, point_mode) in;\n"
5081 "\n"
5082 "in vec4 tcs_tes_result[];\n"
5083 "out vec4 tes_gs_result;\n"
5084 "uniform float uni_scalar;\n"
5085 "uniform vec4 uni_vector;\n"
5086 "uniform mat2 uni_matrix;\n"
5087 "\n"
5088 "STRUCTURE_DEFINITION"
5089 "\n"
5090 "void main()\n"
5091 "{\n"
5092 " vec4 result = vec4(0, 1, 0, 1);\n"
5093 "\n"
5094 "VERIFICATION"
5095 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5096 " {\n"
5097 " result = vec4(1, 0, 0, 1);\n"
5098 " }\n"
5099 "\n"
5100 " tes_gs_result = result;\n"
5101 "}\n"
5102 "\n";
5103
5104 static const GLchar *vertex_shader_template = "VERSION\n"
5105 "\n"
5106 "out vec4 vs_tcs_result;\n"
5107 "uniform float uni_scalar;\n"
5108 "uniform vec4 uni_vector;\n"
5109 "uniform mat2 uni_matrix;\n"
5110 "\n"
5111 "STRUCTURE_DEFINITION"
5112 "\n"
5113 "void main()\n"
5114 "{\n"
5115 " vec4 result = vec4(0, 1, 0, 1);\n"
5116 "\n"
5117 "VERIFICATION"
5118 "\n"
5119 " vs_tcs_result = result;\n"
5120 "}\n"
5121 "\n";
5122
5123 static const GLchar *scalar = "0.5";
5124 static const GLchar *vector = "vec4(0.5, 0.125, 0.375, 0)";
5125 static const GLchar *matrix = "mat2(0.5, 0.125, 0.375, 0)";
5126
5127 const GLchar *shader_template = 0;
5128
5129 switch (in_stage)
5130 {
5131 case Utils::COMPUTE_SHADER:
5132 shader_template = compute_shader_template;
5133 break;
5134 case Utils::FRAGMENT_SHADER:
5135 shader_template = fragment_shader_template;
5136 break;
5137 case Utils::GEOMETRY_SHADER:
5138 shader_template = geometry_shader_template;
5139 break;
5140 case Utils::TESS_CTRL_SHADER:
5141 shader_template = tess_ctrl_shader_template;
5142 break;
5143 case Utils::TESS_EVAL_SHADER:
5144 shader_template = tess_eval_shader_template;
5145 break;
5146 case Utils::VERTEX_SHADER:
5147 shader_template = vertex_shader_template;
5148 break;
5149 default:
5150 TCU_FAIL("Invalid enum");
5151 }
5152
5153 out_source.m_parts[0].m_code = shader_template;
5154
5155 size_t position = 0;
5156 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5157 out_source.m_parts[0].m_code);
5158
5159 Utils::replaceToken("STRUCTURE_DEFINITION", position, struct_definition, out_source.m_parts[0].m_code);
5160
5161 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5162
5163 Utils::replaceAllTokens("SCALAR", scalar, out_source.m_parts[0].m_code);
5164
5165 Utils::replaceAllTokens("VECTOR", vector, out_source.m_parts[0].m_code);
5166
5167 Utils::replaceAllTokens("MATRIX", matrix, out_source.m_parts[0].m_code);
5168 }
5169
5170 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
5171 *
5172 * @param program Current program
5173 **/
prepareUniforms(Utils::program & program)5174 void ConstDynamicValueTest::prepareUniforms(Utils::program &program)
5175 {
5176 static const GLfloat float_data[4] = {0.5f, 0.125f, 0.375f, 0.0f};
5177 static const GLfloat scalar = 0.5f;
5178
5179 program.uniform("uni_scalar", Utils::FLOAT, 1, 1, &scalar);
5180 program.uniform("uni_vector", Utils::FLOAT, 1, 4, float_data);
5181 program.uniform("uni_matrix", Utils::FLOAT, 2, 2, float_data);
5182 }
5183
5184 /** Constructor
5185 *
5186 * @param context Test context
5187 **/
ConstAssignmentTest(deqp::Context & context)5188 ConstAssignmentTest::ConstAssignmentTest(deqp::Context &context)
5189 : NegativeTestBase(context, "const_assignment", "Verifies that constants cannot be overwritten")
5190 , m_current_test_case_index(0)
5191 {
5192 /* Nothing to be done here */
5193 }
5194
5195 /** Set up next test case
5196 *
5197 * @param test_case_index Index of next test case
5198 *
5199 * @return false if there is no more test cases, true otherwise
5200 **/
prepareNextTestCase(glw::GLuint test_case_index)5201 bool ConstAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
5202 {
5203 m_current_test_case_index = test_case_index;
5204
5205 if ((glw::GLuint)-1 == test_case_index)
5206 {
5207 return true;
5208 }
5209 else if (2 <= test_case_index)
5210 {
5211 return false;
5212 }
5213
5214 return true;
5215 }
5216
5217 /** Prepare source for given shader stage
5218 *
5219 * @param in_stage Shader stage, compute shader will use 430
5220 * @param in_use_version_400 Select if 400 or 420 should be used
5221 * @param out_source Prepared shader source instance
5222 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5223 void ConstAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5224 Utils::shaderSource &out_source)
5225 {
5226 static const GLchar *verification_snippet = " const float c1 = INIT;\n"
5227 "\n"
5228 " float temp = c1;\n"
5229 "\n"
5230 " for (uint i = 0; i < 4; ++i)"
5231 " {\n"
5232 " temp += c1 + uni_value;\n"
5233 " c1 -= 0.125;\n"
5234 " }\n"
5235 "\n"
5236 " if (0.0 == temp)\n"
5237 " {\n"
5238 " result = vec4(1, 0, 0, 1);\n"
5239 " }\n";
5240
5241 static const GLchar *compute_shader_template =
5242 "VERSION\n"
5243 "\n"
5244 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5245 "\n"
5246 "writeonly uniform image2D uni_image;\n"
5247 " uniform float uni_value;\n"
5248 "\n"
5249 "void main()\n"
5250 "{\n"
5251 " vec4 result = vec4(0, 1, 0, 1);\n"
5252 "\n"
5253 "VERIFICATION"
5254 "\n"
5255 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5256 "}\n"
5257 "\n";
5258
5259 static const GLchar *fragment_shader_template = "VERSION\n"
5260 "\n"
5261 "in vec4 gs_fs_result;\n"
5262 "out vec4 fs_out_result;\n"
5263 "uniform float uni_value;\n"
5264 "\n"
5265 "void main()\n"
5266 "{\n"
5267 " vec4 result = vec4(0, 1, 0, 1);\n"
5268 "\n"
5269 "VERIFICATION"
5270 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5271 " {\n"
5272 " result = vec4(1, 0, 0, 1);\n"
5273 " }\n"
5274 "\n"
5275 " fs_out_result = result;\n"
5276 "}\n"
5277 "\n";
5278
5279 static const GLchar *geometry_shader_template = "VERSION\n"
5280 "\n"
5281 "layout(points) in;\n"
5282 "layout(triangle_strip, max_vertices = 4) out;\n"
5283 "\n"
5284 "in vec4 tes_gs_result[];\n"
5285 "out vec4 gs_fs_result;\n"
5286 "uniform float uni_value;\n"
5287 "\n"
5288 "void main()\n"
5289 "{\n"
5290 " vec4 result = vec4(0, 1, 0, 1);\n"
5291 "\n"
5292 "VERIFICATION"
5293 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5294 " {\n"
5295 " result = vec4(1, 0, 0, 1);\n"
5296 " }\n"
5297 "\n"
5298 " gs_fs_result = result;\n"
5299 " gl_Position = vec4(-1, -1, 0, 1);\n"
5300 " EmitVertex();\n"
5301 " gs_fs_result = result;\n"
5302 " gl_Position = vec4(-1, 1, 0, 1);\n"
5303 " EmitVertex();\n"
5304 " gs_fs_result = result;\n"
5305 " gl_Position = vec4(1, -1, 0, 1);\n"
5306 " EmitVertex();\n"
5307 " gs_fs_result = result;\n"
5308 " gl_Position = vec4(1, 1, 0, 1);\n"
5309 " EmitVertex();\n"
5310 "}\n"
5311 "\n";
5312
5313 static const GLchar *tess_ctrl_shader_template =
5314 "VERSION\n"
5315 "\n"
5316 "layout(vertices = 1) out;\n"
5317 "\n"
5318 "in vec4 vs_tcs_result[];\n"
5319 "out vec4 tcs_tes_result[];\n"
5320 "uniform float uni_value;\n"
5321 "\n"
5322 "void main()\n"
5323 "{\n"
5324 " vec4 result = vec4(0, 1, 0, 1);\n"
5325 "\n"
5326 "VERIFICATION"
5327 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5328 " {\n"
5329 " result = vec4(1, 0, 0, 1);\n"
5330 " }\n"
5331 "\n"
5332 " tcs_tes_result[gl_InvocationID] = result;\n"
5333 "\n"
5334 " gl_TessLevelOuter[0] = 1.0;\n"
5335 " gl_TessLevelOuter[1] = 1.0;\n"
5336 " gl_TessLevelOuter[2] = 1.0;\n"
5337 " gl_TessLevelOuter[3] = 1.0;\n"
5338 " gl_TessLevelInner[0] = 1.0;\n"
5339 " gl_TessLevelInner[1] = 1.0;\n"
5340 "}\n"
5341 "\n";
5342
5343 static const GLchar *tess_eval_shader_template = "VERSION\n"
5344 "\n"
5345 "layout(isolines, point_mode) in;\n"
5346 "\n"
5347 "in vec4 tcs_tes_result[];\n"
5348 "out vec4 tes_gs_result;\n"
5349 "uniform float uni_value;\n"
5350 "\n"
5351 "void main()\n"
5352 "{\n"
5353 " vec4 result = vec4(0, 1, 0, 1);\n"
5354 "\n"
5355 "VERIFICATION"
5356 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5357 " {\n"
5358 " result = vec4(1, 0, 0, 1);\n"
5359 " }\n"
5360 "\n"
5361 " tes_gs_result = result;\n"
5362 "}\n"
5363 "\n";
5364
5365 static const GLchar *vertex_shader_template = "VERSION\n"
5366 "\n"
5367 "out vec4 vs_tcs_result;\n"
5368 "uniform float uni_value;\n"
5369 "\n"
5370 "void main()\n"
5371 "{\n"
5372 " vec4 result = vec4(0, 1, 0, 1);\n"
5373 "\n"
5374 "VERIFICATION"
5375 "\n"
5376 " vs_tcs_result = result;\n"
5377 "}\n"
5378 "\n";
5379
5380 static const GLchar *dynamic_init = "uni_value";
5381 static const GLchar *const_init = "0.75";
5382
5383 const GLchar *shader_template = 0;
5384 const GLchar *l_init = 0;
5385
5386 switch (in_stage)
5387 {
5388 case Utils::COMPUTE_SHADER:
5389 shader_template = compute_shader_template;
5390 break;
5391 case Utils::FRAGMENT_SHADER:
5392 shader_template = fragment_shader_template;
5393 break;
5394 case Utils::GEOMETRY_SHADER:
5395 shader_template = geometry_shader_template;
5396 break;
5397 case Utils::TESS_CTRL_SHADER:
5398 shader_template = tess_ctrl_shader_template;
5399 break;
5400 case Utils::TESS_EVAL_SHADER:
5401 shader_template = tess_eval_shader_template;
5402 break;
5403 case Utils::VERTEX_SHADER:
5404 shader_template = vertex_shader_template;
5405 break;
5406 default:
5407 TCU_FAIL("Invalid enum");
5408 }
5409
5410 if (0 == m_current_test_case_index)
5411 {
5412 l_init = dynamic_init;
5413 }
5414 else
5415 {
5416 l_init = const_init;
5417 }
5418
5419 out_source.m_parts[0].m_code = shader_template;
5420
5421 size_t position = 0;
5422 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5423 out_source.m_parts[0].m_code);
5424
5425 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5426
5427 Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5428 }
5429
5430 /** Constructor
5431 *
5432 * @param context Test context
5433 **/
ConstDynamicValueAsConstExprTest(deqp::Context & context)5434 ConstDynamicValueAsConstExprTest::ConstDynamicValueAsConstExprTest(deqp::Context &context)
5435 : NegativeTestBase(context, "const_dynamic_value_as_const_expr",
5436 "Verifies that dynamic constants cannot be used as constant foldable expressions")
5437 {
5438 /* Nothing to be done here */
5439 }
5440
5441 /** Prepare source for given shader stage
5442 *
5443 * @param in_stage Shader stage, compute shader will use 430
5444 * @param in_use_version_400 Select if 400 or 420 should be used
5445 * @param out_source Prepared shader source instance
5446 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5447 void ConstDynamicValueAsConstExprTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5448 Utils::shaderSource &out_source)
5449 {
5450 static const GLchar *verification_snippet = " const uint c1 = INIT;\n"
5451 "\n"
5452 " float temp[c1];\n"
5453 "\n"
5454 " for (uint i = 0; i < c1; ++i)"
5455 " {\n"
5456 " temp[i] += uni_value;\n"
5457 " }\n"
5458 "\n"
5459 " if (0.0 == temp[c1 - 1])\n"
5460 " {\n"
5461 " result = vec4(1, 0, 0, 1);\n"
5462 " }\n";
5463
5464 static const GLchar *compute_shader_template =
5465 "VERSION\n"
5466 "\n"
5467 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5468 "\n"
5469 "writeonly uniform image2D uni_image;\n"
5470 " uniform uint uni_value;\n"
5471 "\n"
5472 "void main()\n"
5473 "{\n"
5474 " vec4 result = vec4(0, 1, 0, 1);\n"
5475 "\n"
5476 "VERIFICATION"
5477 "\n"
5478 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5479 "}\n"
5480 "\n";
5481
5482 static const GLchar *fragment_shader_template = "VERSION\n"
5483 "\n"
5484 "in vec4 gs_fs_result;\n"
5485 "out vec4 fs_out_result;\n"
5486 "uniform uint uni_value;\n"
5487 "\n"
5488 "void main()\n"
5489 "{\n"
5490 " vec4 result = vec4(0, 1, 0, 1);\n"
5491 "\n"
5492 "VERIFICATION"
5493 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5494 " {\n"
5495 " result = vec4(1, 0, 0, 1);\n"
5496 " }\n"
5497 "\n"
5498 " fs_out_result = result;\n"
5499 "}\n"
5500 "\n";
5501
5502 static const GLchar *geometry_shader_template = "VERSION\n"
5503 "\n"
5504 "layout(points) in;\n"
5505 "layout(triangle_strip, max_vertices = 4) out;\n"
5506 "\n"
5507 "in vec4 tes_gs_result[];\n"
5508 "out vec4 gs_fs_result;\n"
5509 "uniform uint uni_value;\n"
5510 "\n"
5511 "void main()\n"
5512 "{\n"
5513 " vec4 result = vec4(0, 1, 0, 1);\n"
5514 "\n"
5515 "VERIFICATION"
5516 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5517 " {\n"
5518 " result = vec4(1, 0, 0, 1);\n"
5519 " }\n"
5520 "\n"
5521 " gs_fs_result = result;\n"
5522 " gl_Position = vec4(-1, -1, 0, 1);\n"
5523 " EmitVertex();\n"
5524 " gs_fs_result = result;\n"
5525 " gl_Position = vec4(-1, 1, 0, 1);\n"
5526 " EmitVertex();\n"
5527 " gs_fs_result = result;\n"
5528 " gl_Position = vec4(1, -1, 0, 1);\n"
5529 " EmitVertex();\n"
5530 " gs_fs_result = result;\n"
5531 " gl_Position = vec4(1, 1, 0, 1);\n"
5532 " EmitVertex();\n"
5533 "}\n"
5534 "\n";
5535
5536 static const GLchar *tess_ctrl_shader_template =
5537 "VERSION\n"
5538 "\n"
5539 "layout(vertices = 1) out;\n"
5540 "\n"
5541 "in vec4 vs_tcs_result[];\n"
5542 "out vec4 tcs_tes_result[];\n"
5543 "uniform uint uni_value;\n"
5544 "\n"
5545 "void main()\n"
5546 "{\n"
5547 " vec4 result = vec4(0, 1, 0, 1);\n"
5548 "\n"
5549 "VERIFICATION"
5550 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5551 " {\n"
5552 " result = vec4(1, 0, 0, 1);\n"
5553 " }\n"
5554 "\n"
5555 " tcs_tes_result[gl_InvocationID] = result;\n"
5556 "\n"
5557 " gl_TessLevelOuter[0] = 1.0;\n"
5558 " gl_TessLevelOuter[1] = 1.0;\n"
5559 " gl_TessLevelOuter[2] = 1.0;\n"
5560 " gl_TessLevelOuter[3] = 1.0;\n"
5561 " gl_TessLevelInner[0] = 1.0;\n"
5562 " gl_TessLevelInner[1] = 1.0;\n"
5563 "}\n"
5564 "\n";
5565
5566 static const GLchar *tess_eval_shader_template = "VERSION\n"
5567 "\n"
5568 "layout(isolines, point_mode) in;\n"
5569 "\n"
5570 "in vec4 tcs_tes_result[];\n"
5571 "out vec4 tes_gs_result;\n"
5572 "uniform uint uni_value;\n"
5573 "\n"
5574 "void main()\n"
5575 "{\n"
5576 " vec4 result = vec4(0, 1, 0, 1);\n"
5577 "\n"
5578 "VERIFICATION"
5579 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5580 " {\n"
5581 " result = vec4(1, 0, 0, 1);\n"
5582 " }\n"
5583 "\n"
5584 " tes_gs_result = result;\n"
5585 "}\n"
5586 "\n";
5587
5588 static const GLchar *vertex_shader_template = "VERSION\n"
5589 "\n"
5590 "out vec4 vs_tcs_result;\n"
5591 "uniform uint uni_value;\n"
5592 "\n"
5593 "void main()\n"
5594 "{\n"
5595 " vec4 result = vec4(0, 1, 0, 1);\n"
5596 "\n"
5597 "VERIFICATION"
5598 "\n"
5599 " vs_tcs_result = result;\n"
5600 "}\n"
5601 "\n";
5602
5603 static const GLchar *l_init = "uni_value";
5604
5605 const GLchar *shader_template = 0;
5606
5607 switch (in_stage)
5608 {
5609 case Utils::COMPUTE_SHADER:
5610 shader_template = compute_shader_template;
5611 break;
5612 case Utils::FRAGMENT_SHADER:
5613 shader_template = fragment_shader_template;
5614 break;
5615 case Utils::GEOMETRY_SHADER:
5616 shader_template = geometry_shader_template;
5617 break;
5618 case Utils::TESS_CTRL_SHADER:
5619 shader_template = tess_ctrl_shader_template;
5620 break;
5621 case Utils::TESS_EVAL_SHADER:
5622 shader_template = tess_eval_shader_template;
5623 break;
5624 case Utils::VERTEX_SHADER:
5625 shader_template = vertex_shader_template;
5626 break;
5627 default:
5628 TCU_FAIL("Invalid enum");
5629 }
5630
5631 out_source.m_parts[0].m_code = shader_template;
5632
5633 size_t position = 0;
5634 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5635 out_source.m_parts[0].m_code);
5636
5637 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5638
5639 Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5640 }
5641
5642 /** Constructor
5643 *
5644 * @param context Test context
5645 **/
QualifierOrderTest(deqp::Context & context,Utils::qualifierSet & test_case,glw::GLuint test_id)5646 QualifierOrderTest::QualifierOrderTest(deqp::Context &context, Utils::qualifierSet &test_case, glw::GLuint test_id)
5647 : GLSLTestBase(context, "qualifier_order",
5648 "Test verifies that valid permutation of input and output qalifiers are accepted")
5649 , m_current_test_case_index(0)
5650 {
5651 m_test_cases.push_back(test_case);
5652
5653 std::string name = "qualifier_order_test_id_" + std::to_string(test_id);
5654
5655 TestCase::m_name = name;
5656 }
5657
5658 /** Set up next test case
5659 *
5660 * @param test_case_index Index of next test case
5661 *
5662 * @return false if there is no more test cases, true otherwise
5663 **/
prepareNextTestCase(glw::GLuint test_case_index)5664 bool QualifierOrderTest::prepareNextTestCase(glw::GLuint test_case_index)
5665 {
5666 m_current_test_case_index = test_case_index;
5667
5668 if ((glw::GLuint)-1 == test_case_index)
5669 {
5670 /* Nothing to be done here */
5671 }
5672 else if (m_test_cases.size() <= test_case_index)
5673 {
5674 return false;
5675 }
5676
5677 const Utils::qualifierSet &set = getCurrentTestCase();
5678
5679 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
5680
5681 for (GLuint i = 0; i < set.size(); ++i)
5682 {
5683 message << Utils::getQualifierString(set[i]) << " ";
5684 }
5685
5686 message << tcu::TestLog::EndMessage;
5687
5688 return true;
5689 }
5690
5691 /** Prepare source for given shader stage
5692 *
5693 * @param in_stage Shader stage, compute shader will use 430
5694 * @param in_use_version_400 Select if 400 or 420 should be used
5695 * @param out_source Prepared shader source instance
5696 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5697 void QualifierOrderTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5698 Utils::shaderSource &out_source)
5699 {
5700 static const GLchar *verification_snippet =
5701 " vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
5702 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
5703 " {\n"
5704 " result = INPUT_VARIABLE_NAME;\n"
5705 " }\n";
5706
5707 static const GLchar *fragment_shader_template = "VERSION\n"
5708 "\n"
5709 "in vec4 gs_fs_result;\n"
5710 "layout (location = 0) out vec4 fs_out_result;\n"
5711 "\n"
5712 "VARIABLE_DECLARATION;\n"
5713 "VARIABLE_DECLARATION;\n"
5714 "\n"
5715 "void main()\n"
5716 "{\n"
5717 " vec4 result = vec4(0, 1, 0, 1);\n"
5718 "\n"
5719 "VERIFICATION"
5720 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5721 " {\n"
5722 " result = vec4(1, 0, 0, 1);\n"
5723 " }\n"
5724 "\n"
5725 " fs_out_result = result;\n"
5726 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5727 "}\n"
5728 "\n";
5729
5730 static const GLchar *geometry_shader_template = "VERSION\n"
5731 "\n"
5732 "layout(points) in;\n"
5733 "layout(triangle_strip, max_vertices = 4) out;\n"
5734 "\n"
5735 "in vec4 tes_gs_result[];\n"
5736 "out vec4 gs_fs_result;\n"
5737 "\n"
5738 "VARIABLE_DECLARATION;\n"
5739 "VARIABLE_DECLARATION;\n"
5740 "\n"
5741 "void main()\n"
5742 "{\n"
5743 " vec4 result = vec4(0, 1, 0, 1);\n"
5744 "\n"
5745 "VERIFICATION"
5746 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5747 " {\n"
5748 " result = vec4(1, 0, 0, 1);\n"
5749 " }\n"
5750 "\n"
5751 " gs_fs_result = result;\n"
5752 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5753 " gl_Position = vec4(-1, -1, 0, 1);\n"
5754 " EmitVertex();\n"
5755 " gs_fs_result = result;\n"
5756 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5757 " gl_Position = vec4(-1, 1, 0, 1);\n"
5758 " EmitVertex();\n"
5759 " gs_fs_result = result;\n"
5760 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5761 " gl_Position = vec4(1, -1, 0, 1);\n"
5762 " EmitVertex();\n"
5763 " gs_fs_result = result;\n"
5764 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5765 " gl_Position = vec4(1, 1, 0, 1);\n"
5766 " EmitVertex();\n"
5767 "}\n"
5768 "\n";
5769
5770 static const GLchar *tess_ctrl_shader_template =
5771 "VERSION\n"
5772 "\n"
5773 "layout(vertices = 1) out;\n"
5774 "\n"
5775 "in vec4 vs_tcs_result[];\n"
5776 "out vec4 tcs_tes_result[];\n"
5777 "\n"
5778 "VARIABLE_DECLARATION;\n"
5779 "VARIABLE_DECLARATION;\n"
5780 "\n"
5781 "void main()\n"
5782 "{\n"
5783 " vec4 result = vec4(0, 1, 0, 1);\n"
5784 "\n"
5785 "VERIFICATION"
5786 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5787 " {\n"
5788 " result = vec4(1, 0, 0, 1);\n"
5789 " }\n"
5790 "\n"
5791 " tcs_tes_result[gl_InvocationID] = result;\n"
5792 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5793 "\n"
5794 " gl_TessLevelOuter[0] = 1.0;\n"
5795 " gl_TessLevelOuter[1] = 1.0;\n"
5796 " gl_TessLevelOuter[2] = 1.0;\n"
5797 " gl_TessLevelOuter[3] = 1.0;\n"
5798 " gl_TessLevelInner[0] = 1.0;\n"
5799 " gl_TessLevelInner[1] = 1.0;\n"
5800 "}\n"
5801 "\n";
5802
5803 static const GLchar *tess_eval_shader_template = "VERSION\n"
5804 "\n"
5805 "layout(isolines, point_mode) in;\n"
5806 "\n"
5807 "in vec4 tcs_tes_result[];\n"
5808 "out vec4 tes_gs_result;\n"
5809 "\n"
5810 "VARIABLE_DECLARATION;\n"
5811 "VARIABLE_DECLARATION;\n"
5812 "\n"
5813 "void main()\n"
5814 "{\n"
5815 " vec4 result = vec4(0, 1, 0, 1);\n"
5816 "\n"
5817 "VERIFICATION"
5818 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5819 " {\n"
5820 " result = vec4(1, 0, 0, 1);\n"
5821 " }\n"
5822 "\n"
5823 " tes_gs_result = result;\n"
5824 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5825 "}\n"
5826 "\n";
5827
5828 static const GLchar *vertex_shader_template = "VERSION\n"
5829 "\n"
5830 "out vec4 vs_tcs_result;\n"
5831 "\n"
5832 "VARIABLE_DECLARATION;\n"
5833 "VARIABLE_DECLARATION;\n"
5834 "\n"
5835 "void main()\n"
5836 "{\n"
5837 " vec4 result = vec4(0, 1, 0, 1);\n"
5838 "\n"
5839 "VERIFICATION"
5840 "\n"
5841 " vs_tcs_result = result;\n"
5842 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5843 "}\n"
5844 "\n";
5845
5846 const GLchar *shader_template = 0;
5847
5848 switch (in_stage)
5849 {
5850 case Utils::COMPUTE_SHADER:
5851 return;
5852 case Utils::FRAGMENT_SHADER:
5853 shader_template = fragment_shader_template;
5854 break;
5855 case Utils::GEOMETRY_SHADER:
5856 shader_template = geometry_shader_template;
5857 break;
5858 case Utils::TESS_CTRL_SHADER:
5859 shader_template = tess_ctrl_shader_template;
5860 break;
5861 case Utils::TESS_EVAL_SHADER:
5862 shader_template = tess_eval_shader_template;
5863 break;
5864 case Utils::VERTEX_SHADER:
5865 shader_template = vertex_shader_template;
5866 break;
5867 default:
5868 TCU_FAIL("Invalid enum");
5869 }
5870
5871 const Utils::qualifierSet &test_case = getCurrentTestCase();
5872
5873 std::string in_test_decl;
5874 std::string in_test_ref;
5875 std::string out_test_decl;
5876 std::string out_test_ref;
5877
5878 Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
5879 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
5880
5881 // sample storage qualifier is not a valid qualifier for fragment output
5882 if (in_stage == Utils::FRAGMENT_SHADER)
5883 {
5884 if (out_test_decl.find("sample") != std::string::npos)
5885 out_test_decl.erase(out_test_decl.find("sample"), 7);
5886 }
5887
5888 out_source.m_parts[0].m_code = shader_template;
5889
5890 size_t position = 0;
5891
5892 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5893 out_source.m_parts[0].m_code);
5894
5895 Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
5896
5897 Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
5898
5899 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5900
5901 position -= strlen(verification_snippet);
5902
5903 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
5904
5905 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
5906
5907 Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
5908 }
5909
5910 /**Prepare vertex buffer and vertex array object.
5911 *
5912 * @param program Program instance
5913 * @param buffer Buffer instance
5914 * @param vao VertexArray instance
5915 *
5916 * @return 0
5917 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)5918 void QualifierOrderTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
5919 Utils::vertexArray &vao)
5920 {
5921 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
5922 GLint test_loc = program.getAttribLocation(test_name.c_str());
5923
5924 if (-1 == test_loc)
5925 {
5926 TCU_FAIL("Vertex attribute location is invalid");
5927 }
5928
5929 vao.generate();
5930 vao.bind();
5931
5932 buffer.generate(GL_ARRAY_BUFFER);
5933
5934 GLfloat data[] = {0.0f, 0.0f, 1.0f, 1.0f};
5935 GLsizeiptr data_size = sizeof(data);
5936
5937 buffer.update(data_size, data, GL_STATIC_DRAW);
5938
5939 /* GL entry points */
5940 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
5941
5942 /* Set up vao */
5943 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
5944 0 /* offset */);
5945 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
5946
5947 /* Enable attribute */
5948 gl.enableVertexAttribArray(test_loc);
5949 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
5950 }
5951
5952 /** Returns reference to current test case
5953 *
5954 * @return Reference to testCase
5955 **/
getCurrentTestCase()5956 const Utils::qualifierSet &QualifierOrderTest::getCurrentTestCase()
5957 {
5958 if ((glw::GLuint)-1 == m_current_test_case_index)
5959 {
5960 return m_test_cases[0];
5961 }
5962 else
5963 {
5964 return m_test_cases[m_current_test_case_index];
5965 }
5966 }
5967
5968 /** Constructor
5969 *
5970 * @param context Test context
5971 **/
QualifierOrderBlockTest(deqp::Context & context,Utils::qualifierSet & test_case,glw::GLuint test_id)5972 QualifierOrderBlockTest::QualifierOrderBlockTest(deqp::Context &context, Utils::qualifierSet &test_case,
5973 glw::GLuint test_id)
5974 : GLSLTestBase(context, "qualifier_order_block",
5975 "Verifies that qualifiers of members of input block can be arranged in any order")
5976 , m_current_test_case_index(0)
5977 {
5978 m_test_cases.push_back(test_case);
5979
5980 std::string name = "qualifier_order_block_test_id_" + std::to_string(test_id);
5981
5982 TestCase::m_name = name;
5983 }
5984
5985 /** Set up next test case
5986 *
5987 * @param test_case_index Index of next test case
5988 *
5989 * @return false if there is no more test cases, true otherwise
5990 **/
prepareNextTestCase(glw::GLuint test_case_index)5991 bool QualifierOrderBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
5992 {
5993 m_current_test_case_index = test_case_index;
5994
5995 if ((glw::GLuint)-1 == test_case_index)
5996 {
5997 /* Nothing to be done here */
5998 }
5999 else if (m_test_cases.size() <= test_case_index)
6000 {
6001 return false;
6002 }
6003
6004 const Utils::qualifierSet &set = getCurrentTestCase();
6005
6006 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6007
6008 for (GLuint i = 0; i < set.size(); ++i)
6009 {
6010 message << Utils::getQualifierString(set[i]) << " ";
6011 }
6012
6013 message << tcu::TestLog::EndMessage;
6014
6015 return true;
6016 }
6017
6018 /** Prepare source for given shader stage
6019 *
6020 * @param in_stage Shader stage, compute shader will use 430
6021 * @param in_use_version_400 Select if 400 or 420 should be used
6022 * @param out_source Prepared shader source instance
6023 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6024 void QualifierOrderBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6025 Utils::shaderSource &out_source)
6026 {
6027 static const GLchar *verification_snippet =
6028 " vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6029 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6030 " {\n"
6031 " result = INPUT_VARIABLE_NAME;\n"
6032 " }\n";
6033
6034 static const GLchar *fragment_shader_template = "VERSION\n"
6035 "\n"
6036 "in vec4 gs_fs_result;\n"
6037 "layout (location = 0) out vec4 fs_out_result;\n"
6038 "\n"
6039 "in GSOutputBlock {\n"
6040 " VARIABLE_DECLARATION;\n"
6041 "} input_block;\n"
6042 "out VARIABLE_DECLARATION;\n"
6043 "\n"
6044 "void main()\n"
6045 "{\n"
6046 " vec4 result = vec4(0, 1, 0, 1);\n"
6047 "\n"
6048 "VERIFICATION"
6049 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6050 " {\n"
6051 " result = vec4(1, 0, 0, 1);\n"
6052 " }\n"
6053 "\n"
6054 " fs_out_result = result;\n"
6055 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6056 "}\n"
6057 "\n";
6058
6059 static const GLchar *geometry_shader_template = "VERSION\n"
6060 "\n"
6061 "layout(points) in;\n"
6062 "layout(triangle_strip, max_vertices = 4) out;\n"
6063 "\n"
6064 "in vec4 tes_gs_result[];\n"
6065 "out vec4 gs_fs_result;\n"
6066 "\n"
6067 "in TCSOutputBlock {\n"
6068 " VARIABLE_DECLARATION;\n"
6069 "} input_block [];\n"
6070 "out GSOutputBlock {\n"
6071 " VARIABLE_DECLARATION;\n"
6072 "} output_block;\n"
6073 "\n"
6074 "void main()\n"
6075 "{\n"
6076 " vec4 result = vec4(0, 1, 0, 1);\n"
6077 "\n"
6078 "VERIFICATION"
6079 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6080 " {\n"
6081 " result = vec4(1, 0, 0, 1);\n"
6082 " }\n"
6083 "\n"
6084 " gs_fs_result = result;\n"
6085 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6086 " gl_Position = vec4(-1, -1, 0, 1);\n"
6087 " EmitVertex();\n"
6088 " gs_fs_result = result;\n"
6089 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6090 " gl_Position = vec4(-1, 1, 0, 1);\n"
6091 " EmitVertex();\n"
6092 " gs_fs_result = result;\n"
6093 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6094 " gl_Position = vec4(1, -1, 0, 1);\n"
6095 " EmitVertex();\n"
6096 " gs_fs_result = result;\n"
6097 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6098 " gl_Position = vec4(1, 1, 0, 1);\n"
6099 " EmitVertex();\n"
6100 "}\n"
6101 "\n";
6102
6103 static const GLchar *tess_ctrl_shader_template =
6104 "VERSION\n"
6105 "\n"
6106 "layout(vertices = 1) out;\n"
6107 "\n"
6108 "in vec4 vs_tcs_result[];\n"
6109 "out vec4 tcs_tes_result[];\n"
6110 "\n"
6111 "in VSOutputBlock {\n"
6112 " VARIABLE_DECLARATION;\n"
6113 "} input_block [];\n"
6114 "out TCSOutputBlock {\n"
6115 " VARIABLE_DECLARATION;\n"
6116 "} output_block [];\n"
6117 "\n"
6118 "void main()\n"
6119 "{\n"
6120 " vec4 result = vec4(0, 1, 0, 1);\n"
6121 "\n"
6122 "VERIFICATION"
6123 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6124 " {\n"
6125 " result = vec4(1, 0, 0, 1);\n"
6126 " }\n"
6127 "\n"
6128 " tcs_tes_result[gl_InvocationID] = result;\n"
6129 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6130 "\n"
6131 " gl_TessLevelOuter[0] = 1.0;\n"
6132 " gl_TessLevelOuter[1] = 1.0;\n"
6133 " gl_TessLevelOuter[2] = 1.0;\n"
6134 " gl_TessLevelOuter[3] = 1.0;\n"
6135 " gl_TessLevelInner[0] = 1.0;\n"
6136 " gl_TessLevelInner[1] = 1.0;\n"
6137 "}\n"
6138 "\n";
6139
6140 static const GLchar *tess_eval_shader_template = "VERSION\n"
6141 "\n"
6142 "layout(isolines, point_mode) in;\n"
6143 "\n"
6144 "in vec4 tcs_tes_result[];\n"
6145 "out vec4 tes_gs_result;\n"
6146 "\n"
6147 "in TCSOutputBlock {\n"
6148 " VARIABLE_DECLARATION;\n"
6149 "} input_block [];\n"
6150 "out TCSOutputBlock {\n"
6151 " VARIABLE_DECLARATION;\n"
6152 "} output_block;\n"
6153 "\n"
6154 "void main()\n"
6155 "{\n"
6156 " vec4 result = vec4(0, 1, 0, 1);\n"
6157 "\n"
6158 "VERIFICATION"
6159 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6160 " {\n"
6161 " result = vec4(1, 0, 0, 1);\n"
6162 " }\n"
6163 "\n"
6164 " tes_gs_result = result;\n"
6165 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6166 "}\n"
6167 "\n";
6168
6169 static const GLchar *vertex_shader_template = "VERSION\n"
6170 "\n"
6171 "out vec4 vs_tcs_result;\n"
6172 "\n"
6173 "in VARIABLE_DECLARATION;\n"
6174 "out VSOutputBlock {\n"
6175 " VARIABLE_DECLARATION;\n"
6176 "} output_block;\n"
6177 "\n"
6178 "void main()\n"
6179 "{\n"
6180 " vec4 result = vec4(0, 1, 0, 1);\n"
6181 "\n"
6182 "VERIFICATION"
6183 "\n"
6184 " vs_tcs_result = result;\n"
6185 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6186 "}\n"
6187 "\n";
6188
6189 const GLchar *shader_template = 0;
6190
6191 switch (in_stage)
6192 {
6193 case Utils::COMPUTE_SHADER:
6194 return;
6195 case Utils::FRAGMENT_SHADER:
6196 shader_template = fragment_shader_template;
6197 break;
6198 case Utils::GEOMETRY_SHADER:
6199 shader_template = geometry_shader_template;
6200 break;
6201 case Utils::TESS_CTRL_SHADER:
6202 shader_template = tess_ctrl_shader_template;
6203 break;
6204 case Utils::TESS_EVAL_SHADER:
6205 shader_template = tess_eval_shader_template;
6206 break;
6207 case Utils::VERTEX_SHADER:
6208 shader_template = vertex_shader_template;
6209 break;
6210 default:
6211 TCU_FAIL("Invalid enum");
6212 }
6213
6214 const Utils::qualifierSet &test_case = getCurrentTestCase();
6215
6216 std::string in_test_decl;
6217 std::string in_test_ref;
6218 std::string out_test_decl;
6219 std::string out_test_ref;
6220
6221 switch (in_stage)
6222 {
6223 case Utils::VERTEX_SHADER:
6224 Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
6225 break;
6226 default:
6227 Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", "input_block",
6228 in_test_decl, in_test_ref);
6229 break;
6230 }
6231
6232 switch (in_stage)
6233 {
6234 case Utils::FRAGMENT_SHADER:
6235 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
6236 break;
6237 default:
6238 Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", "output_block",
6239 out_test_decl, out_test_ref);
6240 break;
6241 }
6242
6243 // sample storage qualifier is not a valid qualifier for fragment output
6244 if (in_stage == Utils::FRAGMENT_SHADER)
6245 {
6246 if (out_test_decl.find("sample") != std::string::npos)
6247 out_test_decl.erase(out_test_decl.find("sample"), 7);
6248 }
6249 out_source.m_parts[0].m_code = shader_template;
6250
6251 size_t position = 0;
6252
6253 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6254 out_source.m_parts[0].m_code);
6255
6256 Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
6257
6258 Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
6259
6260 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6261
6262 position -= strlen(verification_snippet);
6263
6264 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
6265
6266 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
6267
6268 Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
6269 }
6270
6271 /**Prepare vertex buffer and vertex array object.
6272 *
6273 * @param program Program instance
6274 * @param buffer Buffer instance
6275 * @param vao VertexArray instance
6276 *
6277 * @return 0
6278 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)6279 void QualifierOrderBlockTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
6280 Utils::vertexArray &vao)
6281 {
6282 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
6283 GLint test_loc = program.getAttribLocation(test_name.c_str());
6284
6285 if (-1 == test_loc)
6286 {
6287 TCU_FAIL("Vertex attribute location is invalid");
6288 }
6289
6290 vao.generate();
6291 vao.bind();
6292
6293 buffer.generate(GL_ARRAY_BUFFER);
6294
6295 GLfloat data[] = {0.0f, 0.0f, 1.0f, 1.0f};
6296 GLsizeiptr data_size = sizeof(data);
6297
6298 buffer.update(data_size, data, GL_STATIC_DRAW);
6299
6300 /* GL entry points */
6301 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
6302
6303 /* Set up vao */
6304 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6305 0 /* offset */);
6306 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6307
6308 /* Enable attribute */
6309 gl.enableVertexAttribArray(test_loc);
6310 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6311 }
6312
6313 /** Returns reference to current test case
6314 *
6315 * @return Reference to testCase
6316 **/
getCurrentTestCase()6317 const Utils::qualifierSet &QualifierOrderBlockTest::getCurrentTestCase()
6318 {
6319 if ((glw::GLuint)-1 == m_current_test_case_index)
6320 {
6321 return m_test_cases[0];
6322 }
6323 else
6324 {
6325 return m_test_cases[m_current_test_case_index];
6326 }
6327 }
6328
6329 /** Constructor
6330 *
6331 * @param context Test context
6332 **/
QualifierOrderUniformTest(deqp::Context & context,Utils::qualifierSet test_case,glw::GLuint test_id)6333 QualifierOrderUniformTest::QualifierOrderUniformTest(deqp::Context &context, Utils::qualifierSet test_case,
6334 glw::GLuint test_id)
6335 : GLSLTestBase(context, "qualifier_order_uniform",
6336 "Test verifies that all valid permutation of input qalifiers are accepted")
6337 , m_current_test_case_index(0)
6338 {
6339 m_test_cases.push_back(test_case);
6340
6341 std::string name = "qualifier_order_uniform_test_id_" + std::to_string(test_id);
6342
6343 TestCase::m_name = name;
6344 }
6345
6346 /** Set up next test case
6347 *
6348 * @param test_case_index Index of next test case
6349 *
6350 * @return false if there is no more test cases, true otherwise
6351 **/
prepareNextTestCase(glw::GLuint test_case_index)6352 bool QualifierOrderUniformTest::prepareNextTestCase(glw::GLuint test_case_index)
6353 {
6354 m_current_test_case_index = test_case_index;
6355
6356 if ((glw::GLuint)-1 == test_case_index)
6357 {
6358 /* Nothing to be done here */
6359 }
6360 else if (m_test_cases.size() <= test_case_index)
6361 {
6362 return false;
6363 }
6364
6365 const Utils::qualifierSet &set = getCurrentTestCase();
6366
6367 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6368
6369 for (GLuint i = 0; i < set.size(); ++i)
6370 {
6371 message << Utils::getQualifierString(set[i]) << " ";
6372 }
6373
6374 message << tcu::TestLog::EndMessage;
6375
6376 return true;
6377 }
6378
6379 /** Prepare source for given shader stage
6380 *
6381 * @param in_stage Shader stage, compute shader will use 430
6382 * @param in_use_version_400 Select if 400 or 420 should be used
6383 * @param out_source Prepared shader source instance
6384 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6385 void QualifierOrderUniformTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6386 Utils::shaderSource &out_source)
6387 {
6388 static const GLchar *verification_snippet =
6389 " vec4 diff = VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6390 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6391 " {\n"
6392 " result = VARIABLE_NAME;\n"
6393 " }\n";
6394
6395 static const GLchar *variable_declaration = " QUALIFIERS VARIABLE_NAME";
6396
6397 static const GLchar *fragment_shader_template = "VERSION\n"
6398 "#extension GL_ARB_explicit_uniform_location : enable\n"
6399 "\n"
6400 "in vec4 gs_fs_result;\n"
6401 "out vec4 fs_out_result;\n"
6402 "\n"
6403 "VARIABLE_DECLARATION;\n"
6404 "\n"
6405 "void main()\n"
6406 "{\n"
6407 " vec4 result = vec4(0, 1, 0, 1);\n"
6408 "\n"
6409 "VERIFICATION"
6410 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6411 " {\n"
6412 " result = vec4(1, 0, 0, 1);\n"
6413 " }\n"
6414 "\n"
6415 " fs_out_result = result;\n"
6416 "}\n"
6417 "\n";
6418
6419 static const GLchar *geometry_shader_template = "VERSION\n"
6420 "#extension GL_ARB_explicit_uniform_location : enable\n"
6421 "\n"
6422 "layout(points) in;\n"
6423 "layout(triangle_strip, max_vertices = 4) out;\n"
6424 "\n"
6425 "in vec4 tes_gs_result[];\n"
6426 "out vec4 gs_fs_result;\n"
6427 "\n"
6428 "VARIABLE_DECLARATION;\n"
6429 "\n"
6430 "void main()\n"
6431 "{\n"
6432 " vec4 result = vec4(0, 1, 0, 1);\n"
6433 "\n"
6434 "VERIFICATION"
6435 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6436 " {\n"
6437 " result = vec4(1, 0, 0, 1);\n"
6438 " }\n"
6439 "\n"
6440 " gs_fs_result = result;\n"
6441 " gl_Position = vec4(-1, -1, 0, 1);\n"
6442 " EmitVertex();\n"
6443 " gs_fs_result = result;\n"
6444 " gl_Position = vec4(-1, 1, 0, 1);\n"
6445 " EmitVertex();\n"
6446 " gs_fs_result = result;\n"
6447 " gl_Position = vec4(1, -1, 0, 1);\n"
6448 " EmitVertex();\n"
6449 " gs_fs_result = result;\n"
6450 " gl_Position = vec4(1, 1, 0, 1);\n"
6451 " EmitVertex();\n"
6452 "}\n"
6453 "\n";
6454
6455 static const GLchar *tess_ctrl_shader_template =
6456 "VERSION\n"
6457 "#extension GL_ARB_explicit_uniform_location : enable\n"
6458 "\n"
6459 "layout(vertices = 1) out;\n"
6460 "\n"
6461 "in vec4 vs_tcs_result[];\n"
6462 "out vec4 tcs_tes_result[];\n"
6463 "\n"
6464 "VARIABLE_DECLARATION;\n"
6465 "\n"
6466 "void main()\n"
6467 "{\n"
6468 " vec4 result = vec4(0, 1, 0, 1);\n"
6469 "\n"
6470 "VERIFICATION"
6471 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6472 " {\n"
6473 " result = vec4(1, 0, 0, 1);\n"
6474 " }\n"
6475 "\n"
6476 " tcs_tes_result[gl_InvocationID] = result;\n"
6477 "\n"
6478 " gl_TessLevelOuter[0] = 1.0;\n"
6479 " gl_TessLevelOuter[1] = 1.0;\n"
6480 " gl_TessLevelOuter[2] = 1.0;\n"
6481 " gl_TessLevelOuter[3] = 1.0;\n"
6482 " gl_TessLevelInner[0] = 1.0;\n"
6483 " gl_TessLevelInner[1] = 1.0;\n"
6484 "}\n"
6485 "\n";
6486
6487 static const GLchar *tess_eval_shader_template = "VERSION\n"
6488 "#extension GL_ARB_explicit_uniform_location : enable\n"
6489 "\n"
6490 "layout(isolines, point_mode) in;\n"
6491 "\n"
6492 "in vec4 tcs_tes_result[];\n"
6493 "out vec4 tes_gs_result;\n"
6494 "\n"
6495 "VARIABLE_DECLARATION;\n"
6496 "\n"
6497 "void main()\n"
6498 "{\n"
6499 " vec4 result = vec4(0, 1, 0, 1);\n"
6500 "\n"
6501 "VERIFICATION"
6502 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6503 " {\n"
6504 " result = vec4(1, 0, 0, 1);\n"
6505 " }\n"
6506 "\n"
6507 " tes_gs_result = result;\n"
6508 "}\n"
6509 "\n";
6510
6511 static const GLchar *vertex_shader_template = "VERSION\n"
6512 "#extension GL_ARB_explicit_uniform_location : enable\n"
6513 "\n"
6514 "out vec4 vs_tcs_result;\n"
6515 "\n"
6516 "VARIABLE_DECLARATION;\n"
6517 "\n"
6518 "void main()\n"
6519 "{\n"
6520 " vec4 result = vec4(0, 1, 0, 1);\n"
6521 "\n"
6522 "VERIFICATION"
6523 "\n"
6524 " vs_tcs_result = result;\n"
6525 "}\n"
6526 "\n";
6527
6528 const GLchar *shader_template = 0;
6529 const GLchar *location_string = 0;
6530
6531 switch (in_stage)
6532 {
6533 case Utils::COMPUTE_SHADER:
6534 return;
6535 case Utils::FRAGMENT_SHADER:
6536 shader_template = fragment_shader_template;
6537 location_string = "0";
6538 break;
6539 case Utils::GEOMETRY_SHADER:
6540 shader_template = geometry_shader_template;
6541 location_string = "1";
6542 break;
6543 case Utils::TESS_CTRL_SHADER:
6544 shader_template = tess_ctrl_shader_template;
6545 location_string = "4";
6546 break;
6547 case Utils::TESS_EVAL_SHADER:
6548 shader_template = tess_eval_shader_template;
6549 location_string = "3";
6550 break;
6551 case Utils::VERTEX_SHADER:
6552 shader_template = vertex_shader_template;
6553 location_string = "2";
6554 break;
6555 default:
6556 TCU_FAIL("Invalid enum");
6557 }
6558
6559 const Utils::qualifierSet &test_case = getCurrentTestCase();
6560
6561 std::string uni_declaration;
6562 std::string uni_reference;
6563 Utils::prepareVariableStrings(in_stage, Utils::UNIFORM, test_case, "vec4", "test", uni_declaration, uni_reference);
6564
6565 out_source.m_parts[0].m_code = shader_template;
6566
6567 size_t position = 0;
6568
6569 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6570 out_source.m_parts[0].m_code);
6571
6572 Utils::replaceToken("VARIABLE_DECLARATION", position, uni_declaration.c_str(), out_source.m_parts[0].m_code);
6573
6574 position -= strlen(variable_declaration);
6575
6576 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6577
6578 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
6579
6580 Utils::replaceAllTokens("LOC_VALUE", location_string, out_source.m_parts[0].m_code);
6581 }
6582
6583 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
6584 *
6585 * @param program Current program
6586 **/
prepareUniforms(Utils::program & program)6587 void QualifierOrderUniformTest::prepareUniforms(Utils::program &program)
6588 {
6589 static const GLfloat float_data[4] = {0.0f, 0.0f, 1.0f, 1.0f};
6590
6591 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6592 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6593 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6594 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6595 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6596 }
6597
6598 /** Prepare test cases
6599 *
6600 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
6601 **/
testInit()6602 bool QualifierOrderUniformTest::testInit()
6603 {
6604 if (false == m_is_explicit_uniform_location)
6605 {
6606 return false;
6607 }
6608
6609 return true;
6610 }
6611
6612 /** Returns reference to current test case
6613 *
6614 * @return Reference to testCase
6615 **/
getCurrentTestCase()6616 const Utils::qualifierSet &QualifierOrderUniformTest::getCurrentTestCase()
6617 {
6618 if ((glw::GLuint)-1 == m_current_test_case_index)
6619 {
6620 return m_test_cases[0];
6621 }
6622 else
6623 {
6624 return m_test_cases[m_current_test_case_index];
6625 }
6626 }
6627
6628 /** Constructor
6629 *
6630 * @param context Test context
6631 **/
QualifierOrderFunctionInoutTest(deqp::Context & context,Utils::qualifierSet test_case,glw::GLuint test_id)6632 QualifierOrderFunctionInoutTest::QualifierOrderFunctionInoutTest(deqp::Context &context, Utils::qualifierSet test_case,
6633 glw::GLuint test_id)
6634 : GLSLTestBase(context, "qualifier_order_function_inout", "Verify order of qualifiers of inout function parameters")
6635 , m_current_test_case_index(0)
6636 {
6637 m_test_cases.push_back(test_case);
6638
6639 std::string name = "qualifier_order_function_inout_test_id_" + std::to_string(test_id);
6640
6641 TestCase::m_name = name;
6642 }
6643
6644 /** Set up next test case
6645 *
6646 * @param test_case_index Index of next test case
6647 *
6648 * @return false if there is no more test cases, true otherwise
6649 **/
prepareNextTestCase(glw::GLuint test_case_index)6650 bool QualifierOrderFunctionInoutTest::prepareNextTestCase(glw::GLuint test_case_index)
6651 {
6652 m_current_test_case_index = test_case_index;
6653
6654 if ((glw::GLuint)-1 == test_case_index)
6655 {
6656 /* Nothing to be done here */
6657 }
6658 else if (m_test_cases.size() <= test_case_index)
6659 {
6660 return false;
6661 }
6662
6663 const Utils::qualifierSet &set = getCurrentTestCase();
6664
6665 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6666
6667 for (GLuint i = 0; i < set.size(); ++i)
6668 {
6669 message << Utils::getQualifierString(set[i]) << " ";
6670 }
6671
6672 message << tcu::TestLog::EndMessage;
6673
6674 return true;
6675 }
6676
6677 /** Prepare source for given shader stage
6678 *
6679 * @param in_stage Shader stage, compute shader will use 430
6680 * @param in_use_version_400 Select if 400 or 420 should be used
6681 * @param out_source Prepared shader source instance
6682 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6683 void QualifierOrderFunctionInoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6684 Utils::shaderSource &out_source)
6685 {
6686 static const GLchar *verification_snippet =
6687 " vec4 temp = VARIABLE_NAME;\n"
6688 "\n"
6689 " function(temp);\n"
6690 "\n"
6691 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
6692 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6693 " {\n"
6694 " result = VARIABLE_NAME;\n"
6695 " }\n";
6696
6697 static const GLchar *function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
6698 "{\n"
6699 " param = param.wzyx;\n"
6700 "}\n";
6701
6702 static const GLchar *fragment_shader_template = "VERSION\n"
6703 "\n"
6704 "in vec4 gs_fs_result;\n"
6705 "out vec4 fs_out_result;\n"
6706 "\n"
6707 "uniform vec4 VARIABLE_NAME;\n"
6708 "\n"
6709 "FUNCTION_DECLARATION\n"
6710 "\n"
6711 "void main()\n"
6712 "{\n"
6713 " vec4 result = vec4(0, 1, 0, 1);\n"
6714 "\n"
6715 "VERIFICATION"
6716 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6717 " {\n"
6718 " result = vec4(1, 0, 0, 1);\n"
6719 " }\n"
6720 "\n"
6721 " fs_out_result = result;\n"
6722 "}\n"
6723 "\n";
6724
6725 static const GLchar *geometry_shader_template = "VERSION\n"
6726 "\n"
6727 "layout(points) in;\n"
6728 "layout(triangle_strip, max_vertices = 4) out;\n"
6729 "\n"
6730 "in vec4 tes_gs_result[];\n"
6731 "out vec4 gs_fs_result;\n"
6732 "\n"
6733 "uniform vec4 VARIABLE_NAME;\n"
6734 "\n"
6735 "FUNCTION_DECLARATION\n"
6736 "\n"
6737 "void main()\n"
6738 "{\n"
6739 " vec4 result = vec4(0, 1, 0, 1);\n"
6740 "\n"
6741 "VERIFICATION"
6742 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6743 " {\n"
6744 " result = vec4(1, 0, 0, 1);\n"
6745 " }\n"
6746 "\n"
6747 " gs_fs_result = result;\n"
6748 " gl_Position = vec4(-1, -1, 0, 1);\n"
6749 " EmitVertex();\n"
6750 " gs_fs_result = result;\n"
6751 " gl_Position = vec4(-1, 1, 0, 1);\n"
6752 " EmitVertex();\n"
6753 " gs_fs_result = result;\n"
6754 " gl_Position = vec4(1, -1, 0, 1);\n"
6755 " EmitVertex();\n"
6756 " gs_fs_result = result;\n"
6757 " gl_Position = vec4(1, 1, 0, 1);\n"
6758 " EmitVertex();\n"
6759 "}\n"
6760 "\n";
6761
6762 static const GLchar *tess_ctrl_shader_template =
6763 "VERSION\n"
6764 "\n"
6765 "layout(vertices = 1) out;\n"
6766 "\n"
6767 "in vec4 vs_tcs_result[];\n"
6768 "out vec4 tcs_tes_result[];\n"
6769 "\n"
6770 "uniform vec4 VARIABLE_NAME;\n"
6771 "\n"
6772 "FUNCTION_DECLARATION\n"
6773 "\n"
6774 "void main()\n"
6775 "{\n"
6776 " vec4 result = vec4(0, 1, 0, 1);\n"
6777 "\n"
6778 "VERIFICATION"
6779 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6780 " {\n"
6781 " result = vec4(1, 0, 0, 1);\n"
6782 " }\n"
6783 "\n"
6784 " tcs_tes_result[gl_InvocationID] = result;\n"
6785 "\n"
6786 " gl_TessLevelOuter[0] = 1.0;\n"
6787 " gl_TessLevelOuter[1] = 1.0;\n"
6788 " gl_TessLevelOuter[2] = 1.0;\n"
6789 " gl_TessLevelOuter[3] = 1.0;\n"
6790 " gl_TessLevelInner[0] = 1.0;\n"
6791 " gl_TessLevelInner[1] = 1.0;\n"
6792 "}\n"
6793 "\n";
6794
6795 static const GLchar *tess_eval_shader_template = "VERSION\n"
6796 "\n"
6797 "layout(isolines, point_mode) in;\n"
6798 "\n"
6799 "in vec4 tcs_tes_result[];\n"
6800 "out vec4 tes_gs_result;\n"
6801 "\n"
6802 "uniform vec4 VARIABLE_NAME;\n"
6803 "\n"
6804 "FUNCTION_DECLARATION\n"
6805 "\n"
6806 "void main()\n"
6807 "{\n"
6808 " vec4 result = vec4(0, 1, 0, 1);\n"
6809 "\n"
6810 "VERIFICATION"
6811 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6812 " {\n"
6813 " result = vec4(1, 0, 0, 1);\n"
6814 " }\n"
6815 "\n"
6816 " tes_gs_result = result;\n"
6817 "}\n"
6818 "\n";
6819
6820 static const GLchar *vertex_shader_template = "VERSION\n"
6821 "\n"
6822 "out vec4 vs_tcs_result;\n"
6823 "\n"
6824 "uniform vec4 VARIABLE_NAME;\n"
6825 "\n"
6826 "FUNCTION_DECLARATION\n"
6827 "\n"
6828 "void main()\n"
6829 "{\n"
6830 " vec4 result = vec4(0, 1, 0, 1);\n"
6831 "\n"
6832 "VERIFICATION"
6833 "\n"
6834 " vs_tcs_result = result;\n"
6835 "}\n"
6836 "\n";
6837
6838 const GLchar *shader_template = 0;
6839
6840 switch (in_stage)
6841 {
6842 case Utils::COMPUTE_SHADER:
6843 return;
6844 case Utils::FRAGMENT_SHADER:
6845 shader_template = fragment_shader_template;
6846 break;
6847 case Utils::GEOMETRY_SHADER:
6848 shader_template = geometry_shader_template;
6849 break;
6850 case Utils::TESS_CTRL_SHADER:
6851 shader_template = tess_ctrl_shader_template;
6852 break;
6853 case Utils::TESS_EVAL_SHADER:
6854 shader_template = tess_eval_shader_template;
6855 break;
6856 case Utils::VERTEX_SHADER:
6857 shader_template = vertex_shader_template;
6858 break;
6859 default:
6860 TCU_FAIL("Invalid enum");
6861 }
6862
6863 const std::string &uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
6864 const std::string &qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
6865
6866 out_source.m_parts[0].m_code = shader_template;
6867
6868 size_t position = 0;
6869
6870 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6871 out_source.m_parts[0].m_code);
6872
6873 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
6874
6875 position -= strlen(function_declaration);
6876
6877 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
6878
6879 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6880
6881 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
6882 }
6883
6884 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
6885 *
6886 * @param program Current program
6887 **/
prepareUniforms(Utils::program & program)6888 void QualifierOrderFunctionInoutTest::prepareUniforms(Utils::program &program)
6889 {
6890 static const GLfloat float_data[4] = {1.0f, 1.0f, 0.0f, 0.0f};
6891
6892 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6893 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6894 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6895 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6896 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6897 }
6898
6899 /** Returns reference to current test case
6900 *
6901 * @return Reference to testCase
6902 **/
getCurrentTestCase()6903 const Utils::qualifierSet &QualifierOrderFunctionInoutTest::getCurrentTestCase()
6904 {
6905 if ((glw::GLuint)-1 == m_current_test_case_index)
6906 {
6907 return m_test_cases[0];
6908 }
6909 else
6910 {
6911 return m_test_cases[m_current_test_case_index];
6912 }
6913 }
6914
6915 /** Constructor
6916 *
6917 * @param context Test context
6918 **/
QualifierOrderFunctionInputTest(deqp::Context & context,Utils::qualifierSet test_case,glw::GLuint test_id)6919 QualifierOrderFunctionInputTest::QualifierOrderFunctionInputTest(deqp::Context &context, Utils::qualifierSet test_case,
6920 glw::GLuint test_id)
6921 : GLSLTestBase(context, "qualifier_order_function_input", "Verify order of qualifiers of function input parameters")
6922 , m_current_test_case_index(0)
6923 {
6924 m_test_cases.push_back(test_case);
6925
6926 std::string name = "qualifier_order_function_input_test_id_" + std::to_string(test_id);
6927
6928 TestCase::m_name = name;
6929 }
6930
6931 /** Set up next test case
6932 *
6933 * @param test_case_index Index of next test case
6934 *
6935 * @return false if there is no more test cases, true otherwise
6936 **/
prepareNextTestCase(glw::GLuint test_case_index)6937 bool QualifierOrderFunctionInputTest::prepareNextTestCase(glw::GLuint test_case_index)
6938 {
6939 m_current_test_case_index = test_case_index;
6940
6941 if ((glw::GLuint)-1 == test_case_index)
6942 {
6943 /* Nothing to be done here */
6944 }
6945 else if (m_test_cases.size() <= test_case_index)
6946 {
6947 return false;
6948 }
6949
6950 const Utils::qualifierSet &set = getCurrentTestCase();
6951
6952 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6953
6954 for (GLuint i = 0; i < set.size(); ++i)
6955 {
6956 message << Utils::getQualifierString(set[i]) << " ";
6957 }
6958
6959 message << tcu::TestLog::EndMessage;
6960
6961 return true;
6962 }
6963
6964 /** Prepare source for given shader stage
6965 *
6966 * @param in_stage Shader stage, compute shader will use 430
6967 * @param in_use_version_400 Select if 400 or 420 should be used
6968 * @param out_source Prepared shader source instance
6969 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6970 void QualifierOrderFunctionInputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6971 Utils::shaderSource &out_source)
6972 {
6973 static const GLchar *verification_snippet =
6974 " vec4 temp = function(VARIABLE_NAME);\n"
6975 "\n"
6976 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
6977 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6978 " {\n"
6979 " result = VARIABLE_NAME;\n"
6980 " }\n";
6981
6982 static const GLchar *function_declaration = "vec4 function(QUALIFIERS_LIST vec4 param)\n"
6983 "{\n"
6984 " return param.wzyx;\n"
6985 "}\n";
6986
6987 static const GLchar *fragment_shader_template = "VERSION\n"
6988 "\n"
6989 "in vec4 gs_fs_result;\n"
6990 "out vec4 fs_out_result;\n"
6991 "\n"
6992 "uniform vec4 VARIABLE_NAME;\n"
6993 "\n"
6994 "FUNCTION_DECLARATION\n"
6995 "\n"
6996 "void main()\n"
6997 "{\n"
6998 " vec4 result = vec4(0, 1, 0, 1);\n"
6999 "\n"
7000 "VERIFICATION"
7001 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7002 " {\n"
7003 " result = vec4(1, 0, 0, 1);\n"
7004 " }\n"
7005 "\n"
7006 " fs_out_result = result;\n"
7007 "}\n"
7008 "\n";
7009
7010 static const GLchar *geometry_shader_template = "VERSION\n"
7011 "\n"
7012 "layout(points) in;\n"
7013 "layout(triangle_strip, max_vertices = 4) out;\n"
7014 "\n"
7015 "in vec4 tes_gs_result[];\n"
7016 "out vec4 gs_fs_result;\n"
7017 "\n"
7018 "uniform vec4 VARIABLE_NAME;\n"
7019 "\n"
7020 "FUNCTION_DECLARATION\n"
7021 "\n"
7022 "void main()\n"
7023 "{\n"
7024 " vec4 result = vec4(0, 1, 0, 1);\n"
7025 "\n"
7026 "VERIFICATION"
7027 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7028 " {\n"
7029 " result = vec4(1, 0, 0, 1);\n"
7030 " }\n"
7031 "\n"
7032 " gs_fs_result = result;\n"
7033 " gl_Position = vec4(-1, -1, 0, 1);\n"
7034 " EmitVertex();\n"
7035 " gs_fs_result = result;\n"
7036 " gl_Position = vec4(-1, 1, 0, 1);\n"
7037 " EmitVertex();\n"
7038 " gs_fs_result = result;\n"
7039 " gl_Position = vec4(1, -1, 0, 1);\n"
7040 " EmitVertex();\n"
7041 " gs_fs_result = result;\n"
7042 " gl_Position = vec4(1, 1, 0, 1);\n"
7043 " EmitVertex();\n"
7044 "}\n"
7045 "\n";
7046
7047 static const GLchar *tess_ctrl_shader_template =
7048 "VERSION\n"
7049 "\n"
7050 "layout(vertices = 1) out;\n"
7051 "\n"
7052 "in vec4 vs_tcs_result[];\n"
7053 "out vec4 tcs_tes_result[];\n"
7054 "\n"
7055 "uniform vec4 VARIABLE_NAME;\n"
7056 "\n"
7057 "FUNCTION_DECLARATION\n"
7058 "\n"
7059 "void main()\n"
7060 "{\n"
7061 " vec4 result = vec4(0, 1, 0, 1);\n"
7062 "\n"
7063 "VERIFICATION"
7064 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7065 " {\n"
7066 " result = vec4(1, 0, 0, 1);\n"
7067 " }\n"
7068 "\n"
7069 " tcs_tes_result[gl_InvocationID] = result;\n"
7070 "\n"
7071 " gl_TessLevelOuter[0] = 1.0;\n"
7072 " gl_TessLevelOuter[1] = 1.0;\n"
7073 " gl_TessLevelOuter[2] = 1.0;\n"
7074 " gl_TessLevelOuter[3] = 1.0;\n"
7075 " gl_TessLevelInner[0] = 1.0;\n"
7076 " gl_TessLevelInner[1] = 1.0;\n"
7077 "}\n"
7078 "\n";
7079
7080 static const GLchar *tess_eval_shader_template = "VERSION\n"
7081 "\n"
7082 "layout(isolines, point_mode) in;\n"
7083 "\n"
7084 "in vec4 tcs_tes_result[];\n"
7085 "out vec4 tes_gs_result;\n"
7086 "\n"
7087 "uniform vec4 VARIABLE_NAME;\n"
7088 "\n"
7089 "FUNCTION_DECLARATION\n"
7090 "\n"
7091 "void main()\n"
7092 "{\n"
7093 " vec4 result = vec4(0, 1, 0, 1);\n"
7094 "\n"
7095 "VERIFICATION"
7096 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7097 " {\n"
7098 " result = vec4(1, 0, 0, 1);\n"
7099 " }\n"
7100 "\n"
7101 " tes_gs_result = result;\n"
7102 "}\n"
7103 "\n";
7104
7105 static const GLchar *vertex_shader_template = "VERSION\n"
7106 "\n"
7107 "out vec4 vs_tcs_result;\n"
7108 "\n"
7109 "uniform vec4 VARIABLE_NAME;\n"
7110 "\n"
7111 "FUNCTION_DECLARATION\n"
7112 "\n"
7113 "void main()\n"
7114 "{\n"
7115 " vec4 result = vec4(0, 1, 0, 1);\n"
7116 "\n"
7117 "VERIFICATION"
7118 "\n"
7119 " vs_tcs_result = result;\n"
7120 "}\n"
7121 "\n";
7122
7123 const GLchar *shader_template = 0;
7124
7125 switch (in_stage)
7126 {
7127 case Utils::COMPUTE_SHADER:
7128 return;
7129 case Utils::FRAGMENT_SHADER:
7130 shader_template = fragment_shader_template;
7131 break;
7132 case Utils::GEOMETRY_SHADER:
7133 shader_template = geometry_shader_template;
7134 break;
7135 case Utils::TESS_CTRL_SHADER:
7136 shader_template = tess_ctrl_shader_template;
7137 break;
7138 case Utils::TESS_EVAL_SHADER:
7139 shader_template = tess_eval_shader_template;
7140 break;
7141 case Utils::VERTEX_SHADER:
7142 shader_template = vertex_shader_template;
7143 break;
7144 default:
7145 TCU_FAIL("Invalid enum");
7146 }
7147
7148 const std::string &uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7149 const std::string &qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7150
7151 out_source.m_parts[0].m_code = shader_template;
7152
7153 size_t position = 0;
7154
7155 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7156 out_source.m_parts[0].m_code);
7157
7158 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7159
7160 position -= strlen(function_declaration);
7161
7162 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7163
7164 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7165
7166 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7167 }
7168
7169 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7170 *
7171 * @param program Current program
7172 **/
prepareUniforms(Utils::program & program)7173 void QualifierOrderFunctionInputTest::prepareUniforms(Utils::program &program)
7174 {
7175 static const GLfloat float_data[4] = {1.0f, 1.0f, 0.0f, 0.0f};
7176
7177 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7178 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7179 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7180 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7181 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7182 }
7183
7184 /** Returns reference to current test case
7185 *
7186 * @return Reference to testCase
7187 **/
getCurrentTestCase()7188 const Utils::qualifierSet &QualifierOrderFunctionInputTest::getCurrentTestCase()
7189 {
7190 if ((glw::GLuint)-1 == m_current_test_case_index)
7191 {
7192 return m_test_cases[0];
7193 }
7194 else
7195 {
7196 return m_test_cases[m_current_test_case_index];
7197 }
7198 }
7199
7200 /** Constructor
7201 *
7202 * @param context Test context
7203 **/
QualifierOrderFunctionOutputTest(deqp::Context & context,Utils::qualifierSet test_case,glw::GLuint test_id)7204 QualifierOrderFunctionOutputTest::QualifierOrderFunctionOutputTest(deqp::Context &context,
7205 Utils::qualifierSet test_case, glw::GLuint test_id)
7206 : GLSLTestBase(context, "qualifier_order_function_output",
7207 "Verify order of qualifiers of output function parameters")
7208 , m_current_test_case_index(0)
7209 {
7210 m_test_cases.push_back(test_case);
7211
7212 std::string name = "qualifier_order_function_output_test_id_" + std::to_string(test_id);
7213
7214 TestCase::m_name = name;
7215 }
7216
7217 /** Set up next test case
7218 *
7219 * @param test_case_index Index of next test case
7220 *
7221 * @return false if there is no more test cases, true otherwise
7222 **/
prepareNextTestCase(glw::GLuint test_case_index)7223 bool QualifierOrderFunctionOutputTest::prepareNextTestCase(glw::GLuint test_case_index)
7224 {
7225 m_current_test_case_index = test_case_index;
7226
7227 if ((glw::GLuint)-1 == test_case_index)
7228 {
7229 /* Nothing to be done here */
7230 }
7231 else if (m_test_cases.size() <= test_case_index)
7232 {
7233 return false;
7234 }
7235
7236 const Utils::qualifierSet &set = getCurrentTestCase();
7237
7238 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7239
7240 for (GLuint i = 0; i < set.size(); ++i)
7241 {
7242 message << Utils::getQualifierString(set[i]) << " ";
7243 }
7244
7245 message << tcu::TestLog::EndMessage;
7246
7247 return true;
7248 }
7249
7250 /** Prepare source for given shader stage
7251 *
7252 * @param in_stage Shader stage, compute shader will use 430
7253 * @param in_use_version_400 Select if 400 or 420 should be used
7254 * @param out_source Prepared shader source instance
7255 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7256 void QualifierOrderFunctionOutputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7257 Utils::shaderSource &out_source)
7258 {
7259 static const GLchar *verification_snippet =
7260 " vec4 temp;\n"
7261 "\n"
7262 " function(temp);\n"
7263 "\n"
7264 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7265 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7266 " {\n"
7267 " result = VARIABLE_NAME;\n"
7268 " }\n";
7269
7270 static const GLchar *function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
7271 "{\n"
7272 " param = VARIABLE_NAME.wzyx;\n"
7273 "}\n";
7274
7275 static const GLchar *fragment_shader_template = "VERSION\n"
7276 "\n"
7277 "in vec4 gs_fs_result;\n"
7278 "out vec4 fs_out_result;\n"
7279 "\n"
7280 "uniform vec4 VARIABLE_NAME;\n"
7281 "\n"
7282 "FUNCTION_DECLARATION\n"
7283 "\n"
7284 "void main()\n"
7285 "{\n"
7286 " vec4 result = vec4(0, 1, 0, 1);\n"
7287 "\n"
7288 "VERIFICATION"
7289 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7290 " {\n"
7291 " result = vec4(1, 0, 0, 1);\n"
7292 " }\n"
7293 "\n"
7294 " fs_out_result = result;\n"
7295 "}\n"
7296 "\n";
7297
7298 static const GLchar *geometry_shader_template = "VERSION\n"
7299 "\n"
7300 "layout(points) in;\n"
7301 "layout(triangle_strip, max_vertices = 4) out;\n"
7302 "\n"
7303 "in vec4 tes_gs_result[];\n"
7304 "out vec4 gs_fs_result;\n"
7305 "\n"
7306 "uniform vec4 VARIABLE_NAME;\n"
7307 "\n"
7308 "FUNCTION_DECLARATION\n"
7309 "\n"
7310 "void main()\n"
7311 "{\n"
7312 " vec4 result = vec4(0, 1, 0, 1);\n"
7313 "\n"
7314 "VERIFICATION"
7315 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7316 " {\n"
7317 " result = vec4(1, 0, 0, 1);\n"
7318 " }\n"
7319 "\n"
7320 " gs_fs_result = result;\n"
7321 " gl_Position = vec4(-1, -1, 0, 1);\n"
7322 " EmitVertex();\n"
7323 " gs_fs_result = result;\n"
7324 " gl_Position = vec4(-1, 1, 0, 1);\n"
7325 " EmitVertex();\n"
7326 " gs_fs_result = result;\n"
7327 " gl_Position = vec4(1, -1, 0, 1);\n"
7328 " EmitVertex();\n"
7329 " gs_fs_result = result;\n"
7330 " gl_Position = vec4(1, 1, 0, 1);\n"
7331 " EmitVertex();\n"
7332 "}\n"
7333 "\n";
7334
7335 static const GLchar *tess_ctrl_shader_template =
7336 "VERSION\n"
7337 "\n"
7338 "layout(vertices = 1) out;\n"
7339 "\n"
7340 "in vec4 vs_tcs_result[];\n"
7341 "out vec4 tcs_tes_result[];\n"
7342 "\n"
7343 "uniform vec4 VARIABLE_NAME;\n"
7344 "\n"
7345 "FUNCTION_DECLARATION\n"
7346 "\n"
7347 "void main()\n"
7348 "{\n"
7349 " vec4 result = vec4(0, 1, 0, 1);\n"
7350 "\n"
7351 "VERIFICATION"
7352 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7353 " {\n"
7354 " result = vec4(1, 0, 0, 1);\n"
7355 " }\n"
7356 "\n"
7357 " tcs_tes_result[gl_InvocationID] = result;\n"
7358 "\n"
7359 " gl_TessLevelOuter[0] = 1.0;\n"
7360 " gl_TessLevelOuter[1] = 1.0;\n"
7361 " gl_TessLevelOuter[2] = 1.0;\n"
7362 " gl_TessLevelOuter[3] = 1.0;\n"
7363 " gl_TessLevelInner[0] = 1.0;\n"
7364 " gl_TessLevelInner[1] = 1.0;\n"
7365 "}\n"
7366 "\n";
7367
7368 static const GLchar *tess_eval_shader_template = "VERSION\n"
7369 "\n"
7370 "layout(isolines, point_mode) in;\n"
7371 "\n"
7372 "in vec4 tcs_tes_result[];\n"
7373 "out vec4 tes_gs_result;\n"
7374 "\n"
7375 "uniform vec4 VARIABLE_NAME;\n"
7376 "\n"
7377 "FUNCTION_DECLARATION\n"
7378 "\n"
7379 "void main()\n"
7380 "{\n"
7381 " vec4 result = vec4(0, 1, 0, 1);\n"
7382 "\n"
7383 "VERIFICATION"
7384 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7385 " {\n"
7386 " result = vec4(1, 0, 0, 1);\n"
7387 " }\n"
7388 "\n"
7389 " tes_gs_result = result;\n"
7390 "}\n"
7391 "\n";
7392
7393 static const GLchar *vertex_shader_template = "VERSION\n"
7394 "\n"
7395 "out vec4 vs_tcs_result;\n"
7396 "\n"
7397 "uniform vec4 VARIABLE_NAME;\n"
7398 "\n"
7399 "FUNCTION_DECLARATION\n"
7400 "\n"
7401 "void main()\n"
7402 "{\n"
7403 " vec4 result = vec4(0, 1, 0, 1);\n"
7404 "\n"
7405 "VERIFICATION"
7406 "\n"
7407 " vs_tcs_result = result;\n"
7408 "}\n"
7409 "\n";
7410
7411 const GLchar *shader_template = 0;
7412
7413 switch (in_stage)
7414 {
7415 case Utils::COMPUTE_SHADER:
7416 return;
7417 case Utils::FRAGMENT_SHADER:
7418 shader_template = fragment_shader_template;
7419 break;
7420 case Utils::GEOMETRY_SHADER:
7421 shader_template = geometry_shader_template;
7422 break;
7423 case Utils::TESS_CTRL_SHADER:
7424 shader_template = tess_ctrl_shader_template;
7425 break;
7426 case Utils::TESS_EVAL_SHADER:
7427 shader_template = tess_eval_shader_template;
7428 break;
7429 case Utils::VERTEX_SHADER:
7430 shader_template = vertex_shader_template;
7431 break;
7432 default:
7433 TCU_FAIL("Invalid enum");
7434 }
7435
7436 const std::string &uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7437 const std::string &qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7438
7439 out_source.m_parts[0].m_code = shader_template;
7440
7441 size_t position = 0;
7442
7443 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7444 out_source.m_parts[0].m_code);
7445
7446 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7447
7448 position -= strlen(function_declaration);
7449
7450 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7451
7452 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7453
7454 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7455 }
7456
7457 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7458 *
7459 * @param program Current program
7460 **/
prepareUniforms(Utils::program & program)7461 void QualifierOrderFunctionOutputTest::prepareUniforms(Utils::program &program)
7462 {
7463 static const GLfloat float_data[4] = {1.0f, 1.0f, 0.0f, 0.0f};
7464
7465 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7466 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7467 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7468 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7469 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7470 }
7471
7472 /** Returns reference to current test case
7473 *
7474 * @return Reference to testCase
7475 **/
getCurrentTestCase()7476 const Utils::qualifierSet &QualifierOrderFunctionOutputTest::getCurrentTestCase()
7477 {
7478 if ((glw::GLuint)-1 == m_current_test_case_index)
7479 {
7480 return m_test_cases[0];
7481 }
7482 else
7483 {
7484 return m_test_cases[m_current_test_case_index];
7485 }
7486 }
7487
7488 /** Constructor
7489 *
7490 * @param context Test context
7491 **/
QualifierOverrideLayoutTest(deqp::Context & context)7492 QualifierOverrideLayoutTest::QualifierOverrideLayoutTest(deqp::Context &context)
7493 : GLSLTestBase(context, "qualifier_override_layout", "Verifies overriding layout qualifiers")
7494 {
7495 /* Nothing to be done here */
7496 }
7497
7498 /** Prepare source for given shader stage
7499 *
7500 * @param in_stage Shader stage, compute shader will use 430
7501 * @param in_use_version_400 Select if 400 or 420 should be used
7502 * @param out_source Prepared shader source instance
7503 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7504 void QualifierOverrideLayoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7505 Utils::shaderSource &out_source)
7506 {
7507 static const GLchar *fragment_shader_template = "VERSION\n"
7508 "\n"
7509 "in layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7510 "out vec4 fs_out_result;\n"
7511 "\n"
7512 "void main()\n"
7513 "{\n"
7514 " vec4 result = vec4(0, 1, 0, 1);\n"
7515 "\n"
7516 " if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7517 " {\n"
7518 " result = vec4(1, 0, 0, 1);\n"
7519 " }\n"
7520 "\n"
7521 " fs_out_result = result;\n"
7522 "}\n"
7523 "\n";
7524
7525 static const GLchar *geometry_shader_template =
7526 "VERSION\n"
7527 "\n"
7528 "layout(points) in;\n"
7529 "layout(triangle_strip, max_vertices = 2) layout(max_vertices = 4) out;\n"
7530 "\n"
7531 "in layout(location = 3) layout(location = 2) vec4 tes_gs_result[];\n"
7532 "out layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7533 "\n"
7534 "void main()\n"
7535 "{\n"
7536 " vec4 result = vec4(0, 1, 0, 1);\n"
7537 "\n"
7538 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7539 " {\n"
7540 " result = vec4(1, 0, 0, 1);\n"
7541 " }\n"
7542 "\n"
7543 " gs_fs_result = result;\n"
7544 " gl_Position = vec4(-1, -1, 0, 1);\n"
7545 " EmitVertex();\n"
7546 " gs_fs_result = result;\n"
7547 " gl_Position = vec4(-1, 1, 0, 1);\n"
7548 " EmitVertex();\n"
7549 " gs_fs_result = result;\n"
7550 " gl_Position = vec4(1, -1, 0, 1);\n"
7551 " EmitVertex();\n"
7552 " gs_fs_result = result;\n"
7553 " gl_Position = vec4(1, 1, 0, 1);\n"
7554 " EmitVertex();\n"
7555 "}\n"
7556 "\n";
7557
7558 static const GLchar *tess_ctrl_shader_template =
7559 "VERSION\n"
7560 "\n"
7561 "layout(vertices = 4) layout(vertices = 1) out;\n"
7562 "\n"
7563 "in layout(location = 3) layout(location = 2) vec4 vs_tcs_result[];\n"
7564 "out layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7565 "\n"
7566 "void main()\n"
7567 "{\n"
7568 " vec4 result = vec4(0, 1, 0, 1);\n"
7569 "\n"
7570 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7571 " {\n"
7572 " result = vec4(1, 0, 0, 1);\n"
7573 " }\n"
7574 "\n"
7575 " tcs_tes_result[gl_InvocationID] = result;\n"
7576 "\n"
7577 " gl_TessLevelOuter[0] = 1.0;\n"
7578 " gl_TessLevelOuter[1] = 1.0;\n"
7579 " gl_TessLevelOuter[2] = 1.0;\n"
7580 " gl_TessLevelOuter[3] = 1.0;\n"
7581 " gl_TessLevelInner[0] = 1.0;\n"
7582 " gl_TessLevelInner[1] = 1.0;\n"
7583 "}\n"
7584 "\n";
7585
7586 static const GLchar *tess_eval_shader_template =
7587 "VERSION\n"
7588 "\n"
7589 "layout(isolines, point_mode) in;\n"
7590 "\n"
7591 "in layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7592 "out layout(location = 3) layout(location = 2) vec4 tes_gs_result;\n"
7593 "\n"
7594 "void main()\n"
7595 "{\n"
7596 " vec4 result = vec4(0, 1, 0, 1);\n"
7597 "\n"
7598 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7599 " {\n"
7600 " result = vec4(1, 0, 0, 1);\n"
7601 " }\n"
7602 "\n"
7603 " tes_gs_result = result;\n"
7604 "}\n"
7605 "\n";
7606
7607 static const GLchar *vertex_shader_template = "VERSION\n"
7608 "\n"
7609 "in layout(location = 3) layout(location = 2) vec4 in_vs_test;\n"
7610 "out layout(location = 3) layout(location = 2) vec4 vs_tcs_result;\n"
7611 "\n"
7612 "void main()\n"
7613 "{\n"
7614 " vec4 result = in_vs_test;\n"
7615 "\n"
7616 " vs_tcs_result = result;\n"
7617 "}\n"
7618 "\n";
7619
7620 const GLchar *shader_template = 0;
7621
7622 switch (in_stage)
7623 {
7624 case Utils::COMPUTE_SHADER:
7625 return;
7626 case Utils::FRAGMENT_SHADER:
7627 shader_template = fragment_shader_template;
7628 break;
7629 case Utils::GEOMETRY_SHADER:
7630 shader_template = geometry_shader_template;
7631 break;
7632 case Utils::TESS_CTRL_SHADER:
7633 shader_template = tess_ctrl_shader_template;
7634 break;
7635 case Utils::TESS_EVAL_SHADER:
7636 shader_template = tess_eval_shader_template;
7637 break;
7638 case Utils::VERTEX_SHADER:
7639 shader_template = vertex_shader_template;
7640 break;
7641 default:
7642 TCU_FAIL("Invalid enum");
7643 }
7644
7645 out_source.m_parts[0].m_code = shader_template;
7646
7647 size_t position = 0;
7648
7649 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7650 out_source.m_parts[0].m_code);
7651 }
7652
7653 /**Prepare vertex buffer and vertex array object.
7654 *
7655 * @param program Program instance
7656 * @param buffer Buffer instance
7657 * @param vao VertexArray instance
7658 *
7659 * @return 0
7660 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)7661 void QualifierOverrideLayoutTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
7662 Utils::vertexArray &vao)
7663 {
7664 static const GLint expected_location = 2;
7665
7666 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
7667 GLint test_loc = program.getAttribLocation(test_name.c_str());
7668
7669 if (expected_location != test_loc)
7670 {
7671 TCU_FAIL("Vertex attribute location is invalid");
7672 }
7673
7674 vao.generate();
7675 vao.bind();
7676
7677 buffer.generate(GL_ARRAY_BUFFER);
7678
7679 GLfloat data[] = {0.0f, 1.0f, 0.0f, 1.0f};
7680 GLsizeiptr data_size = sizeof(data);
7681
7682 buffer.update(data_size, data, GL_STATIC_DRAW);
7683
7684 /* GL entry points */
7685 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7686
7687 /* Set up vao */
7688 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
7689 0 /* offset */);
7690 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
7691
7692 /* Enable attribute */
7693 gl.enableVertexAttribArray(test_loc);
7694 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
7695 }
7696
7697 /** Constructor
7698 *
7699 * @param context Test context
7700 **/
BindingUniformBlocksTest(deqp::Context & context)7701 BindingUniformBlocksTest::BindingUniformBlocksTest(deqp::Context &context)
7702 : GLSLTestBase(context, "binding_uniform_blocks", "Test verifies uniform block binding")
7703 , m_goku_buffer(context)
7704 , m_vegeta_buffer(context)
7705 , m_children_buffer(context)
7706 {
7707 /* Nothing to be done here */
7708 }
7709
7710 /** Prepare source for given shader stage
7711 *
7712 * @param in_stage Shader stage, compute shader will use 430
7713 * @param in_use_version_400 Select if 400 or 420 should be used
7714 * @param out_source Prepared shader source instance
7715 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7716 void BindingUniformBlocksTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7717 Utils::shaderSource &out_source)
7718 {
7719 static const GLchar *uni_goku = "layout(std140, binding = 0) uniform GOKU {\n"
7720 " vec4 chichi;\n"
7721 "} goku;\n";
7722
7723 static const GLchar *uni_vegeta = "layout(std140, binding = 1) uniform VEGETA {\n"
7724 " vec3 bulma;\n"
7725 "} vegeta;\n";
7726
7727 static const GLchar *uni_children = "layout(std140, binding = 3) uniform CHILDREN {\n"
7728 " vec4 gohan;\n"
7729 " vec4 trunks;\n"
7730 "} children;\n\n";
7731
7732 static const GLchar *verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.chichi) ||\n"
7733 " (vec3(0, 1, 0) != vegeta.bulma) ||\n"
7734 " (vec4(0, 0, 1, 0) != children.gohan) ||\n"
7735 " (vec4(0, 0, 0, 1) != children.trunks) )\n"
7736 " {\n"
7737 " result = vec4(1, 0, 0, 1);\n"
7738 " }\n";
7739
7740 static const GLchar *compute_shader_template =
7741 "VERSION\n"
7742 "\n"
7743 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7744 "\n"
7745 "writeonly uniform image2D uni_image;\n"
7746 "\n"
7747 "UNI_GOKU\n"
7748 "UNI_VEGETA\n"
7749 "UNI_CHILDREN\n"
7750 "\n"
7751 "void main()\n"
7752 "{\n"
7753 " vec4 result = vec4(0, 1, 0, 1);\n"
7754 "\n"
7755 "VERIFICATION"
7756 "\n"
7757 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
7758 "}\n"
7759 "\n";
7760
7761 static const GLchar *fragment_shader_template = "VERSION\n"
7762 "\n"
7763 "in vec4 gs_fs_result;\n"
7764 "out vec4 fs_out_result;\n"
7765 "\n"
7766 "UNI_GOKU\n"
7767 "UNI_VEGETA\n"
7768 "UNI_CHILDREN\n"
7769 "\n"
7770 "void main()\n"
7771 "{\n"
7772 " vec4 result = vec4(0, 1, 0, 1);\n"
7773 "\n"
7774 "VERIFICATION"
7775 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7776 " {\n"
7777 " result = vec4(1, 0, 0, 1);\n"
7778 " }\n"
7779 "\n"
7780 " fs_out_result = result;\n"
7781 "}\n"
7782 "\n";
7783
7784 static const GLchar *geometry_shader_template = "VERSION\n"
7785 "\n"
7786 "layout(points) in;\n"
7787 "layout(triangle_strip, max_vertices = 4) out;\n"
7788 "\n"
7789 "in vec4 tes_gs_result[];\n"
7790 "out vec4 gs_fs_result;\n"
7791 "\n"
7792 "UNI_CHILDREN\n"
7793 "UNI_GOKU\n"
7794 "UNI_VEGETA\n"
7795 "\n"
7796 "void main()\n"
7797 "{\n"
7798 " vec4 result = vec4(0, 1, 0, 1);\n"
7799 "\n"
7800 "VERIFICATION"
7801 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7802 " {\n"
7803 " result = vec4(1, 0, 0, 1);\n"
7804 " }\n"
7805 "\n"
7806 " gs_fs_result = result;\n"
7807 " gl_Position = vec4(-1, -1, 0, 1);\n"
7808 " EmitVertex();\n"
7809 " gs_fs_result = result;\n"
7810 " gl_Position = vec4(-1, 1, 0, 1);\n"
7811 " EmitVertex();\n"
7812 " gs_fs_result = result;\n"
7813 " gl_Position = vec4(1, -1, 0, 1);\n"
7814 " EmitVertex();\n"
7815 " gs_fs_result = result;\n"
7816 " gl_Position = vec4(1, 1, 0, 1);\n"
7817 " EmitVertex();\n"
7818 "}\n"
7819 "\n";
7820
7821 static const GLchar *tess_ctrl_shader_template =
7822 "VERSION\n"
7823 "\n"
7824 "layout(vertices = 1) out;\n"
7825 "\n"
7826 "in vec4 vs_tcs_result[];\n"
7827 "out vec4 tcs_tes_result[];\n"
7828 "\n"
7829 "UNI_VEGETA\n"
7830 "UNI_CHILDREN\n"
7831 "UNI_GOKU\n"
7832 "\n"
7833 "void main()\n"
7834 "{\n"
7835 " vec4 result = vec4(0, 1, 0, 1);\n"
7836 "\n"
7837 "VERIFICATION"
7838 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7839 " {\n"
7840 " result = vec4(1, 0, 0, 1);\n"
7841 " }\n"
7842 "\n"
7843 " tcs_tes_result[gl_InvocationID] = result;\n"
7844 "\n"
7845 " gl_TessLevelOuter[0] = 1.0;\n"
7846 " gl_TessLevelOuter[1] = 1.0;\n"
7847 " gl_TessLevelOuter[2] = 1.0;\n"
7848 " gl_TessLevelOuter[3] = 1.0;\n"
7849 " gl_TessLevelInner[0] = 1.0;\n"
7850 " gl_TessLevelInner[1] = 1.0;\n"
7851 "}\n"
7852 "\n";
7853
7854 static const GLchar *tess_eval_shader_template = "VERSION\n"
7855 "\n"
7856 "layout(isolines, point_mode) in;\n"
7857 "\n"
7858 "in vec4 tcs_tes_result[];\n"
7859 "out vec4 tes_gs_result;\n"
7860 "\n"
7861 "UNI_GOKU\n"
7862 "UNI_CHILDREN\n"
7863 "UNI_VEGETA\n"
7864 "\n"
7865 "void main()\n"
7866 "{\n"
7867 " vec4 result = vec4(0, 1, 0, 1);\n"
7868 "\n"
7869 "VERIFICATION"
7870 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7871 " {\n"
7872 " result = vec4(1, 0, 0, 1);\n"
7873 " }\n"
7874 "\n"
7875 " tes_gs_result = result;\n"
7876 "}\n"
7877 "\n";
7878
7879 static const GLchar *vertex_shader_template = "VERSION\n"
7880 "\n"
7881 "out vec4 vs_tcs_result;\n"
7882 "\n"
7883 "UNI_CHILDREN\n"
7884 "UNI_VEGETA\n"
7885 "UNI_GOKU\n"
7886 "\n"
7887 "void main()\n"
7888 "{\n"
7889 " vec4 result = vec4(0, 1, 0, 1);\n"
7890 "\n"
7891 "VERIFICATION"
7892 "\n"
7893 " vs_tcs_result = result;\n"
7894 "}\n"
7895 "\n";
7896
7897 const GLchar *shader_template = 0;
7898
7899 switch (in_stage)
7900 {
7901 case Utils::COMPUTE_SHADER:
7902 shader_template = compute_shader_template;
7903 break;
7904 case Utils::FRAGMENT_SHADER:
7905 shader_template = fragment_shader_template;
7906 break;
7907 case Utils::GEOMETRY_SHADER:
7908 shader_template = geometry_shader_template;
7909 break;
7910 case Utils::TESS_CTRL_SHADER:
7911 shader_template = tess_ctrl_shader_template;
7912 break;
7913 case Utils::TESS_EVAL_SHADER:
7914 shader_template = tess_eval_shader_template;
7915 break;
7916 case Utils::VERTEX_SHADER:
7917 shader_template = vertex_shader_template;
7918 break;
7919 default:
7920 TCU_FAIL("Invalid enum");
7921 }
7922
7923 out_source.m_parts[0].m_code = shader_template;
7924
7925 size_t position = 0;
7926
7927 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7928 out_source.m_parts[0].m_code);
7929
7930 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7931
7932 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
7933
7934 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
7935
7936 Utils::replaceAllTokens("UNI_CHILDREN", uni_children, out_source.m_parts[0].m_code);
7937 }
7938
7939 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7940 *
7941 * @param program Current program
7942 **/
prepareUniforms(Utils::program & program)7943 void BindingUniformBlocksTest::prepareUniforms(Utils::program &program)
7944 {
7945 (void)program;
7946 static const GLfloat goku_data[4] = {1.0f, 0.0f, 0.0f, 0.0f};
7947 static const GLfloat vegeta_data[3] = {0.0f, 1.0f, 0.0f};
7948 static const GLfloat children_data[8] = {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
7949
7950 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
7951 m_vegeta_buffer.generate(GL_UNIFORM_BUFFER);
7952 m_children_buffer.generate(GL_UNIFORM_BUFFER);
7953
7954 m_goku_buffer.update(sizeof(goku_data), (GLvoid *)goku_data, GL_STATIC_DRAW);
7955 m_vegeta_buffer.update(sizeof(vegeta_data), (GLvoid *)vegeta_data, GL_STATIC_DRAW);
7956 m_children_buffer.update(sizeof(children_data), (GLvoid *)children_data, GL_STATIC_DRAW);
7957
7958 m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
7959 m_vegeta_buffer.bindRange(1 /* index */, 0 /* offset */, sizeof(vegeta_data));
7960 m_children_buffer.bindRange(3 /* index */, 0 /* offset */, sizeof(children_data));
7961 }
7962
7963 /** Overwrite of releaseResource method, release extra uniform buffer
7964 *
7965 * @param ignored
7966 **/
releaseResource()7967 void BindingUniformBlocksTest::releaseResource()
7968 {
7969 m_goku_buffer.release();
7970 m_vegeta_buffer.release();
7971 m_children_buffer.release();
7972 }
7973
7974 /** Constructor
7975 *
7976 * @param context Test context
7977 **/
BindingUniformSingleBlockTest(deqp::Context & context,Utils::SHADER_STAGES test_stage)7978 BindingUniformSingleBlockTest::BindingUniformSingleBlockTest(deqp::Context &context, Utils::SHADER_STAGES test_stage)
7979 : GLSLTestBase(context, "binding_uniform_single_block", "Test verifies uniform block binding")
7980 , m_goku_buffer(context)
7981 , m_test_stage(test_stage)
7982 {
7983 std::string name = "binding_uniform_single_block_stage_" + std::string(Utils::getShaderStageName(m_test_stage));
7984
7985 TestCase::m_name = name;
7986 }
7987
7988 /** Set up next test case
7989 *
7990 * @param test_case_index Index of next test case
7991 *
7992 * @return false if there is no more test cases, true otherwise
7993 **/
prepareNextTestCase(glw::GLuint test_case_index)7994 bool BindingUniformSingleBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
7995 {
7996 if (test_case_index > 0)
7997 {
7998 return false;
7999 }
8000
8001 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
8002 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
8003 << tcu::TestLog::EndMessage;
8004
8005 return true;
8006 }
8007
8008 /** Prepare source for given shader stage
8009 *
8010 * @param in_stage Shader stage, compute shader will use 430
8011 * @param in_use_version_400 Select if 400 or 420 should be used
8012 * @param out_source Prepared shader source instance
8013 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8014 void BindingUniformSingleBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8015 Utils::shaderSource &out_source)
8016 {
8017 static const GLchar *uni_goku_with_binding = "layout(std140, binding = 0) uniform GOKU {\n"
8018 " vec4 gohan;\n"
8019 " vec4 goten;\n"
8020 "} goku;\n";
8021
8022 static const GLchar *uni_goku_no_binding = "layout(std140) uniform GOKU {\n"
8023 " vec4 gohan;\n"
8024 " vec4 goten;\n"
8025 "} goku;\n";
8026
8027 static const GLchar *verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
8028 " (vec4(0, 1, 0, 0) != goku.goten) )\n"
8029 " {\n"
8030 " result = vec4(1, 0, 0, 1);\n"
8031 " }\n";
8032
8033 static const GLchar *compute_shader_template =
8034 "VERSION\n"
8035 "\n"
8036 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8037 "\n"
8038 "writeonly uniform image2D uni_image;\n"
8039 "\n"
8040 "UNI_GOKU\n"
8041 "\n"
8042 "void main()\n"
8043 "{\n"
8044 " vec4 result = vec4(0, 1, 0, 1);\n"
8045 "\n"
8046 "VERIFICATION"
8047 "\n"
8048 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8049 "}\n"
8050 "\n";
8051
8052 static const GLchar *fragment_shader_template = "VERSION\n"
8053 "\n"
8054 "in vec4 gs_fs_result;\n"
8055 "out vec4 fs_out_result;\n"
8056 "\n"
8057 "UNI_GOKU\n"
8058 "\n"
8059 "void main()\n"
8060 "{\n"
8061 " vec4 result = vec4(0, 1, 0, 1);\n"
8062 "\n"
8063 "VERIFICATION"
8064 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8065 " {\n"
8066 " result = vec4(1, 0, 0, 1);\n"
8067 " }\n"
8068 "\n"
8069 " fs_out_result = result;\n"
8070 "}\n"
8071 "\n";
8072
8073 static const GLchar *geometry_shader_template = "VERSION\n"
8074 "\n"
8075 "layout(points) in;\n"
8076 "layout(triangle_strip, max_vertices = 4) out;\n"
8077 "\n"
8078 "in vec4 tes_gs_result[];\n"
8079 "out vec4 gs_fs_result;\n"
8080 "\n"
8081 "UNI_GOKU\n"
8082 "\n"
8083 "void main()\n"
8084 "{\n"
8085 " vec4 result = vec4(0, 1, 0, 1);\n"
8086 "\n"
8087 "VERIFICATION"
8088 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8089 " {\n"
8090 " result = vec4(1, 0, 0, 1);\n"
8091 " }\n"
8092 "\n"
8093 " gs_fs_result = result;\n"
8094 " gl_Position = vec4(-1, -1, 0, 1);\n"
8095 " EmitVertex();\n"
8096 " gs_fs_result = result;\n"
8097 " gl_Position = vec4(-1, 1, 0, 1);\n"
8098 " EmitVertex();\n"
8099 " gs_fs_result = result;\n"
8100 " gl_Position = vec4(1, -1, 0, 1);\n"
8101 " EmitVertex();\n"
8102 " gs_fs_result = result;\n"
8103 " gl_Position = vec4(1, 1, 0, 1);\n"
8104 " EmitVertex();\n"
8105 "}\n"
8106 "\n";
8107
8108 static const GLchar *tess_ctrl_shader_template =
8109 "VERSION\n"
8110 "\n"
8111 "layout(vertices = 1) out;\n"
8112 "\n"
8113 "in vec4 vs_tcs_result[];\n"
8114 "out vec4 tcs_tes_result[];\n"
8115 "\n"
8116 "UNI_GOKU\n"
8117 "\n"
8118 "void main()\n"
8119 "{\n"
8120 " vec4 result = vec4(0, 1, 0, 1);\n"
8121 "\n"
8122 "VERIFICATION"
8123 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8124 " {\n"
8125 " result = vec4(1, 0, 0, 1);\n"
8126 " }\n"
8127 "\n"
8128 " tcs_tes_result[gl_InvocationID] = result;\n"
8129 "\n"
8130 " gl_TessLevelOuter[0] = 1.0;\n"
8131 " gl_TessLevelOuter[1] = 1.0;\n"
8132 " gl_TessLevelOuter[2] = 1.0;\n"
8133 " gl_TessLevelOuter[3] = 1.0;\n"
8134 " gl_TessLevelInner[0] = 1.0;\n"
8135 " gl_TessLevelInner[1] = 1.0;\n"
8136 "}\n"
8137 "\n";
8138
8139 static const GLchar *tess_eval_shader_template = "VERSION\n"
8140 "\n"
8141 "layout(isolines, point_mode) in;\n"
8142 "\n"
8143 "in vec4 tcs_tes_result[];\n"
8144 "out vec4 tes_gs_result;\n"
8145 "\n"
8146 "UNI_GOKU\n"
8147 "\n"
8148 "void main()\n"
8149 "{\n"
8150 " vec4 result = vec4(0, 1, 0, 1);\n"
8151 "\n"
8152 "VERIFICATION"
8153 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8154 " {\n"
8155 " result = vec4(1, 0, 0, 1);\n"
8156 " }\n"
8157 "\n"
8158 " tes_gs_result = result;\n"
8159 "}\n"
8160 "\n";
8161
8162 static const GLchar *vertex_shader_template = "VERSION\n"
8163 "\n"
8164 "out vec4 vs_tcs_result;\n"
8165 "\n"
8166 "UNI_GOKU\n"
8167 "\n"
8168 "void main()\n"
8169 "{\n"
8170 " vec4 result = vec4(0, 1, 0, 1);\n"
8171 "\n"
8172 "VERIFICATION"
8173 "\n"
8174 " vs_tcs_result = result;\n"
8175 "}\n"
8176 "\n";
8177
8178 const GLchar *shader_template = 0;
8179 const GLchar *uniform_definition = uni_goku_no_binding;
8180
8181 switch (in_stage)
8182 {
8183 case Utils::COMPUTE_SHADER:
8184 shader_template = compute_shader_template;
8185 uniform_definition = uni_goku_with_binding;
8186 break;
8187 case Utils::FRAGMENT_SHADER:
8188 shader_template = fragment_shader_template;
8189 break;
8190 case Utils::GEOMETRY_SHADER:
8191 shader_template = geometry_shader_template;
8192 break;
8193 case Utils::TESS_CTRL_SHADER:
8194 shader_template = tess_ctrl_shader_template;
8195 break;
8196 case Utils::TESS_EVAL_SHADER:
8197 shader_template = tess_eval_shader_template;
8198 break;
8199 case Utils::VERTEX_SHADER:
8200 shader_template = vertex_shader_template;
8201 break;
8202 default:
8203 TCU_FAIL("Invalid enum");
8204 }
8205
8206 if (in_stage == m_test_stage)
8207 {
8208 uniform_definition = uni_goku_with_binding;
8209 }
8210
8211 out_source.m_parts[0].m_code = shader_template;
8212
8213 size_t position = 0;
8214
8215 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8216 out_source.m_parts[0].m_code);
8217
8218 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8219
8220 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
8221 }
8222
8223 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8224 *
8225 * @param program Current program
8226 **/
prepareUniforms(Utils::program & program)8227 void BindingUniformSingleBlockTest::prepareUniforms(Utils::program &program)
8228 {
8229 (void)program;
8230 static const GLfloat goku_data[8] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
8231
8232 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8233
8234 m_goku_buffer.update(sizeof(goku_data), (GLvoid *)goku_data, GL_STATIC_DRAW);
8235
8236 m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8237 }
8238
8239 /** Overwrite of releaseResource method, release extra uniform buffer
8240 *
8241 * @param ignored
8242 **/
releaseResource()8243 void BindingUniformSingleBlockTest::releaseResource()
8244 {
8245 m_goku_buffer.release();
8246 }
8247
8248 /** Constructor
8249 *
8250 * @param context Test context
8251 **/
BindingUniformBlockArrayTest(deqp::Context & context)8252 BindingUniformBlockArrayTest::BindingUniformBlockArrayTest(deqp::Context &context)
8253 : GLSLTestBase(context, "binding_uniform_block_array", "Test verifies binding of uniform block arrays")
8254 , m_goku_00_buffer(context)
8255 , m_goku_01_buffer(context)
8256 , m_goku_02_buffer(context)
8257 , m_goku_03_buffer(context)
8258 , m_goku_04_buffer(context)
8259 , m_goku_05_buffer(context)
8260 , m_goku_06_buffer(context)
8261 , m_goku_07_buffer(context)
8262 , m_goku_08_buffer(context)
8263 , m_goku_09_buffer(context)
8264 , m_goku_10_buffer(context)
8265 , m_goku_11_buffer(context)
8266 , m_goku_12_buffer(context)
8267 , m_goku_13_buffer(context)
8268 {
8269 /* Nothing to be done here */
8270 }
8271
8272 /** Prepare source for given shader stage
8273 *
8274 * @param in_stage Shader stage, compute shader will use 430
8275 * @param in_use_version_400 Select if 400 or 420 should be used
8276 * @param out_source Prepared shader source instance
8277 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8278 void BindingUniformBlockArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8279 Utils::shaderSource &out_source)
8280 {
8281 static const GLchar *uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
8282 " vec4 gohan;\n"
8283 " vec4 goten;\n"
8284 "} goku[14];\n";
8285
8286 static const GLchar *verification_snippet = " if ((vec4(0, 0, 0, 0) != goku[0].gohan) ||\n"
8287 " (vec4(0, 0, 0, 1) != goku[0].goten) ||\n"
8288 " (vec4(0, 0, 1, 0) != goku[1].gohan) ||\n"
8289 " (vec4(0, 0, 1, 1) != goku[1].goten) ||\n"
8290 " (vec4(0, 1, 0, 0) != goku[2].gohan) ||\n"
8291 " (vec4(0, 1, 0, 1) != goku[2].goten) ||\n"
8292 " (vec4(0, 1, 1, 0) != goku[3].gohan) ||\n"
8293 " (vec4(0, 1, 1, 1) != goku[3].goten) ||\n"
8294 " (vec4(1, 0, 0, 0) != goku[4].gohan) ||\n"
8295 " (vec4(1, 0, 0, 1) != goku[4].goten) ||\n"
8296 " (vec4(1, 0, 1, 0) != goku[5].gohan) ||\n"
8297 " (vec4(1, 0, 1, 1) != goku[5].goten) ||\n"
8298 " (vec4(1, 1, 0, 0) != goku[6].gohan) ||\n"
8299 " (vec4(1, 1, 0, 1) != goku[6].goten) ||\n"
8300 " (vec4(1, 1, 1, 0) != goku[7].gohan) ||\n"
8301 " (vec4(1, 1, 1, 1) != goku[7].goten) ||\n"
8302 " (vec4(0, 0, 0, 0) != goku[8].gohan) ||\n"
8303 " (vec4(0, 0, 0, 1) != goku[8].goten) ||\n"
8304 " (vec4(0, 0, 1, 0) != goku[9].gohan) ||\n"
8305 " (vec4(0, 0, 1, 1) != goku[9].goten) ||\n"
8306 " (vec4(0, 1, 0, 0) != goku[10].gohan) ||\n"
8307 " (vec4(0, 1, 0, 1) != goku[10].goten) ||\n"
8308 " (vec4(0, 1, 1, 0) != goku[11].gohan) ||\n"
8309 " (vec4(0, 1, 1, 1) != goku[11].goten) ||\n"
8310 " (vec4(1, 0, 0, 0) != goku[12].gohan) ||\n"
8311 " (vec4(1, 0, 0, 1) != goku[12].goten) ||\n"
8312 " (vec4(1, 0, 1, 0) != goku[13].gohan) ||\n"
8313 " (vec4(1, 0, 1, 1) != goku[13].goten) )\n"
8314 " {\n"
8315 " result = vec4(1, 0, 0, 1);\n"
8316 " }\n";
8317
8318 static const GLchar *compute_shader_template =
8319 "VERSION\n"
8320 "\n"
8321 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8322 "\n"
8323 "writeonly uniform image2D uni_image;\n"
8324 "\n"
8325 "UNI_GOKU\n"
8326 "\n"
8327 "void main()\n"
8328 "{\n"
8329 " vec4 result = vec4(0, 1, 0, 1);\n"
8330 "\n"
8331 "VERIFICATION"
8332 "\n"
8333 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8334 "}\n"
8335 "\n";
8336
8337 static const GLchar *fragment_shader_template = "VERSION\n"
8338 "\n"
8339 "in vec4 gs_fs_result;\n"
8340 "out vec4 fs_out_result;\n"
8341 "\n"
8342 "UNI_GOKU\n"
8343 "\n"
8344 "void main()\n"
8345 "{\n"
8346 " vec4 result = vec4(0, 1, 0, 1);\n"
8347 "\n"
8348 "VERIFICATION"
8349 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8350 " {\n"
8351 " result = vec4(1, 0, 0, 1);\n"
8352 " }\n"
8353 "\n"
8354 " fs_out_result = result;\n"
8355 "}\n"
8356 "\n";
8357
8358 static const GLchar *geometry_shader_template = "VERSION\n"
8359 "\n"
8360 "layout(points) in;\n"
8361 "layout(triangle_strip, max_vertices = 4) out;\n"
8362 "\n"
8363 "in vec4 tes_gs_result[];\n"
8364 "out vec4 gs_fs_result;\n"
8365 "\n"
8366 "UNI_GOKU\n"
8367 "\n"
8368 "void main()\n"
8369 "{\n"
8370 " vec4 result = vec4(0, 1, 0, 1);\n"
8371 "\n"
8372 "VERIFICATION"
8373 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8374 " {\n"
8375 " result = vec4(1, 0, 0, 1);\n"
8376 " }\n"
8377 "\n"
8378 " gs_fs_result = result;\n"
8379 " gl_Position = vec4(-1, -1, 0, 1);\n"
8380 " EmitVertex();\n"
8381 " gs_fs_result = result;\n"
8382 " gl_Position = vec4(-1, 1, 0, 1);\n"
8383 " EmitVertex();\n"
8384 " gs_fs_result = result;\n"
8385 " gl_Position = vec4(1, -1, 0, 1);\n"
8386 " EmitVertex();\n"
8387 " gs_fs_result = result;\n"
8388 " gl_Position = vec4(1, 1, 0, 1);\n"
8389 " EmitVertex();\n"
8390 "}\n"
8391 "\n";
8392
8393 static const GLchar *tess_ctrl_shader_template =
8394 "VERSION\n"
8395 "\n"
8396 "layout(vertices = 1) out;\n"
8397 "\n"
8398 "in vec4 vs_tcs_result[];\n"
8399 "out vec4 tcs_tes_result[];\n"
8400 "\n"
8401 "UNI_GOKU\n"
8402 "\n"
8403 "void main()\n"
8404 "{\n"
8405 " vec4 result = vec4(0, 1, 0, 1);\n"
8406 "\n"
8407 "VERIFICATION"
8408 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8409 " {\n"
8410 " result = vec4(1, 0, 0, 1);\n"
8411 " }\n"
8412 "\n"
8413 " tcs_tes_result[gl_InvocationID] = result;\n"
8414 "\n"
8415 " gl_TessLevelOuter[0] = 1.0;\n"
8416 " gl_TessLevelOuter[1] = 1.0;\n"
8417 " gl_TessLevelOuter[2] = 1.0;\n"
8418 " gl_TessLevelOuter[3] = 1.0;\n"
8419 " gl_TessLevelInner[0] = 1.0;\n"
8420 " gl_TessLevelInner[1] = 1.0;\n"
8421 "}\n"
8422 "\n";
8423
8424 static const GLchar *tess_eval_shader_template = "VERSION\n"
8425 "\n"
8426 "layout(isolines, point_mode) in;\n"
8427 "\n"
8428 "in vec4 tcs_tes_result[];\n"
8429 "out vec4 tes_gs_result;\n"
8430 "\n"
8431 "UNI_GOKU\n"
8432 "\n"
8433 "void main()\n"
8434 "{\n"
8435 " vec4 result = vec4(0, 1, 0, 1);\n"
8436 "\n"
8437 "VERIFICATION"
8438 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8439 " {\n"
8440 " result = vec4(1, 0, 0, 1);\n"
8441 " }\n"
8442 "\n"
8443 " tes_gs_result = result;\n"
8444 "}\n"
8445 "\n";
8446
8447 static const GLchar *vertex_shader_template = "VERSION\n"
8448 "\n"
8449 "out vec4 vs_tcs_result;\n"
8450 "\n"
8451 "UNI_GOKU\n"
8452 "\n"
8453 "void main()\n"
8454 "{\n"
8455 " vec4 result = vec4(0, 1, 0, 1);\n"
8456 "\n"
8457 "VERIFICATION"
8458 "\n"
8459 " vs_tcs_result = result;\n"
8460 "}\n"
8461 "\n";
8462
8463 const GLchar *shader_template = 0;
8464
8465 switch (in_stage)
8466 {
8467 case Utils::COMPUTE_SHADER:
8468 shader_template = compute_shader_template;
8469 break;
8470 case Utils::FRAGMENT_SHADER:
8471 shader_template = fragment_shader_template;
8472 break;
8473 case Utils::GEOMETRY_SHADER:
8474 shader_template = geometry_shader_template;
8475 break;
8476 case Utils::TESS_CTRL_SHADER:
8477 shader_template = tess_ctrl_shader_template;
8478 break;
8479 case Utils::TESS_EVAL_SHADER:
8480 shader_template = tess_eval_shader_template;
8481 break;
8482 case Utils::VERTEX_SHADER:
8483 shader_template = vertex_shader_template;
8484 break;
8485 default:
8486 TCU_FAIL("Invalid enum");
8487 }
8488
8489 out_source.m_parts[0].m_code = shader_template;
8490
8491 size_t position = 0;
8492
8493 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8494 out_source.m_parts[0].m_code);
8495
8496 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8497
8498 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8499 }
8500
8501 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8502 *
8503 * @param program Current program
8504 **/
prepareUniforms(Utils::program & program)8505 void BindingUniformBlockArrayTest::prepareUniforms(Utils::program &program)
8506 {
8507 static const GLfloat goku_data[][8] = {
8508 {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f},
8509 {0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f},
8510 {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f},
8511 {1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f},
8512 {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f},
8513 {0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f},
8514 {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f}};
8515
8516 Utils::buffer *buffers[14] = {&m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8517 &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8518 &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8519 &m_goku_12_buffer, &m_goku_13_buffer};
8520
8521 for (GLuint i = 0; i < 14; ++i)
8522 {
8523 checkBinding(program, i, i + 2);
8524
8525 buffers[i]->generate(GL_UNIFORM_BUFFER);
8526 buffers[i]->update(sizeof(GLfloat) * 8, (GLvoid *)goku_data[i], GL_STATIC_DRAW);
8527 buffers[i]->bindRange(i + 2 /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
8528 }
8529 }
8530
8531 /** Overwrite of releaseResource method, release extra uniform buffer
8532 *
8533 * @param ignored
8534 **/
releaseResource()8535 void BindingUniformBlockArrayTest::releaseResource()
8536 {
8537 Utils::buffer *buffers[14] = {&m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8538 &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8539 &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8540 &m_goku_12_buffer, &m_goku_13_buffer};
8541
8542 for (GLuint i = 0; i < 14; ++i)
8543 {
8544 buffers[i]->release();
8545 }
8546 }
8547
8548 /** Verifies that API reports correct uniform binding
8549 *
8550 * @param program Program
8551 * @param index Index of array element
8552 * @param expected_binding Expected binding
8553 **/
checkBinding(Utils::program & program,glw::GLuint index,glw::GLint expected_binding)8554 void BindingUniformBlockArrayTest::checkBinding(Utils::program &program, glw::GLuint index, glw::GLint expected_binding)
8555 {
8556 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8557
8558 GLchar buffer[64];
8559 sprintf(buffer, "GOKU[%d]", index);
8560
8561 const GLuint uniform_index = gl.getUniformBlockIndex(program.m_program_object_id, buffer);
8562 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8563 if (GL_INVALID_INDEX == uniform_index)
8564 {
8565 TCU_FAIL("Uniform block is inactive");
8566 }
8567
8568 GLint binding = -1;
8569
8570 gl.getActiveUniformBlockiv(program.m_program_object_id, uniform_index, GL_UNIFORM_BLOCK_BINDING, &binding);
8571 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8572
8573 if (expected_binding != binding)
8574 {
8575 TCU_FAIL("Wrong binding reported by API");
8576 }
8577 }
8578
8579 /** Constructor
8580 *
8581 * @param context Test context
8582 **/
BindingUniformDefaultTest(deqp::Context & context)8583 BindingUniformDefaultTest::BindingUniformDefaultTest(deqp::Context &context)
8584 : APITestBase(context, "binding_uniform_default", "Test verifies default binding of uniform block")
8585 {
8586 /* Nothing to be done here */
8587 }
8588
8589 /** Execute API call and verifies results
8590 *
8591 * @return true when results are positive, false otherwise
8592 **/
checkResults(Utils::program & program)8593 bool BindingUniformDefaultTest::checkResults(Utils::program &program)
8594 {
8595 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8596
8597 const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
8598 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8599 if (GL_INVALID_INDEX == index)
8600 {
8601 TCU_FAIL("Uniform block is inactive");
8602 return false;
8603 }
8604
8605 GLint binding = -1;
8606
8607 gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
8608 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8609
8610 if (0 != binding)
8611 {
8612 return false;
8613 }
8614
8615 return true;
8616 }
8617
8618 /** Prepare source for given shader stage
8619 *
8620 * @param in_stage Shader stage, compute shader will use 430
8621 * @param in_use_version_400 Select if 400 or 420 should be used
8622 * @param out_source Prepared shader source instance
8623 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8624 void BindingUniformDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8625 Utils::shaderSource &out_source)
8626 {
8627 static const GLchar *uni_goku = "layout(std140) uniform GOKU {\n"
8628 " vec4 gohan;\n"
8629 " vec4 goten;\n"
8630 "} goku;\n";
8631
8632 static const GLchar *verification_snippet = " if ((vec4(0, 0, 0, 0) != goku.gohan) ||\n"
8633 " (vec4(0, 0, 0, 1) != goku.goten) )\n"
8634 " {\n"
8635 " result = vec4(1, 0, 0, 1);\n"
8636 " }\n";
8637
8638 static const GLchar *compute_shader_template =
8639 "VERSION\n"
8640 "\n"
8641 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8642 "\n"
8643 "writeonly uniform image2D uni_image;\n"
8644 "\n"
8645 "UNI_GOKU\n"
8646 "\n"
8647 "void main()\n"
8648 "{\n"
8649 " vec4 result = vec4(0, 1, 0, 1);\n"
8650 "\n"
8651 "VERIFICATION"
8652 "\n"
8653 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8654 "}\n"
8655 "\n";
8656
8657 static const GLchar *fragment_shader_template = "VERSION\n"
8658 "\n"
8659 "in vec4 gs_fs_result;\n"
8660 "out vec4 fs_out_result;\n"
8661 "\n"
8662 "UNI_GOKU\n"
8663 "\n"
8664 "void main()\n"
8665 "{\n"
8666 " vec4 result = vec4(0, 1, 0, 1);\n"
8667 "\n"
8668 "VERIFICATION"
8669 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8670 " {\n"
8671 " result = vec4(1, 0, 0, 1);\n"
8672 " }\n"
8673 "\n"
8674 " fs_out_result = result;\n"
8675 "}\n"
8676 "\n";
8677
8678 static const GLchar *geometry_shader_template = "VERSION\n"
8679 "\n"
8680 "layout(points) in;\n"
8681 "layout(triangle_strip, max_vertices = 4) out;\n"
8682 "\n"
8683 "in vec4 tes_gs_result[];\n"
8684 "out vec4 gs_fs_result;\n"
8685 "\n"
8686 "UNI_GOKU\n"
8687 "\n"
8688 "void main()\n"
8689 "{\n"
8690 " vec4 result = vec4(0, 1, 0, 1);\n"
8691 "\n"
8692 "VERIFICATION"
8693 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8694 " {\n"
8695 " result = vec4(1, 0, 0, 1);\n"
8696 " }\n"
8697 "\n"
8698 " gs_fs_result = result;\n"
8699 " gl_Position = vec4(-1, -1, 0, 1);\n"
8700 " EmitVertex();\n"
8701 " gs_fs_result = result;\n"
8702 " gl_Position = vec4(-1, 1, 0, 1);\n"
8703 " EmitVertex();\n"
8704 " gs_fs_result = result;\n"
8705 " gl_Position = vec4(1, -1, 0, 1);\n"
8706 " EmitVertex();\n"
8707 " gs_fs_result = result;\n"
8708 " gl_Position = vec4(1, 1, 0, 1);\n"
8709 " EmitVertex();\n"
8710 "}\n"
8711 "\n";
8712
8713 static const GLchar *tess_ctrl_shader_template =
8714 "VERSION\n"
8715 "\n"
8716 "layout(vertices = 1) out;\n"
8717 "\n"
8718 "in vec4 vs_tcs_result[];\n"
8719 "out vec4 tcs_tes_result[];\n"
8720 "\n"
8721 "UNI_GOKU\n"
8722 "\n"
8723 "void main()\n"
8724 "{\n"
8725 " vec4 result = vec4(0, 1, 0, 1);\n"
8726 "\n"
8727 "VERIFICATION"
8728 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8729 " {\n"
8730 " result = vec4(1, 0, 0, 1);\n"
8731 " }\n"
8732 "\n"
8733 " tcs_tes_result[gl_InvocationID] = result;\n"
8734 "\n"
8735 " gl_TessLevelOuter[0] = 1.0;\n"
8736 " gl_TessLevelOuter[1] = 1.0;\n"
8737 " gl_TessLevelOuter[2] = 1.0;\n"
8738 " gl_TessLevelOuter[3] = 1.0;\n"
8739 " gl_TessLevelInner[0] = 1.0;\n"
8740 " gl_TessLevelInner[1] = 1.0;\n"
8741 "}\n"
8742 "\n";
8743
8744 static const GLchar *tess_eval_shader_template = "VERSION\n"
8745 "\n"
8746 "layout(isolines, point_mode) in;\n"
8747 "\n"
8748 "in vec4 tcs_tes_result[];\n"
8749 "out vec4 tes_gs_result;\n"
8750 "\n"
8751 "UNI_GOKU\n"
8752 "\n"
8753 "void main()\n"
8754 "{\n"
8755 " vec4 result = vec4(0, 1, 0, 1);\n"
8756 "\n"
8757 "VERIFICATION"
8758 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8759 " {\n"
8760 " result = vec4(1, 0, 0, 1);\n"
8761 " }\n"
8762 "\n"
8763 " tes_gs_result = result;\n"
8764 "}\n"
8765 "\n";
8766
8767 static const GLchar *vertex_shader_template = "VERSION\n"
8768 "\n"
8769 "out vec4 vs_tcs_result;\n"
8770 "\n"
8771 "UNI_GOKU\n"
8772 "\n"
8773 "void main()\n"
8774 "{\n"
8775 " vec4 result = vec4(0, 1, 0, 1);\n"
8776 "\n"
8777 "VERIFICATION"
8778 "\n"
8779 " vs_tcs_result = result;\n"
8780 "}\n"
8781 "\n";
8782
8783 const GLchar *shader_template = 0;
8784
8785 switch (in_stage)
8786 {
8787 case Utils::COMPUTE_SHADER:
8788 shader_template = compute_shader_template;
8789 break;
8790 case Utils::FRAGMENT_SHADER:
8791 shader_template = fragment_shader_template;
8792 break;
8793 case Utils::GEOMETRY_SHADER:
8794 shader_template = geometry_shader_template;
8795 break;
8796 case Utils::TESS_CTRL_SHADER:
8797 shader_template = tess_ctrl_shader_template;
8798 break;
8799 case Utils::TESS_EVAL_SHADER:
8800 shader_template = tess_eval_shader_template;
8801 break;
8802 case Utils::VERTEX_SHADER:
8803 shader_template = vertex_shader_template;
8804 break;
8805 default:
8806 TCU_FAIL("Invalid enum");
8807 }
8808
8809 out_source.m_parts[0].m_code = shader_template;
8810
8811 size_t position = 0;
8812
8813 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8814 out_source.m_parts[0].m_code);
8815
8816 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8817
8818 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8819 }
8820
8821 /** Constructor
8822 *
8823 * @param context Test context
8824 **/
BindingUniformAPIOverirdeTest(deqp::Context & context)8825 BindingUniformAPIOverirdeTest::BindingUniformAPIOverirdeTest(deqp::Context &context)
8826 : GLSLTestBase(context, "binding_uniform_api_overirde", "Test verifies if binding can be overriden with API")
8827 , m_goku_buffer(context)
8828 {
8829 /* Nothing to be done here */
8830 }
8831
8832 /** Prepare source for given shader stage
8833 *
8834 * @param in_stage Shader stage, compute shader will use 430
8835 * @param in_use_version_400 Select if 400 or 420 should be used
8836 * @param out_source Prepared shader source instance
8837 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8838 void BindingUniformAPIOverirdeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8839 Utils::shaderSource &out_source)
8840 {
8841 static const GLchar *uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
8842 " vec4 gohan;\n"
8843 " vec4 goten;\n"
8844 "} goku;\n";
8845
8846 static const GLchar *verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
8847 " (vec4(0, 1, 0, 0) != goku.goten) )\n"
8848 " {\n"
8849 " result = vec4(1, 0, 0, 1);\n"
8850 " }\n";
8851
8852 static const GLchar *compute_shader_template =
8853 "VERSION\n"
8854 "\n"
8855 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8856 "\n"
8857 "writeonly uniform image2D uni_image;\n"
8858 "\n"
8859 "UNI_GOKU\n"
8860 "\n"
8861 "void main()\n"
8862 "{\n"
8863 " vec4 result = vec4(0, 1, 0, 1);\n"
8864 "\n"
8865 "VERIFICATION"
8866 "\n"
8867 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8868 "}\n"
8869 "\n";
8870
8871 static const GLchar *fragment_shader_template = "VERSION\n"
8872 "\n"
8873 "in vec4 gs_fs_result;\n"
8874 "out vec4 fs_out_result;\n"
8875 "\n"
8876 "UNI_GOKU\n"
8877 "\n"
8878 "void main()\n"
8879 "{\n"
8880 " vec4 result = vec4(0, 1, 0, 1);\n"
8881 "\n"
8882 "VERIFICATION"
8883 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8884 " {\n"
8885 " result = vec4(1, 0, 0, 1);\n"
8886 " }\n"
8887 "\n"
8888 " fs_out_result = result;\n"
8889 "}\n"
8890 "\n";
8891
8892 static const GLchar *geometry_shader_template = "VERSION\n"
8893 "\n"
8894 "layout(points) in;\n"
8895 "layout(triangle_strip, max_vertices = 4) out;\n"
8896 "\n"
8897 "in vec4 tes_gs_result[];\n"
8898 "out vec4 gs_fs_result;\n"
8899 "\n"
8900 "UNI_GOKU\n"
8901 "\n"
8902 "void main()\n"
8903 "{\n"
8904 " vec4 result = vec4(0, 1, 0, 1);\n"
8905 "\n"
8906 "VERIFICATION"
8907 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8908 " {\n"
8909 " result = vec4(1, 0, 0, 1);\n"
8910 " }\n"
8911 "\n"
8912 " gs_fs_result = result;\n"
8913 " gl_Position = vec4(-1, -1, 0, 1);\n"
8914 " EmitVertex();\n"
8915 " gs_fs_result = result;\n"
8916 " gl_Position = vec4(-1, 1, 0, 1);\n"
8917 " EmitVertex();\n"
8918 " gs_fs_result = result;\n"
8919 " gl_Position = vec4(1, -1, 0, 1);\n"
8920 " EmitVertex();\n"
8921 " gs_fs_result = result;\n"
8922 " gl_Position = vec4(1, 1, 0, 1);\n"
8923 " EmitVertex();\n"
8924 "}\n"
8925 "\n";
8926
8927 static const GLchar *tess_ctrl_shader_template =
8928 "VERSION\n"
8929 "\n"
8930 "layout(vertices = 1) out;\n"
8931 "\n"
8932 "in vec4 vs_tcs_result[];\n"
8933 "out vec4 tcs_tes_result[];\n"
8934 "\n"
8935 "UNI_GOKU\n"
8936 "\n"
8937 "void main()\n"
8938 "{\n"
8939 " vec4 result = vec4(0, 1, 0, 1);\n"
8940 "\n"
8941 "VERIFICATION"
8942 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8943 " {\n"
8944 " result = vec4(1, 0, 0, 1);\n"
8945 " }\n"
8946 "\n"
8947 " tcs_tes_result[gl_InvocationID] = result;\n"
8948 "\n"
8949 " gl_TessLevelOuter[0] = 1.0;\n"
8950 " gl_TessLevelOuter[1] = 1.0;\n"
8951 " gl_TessLevelOuter[2] = 1.0;\n"
8952 " gl_TessLevelOuter[3] = 1.0;\n"
8953 " gl_TessLevelInner[0] = 1.0;\n"
8954 " gl_TessLevelInner[1] = 1.0;\n"
8955 "}\n"
8956 "\n";
8957
8958 static const GLchar *tess_eval_shader_template = "VERSION\n"
8959 "\n"
8960 "layout(isolines, point_mode) in;\n"
8961 "\n"
8962 "in vec4 tcs_tes_result[];\n"
8963 "out vec4 tes_gs_result;\n"
8964 "\n"
8965 "UNI_GOKU\n"
8966 "\n"
8967 "void main()\n"
8968 "{\n"
8969 " vec4 result = vec4(0, 1, 0, 1);\n"
8970 "\n"
8971 "VERIFICATION"
8972 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8973 " {\n"
8974 " result = vec4(1, 0, 0, 1);\n"
8975 " }\n"
8976 "\n"
8977 " tes_gs_result = result;\n"
8978 "}\n"
8979 "\n";
8980
8981 static const GLchar *vertex_shader_template = "VERSION\n"
8982 "\n"
8983 "out vec4 vs_tcs_result;\n"
8984 "\n"
8985 "UNI_GOKU\n"
8986 "\n"
8987 "void main()\n"
8988 "{\n"
8989 " vec4 result = vec4(0, 1, 0, 1);\n"
8990 "\n"
8991 "VERIFICATION"
8992 "\n"
8993 " vs_tcs_result = result;\n"
8994 "}\n"
8995 "\n";
8996
8997 const GLchar *shader_template = 0;
8998
8999 switch (in_stage)
9000 {
9001 case Utils::COMPUTE_SHADER:
9002 shader_template = compute_shader_template;
9003 break;
9004 case Utils::FRAGMENT_SHADER:
9005 shader_template = fragment_shader_template;
9006 break;
9007 case Utils::GEOMETRY_SHADER:
9008 shader_template = geometry_shader_template;
9009 break;
9010 case Utils::TESS_CTRL_SHADER:
9011 shader_template = tess_ctrl_shader_template;
9012 break;
9013 case Utils::TESS_EVAL_SHADER:
9014 shader_template = tess_eval_shader_template;
9015 break;
9016 case Utils::VERTEX_SHADER:
9017 shader_template = vertex_shader_template;
9018 break;
9019 default:
9020 TCU_FAIL("Invalid enum");
9021 }
9022
9023 out_source.m_parts[0].m_code = shader_template;
9024
9025 size_t position = 0;
9026
9027 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9028 out_source.m_parts[0].m_code);
9029
9030 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9031
9032 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9033 }
9034
9035 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
9036 *
9037 * @param program Current program
9038 **/
prepareUniforms(Utils::program & program)9039 void BindingUniformAPIOverirdeTest::prepareUniforms(Utils::program &program)
9040 {
9041 static const GLfloat goku_data[8] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
9042
9043 static const GLuint new_binding = 11;
9044
9045 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9046
9047 const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
9048 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
9049 if (GL_INVALID_INDEX == index)
9050 {
9051 TCU_FAIL("Uniform block is inactive");
9052 return;
9053 }
9054
9055 gl.uniformBlockBinding(program.m_program_object_id, index, new_binding);
9056 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformBlockBinding");
9057
9058 GLint binding = -1;
9059
9060 gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
9061 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
9062
9063 if (new_binding != binding)
9064 {
9065 TCU_FAIL("GetActiveUniformBlockiv returned wrong binding");
9066 return;
9067 }
9068
9069 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
9070 m_goku_buffer.update(sizeof(GLfloat) * 8, (GLvoid *)goku_data, GL_STATIC_DRAW);
9071 m_goku_buffer.bindRange(new_binding /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
9072 }
9073
9074 /** Overwrite of releaseResource method, release extra uniform buffer
9075 *
9076 * @param ignored
9077 **/
releaseResource()9078 void BindingUniformAPIOverirdeTest::releaseResource()
9079 {
9080 m_goku_buffer.release();
9081 }
9082
9083 /** Constructor
9084 *
9085 * @param context Test context
9086 **/
BindingUniformGlobalBlockTest(deqp::Context & context)9087 BindingUniformGlobalBlockTest::BindingUniformGlobalBlockTest(deqp::Context &context)
9088 : NegativeTestBase(context, "binding_uniform_global_block",
9089 "Test verifies that global uniform cannot be qualified with binding")
9090 {
9091 /* Nothing to be done here */
9092 }
9093
9094 /** Prepare source for given shader stage
9095 *
9096 * @param in_stage Shader stage, compute shader will use 430
9097 * @param in_use_version_400 Select if 400 or 420 should be used
9098 * @param out_source Prepared shader source instance
9099 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9100 void BindingUniformGlobalBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9101 Utils::shaderSource &out_source)
9102 {
9103 static const GLchar *verification_snippet = " if (vec4(0, 0, 1, 1) != uni_test)\n"
9104 " {\n"
9105 " result = vec4(1, 0, 0, 1);\n"
9106 " }\n";
9107
9108 static const GLchar *uniform_definition = "layout(binding = 0) uniform vec4 uni_test;\n";
9109
9110 static const GLchar *compute_shader_template =
9111 "VERSION\n"
9112 "\n"
9113 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9114 "\n"
9115 "writeonly uniform image2D uni_image;\n"
9116 "\n"
9117 "UNIFORM_DEFINITION\n"
9118 "\n"
9119 "void main()\n"
9120 "{\n"
9121 " vec4 result = vec4(0, 1, 0, 1);\n"
9122 "\n"
9123 "VERIFICATION"
9124 "\n"
9125 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9126 "}\n"
9127 "\n";
9128
9129 static const GLchar *fragment_shader_template = "VERSION\n"
9130 "\n"
9131 "in vec4 gs_fs_result;\n"
9132 "out vec4 fs_out_result;\n"
9133 "\n"
9134 "UNIFORM_DEFINITION\n"
9135 "\n"
9136 "void main()\n"
9137 "{\n"
9138 " vec4 result = vec4(0, 1, 0, 1);\n"
9139 "\n"
9140 "VERIFICATION"
9141 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9142 " {\n"
9143 " result = vec4(1, 0, 0, 1);\n"
9144 " }\n"
9145 "\n"
9146 " fs_out_result = result;\n"
9147 "}\n"
9148 "\n";
9149
9150 static const GLchar *geometry_shader_template = "VERSION\n"
9151 "\n"
9152 "layout(points) in;\n"
9153 "layout(triangle_strip, max_vertices = 4) out;\n"
9154 "\n"
9155 "in vec4 tes_gs_result[];\n"
9156 "out vec4 gs_fs_result;\n"
9157 "\n"
9158 "UNIFORM_DEFINITION\n"
9159 "\n"
9160 "void main()\n"
9161 "{\n"
9162 " vec4 result = vec4(0, 1, 0, 1);\n"
9163 "\n"
9164 "VERIFICATION"
9165 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9166 " {\n"
9167 " result = vec4(1, 0, 0, 1);\n"
9168 " }\n"
9169 "\n"
9170 " gs_fs_result = result;\n"
9171 " gl_Position = vec4(-1, -1, 0, 1);\n"
9172 " EmitVertex();\n"
9173 " gs_fs_result = result;\n"
9174 " gl_Position = vec4(-1, 1, 0, 1);\n"
9175 " EmitVertex();\n"
9176 " gs_fs_result = result;\n"
9177 " gl_Position = vec4(1, -1, 0, 1);\n"
9178 " EmitVertex();\n"
9179 " gs_fs_result = result;\n"
9180 " gl_Position = vec4(1, 1, 0, 1);\n"
9181 " EmitVertex();\n"
9182 "}\n"
9183 "\n";
9184
9185 static const GLchar *tess_ctrl_shader_template =
9186 "VERSION\n"
9187 "\n"
9188 "layout(vertices = 1) out;\n"
9189 "\n"
9190 "in vec4 vs_tcs_result[];\n"
9191 "out vec4 tcs_tes_result[];\n"
9192 "\n"
9193 "UNIFORM_DEFINITION\n"
9194 "\n"
9195 "void main()\n"
9196 "{\n"
9197 " vec4 result = vec4(0, 1, 0, 1);\n"
9198 "\n"
9199 "VERIFICATION"
9200 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9201 " {\n"
9202 " result = vec4(1, 0, 0, 1);\n"
9203 " }\n"
9204 "\n"
9205 " tcs_tes_result[gl_InvocationID] = result;\n"
9206 "\n"
9207 " gl_TessLevelOuter[0] = 1.0;\n"
9208 " gl_TessLevelOuter[1] = 1.0;\n"
9209 " gl_TessLevelOuter[2] = 1.0;\n"
9210 " gl_TessLevelOuter[3] = 1.0;\n"
9211 " gl_TessLevelInner[0] = 1.0;\n"
9212 " gl_TessLevelInner[1] = 1.0;\n"
9213 "}\n"
9214 "\n";
9215
9216 static const GLchar *tess_eval_shader_template = "VERSION\n"
9217 "\n"
9218 "layout(isolines, point_mode) in;\n"
9219 "\n"
9220 "in vec4 tcs_tes_result[];\n"
9221 "out vec4 tes_gs_result;\n"
9222 "\n"
9223 "UNIFORM_DEFINITION\n"
9224 "\n"
9225 "void main()\n"
9226 "{\n"
9227 " vec4 result = vec4(0, 1, 0, 1);\n"
9228 "\n"
9229 "VERIFICATION"
9230 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9231 " {\n"
9232 " result = vec4(1, 0, 0, 1);\n"
9233 " }\n"
9234 "\n"
9235 " tes_gs_result = result;\n"
9236 "}\n"
9237 "\n";
9238
9239 static const GLchar *vertex_shader_template = "VERSION\n"
9240 "\n"
9241 "out vec4 vs_tcs_result;\n"
9242 "\n"
9243 "UNIFORM_DEFINITION\n"
9244 "\n"
9245 "void main()\n"
9246 "{\n"
9247 " vec4 result = vec4(0, 1, 0, 1);\n"
9248 "\n"
9249 "VERIFICATION"
9250 "\n"
9251 " vs_tcs_result = result;\n"
9252 "}\n"
9253 "\n";
9254
9255 const GLchar *shader_template = 0;
9256
9257 switch (in_stage)
9258 {
9259 case Utils::COMPUTE_SHADER:
9260 shader_template = compute_shader_template;
9261 break;
9262 case Utils::FRAGMENT_SHADER:
9263 shader_template = fragment_shader_template;
9264 break;
9265 case Utils::GEOMETRY_SHADER:
9266 shader_template = geometry_shader_template;
9267 break;
9268 case Utils::TESS_CTRL_SHADER:
9269 shader_template = tess_ctrl_shader_template;
9270 break;
9271 case Utils::TESS_EVAL_SHADER:
9272 shader_template = tess_eval_shader_template;
9273 break;
9274 case Utils::VERTEX_SHADER:
9275 shader_template = vertex_shader_template;
9276 break;
9277 default:
9278 TCU_FAIL("Invalid enum");
9279 }
9280
9281 out_source.m_parts[0].m_code = shader_template;
9282
9283 size_t position = 0;
9284 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9285 out_source.m_parts[0].m_code);
9286
9287 Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9288
9289 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9290 }
9291
9292 /** Constructor
9293 *
9294 * @param context Test context
9295 **/
BindingUniformInvalidTest(deqp::Context & context,TESTCASES case_index)9296 BindingUniformInvalidTest::BindingUniformInvalidTest(deqp::Context &context, TESTCASES case_index)
9297 : NegativeTestBase(context, "binding_uniform_invalid", "Test verifies invalid binding values")
9298 , m_case(TEST_CASES_MAX)
9299 , m_test_case_idx(case_index)
9300 {
9301 std::string name = "binding_uniform_invalid_case_" + std::string(getTestCaseString(m_test_case_idx));
9302
9303 TestCase::m_name = name;
9304 }
9305
getTestCaseString(TESTCASES test_case)9306 const GLchar *BindingUniformInvalidTest::getTestCaseString(TESTCASES test_case)
9307 {
9308 const GLchar *name = 0;
9309
9310 switch (test_case)
9311 {
9312 case NEGATIVE_VALUE:
9313 name = "-1";
9314 break;
9315 case VARIABLE_NAME:
9316 name = "goku";
9317 break;
9318 case STD140:
9319 name = "std140";
9320 break;
9321 case MISSING:
9322 name = "";
9323 break;
9324 case TEST_CASES_MAX:
9325 name = "0";
9326 break;
9327 default:
9328 TCU_FAIL("Invalid enum");
9329 }
9330
9331 return name;
9332 }
9333
9334 /** Set up next test case
9335 *
9336 * @param test_case_index Index of next test case
9337 *
9338 * @return false if there is no more test cases, true otherwise
9339 **/
prepareNextTestCase(glw::GLuint test_case_index)9340 bool BindingUniformInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
9341 {
9342 if (test_case_index > 0)
9343 {
9344 return false;
9345 }
9346 switch (m_test_case_idx)
9347 {
9348 // case (glw::GLuint)-1:
9349 // m_case = TEST_CASES_MAX;
9350 // break;
9351 case NEGATIVE_VALUE:
9352 case VARIABLE_NAME:
9353 case STD140:
9354 case MISSING:
9355 m_case = (TESTCASES)m_test_case_idx;
9356 break;
9357 default:
9358 return false;
9359 }
9360
9361 return true;
9362 }
9363
9364 /** Prepare source for given shader stage
9365 *
9366 * @param in_stage Shader stage, compute shader will use 430
9367 * @param in_use_version_400 Select if 400 or 420 should be used
9368 * @param out_source Prepared shader source instance
9369 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9370 void BindingUniformInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9371 Utils::shaderSource &out_source)
9372 {
9373 static const GLchar *verification_snippet = " if (vec4(0, 0, 1, 1) != goku.gohan)\n"
9374 " {\n"
9375 " result = vec4(1, 0, 0, 1);\n"
9376 " }\n";
9377
9378 static const GLchar *uniform_definition = "layout(std140, binding BINDING) uniform GOKU {\n"
9379 " vec4 gohan;\n"
9380 " vec4 goten;\n"
9381 "} goku;\n";
9382
9383 static const GLchar *compute_shader_template =
9384 "VERSION\n"
9385 "\n"
9386 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9387 "\n"
9388 "writeonly uniform image2D uni_image;\n"
9389 "\n"
9390 "UNIFORM_DEFINITION\n"
9391 "\n"
9392 "void main()\n"
9393 "{\n"
9394 " vec4 result = vec4(0, 1, 0, 1);\n"
9395 "\n"
9396 "VERIFICATION"
9397 "\n"
9398 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9399 "}\n"
9400 "\n";
9401
9402 static const GLchar *fragment_shader_template = "VERSION\n"
9403 "\n"
9404 "in vec4 gs_fs_result;\n"
9405 "out vec4 fs_out_result;\n"
9406 "\n"
9407 "UNIFORM_DEFINITION\n"
9408 "\n"
9409 "void main()\n"
9410 "{\n"
9411 " vec4 result = vec4(0, 1, 0, 1);\n"
9412 "\n"
9413 "VERIFICATION"
9414 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9415 " {\n"
9416 " result = vec4(1, 0, 0, 1);\n"
9417 " }\n"
9418 "\n"
9419 " fs_out_result = result;\n"
9420 "}\n"
9421 "\n";
9422
9423 static const GLchar *geometry_shader_template = "VERSION\n"
9424 "\n"
9425 "layout(points) in;\n"
9426 "layout(triangle_strip, max_vertices = 4) out;\n"
9427 "\n"
9428 "in vec4 tes_gs_result[];\n"
9429 "out vec4 gs_fs_result;\n"
9430 "\n"
9431 "UNIFORM_DEFINITION\n"
9432 "\n"
9433 "void main()\n"
9434 "{\n"
9435 " vec4 result = vec4(0, 1, 0, 1);\n"
9436 "\n"
9437 "VERIFICATION"
9438 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9439 " {\n"
9440 " result = vec4(1, 0, 0, 1);\n"
9441 " }\n"
9442 "\n"
9443 " gs_fs_result = result;\n"
9444 " gl_Position = vec4(-1, -1, 0, 1);\n"
9445 " EmitVertex();\n"
9446 " gs_fs_result = result;\n"
9447 " gl_Position = vec4(-1, 1, 0, 1);\n"
9448 " EmitVertex();\n"
9449 " gs_fs_result = result;\n"
9450 " gl_Position = vec4(1, -1, 0, 1);\n"
9451 " EmitVertex();\n"
9452 " gs_fs_result = result;\n"
9453 " gl_Position = vec4(1, 1, 0, 1);\n"
9454 " EmitVertex();\n"
9455 "}\n"
9456 "\n";
9457
9458 static const GLchar *tess_ctrl_shader_template =
9459 "VERSION\n"
9460 "\n"
9461 "layout(vertices = 1) out;\n"
9462 "\n"
9463 "in vec4 vs_tcs_result[];\n"
9464 "out vec4 tcs_tes_result[];\n"
9465 "\n"
9466 "UNIFORM_DEFINITION\n"
9467 "\n"
9468 "void main()\n"
9469 "{\n"
9470 " vec4 result = vec4(0, 1, 0, 1);\n"
9471 "\n"
9472 "VERIFICATION"
9473 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9474 " {\n"
9475 " result = vec4(1, 0, 0, 1);\n"
9476 " }\n"
9477 "\n"
9478 " tcs_tes_result[gl_InvocationID] = result;\n"
9479 "\n"
9480 " gl_TessLevelOuter[0] = 1.0;\n"
9481 " gl_TessLevelOuter[1] = 1.0;\n"
9482 " gl_TessLevelOuter[2] = 1.0;\n"
9483 " gl_TessLevelOuter[3] = 1.0;\n"
9484 " gl_TessLevelInner[0] = 1.0;\n"
9485 " gl_TessLevelInner[1] = 1.0;\n"
9486 "}\n"
9487 "\n";
9488
9489 static const GLchar *tess_eval_shader_template = "VERSION\n"
9490 "\n"
9491 "layout(isolines, point_mode) in;\n"
9492 "\n"
9493 "in vec4 tcs_tes_result[];\n"
9494 "out vec4 tes_gs_result;\n"
9495 "\n"
9496 "UNIFORM_DEFINITION\n"
9497 "\n"
9498 "void main()\n"
9499 "{\n"
9500 " vec4 result = vec4(0, 1, 0, 1);\n"
9501 "\n"
9502 "VERIFICATION"
9503 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9504 " {\n"
9505 " result = vec4(1, 0, 0, 1);\n"
9506 " }\n"
9507 "\n"
9508 " tes_gs_result = result;\n"
9509 "}\n"
9510 "\n";
9511
9512 static const GLchar *vertex_shader_template = "VERSION\n"
9513 "\n"
9514 "out vec4 vs_tcs_result;\n"
9515 "\n"
9516 "UNIFORM_DEFINITION\n"
9517 "\n"
9518 "void main()\n"
9519 "{\n"
9520 " vec4 result = vec4(0, 1, 0, 1);\n"
9521 "\n"
9522 "VERIFICATION"
9523 "\n"
9524 " vs_tcs_result = result;\n"
9525 "}\n"
9526 "\n";
9527
9528 const GLchar *shader_template = 0;
9529
9530 switch (in_stage)
9531 {
9532 case Utils::COMPUTE_SHADER:
9533 shader_template = compute_shader_template;
9534 break;
9535 case Utils::FRAGMENT_SHADER:
9536 shader_template = fragment_shader_template;
9537 break;
9538 case Utils::GEOMETRY_SHADER:
9539 shader_template = geometry_shader_template;
9540 break;
9541 case Utils::TESS_CTRL_SHADER:
9542 shader_template = tess_ctrl_shader_template;
9543 break;
9544 case Utils::TESS_EVAL_SHADER:
9545 shader_template = tess_eval_shader_template;
9546 break;
9547 case Utils::VERTEX_SHADER:
9548 shader_template = vertex_shader_template;
9549 break;
9550 default:
9551 TCU_FAIL("Invalid enum");
9552 }
9553
9554 out_source.m_parts[0].m_code = shader_template;
9555
9556 size_t position = 0;
9557 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9558 out_source.m_parts[0].m_code);
9559
9560 Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9561
9562 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9563
9564 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
9565 }
9566
getCaseString(TESTCASES test_case)9567 const GLchar *BindingUniformInvalidTest::getCaseString(TESTCASES test_case)
9568 {
9569 (void)test_case;
9570 const GLchar *binding = 0;
9571
9572 switch (m_case)
9573 {
9574 case NEGATIVE_VALUE:
9575 binding = "-1";
9576 break;
9577 case VARIABLE_NAME:
9578 binding = "goku";
9579 break;
9580 case STD140:
9581 binding = "std140";
9582 break;
9583 case MISSING:
9584 binding = "missing";
9585 break;
9586 case TEST_CASES_MAX:
9587 binding = "0";
9588 break;
9589 default:
9590 TCU_FAIL("Invalid enum");
9591 }
9592
9593 return binding;
9594 }
9595
9596 /** Constructor
9597 *
9598 * @param context Test context
9599 **/
BindingSamplersTest(deqp::Context & context,Utils::TEXTURE_TYPES test_case)9600 BindingSamplersTest::BindingSamplersTest(deqp::Context &context, Utils::TEXTURE_TYPES test_case)
9601 : GLSLTestBase(context, "binding_samplers", "Test verifies smaplers binding")
9602 , m_goku_texture(context)
9603 , m_vegeta_texture(context)
9604 , m_trunks_texture(context)
9605 , m_buffer(context)
9606 , m_test_case(test_case)
9607 {
9608 std::string name = "binding_samplers_texture_type_" + std::string(Utils::getTextureTypeName(test_case));
9609
9610 TestCase::m_name = name;
9611 }
9612
9613 /** Set up next test case
9614 *
9615 * @param test_case_index Index of next test case
9616 *
9617 * @return false if there is no more test cases, true otherwise
9618 **/
prepareNextTestCase(glw::GLuint test_case_index)9619 bool BindingSamplersTest::prepareNextTestCase(glw::GLuint test_case_index)
9620 {
9621 if (test_case_index > 0)
9622 {
9623 return false;
9624 }
9625
9626 m_context.getTestContext().getLog() << tcu::TestLog::Message
9627 << "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
9628 << tcu::TestLog::EndMessage;
9629
9630 return true;
9631 }
9632
9633 /** Prepare source for given shader stage
9634 *
9635 * @param in_stage Shader stage, compute shader will use 430
9636 * @param in_use_version_400 Select if 400 or 420 should be used
9637 * @param out_source Prepared shader source instance
9638 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9639 void BindingSamplersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9640 Utils::shaderSource &out_source)
9641 {
9642 static const GLchar *uni_goku = "layout(binding = 0) uniform TYPE goku;\n";
9643
9644 static const GLchar *uni_vegeta = "layout(binding = 1) uniform TYPE vegeta;\n";
9645
9646 static const GLchar *uni_trunks = "layout(binding = 3) uniform TYPE trunks;\n\n";
9647
9648 static const GLchar *verification_snippet = " TEX_COORD_TYPE tex_coord = TEX_COORD_TYPE(COORDINATES);\n"
9649 " vec4 goku_color = SAMPLING_FUNCTION(goku, tex_coord);\n"
9650 " vec4 vegeta_color = SAMPLING_FUNCTION(vegeta, tex_coord);\n"
9651 " vec4 trunks_color = SAMPLING_FUNCTION(trunks, tex_coord);\n"
9652 "\n"
9653 " if ((vec4(1, 0, 0, 0) != goku_color) ||\n"
9654 " (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
9655 " (vec4(0, 0, 1, 0) != trunks_color) )\n"
9656 " {\n"
9657 " result = vec4(1, 0, 0, 1);\n"
9658 " }\n";
9659
9660 static const GLchar *compute_shader_template =
9661 "VERSION\n"
9662 "\n"
9663 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9664 "\n"
9665 "writeonly uniform image2D uni_image;\n"
9666 "\n"
9667 "UNI_GOKU\n"
9668 "UNI_VEGETA\n"
9669 "UNI_TRUNKS\n"
9670 "\n"
9671 "void main()\n"
9672 "{\n"
9673 " vec4 result = vec4(0, 1, 0, 1);\n"
9674 "\n"
9675 "VERIFICATION"
9676 "\n"
9677 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9678 "}\n"
9679 "\n";
9680
9681 static const GLchar *fragment_shader_template = "VERSION\n"
9682 "\n"
9683 "in vec4 gs_fs_result;\n"
9684 "out vec4 fs_out_result;\n"
9685 "\n"
9686 "UNI_GOKU\n"
9687 "UNI_VEGETA\n"
9688 "UNI_TRUNKS\n"
9689 "\n"
9690 "void main()\n"
9691 "{\n"
9692 " vec4 result = vec4(0, 1, 0, 1);\n"
9693 "\n"
9694 "VERIFICATION"
9695 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9696 " {\n"
9697 " result = vec4(1, 0, 0, 1);\n"
9698 " }\n"
9699 "\n"
9700 " fs_out_result = result;\n"
9701 "}\n"
9702 "\n";
9703
9704 static const GLchar *geometry_shader_template = "VERSION\n"
9705 "\n"
9706 "layout(points) in;\n"
9707 "layout(triangle_strip, max_vertices = 4) out;\n"
9708 "\n"
9709 "in vec4 tes_gs_result[];\n"
9710 "out vec4 gs_fs_result;\n"
9711 "\n"
9712 "UNI_TRUNKS\n"
9713 "UNI_GOKU\n"
9714 "UNI_VEGETA\n"
9715 "\n"
9716 "void main()\n"
9717 "{\n"
9718 " vec4 result = vec4(0, 1, 0, 1);\n"
9719 "\n"
9720 "VERIFICATION"
9721 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9722 " {\n"
9723 " result = vec4(1, 0, 0, 1);\n"
9724 " }\n"
9725 "\n"
9726 " gs_fs_result = result;\n"
9727 " gl_Position = vec4(-1, -1, 0, 1);\n"
9728 " EmitVertex();\n"
9729 " gs_fs_result = result;\n"
9730 " gl_Position = vec4(-1, 1, 0, 1);\n"
9731 " EmitVertex();\n"
9732 " gs_fs_result = result;\n"
9733 " gl_Position = vec4(1, -1, 0, 1);\n"
9734 " EmitVertex();\n"
9735 " gs_fs_result = result;\n"
9736 " gl_Position = vec4(1, 1, 0, 1);\n"
9737 " EmitVertex();\n"
9738 "}\n"
9739 "\n";
9740
9741 static const GLchar *tess_ctrl_shader_template =
9742 "VERSION\n"
9743 "\n"
9744 "layout(vertices = 1) out;\n"
9745 "\n"
9746 "in vec4 vs_tcs_result[];\n"
9747 "out vec4 tcs_tes_result[];\n"
9748 "\n"
9749 "UNI_VEGETA\n"
9750 "UNI_TRUNKS\n"
9751 "UNI_GOKU\n"
9752 "\n"
9753 "void main()\n"
9754 "{\n"
9755 " vec4 result = vec4(0, 1, 0, 1);\n"
9756 "\n"
9757 "VERIFICATION"
9758 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9759 " {\n"
9760 " result = vec4(1, 0, 0, 1);\n"
9761 " }\n"
9762 "\n"
9763 " tcs_tes_result[gl_InvocationID] = result;\n"
9764 "\n"
9765 " gl_TessLevelOuter[0] = 1.0;\n"
9766 " gl_TessLevelOuter[1] = 1.0;\n"
9767 " gl_TessLevelOuter[2] = 1.0;\n"
9768 " gl_TessLevelOuter[3] = 1.0;\n"
9769 " gl_TessLevelInner[0] = 1.0;\n"
9770 " gl_TessLevelInner[1] = 1.0;\n"
9771 "}\n"
9772 "\n";
9773
9774 static const GLchar *tess_eval_shader_template = "VERSION\n"
9775 "\n"
9776 "layout(isolines, point_mode) in;\n"
9777 "\n"
9778 "in vec4 tcs_tes_result[];\n"
9779 "out vec4 tes_gs_result;\n"
9780 "\n"
9781 "UNI_GOKU\n"
9782 "UNI_TRUNKS\n"
9783 "UNI_VEGETA\n"
9784 "\n"
9785 "void main()\n"
9786 "{\n"
9787 " vec4 result = vec4(0, 1, 0, 1);\n"
9788 "\n"
9789 "VERIFICATION"
9790 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9791 " {\n"
9792 " result = vec4(1, 0, 0, 1);\n"
9793 " }\n"
9794 "\n"
9795 " tes_gs_result = result;\n"
9796 "}\n"
9797 "\n";
9798
9799 static const GLchar *vertex_shader_template = "VERSION\n"
9800 "\n"
9801 "out vec4 vs_tcs_result;\n"
9802 "\n"
9803 "UNI_TRUNKS\n"
9804 "UNI_VEGETA\n"
9805 "UNI_GOKU\n"
9806 "\n"
9807 "void main()\n"
9808 "{\n"
9809 " vec4 result = vec4(0, 1, 0, 1);\n"
9810 "\n"
9811 "VERIFICATION"
9812 "\n"
9813 " vs_tcs_result = result;\n"
9814 "}\n"
9815 "\n";
9816
9817 const Utils::TYPES base_tex_coord_type = (Utils::TEX_BUFFER == m_test_case) ? Utils::INT : Utils::FLOAT;
9818 const GLchar *coordinates = 0;
9819 GLuint n_coordinates = Utils::getNumberOfCoordinates(m_test_case);
9820 const GLchar *shader_template = 0;
9821 const GLchar *sampler_type = Utils::getSamplerType(m_test_case);
9822 const GLchar *sampling_function = (Utils::TEX_BUFFER == m_test_case) ? "texelFetch" : "texture";
9823 const GLchar *tex_coord_type = Utils::getTypeName(base_tex_coord_type, 1 /* n_columns */, n_coordinates);
9824
9825 switch (in_stage)
9826 {
9827 case Utils::COMPUTE_SHADER:
9828 shader_template = compute_shader_template;
9829 break;
9830 case Utils::FRAGMENT_SHADER:
9831 shader_template = fragment_shader_template;
9832 break;
9833 case Utils::GEOMETRY_SHADER:
9834 shader_template = geometry_shader_template;
9835 break;
9836 case Utils::TESS_CTRL_SHADER:
9837 shader_template = tess_ctrl_shader_template;
9838 break;
9839 case Utils::TESS_EVAL_SHADER:
9840 shader_template = tess_eval_shader_template;
9841 break;
9842 case Utils::VERTEX_SHADER:
9843 shader_template = vertex_shader_template;
9844 break;
9845 default:
9846 TCU_FAIL("Invalid enum");
9847 }
9848
9849 switch (n_coordinates)
9850 {
9851 case 1:
9852 coordinates = "0";
9853 break;
9854 case 2:
9855 coordinates = "0, 0";
9856 break;
9857 case 3:
9858 coordinates = "0, 0, 0";
9859 break;
9860 case 4:
9861 coordinates = "0, 0, 0, 0";
9862 break;
9863 }
9864
9865 out_source.m_parts[0].m_code = shader_template;
9866
9867 size_t position = 0;
9868
9869 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9870 out_source.m_parts[0].m_code);
9871
9872 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9873
9874 position -= strlen(verification_snippet);
9875
9876 Utils::replaceToken("COORDINATES", position, coordinates, out_source.m_parts[0].m_code);
9877
9878 Utils::replaceAllTokens("SAMPLING_FUNCTION", sampling_function, out_source.m_parts[0].m_code);
9879
9880 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9881
9882 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
9883
9884 Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
9885
9886 Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
9887
9888 Utils::replaceAllTokens("TYPE", sampler_type, out_source.m_parts[0].m_code);
9889 }
9890
9891 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
9892 *
9893 * @param program Current program
9894 **/
prepareUniforms(Utils::program & program)9895 void BindingSamplersTest::prepareUniforms(Utils::program &program)
9896 {
9897 (void)program;
9898 static const GLuint goku_data = 0x000000ff;
9899 static const GLuint vegeta_data = 0x0000ff00;
9900 static const GLuint trunks_data = 0x00ff0000;
9901
9902 prepareTexture(m_goku_texture, m_test_case, goku_data);
9903 prepareTexture(m_vegeta_texture, m_test_case, vegeta_data);
9904 prepareTexture(m_trunks_texture, m_test_case, trunks_data);
9905
9906 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9907
9908 gl.activeTexture(GL_TEXTURE0);
9909 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
9910
9911 m_goku_texture.bind();
9912
9913 gl.activeTexture(GL_TEXTURE1);
9914 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
9915
9916 m_vegeta_texture.bind();
9917
9918 gl.activeTexture(GL_TEXTURE3);
9919 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
9920
9921 m_trunks_texture.bind();
9922 }
9923
9924 /** Overwrite of releaseResource method, release extra buffer and texture
9925 *
9926 * @param ignored
9927 **/
releaseResource()9928 void BindingSamplersTest::releaseResource()
9929 {
9930 m_goku_texture.release();
9931 m_vegeta_texture.release();
9932 m_trunks_texture.release();
9933 m_buffer.release();
9934 }
9935
9936 /** Prepare texture of given type filled with given color
9937 *
9938 * @param texture Texture
9939 * @param texture_type Type of texture
9940 * @param color Color
9941 **/
prepareTexture(Utils::texture & texture,Utils::TEXTURE_TYPES texture_type,glw::GLuint color)9942 void BindingSamplersTest::prepareTexture(Utils::texture &texture, Utils::TEXTURE_TYPES texture_type, glw::GLuint color)
9943 {
9944 (void)texture_type;
9945 static const GLuint width = 16;
9946 static const GLuint height = 16;
9947 static const GLuint depth = 1;
9948
9949 std::vector<GLuint> texture_data;
9950 texture_data.resize(width * height);
9951
9952 for (GLuint i = 0; i < texture_data.size(); ++i)
9953 {
9954 texture_data[i] = color;
9955 }
9956
9957 if (Utils::TEX_BUFFER != m_test_case)
9958 {
9959 texture.create(width, height, depth, GL_RGBA8, m_test_case);
9960
9961 texture.update(width, height, depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
9962 }
9963 else
9964 {
9965 m_buffer.generate(GL_TEXTURE_BUFFER);
9966 m_buffer.update(texture_data.size(), &texture_data[0], GL_STATIC_DRAW);
9967
9968 texture.createBuffer(GL_RGBA8, m_buffer.m_id);
9969 }
9970 }
9971
9972 /** Constructor
9973 *
9974 * @param context Test context
9975 **/
BindingSamplerSingleTest(deqp::Context & context,Utils::SHADER_STAGES test_stage)9976 BindingSamplerSingleTest::BindingSamplerSingleTest(deqp::Context &context, Utils::SHADER_STAGES test_stage)
9977 : GLSLTestBase(context, "binding_sampler_single", "Test verifies sampler binding")
9978 , m_goku_texture(context)
9979 , m_test_stage(test_stage)
9980 {
9981 std::string name = "binding_sampler_single_stage_" + std::string(Utils::getShaderStageName(m_test_stage));
9982
9983 TestCase::m_name = name;
9984 }
9985
9986 /** Set up next test case
9987 *
9988 * @param test_case_index Index of next test case
9989 *
9990 * @return false if there is no more test cases, true otherwise
9991 **/
prepareNextTestCase(glw::GLuint test_case_index)9992 bool BindingSamplerSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
9993 {
9994 if (test_case_index > 0)
9995 {
9996 return false;
9997 }
9998
9999 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
10000 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
10001 << tcu::TestLog::EndMessage;
10002
10003 return true;
10004 }
10005
10006 /** Prepare source for given shader stage
10007 *
10008 * @param in_stage Shader stage, compute shader will use 430
10009 * @param in_use_version_400 Select if 400 or 420 should be used
10010 * @param out_source Prepared shader source instance
10011 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10012 void BindingSamplerSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10013 Utils::shaderSource &out_source)
10014 {
10015 static const GLchar *uni_goku_with_binding = "layout(binding = 2) uniform sampler2D goku;\n";
10016
10017 static const GLchar *uni_goku_no_binding = "uniform sampler2D goku;\n";
10018
10019 static const GLchar *verification_snippet = " vec4 goku_color = texture(goku, vec2(0,0));\n"
10020 "\n"
10021 " if (vec4(1, 0, 0, 0) != goku_color)\n"
10022 " {\n"
10023 " result = vec4(1, 0, 0, 1);\n"
10024 " }\n";
10025
10026 static const GLchar *compute_shader_template =
10027 "VERSION\n"
10028 "\n"
10029 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10030 "\n"
10031 "writeonly uniform image2D uni_image;\n"
10032 "\n"
10033 "UNI_GOKU\n"
10034 "\n"
10035 "void main()\n"
10036 "{\n"
10037 " vec4 result = vec4(0, 1, 0, 1);\n"
10038 "\n"
10039 "VERIFICATION"
10040 "\n"
10041 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10042 "}\n"
10043 "\n";
10044
10045 static const GLchar *fragment_shader_template = "VERSION\n"
10046 "\n"
10047 "in vec4 gs_fs_result;\n"
10048 "out vec4 fs_out_result;\n"
10049 "\n"
10050 "UNI_GOKU\n"
10051 "\n"
10052 "void main()\n"
10053 "{\n"
10054 " vec4 result = vec4(0, 1, 0, 1);\n"
10055 "\n"
10056 "VERIFICATION"
10057 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10058 " {\n"
10059 " result = vec4(1, 0, 0, 1);\n"
10060 " }\n"
10061 "\n"
10062 " fs_out_result = result;\n"
10063 "}\n"
10064 "\n";
10065
10066 static const GLchar *geometry_shader_template = "VERSION\n"
10067 "\n"
10068 "layout(points) in;\n"
10069 "layout(triangle_strip, max_vertices = 4) out;\n"
10070 "\n"
10071 "in vec4 tes_gs_result[];\n"
10072 "out vec4 gs_fs_result;\n"
10073 "\n"
10074 "UNI_GOKU\n"
10075 "\n"
10076 "void main()\n"
10077 "{\n"
10078 " vec4 result = vec4(0, 1, 0, 1);\n"
10079 "\n"
10080 "VERIFICATION"
10081 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10082 " {\n"
10083 " result = vec4(1, 0, 0, 1);\n"
10084 " }\n"
10085 "\n"
10086 " gs_fs_result = result;\n"
10087 " gl_Position = vec4(-1, -1, 0, 1);\n"
10088 " EmitVertex();\n"
10089 " gs_fs_result = result;\n"
10090 " gl_Position = vec4(-1, 1, 0, 1);\n"
10091 " EmitVertex();\n"
10092 " gs_fs_result = result;\n"
10093 " gl_Position = vec4(1, -1, 0, 1);\n"
10094 " EmitVertex();\n"
10095 " gs_fs_result = result;\n"
10096 " gl_Position = vec4(1, 1, 0, 1);\n"
10097 " EmitVertex();\n"
10098 "}\n"
10099 "\n";
10100
10101 static const GLchar *tess_ctrl_shader_template =
10102 "VERSION\n"
10103 "\n"
10104 "layout(vertices = 1) out;\n"
10105 "\n"
10106 "in vec4 vs_tcs_result[];\n"
10107 "out vec4 tcs_tes_result[];\n"
10108 "\n"
10109 "UNI_GOKU\n"
10110 "\n"
10111 "void main()\n"
10112 "{\n"
10113 " vec4 result = vec4(0, 1, 0, 1);\n"
10114 "\n"
10115 "VERIFICATION"
10116 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10117 " {\n"
10118 " result = vec4(1, 0, 0, 1);\n"
10119 " }\n"
10120 "\n"
10121 " tcs_tes_result[gl_InvocationID] = result;\n"
10122 "\n"
10123 " gl_TessLevelOuter[0] = 1.0;\n"
10124 " gl_TessLevelOuter[1] = 1.0;\n"
10125 " gl_TessLevelOuter[2] = 1.0;\n"
10126 " gl_TessLevelOuter[3] = 1.0;\n"
10127 " gl_TessLevelInner[0] = 1.0;\n"
10128 " gl_TessLevelInner[1] = 1.0;\n"
10129 "}\n"
10130 "\n";
10131
10132 static const GLchar *tess_eval_shader_template = "VERSION\n"
10133 "\n"
10134 "layout(isolines, point_mode) in;\n"
10135 "\n"
10136 "in vec4 tcs_tes_result[];\n"
10137 "out vec4 tes_gs_result;\n"
10138 "\n"
10139 "UNI_GOKU\n"
10140 "\n"
10141 "void main()\n"
10142 "{\n"
10143 " vec4 result = vec4(0, 1, 0, 1);\n"
10144 "\n"
10145 "VERIFICATION"
10146 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10147 " {\n"
10148 " result = vec4(1, 0, 0, 1);\n"
10149 " }\n"
10150 "\n"
10151 " tes_gs_result = result;\n"
10152 "}\n"
10153 "\n";
10154
10155 static const GLchar *vertex_shader_template = "VERSION\n"
10156 "\n"
10157 "out vec4 vs_tcs_result;\n"
10158 "\n"
10159 "UNI_GOKU\n"
10160 "\n"
10161 "void main()\n"
10162 "{\n"
10163 " vec4 result = vec4(0, 1, 0, 1);\n"
10164 "\n"
10165 "VERIFICATION"
10166 "\n"
10167 " vs_tcs_result = result;\n"
10168 "}\n"
10169 "\n";
10170
10171 const GLchar *shader_template = 0;
10172 const GLchar *uniform_definition = uni_goku_no_binding;
10173
10174 switch (in_stage)
10175 {
10176 case Utils::COMPUTE_SHADER:
10177 shader_template = compute_shader_template;
10178 uniform_definition = uni_goku_with_binding;
10179 break;
10180 case Utils::FRAGMENT_SHADER:
10181 shader_template = fragment_shader_template;
10182 break;
10183 case Utils::GEOMETRY_SHADER:
10184 shader_template = geometry_shader_template;
10185 break;
10186 case Utils::TESS_CTRL_SHADER:
10187 shader_template = tess_ctrl_shader_template;
10188 break;
10189 case Utils::TESS_EVAL_SHADER:
10190 shader_template = tess_eval_shader_template;
10191 break;
10192 case Utils::VERTEX_SHADER:
10193 shader_template = vertex_shader_template;
10194 break;
10195 default:
10196 TCU_FAIL("Invalid enum");
10197 }
10198
10199 if (in_stage == m_test_stage)
10200 {
10201 uniform_definition = uni_goku_with_binding;
10202 }
10203
10204 out_source.m_parts[0].m_code = shader_template;
10205
10206 size_t position = 0;
10207
10208 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10209 out_source.m_parts[0].m_code);
10210
10211 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10212
10213 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
10214 }
10215
10216 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10217 *
10218 * @param program Current program
10219 **/
prepareUniforms(Utils::program & program)10220 void BindingSamplerSingleTest::prepareUniforms(Utils::program &program)
10221 {
10222 (void)program;
10223 static const GLuint goku_data = 0x000000ff;
10224
10225 m_goku_texture.create(16, 16, GL_RGBA8);
10226
10227 std::vector<GLuint> texture_data;
10228 texture_data.resize(16 * 16);
10229
10230 for (GLuint i = 0; i < texture_data.size(); ++i)
10231 {
10232 texture_data[i] = goku_data;
10233 }
10234
10235 m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10236
10237 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10238
10239 gl.activeTexture(GL_TEXTURE2);
10240 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10241
10242 m_goku_texture.bind();
10243 }
10244
10245 /** Overwrite of releaseResource method, release extra texture
10246 *
10247 * @param ignored
10248 **/
releaseResource()10249 void BindingSamplerSingleTest::releaseResource()
10250 {
10251 m_goku_texture.release();
10252 }
10253
10254 /** Constructor
10255 *
10256 * @param context Test context
10257 **/
BindingSamplerArrayTest(deqp::Context & context)10258 BindingSamplerArrayTest::BindingSamplerArrayTest(deqp::Context &context)
10259 : GLSLTestBase(context, "binding_sampler_array", "Test verifies binding of sampler arrays")
10260 , m_goku_00_texture(context)
10261 , m_goku_01_texture(context)
10262 , m_goku_02_texture(context)
10263 , m_goku_03_texture(context)
10264 , m_goku_04_texture(context)
10265 , m_goku_05_texture(context)
10266 , m_goku_06_texture(context)
10267 {
10268 /* Nothing to be done here */
10269 }
10270
10271 /** Prepare source for given shader stage
10272 *
10273 * @param in_stage Shader stage, compute shader will use 430
10274 * @param in_use_version_400 Select if 400 or 420 should be used
10275 * @param out_source Prepared shader source instance
10276 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10277 void BindingSamplerArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10278 Utils::shaderSource &out_source)
10279 {
10280 static const GLchar *uni_goku = "layout(binding = 1) uniform sampler2D goku[7];\n";
10281
10282 static const GLchar *verification_snippet = " vec4 color[7];\n"
10283 "\n"
10284 " for (uint i = 0u; i < 7; ++i)\n"
10285 " {\n"
10286 " color[i] = texture(goku[i], vec2(0, 0));\n"
10287 " }\n"
10288 "\n"
10289 " if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
10290 " (vec4(0, 0, 0, 1) != color[1]) ||\n"
10291 " (vec4(0, 0, 1, 0) != color[2]) ||\n"
10292 " (vec4(0, 0, 1, 1) != color[3]) ||\n"
10293 " (vec4(0, 1, 0, 0) != color[4]) ||\n"
10294 " (vec4(0, 1, 0, 1) != color[5]) ||\n"
10295 " (vec4(0, 1, 1, 0) != color[6]) )\n"
10296 " {\n"
10297 " result = vec4(1, 0, 0, 1);\n"
10298 " }\n";
10299
10300 static const GLchar *compute_shader_template =
10301 "VERSION\n"
10302 "\n"
10303 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10304 "\n"
10305 "writeonly uniform image2D uni_image;\n"
10306 "\n"
10307 "UNI_GOKU\n"
10308 "\n"
10309 "void main()\n"
10310 "{\n"
10311 " vec4 result = vec4(0, 1, 0, 1);\n"
10312 "\n"
10313 "VERIFICATION"
10314 "\n"
10315 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10316 "}\n"
10317 "\n";
10318
10319 static const GLchar *fragment_shader_template = "VERSION\n"
10320 "\n"
10321 "in vec4 gs_fs_result;\n"
10322 "out vec4 fs_out_result;\n"
10323 "\n"
10324 "UNI_GOKU\n"
10325 "\n"
10326 "void main()\n"
10327 "{\n"
10328 " vec4 result = vec4(0, 1, 0, 1);\n"
10329 "\n"
10330 "VERIFICATION"
10331 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10332 " {\n"
10333 " result = vec4(1, 0, 0, 1);\n"
10334 " }\n"
10335 "\n"
10336 " fs_out_result = result;\n"
10337 "}\n"
10338 "\n";
10339
10340 static const GLchar *geometry_shader_template = "VERSION\n"
10341 "\n"
10342 "layout(points) in;\n"
10343 "layout(triangle_strip, max_vertices = 4) out;\n"
10344 "\n"
10345 "in vec4 tes_gs_result[];\n"
10346 "out vec4 gs_fs_result;\n"
10347 "\n"
10348 "UNI_GOKU\n"
10349 "\n"
10350 "void main()\n"
10351 "{\n"
10352 " vec4 result = vec4(0, 1, 0, 1);\n"
10353 "\n"
10354 "VERIFICATION"
10355 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10356 " {\n"
10357 " result = vec4(1, 0, 0, 1);\n"
10358 " }\n"
10359 "\n"
10360 " gs_fs_result = result;\n"
10361 " gl_Position = vec4(-1, -1, 0, 1);\n"
10362 " EmitVertex();\n"
10363 " gs_fs_result = result;\n"
10364 " gl_Position = vec4(-1, 1, 0, 1);\n"
10365 " EmitVertex();\n"
10366 " gs_fs_result = result;\n"
10367 " gl_Position = vec4(1, -1, 0, 1);\n"
10368 " EmitVertex();\n"
10369 " gs_fs_result = result;\n"
10370 " gl_Position = vec4(1, 1, 0, 1);\n"
10371 " EmitVertex();\n"
10372 "}\n"
10373 "\n";
10374
10375 static const GLchar *tess_ctrl_shader_template =
10376 "VERSION\n"
10377 "\n"
10378 "layout(vertices = 1) out;\n"
10379 "\n"
10380 "in vec4 vs_tcs_result[];\n"
10381 "out vec4 tcs_tes_result[];\n"
10382 "\n"
10383 "UNI_GOKU\n"
10384 "\n"
10385 "void main()\n"
10386 "{\n"
10387 " vec4 result = vec4(0, 1, 0, 1);\n"
10388 "\n"
10389 "VERIFICATION"
10390 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10391 " {\n"
10392 " result = vec4(1, 0, 0, 1);\n"
10393 " }\n"
10394 "\n"
10395 " tcs_tes_result[gl_InvocationID] = result;\n"
10396 "\n"
10397 " gl_TessLevelOuter[0] = 1.0;\n"
10398 " gl_TessLevelOuter[1] = 1.0;\n"
10399 " gl_TessLevelOuter[2] = 1.0;\n"
10400 " gl_TessLevelOuter[3] = 1.0;\n"
10401 " gl_TessLevelInner[0] = 1.0;\n"
10402 " gl_TessLevelInner[1] = 1.0;\n"
10403 "}\n"
10404 "\n";
10405
10406 static const GLchar *tess_eval_shader_template = "VERSION\n"
10407 "\n"
10408 "layout(isolines, point_mode) in;\n"
10409 "\n"
10410 "in vec4 tcs_tes_result[];\n"
10411 "out vec4 tes_gs_result;\n"
10412 "\n"
10413 "UNI_GOKU\n"
10414 "\n"
10415 "void main()\n"
10416 "{\n"
10417 " vec4 result = vec4(0, 1, 0, 1);\n"
10418 "\n"
10419 "VERIFICATION"
10420 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10421 " {\n"
10422 " result = vec4(1, 0, 0, 1);\n"
10423 " }\n"
10424 "\n"
10425 " tes_gs_result = result;\n"
10426 "}\n"
10427 "\n";
10428
10429 static const GLchar *vertex_shader_template = "VERSION\n"
10430 "\n"
10431 "out vec4 vs_tcs_result;\n"
10432 "\n"
10433 "UNI_GOKU\n"
10434 "\n"
10435 "void main()\n"
10436 "{\n"
10437 " vec4 result = vec4(0, 1, 0, 1);\n"
10438 "\n"
10439 "VERIFICATION"
10440 "\n"
10441 " vs_tcs_result = result;\n"
10442 "}\n"
10443 "\n";
10444
10445 const GLchar *shader_template = 0;
10446
10447 switch (in_stage)
10448 {
10449 case Utils::COMPUTE_SHADER:
10450 shader_template = compute_shader_template;
10451 break;
10452 case Utils::FRAGMENT_SHADER:
10453 shader_template = fragment_shader_template;
10454 break;
10455 case Utils::GEOMETRY_SHADER:
10456 shader_template = geometry_shader_template;
10457 break;
10458 case Utils::TESS_CTRL_SHADER:
10459 shader_template = tess_ctrl_shader_template;
10460 break;
10461 case Utils::TESS_EVAL_SHADER:
10462 shader_template = tess_eval_shader_template;
10463 break;
10464 case Utils::VERTEX_SHADER:
10465 shader_template = vertex_shader_template;
10466 break;
10467 default:
10468 TCU_FAIL("Invalid enum");
10469 }
10470
10471 out_source.m_parts[0].m_code = shader_template;
10472
10473 size_t position = 0;
10474
10475 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10476 out_source.m_parts[0].m_code);
10477
10478 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10479
10480 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10481 }
10482
10483 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10484 *
10485 * @param program Current program
10486 **/
prepareUniforms(Utils::program & program)10487 void BindingSamplerArrayTest::prepareUniforms(Utils::program &program)
10488 {
10489 static const GLuint goku_data[7] = {
10490 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
10491 };
10492
10493 static const GLuint binding_offset = 1;
10494
10495 Utils::texture *textures[7] = {
10496 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10497 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10498 };
10499
10500 std::vector<GLuint> texture_data;
10501 texture_data.resize(16 * 16);
10502
10503 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10504
10505 for (GLuint i = 0; i < 7; ++i)
10506 {
10507 GLint expected_binding = i + binding_offset;
10508
10509 checkBinding(program, i, expected_binding);
10510
10511 gl.activeTexture(GL_TEXTURE0 + expected_binding);
10512 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10513
10514 textures[i]->create(16, 16, GL_RGBA8);
10515
10516 for (GLuint j = 0; j < texture_data.size(); ++j)
10517 {
10518 texture_data[j] = goku_data[i];
10519 }
10520
10521 textures[i]->update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10522 }
10523 }
10524
10525 /** Overwrite of releaseResource method, release extra textures
10526 *
10527 * @param ignored
10528 **/
releaseResource()10529 void BindingSamplerArrayTest::releaseResource()
10530 {
10531 Utils::texture *textures[7] = {
10532 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10533 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10534 };
10535
10536 for (GLuint i = 0; i < 7; ++i)
10537 {
10538 textures[i]->release();
10539 }
10540 }
10541
10542 /** Verifies that API reports correct uniform binding
10543 *
10544 * @param program Program
10545 * @param index Index of array element
10546 * @param expected_binding Expected binding
10547 **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)10548 void BindingSamplerArrayTest::checkBinding(Utils::program &program, GLuint index, GLint expected_binding)
10549 {
10550 if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
10551 {
10552 TCU_FAIL("Wrong binding reported by API");
10553 }
10554 }
10555
10556 /** Constructor
10557 *
10558 * @param context Test context
10559 **/
BindingSamplerDefaultTest(deqp::Context & context)10560 BindingSamplerDefaultTest::BindingSamplerDefaultTest(deqp::Context &context)
10561 : APITestBase(context, "binding_sampler_default", "Test verifies default sampler binding")
10562 {
10563 /* Nothing to be done here */
10564 }
10565
10566 /** Execute API call and verifies results
10567 *
10568 * @return true when results are positive, false otherwise
10569 **/
checkResults(Utils::program & program)10570 bool BindingSamplerDefaultTest::checkResults(Utils::program &program)
10571 {
10572 return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
10573 }
10574
10575 /** Prepare source for given shader stage
10576 *
10577 * @param in_stage Shader stage, compute shader will use 430
10578 * @param in_use_version_400 Select if 400 or 420 should be used
10579 * @param out_source Prepared shader source instance
10580 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10581 void BindingSamplerDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10582 Utils::shaderSource &out_source)
10583 {
10584 static const GLchar *uni_goku = "uniform sampler2D goku;\n";
10585
10586 static const GLchar *verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
10587 " if (vec4(1, 0, 0, 0) != color)\n"
10588 " {\n"
10589 " result = vec4(1, 0, 0, 1);\n"
10590 " }\n";
10591
10592 static const GLchar *compute_shader_template =
10593 "VERSION\n"
10594 "\n"
10595 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10596 "\n"
10597 "writeonly uniform image2D uni_image;\n"
10598 "\n"
10599 "UNI_GOKU\n"
10600 "\n"
10601 "void main()\n"
10602 "{\n"
10603 " vec4 result = vec4(0, 1, 0, 1);\n"
10604 "\n"
10605 "VERIFICATION"
10606 "\n"
10607 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10608 "}\n"
10609 "\n";
10610
10611 static const GLchar *fragment_shader_template = "VERSION\n"
10612 "\n"
10613 "in vec4 gs_fs_result;\n"
10614 "out vec4 fs_out_result;\n"
10615 "\n"
10616 "UNI_GOKU\n"
10617 "\n"
10618 "void main()\n"
10619 "{\n"
10620 " vec4 result = vec4(0, 1, 0, 1);\n"
10621 "\n"
10622 "VERIFICATION"
10623 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10624 " {\n"
10625 " result = vec4(1, 0, 0, 1);\n"
10626 " }\n"
10627 "\n"
10628 " fs_out_result = result;\n"
10629 "}\n"
10630 "\n";
10631
10632 static const GLchar *geometry_shader_template = "VERSION\n"
10633 "\n"
10634 "layout(points) in;\n"
10635 "layout(triangle_strip, max_vertices = 4) out;\n"
10636 "\n"
10637 "in vec4 tes_gs_result[];\n"
10638 "out vec4 gs_fs_result;\n"
10639 "\n"
10640 "UNI_GOKU\n"
10641 "\n"
10642 "void main()\n"
10643 "{\n"
10644 " vec4 result = vec4(0, 1, 0, 1);\n"
10645 "\n"
10646 "VERIFICATION"
10647 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10648 " {\n"
10649 " result = vec4(1, 0, 0, 1);\n"
10650 " }\n"
10651 "\n"
10652 " gs_fs_result = result;\n"
10653 " gl_Position = vec4(-1, -1, 0, 1);\n"
10654 " EmitVertex();\n"
10655 " gs_fs_result = result;\n"
10656 " gl_Position = vec4(-1, 1, 0, 1);\n"
10657 " EmitVertex();\n"
10658 " gs_fs_result = result;\n"
10659 " gl_Position = vec4(1, -1, 0, 1);\n"
10660 " EmitVertex();\n"
10661 " gs_fs_result = result;\n"
10662 " gl_Position = vec4(1, 1, 0, 1);\n"
10663 " EmitVertex();\n"
10664 "}\n"
10665 "\n";
10666
10667 static const GLchar *tess_ctrl_shader_template =
10668 "VERSION\n"
10669 "\n"
10670 "layout(vertices = 1) out;\n"
10671 "\n"
10672 "in vec4 vs_tcs_result[];\n"
10673 "out vec4 tcs_tes_result[];\n"
10674 "\n"
10675 "UNI_GOKU\n"
10676 "\n"
10677 "void main()\n"
10678 "{\n"
10679 " vec4 result = vec4(0, 1, 0, 1);\n"
10680 "\n"
10681 "VERIFICATION"
10682 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10683 " {\n"
10684 " result = vec4(1, 0, 0, 1);\n"
10685 " }\n"
10686 "\n"
10687 " tcs_tes_result[gl_InvocationID] = result;\n"
10688 "\n"
10689 " gl_TessLevelOuter[0] = 1.0;\n"
10690 " gl_TessLevelOuter[1] = 1.0;\n"
10691 " gl_TessLevelOuter[2] = 1.0;\n"
10692 " gl_TessLevelOuter[3] = 1.0;\n"
10693 " gl_TessLevelInner[0] = 1.0;\n"
10694 " gl_TessLevelInner[1] = 1.0;\n"
10695 "}\n"
10696 "\n";
10697
10698 static const GLchar *tess_eval_shader_template = "VERSION\n"
10699 "\n"
10700 "layout(isolines, point_mode) in;\n"
10701 "\n"
10702 "in vec4 tcs_tes_result[];\n"
10703 "out vec4 tes_gs_result;\n"
10704 "\n"
10705 "UNI_GOKU\n"
10706 "\n"
10707 "void main()\n"
10708 "{\n"
10709 " vec4 result = vec4(0, 1, 0, 1);\n"
10710 "\n"
10711 "VERIFICATION"
10712 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10713 " {\n"
10714 " result = vec4(1, 0, 0, 1);\n"
10715 " }\n"
10716 "\n"
10717 " tes_gs_result = result;\n"
10718 "}\n"
10719 "\n";
10720
10721 static const GLchar *vertex_shader_template = "VERSION\n"
10722 "\n"
10723 "out vec4 vs_tcs_result;\n"
10724 "\n"
10725 "UNI_GOKU\n"
10726 "\n"
10727 "void main()\n"
10728 "{\n"
10729 " vec4 result = vec4(0, 1, 0, 1);\n"
10730 "\n"
10731 "VERIFICATION"
10732 "\n"
10733 " vs_tcs_result = result;\n"
10734 "}\n"
10735 "\n";
10736
10737 const GLchar *shader_template = 0;
10738
10739 switch (in_stage)
10740 {
10741 case Utils::COMPUTE_SHADER:
10742 shader_template = compute_shader_template;
10743 break;
10744 case Utils::FRAGMENT_SHADER:
10745 shader_template = fragment_shader_template;
10746 break;
10747 case Utils::GEOMETRY_SHADER:
10748 shader_template = geometry_shader_template;
10749 break;
10750 case Utils::TESS_CTRL_SHADER:
10751 shader_template = tess_ctrl_shader_template;
10752 break;
10753 case Utils::TESS_EVAL_SHADER:
10754 shader_template = tess_eval_shader_template;
10755 break;
10756 case Utils::VERTEX_SHADER:
10757 shader_template = vertex_shader_template;
10758 break;
10759 default:
10760 TCU_FAIL("Invalid enum");
10761 }
10762
10763 out_source.m_parts[0].m_code = shader_template;
10764
10765 size_t position = 0;
10766
10767 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10768 out_source.m_parts[0].m_code);
10769
10770 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10771
10772 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10773 }
10774
10775 /** Constructor
10776 *
10777 * @param context Test context
10778 **/
BindingSamplerAPIOverrideTest(deqp::Context & context)10779 BindingSamplerAPIOverrideTest::BindingSamplerAPIOverrideTest(deqp::Context &context)
10780 : GLSLTestBase(context, "binding_sampler_api_override", "Verifies that API can override sampler binding")
10781 , m_goku_texture(context)
10782 {
10783 /* Nothing to be done here */
10784 }
10785
10786 /** Prepare source for given shader stage
10787 *
10788 * @param in_stage Shader stage, compute shader will use 430
10789 * @param in_use_version_400 Select if 400 or 420 should be used
10790 * @param out_source Prepared shader source instance
10791 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10792 void BindingSamplerAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10793 Utils::shaderSource &out_source)
10794 {
10795 static const GLchar *uni_goku = "layout(binding = 2) uniform sampler2D goku;\n";
10796
10797 static const GLchar *verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
10798 " if (vec4(1, 0, 0, 0) != color)\n"
10799 " {\n"
10800 " result = vec4(1, 0, 0, 1);\n"
10801 " }\n";
10802
10803 static const GLchar *compute_shader_template =
10804 "VERSION\n"
10805 "\n"
10806 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10807 "\n"
10808 "writeonly uniform image2D uni_image;\n"
10809 "\n"
10810 "UNI_GOKU\n"
10811 "\n"
10812 "void main()\n"
10813 "{\n"
10814 " vec4 result = vec4(0, 1, 0, 1);\n"
10815 "\n"
10816 "VERIFICATION"
10817 "\n"
10818 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10819 "}\n"
10820 "\n";
10821
10822 static const GLchar *fragment_shader_template = "VERSION\n"
10823 "\n"
10824 "in vec4 gs_fs_result;\n"
10825 "out vec4 fs_out_result;\n"
10826 "\n"
10827 "UNI_GOKU\n"
10828 "\n"
10829 "void main()\n"
10830 "{\n"
10831 " vec4 result = vec4(0, 1, 0, 1);\n"
10832 "\n"
10833 "VERIFICATION"
10834 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10835 " {\n"
10836 " result = vec4(1, 0, 0, 1);\n"
10837 " }\n"
10838 "\n"
10839 " fs_out_result = result;\n"
10840 "}\n"
10841 "\n";
10842
10843 static const GLchar *geometry_shader_template = "VERSION\n"
10844 "\n"
10845 "layout(points) in;\n"
10846 "layout(triangle_strip, max_vertices = 4) out;\n"
10847 "\n"
10848 "in vec4 tes_gs_result[];\n"
10849 "out vec4 gs_fs_result;\n"
10850 "\n"
10851 "UNI_GOKU\n"
10852 "\n"
10853 "void main()\n"
10854 "{\n"
10855 " vec4 result = vec4(0, 1, 0, 1);\n"
10856 "\n"
10857 "VERIFICATION"
10858 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10859 " {\n"
10860 " result = vec4(1, 0, 0, 1);\n"
10861 " }\n"
10862 "\n"
10863 " gs_fs_result = result;\n"
10864 " gl_Position = vec4(-1, -1, 0, 1);\n"
10865 " EmitVertex();\n"
10866 " gs_fs_result = result;\n"
10867 " gl_Position = vec4(-1, 1, 0, 1);\n"
10868 " EmitVertex();\n"
10869 " gs_fs_result = result;\n"
10870 " gl_Position = vec4(1, -1, 0, 1);\n"
10871 " EmitVertex();\n"
10872 " gs_fs_result = result;\n"
10873 " gl_Position = vec4(1, 1, 0, 1);\n"
10874 " EmitVertex();\n"
10875 "}\n"
10876 "\n";
10877
10878 static const GLchar *tess_ctrl_shader_template =
10879 "VERSION\n"
10880 "\n"
10881 "layout(vertices = 1) out;\n"
10882 "\n"
10883 "in vec4 vs_tcs_result[];\n"
10884 "out vec4 tcs_tes_result[];\n"
10885 "\n"
10886 "UNI_GOKU\n"
10887 "\n"
10888 "void main()\n"
10889 "{\n"
10890 " vec4 result = vec4(0, 1, 0, 1);\n"
10891 "\n"
10892 "VERIFICATION"
10893 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10894 " {\n"
10895 " result = vec4(1, 0, 0, 1);\n"
10896 " }\n"
10897 "\n"
10898 " tcs_tes_result[gl_InvocationID] = result;\n"
10899 "\n"
10900 " gl_TessLevelOuter[0] = 1.0;\n"
10901 " gl_TessLevelOuter[1] = 1.0;\n"
10902 " gl_TessLevelOuter[2] = 1.0;\n"
10903 " gl_TessLevelOuter[3] = 1.0;\n"
10904 " gl_TessLevelInner[0] = 1.0;\n"
10905 " gl_TessLevelInner[1] = 1.0;\n"
10906 "}\n"
10907 "\n";
10908
10909 static const GLchar *tess_eval_shader_template = "VERSION\n"
10910 "\n"
10911 "layout(isolines, point_mode) in;\n"
10912 "\n"
10913 "in vec4 tcs_tes_result[];\n"
10914 "out vec4 tes_gs_result;\n"
10915 "\n"
10916 "UNI_GOKU\n"
10917 "\n"
10918 "void main()\n"
10919 "{\n"
10920 " vec4 result = vec4(0, 1, 0, 1);\n"
10921 "\n"
10922 "VERIFICATION"
10923 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10924 " {\n"
10925 " result = vec4(1, 0, 0, 1);\n"
10926 " }\n"
10927 "\n"
10928 " tes_gs_result = result;\n"
10929 "}\n"
10930 "\n";
10931
10932 static const GLchar *vertex_shader_template = "VERSION\n"
10933 "\n"
10934 "out vec4 vs_tcs_result;\n"
10935 "\n"
10936 "UNI_GOKU\n"
10937 "\n"
10938 "void main()\n"
10939 "{\n"
10940 " vec4 result = vec4(0, 1, 0, 1);\n"
10941 "\n"
10942 "VERIFICATION"
10943 "\n"
10944 " vs_tcs_result = result;\n"
10945 "}\n"
10946 "\n";
10947
10948 const GLchar *shader_template = 0;
10949
10950 switch (in_stage)
10951 {
10952 case Utils::COMPUTE_SHADER:
10953 shader_template = compute_shader_template;
10954 break;
10955 case Utils::FRAGMENT_SHADER:
10956 shader_template = fragment_shader_template;
10957 break;
10958 case Utils::GEOMETRY_SHADER:
10959 shader_template = geometry_shader_template;
10960 break;
10961 case Utils::TESS_CTRL_SHADER:
10962 shader_template = tess_ctrl_shader_template;
10963 break;
10964 case Utils::TESS_EVAL_SHADER:
10965 shader_template = tess_eval_shader_template;
10966 break;
10967 case Utils::VERTEX_SHADER:
10968 shader_template = vertex_shader_template;
10969 break;
10970 default:
10971 TCU_FAIL("Invalid enum");
10972 }
10973
10974 out_source.m_parts[0].m_code = shader_template;
10975
10976 size_t position = 0;
10977
10978 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10979 out_source.m_parts[0].m_code);
10980
10981 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10982
10983 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10984 }
10985
10986 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10987 *
10988 * @param program Current program
10989 **/
prepareUniforms(Utils::program & program)10990 void BindingSamplerAPIOverrideTest::prepareUniforms(Utils::program &program)
10991 {
10992 static const GLuint goku_data = 0x000000ff;
10993 static const GLint new_binding = 11;
10994
10995 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10996
10997 const GLint uniform_location = program.getUniformLocation("goku");
10998 if (-1 == uniform_location)
10999 {
11000 TCU_FAIL("Uniform is inactive");
11001 }
11002
11003 gl.uniform1i(uniform_location, new_binding);
11004
11005 GLint binding = -1;
11006
11007 gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
11008 GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
11009
11010 if (new_binding != binding)
11011 {
11012 TCU_FAIL("Wrong binding value");
11013 return;
11014 }
11015
11016 m_goku_texture.create(16, 16, GL_RGBA8);
11017
11018 std::vector<GLuint> texture_data;
11019 texture_data.resize(16 * 16);
11020
11021 for (GLuint i = 0; i < texture_data.size(); ++i)
11022 {
11023 texture_data[i] = goku_data;
11024 }
11025
11026 m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
11027
11028 gl.activeTexture(GL_TEXTURE11);
11029 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
11030
11031 m_goku_texture.bind();
11032 }
11033
11034 /** Overwrite of releaseResource method, release extra texture
11035 *
11036 * @param ignored
11037 **/
releaseResource()11038 void BindingSamplerAPIOverrideTest::releaseResource()
11039 {
11040 m_goku_texture.release();
11041 }
11042
11043 /** Constructor
11044 *
11045 * @param context Test context
11046 **/
BindingSamplerInvalidTest(deqp::Context & context,TESTCASES case_index)11047 BindingSamplerInvalidTest::BindingSamplerInvalidTest(deqp::Context &context, TESTCASES case_index)
11048 : NegativeTestBase(context, "binding_sampler_invalid", "Test verifies invalid binding values")
11049 , m_test_case_idx(case_index)
11050 {
11051 std::string name = "binding_sampler_invalid_case_" + std::string(getTestCaseString(m_test_case_idx));
11052
11053 TestCase::m_name = name;
11054 }
11055
getTestCaseString(TESTCASES test_case)11056 const GLchar *BindingSamplerInvalidTest::getTestCaseString(TESTCASES test_case)
11057 {
11058 const GLchar *name = 0;
11059
11060 switch (test_case)
11061 {
11062 case NEGATIVE_VALUE:
11063 name = "-1";
11064 break;
11065 case VARIABLE_NAME:
11066 name = "goku";
11067 break;
11068 case STD140:
11069 name = "std140";
11070 break;
11071 case MISSING:
11072 name = "";
11073 break;
11074 case TEST_CASES_MAX:
11075 name = "0";
11076 break;
11077 default:
11078 TCU_FAIL("Invalid enum");
11079 }
11080
11081 return name;
11082 }
11083
11084 /** Set up next test case
11085 *
11086 * @param test_case_index Index of next test case
11087 *
11088 * @return false if there is no more test cases, true otherwise
11089 **/
prepareNextTestCase(glw::GLuint test_case_index)11090 bool BindingSamplerInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
11091 {
11092 if (test_case_index > 0)
11093 {
11094 return false;
11095 }
11096 switch (m_test_case_idx)
11097 {
11098 // case (glw::GLuint)-1:
11099 // m_case = TEST_CASES_MAX;
11100 // break;
11101 case NEGATIVE_VALUE:
11102 case VARIABLE_NAME:
11103 case STD140:
11104 case MISSING:
11105 m_case = (TESTCASES)m_test_case_idx;
11106 break;
11107 default:
11108 return false;
11109 }
11110
11111 return true;
11112 }
11113
11114 /** Prepare source for given shader stage
11115 *
11116 * @param in_stage Shader stage, compute shader will use 430
11117 * @param in_use_version_400 Select if 400 or 420 should be used
11118 * @param out_source Prepared shader source instance
11119 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11120 void BindingSamplerInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11121 Utils::shaderSource &out_source)
11122 {
11123 static const GLchar *uni_goku = "layout(binding BINDING) uniform sampler2D goku;\n";
11124
11125 static const GLchar *verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
11126 " if (vec4(1, 0, 0, 0) != color)\n"
11127 " {\n"
11128 " result = vec4(1, 0, 0, 1);\n"
11129 " }\n";
11130
11131 static const GLchar *compute_shader_template =
11132 "VERSION\n"
11133 "\n"
11134 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11135 "\n"
11136 "writeonly uniform image2D uni_image;\n"
11137 "\n"
11138 "UNI_GOKU\n"
11139 "\n"
11140 "void main()\n"
11141 "{\n"
11142 " vec4 result = vec4(0, 1, 0, 1);\n"
11143 "\n"
11144 "VERIFICATION"
11145 "\n"
11146 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11147 "}\n"
11148 "\n";
11149
11150 static const GLchar *fragment_shader_template = "VERSION\n"
11151 "\n"
11152 "in vec4 gs_fs_result;\n"
11153 "out vec4 fs_out_result;\n"
11154 "\n"
11155 "UNI_GOKU\n"
11156 "\n"
11157 "void main()\n"
11158 "{\n"
11159 " vec4 result = vec4(0, 1, 0, 1);\n"
11160 "\n"
11161 "VERIFICATION"
11162 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11163 " {\n"
11164 " result = vec4(1, 0, 0, 1);\n"
11165 " }\n"
11166 "\n"
11167 " fs_out_result = result;\n"
11168 "}\n"
11169 "\n";
11170
11171 static const GLchar *geometry_shader_template = "VERSION\n"
11172 "\n"
11173 "layout(points) in;\n"
11174 "layout(triangle_strip, max_vertices = 4) out;\n"
11175 "\n"
11176 "in vec4 tes_gs_result[];\n"
11177 "out vec4 gs_fs_result;\n"
11178 "\n"
11179 "UNI_GOKU\n"
11180 "\n"
11181 "void main()\n"
11182 "{\n"
11183 " vec4 result = vec4(0, 1, 0, 1);\n"
11184 "\n"
11185 "VERIFICATION"
11186 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11187 " {\n"
11188 " result = vec4(1, 0, 0, 1);\n"
11189 " }\n"
11190 "\n"
11191 " gs_fs_result = result;\n"
11192 " gl_Position = vec4(-1, -1, 0, 1);\n"
11193 " EmitVertex();\n"
11194 " gs_fs_result = result;\n"
11195 " gl_Position = vec4(-1, 1, 0, 1);\n"
11196 " EmitVertex();\n"
11197 " gs_fs_result = result;\n"
11198 " gl_Position = vec4(1, -1, 0, 1);\n"
11199 " EmitVertex();\n"
11200 " gs_fs_result = result;\n"
11201 " gl_Position = vec4(1, 1, 0, 1);\n"
11202 " EmitVertex();\n"
11203 "}\n"
11204 "\n";
11205
11206 static const GLchar *tess_ctrl_shader_template =
11207 "VERSION\n"
11208 "\n"
11209 "layout(vertices = 1) out;\n"
11210 "\n"
11211 "in vec4 vs_tcs_result[];\n"
11212 "out vec4 tcs_tes_result[];\n"
11213 "\n"
11214 "UNI_GOKU\n"
11215 "\n"
11216 "void main()\n"
11217 "{\n"
11218 " vec4 result = vec4(0, 1, 0, 1);\n"
11219 "\n"
11220 "VERIFICATION"
11221 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11222 " {\n"
11223 " result = vec4(1, 0, 0, 1);\n"
11224 " }\n"
11225 "\n"
11226 " tcs_tes_result[gl_InvocationID] = result;\n"
11227 "\n"
11228 " gl_TessLevelOuter[0] = 1.0;\n"
11229 " gl_TessLevelOuter[1] = 1.0;\n"
11230 " gl_TessLevelOuter[2] = 1.0;\n"
11231 " gl_TessLevelOuter[3] = 1.0;\n"
11232 " gl_TessLevelInner[0] = 1.0;\n"
11233 " gl_TessLevelInner[1] = 1.0;\n"
11234 "}\n"
11235 "\n";
11236
11237 static const GLchar *tess_eval_shader_template = "VERSION\n"
11238 "\n"
11239 "layout(isolines, point_mode) in;\n"
11240 "\n"
11241 "in vec4 tcs_tes_result[];\n"
11242 "out vec4 tes_gs_result;\n"
11243 "\n"
11244 "UNI_GOKU\n"
11245 "\n"
11246 "void main()\n"
11247 "{\n"
11248 " vec4 result = vec4(0, 1, 0, 1);\n"
11249 "\n"
11250 "VERIFICATION"
11251 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11252 " {\n"
11253 " result = vec4(1, 0, 0, 1);\n"
11254 " }\n"
11255 "\n"
11256 " tes_gs_result = result;\n"
11257 "}\n"
11258 "\n";
11259
11260 static const GLchar *vertex_shader_template = "VERSION\n"
11261 "\n"
11262 "out vec4 vs_tcs_result;\n"
11263 "\n"
11264 "UNI_GOKU\n"
11265 "\n"
11266 "void main()\n"
11267 "{\n"
11268 " vec4 result = vec4(0, 1, 0, 1);\n"
11269 "\n"
11270 "VERIFICATION"
11271 "\n"
11272 " vs_tcs_result = result;\n"
11273 "}\n"
11274 "\n";
11275
11276 const GLchar *shader_template = 0;
11277
11278 switch (in_stage)
11279 {
11280 case Utils::COMPUTE_SHADER:
11281 shader_template = compute_shader_template;
11282 break;
11283 case Utils::FRAGMENT_SHADER:
11284 shader_template = fragment_shader_template;
11285 break;
11286 case Utils::GEOMETRY_SHADER:
11287 shader_template = geometry_shader_template;
11288 break;
11289 case Utils::TESS_CTRL_SHADER:
11290 shader_template = tess_ctrl_shader_template;
11291 break;
11292 case Utils::TESS_EVAL_SHADER:
11293 shader_template = tess_eval_shader_template;
11294 break;
11295 case Utils::VERTEX_SHADER:
11296 shader_template = vertex_shader_template;
11297 break;
11298 default:
11299 TCU_FAIL("Invalid enum");
11300 }
11301
11302 out_source.m_parts[0].m_code = shader_template;
11303
11304 size_t position = 0;
11305
11306 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11307 out_source.m_parts[0].m_code);
11308
11309 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11310
11311 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11312
11313 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
11314 }
11315
getCaseString(TESTCASES test_case)11316 const GLchar *BindingSamplerInvalidTest::getCaseString(TESTCASES test_case)
11317 {
11318 (void)test_case;
11319 const GLchar *binding = 0;
11320
11321 switch (m_case)
11322 {
11323 case NEGATIVE_VALUE:
11324 binding = "= -1";
11325 break;
11326 case VARIABLE_NAME:
11327 binding = "= goku";
11328 break;
11329 case STD140:
11330 binding = "= std140";
11331 break;
11332 case MISSING:
11333 binding = "";
11334 break;
11335 case TEST_CASES_MAX:
11336 binding = "= 0";
11337 break;
11338 default:
11339 TCU_FAIL("Invalid enum");
11340 }
11341
11342 return binding;
11343 }
11344
11345 /* Constants used by BindingImagesTest */
11346 const GLuint BindingImagesTest::m_goku_data = 0x000000ff;
11347 const GLuint BindingImagesTest::m_vegeta_data = 0x0000ff00;
11348 const GLuint BindingImagesTest::m_trunks_data = 0x00ff0000;
11349
11350 /** Constructor
11351 *
11352 * @param context Test context
11353 **/
BindingImagesTest(deqp::Context & context,Utils::TEXTURE_TYPES test_case)11354 BindingImagesTest::BindingImagesTest(deqp::Context &context, Utils::TEXTURE_TYPES test_case)
11355 : BindingImageTest(context, "binding_images", "Test verifies binding of images")
11356 , m_goku_texture(context)
11357 , m_vegeta_texture(context)
11358 , m_trunks_texture(context)
11359 , m_goku_buffer(context)
11360 , m_vegeta_buffer(context)
11361 , m_trunks_buffer(context)
11362 , m_test_case(test_case)
11363 {
11364 std::string name = "binding_images_texture_type_" + std::string(Utils::getTextureTypeName(m_test_case));
11365
11366 TestCase::m_name = name;
11367 }
11368
11369 /** Set up next test case
11370 *
11371 * @param test_case_index Index of next test case
11372 *
11373 * @return false if there is no more test cases, true otherwise
11374 **/
prepareNextTestCase(glw::GLuint test_case_index)11375 bool BindingImagesTest::prepareNextTestCase(glw::GLuint test_case_index)
11376 {
11377 if (test_case_index > 0)
11378 {
11379 return false;
11380 }
11381
11382 m_context.getTestContext().getLog() << tcu::TestLog::Message
11383 << "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
11384 << tcu::TestLog::EndMessage;
11385
11386 return true;
11387 }
11388
11389 /** Prepare source for given shader stage
11390 *
11391 * @param in_stage Shader stage, compute shader will use 430
11392 * @param in_use_version_400 Select if 400 or 420 should be used
11393 * @param out_source Prepared shader source instance
11394 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11395 void BindingImagesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11396 Utils::shaderSource &out_source)
11397 {
11398 static const GLchar *uni_goku = "layout(binding = 1, rgba8) uniform TYPE goku;\n";
11399
11400 static const GLchar *uni_vegeta = "layout(binding = 2, rgba8) uniform TYPE vegeta;\n";
11401
11402 static const GLchar *uni_trunks = "layout(binding = 4, rgba8) uniform TYPE trunks;\n\n";
11403
11404 static const GLchar *verification_snippet = " TEX_COORD_TYPE tex_coord_read = TEX_COORD_TYPE(COORDINATES);\n"
11405 " TEX_COORD_TYPE tex_coord_write = TEX_COORD_TYPE(COORDINATES);\n"
11406 " vec4 goku_color = imageLoad(goku, tex_coord_read);\n"
11407 " vec4 vegeta_color = imageLoad(vegeta, tex_coord_read);\n"
11408 " vec4 trunks_color = imageLoad(trunks, tex_coord_read);\n"
11409 "\n"
11410 " imageStore(goku, tex_coord_write, vec4(0, 1, 0, 1));\n"
11411 " imageStore(vegeta, tex_coord_write, vec4(0, 1, 0, 1));\n"
11412 " imageStore(trunks, tex_coord_write, vec4(0, 1, 0, 1));\n"
11413 "\n"
11414 " if ((vec4(1, 0, 0, 0) != goku_color) ||\n"
11415 " (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
11416 " (vec4(0, 0, 1, 0) != trunks_color) )\n"
11417 " {\n"
11418 " result = goku_color;\n"
11419 " //result = vec4(1, 0, 0, 1);\n"
11420 " }\n";
11421
11422 static const GLchar *compute_shader_template =
11423 "VERSION\n"
11424 "#extension GL_ARB_shader_image_load_store : enable\n"
11425 "\n"
11426 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11427 "\n"
11428 "writeonly uniform image2D uni_image;\n"
11429 "\n"
11430 "UNI_GOKU\n"
11431 "UNI_VEGETA\n"
11432 "UNI_TRUNKS\n"
11433 "\n"
11434 "void main()\n"
11435 "{\n"
11436 " vec4 result = vec4(0, 1, 0, 1);\n"
11437 "\n"
11438 " if(gl_GlobalInvocationID.xy == vec2(0, 0)) {\n"
11439 "VERIFICATION"
11440 " }\n"
11441 "\n"
11442 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11443 "}\n"
11444 "\n";
11445
11446 static const GLchar *fragment_shader_template = "VERSION\n"
11447 "#extension GL_ARB_shader_image_load_store : enable\n"
11448 "\n"
11449 "in vec4 gs_fs_result;\n"
11450 "out vec4 fs_out_result;\n"
11451 "\n"
11452 "UNI_GOKU\n"
11453 "UNI_VEGETA\n"
11454 "UNI_TRUNKS\n"
11455 "\n"
11456 "void main()\n"
11457 "{\n"
11458 " vec4 result = vec4(0, 1, 0, 1);\n"
11459 "\n"
11460 "VERIFICATION"
11461 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11462 " {\n"
11463 " result = vec4(1, 0, 0, 1);\n"
11464 " }\n"
11465 "\n"
11466 " fs_out_result = result;\n"
11467 "}\n"
11468 "\n";
11469
11470 static const GLchar *geometry_shader_template = "VERSION\n"
11471 "#extension GL_ARB_shader_image_load_store : enable\n"
11472 "\n"
11473 "layout(points) in;\n"
11474 "layout(triangle_strip, max_vertices = 4) out;\n"
11475 "\n"
11476 "in vec4 tes_gs_result[];\n"
11477 "out vec4 gs_fs_result;\n"
11478 "\n"
11479 "#if IMAGES\n"
11480 "UNI_TRUNKS\n"
11481 "UNI_GOKU\n"
11482 "UNI_VEGETA\n"
11483 "#endif\n"
11484 "\n"
11485 "void main()\n"
11486 "{\n"
11487 " vec4 result = vec4(0, 1, 0, 1);\n"
11488 "\n"
11489 "#if IMAGES\n"
11490 "VERIFICATION else\n"
11491 "#endif\n"
11492 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11493 " {\n"
11494 " result = vec4(1, 0, 0, 1);\n"
11495 " }\n"
11496 "\n"
11497 " gs_fs_result = result;\n"
11498 " gl_Position = vec4(-1, -1, 0, 1);\n"
11499 " EmitVertex();\n"
11500 " gs_fs_result = result;\n"
11501 " gl_Position = vec4(-1, 1, 0, 1);\n"
11502 " EmitVertex();\n"
11503 " gs_fs_result = result;\n"
11504 " gl_Position = vec4(1, -1, 0, 1);\n"
11505 " EmitVertex();\n"
11506 " gs_fs_result = result;\n"
11507 " gl_Position = vec4(1, 1, 0, 1);\n"
11508 " EmitVertex();\n"
11509 "}\n"
11510 "\n";
11511
11512 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
11513 "#extension GL_ARB_shader_image_load_store : enable\n"
11514 "\n"
11515 "layout(vertices = 1) out;\n"
11516 "\n"
11517 "in vec4 vs_tcs_result[];\n"
11518 "out vec4 tcs_tes_result[];\n"
11519 "\n"
11520 "#if IMAGES\n"
11521 "UNI_VEGETA\n"
11522 "UNI_TRUNKS\n"
11523 "UNI_GOKU\n"
11524 "#endif\n"
11525 "\n"
11526 "void main()\n"
11527 "{\n"
11528 " vec4 result = vec4(0, 1, 0, 1);\n"
11529 "\n"
11530 "#if IMAGES\n"
11531 "VERIFICATION else\n"
11532 "#endif\n"
11533 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11534 " {\n"
11535 " result = vec4(1, 0, 0, 1);\n"
11536 " }\n"
11537 "\n"
11538 " tcs_tes_result[gl_InvocationID] = result;\n"
11539 "\n"
11540 " gl_TessLevelOuter[0] = 1.0;\n"
11541 " gl_TessLevelOuter[1] = 1.0;\n"
11542 " gl_TessLevelOuter[2] = 1.0;\n"
11543 " gl_TessLevelOuter[3] = 1.0;\n"
11544 " gl_TessLevelInner[0] = 1.0;\n"
11545 " gl_TessLevelInner[1] = 1.0;\n"
11546 "}\n"
11547 "\n";
11548
11549 static const GLchar *tess_eval_shader_template = "VERSION\n"
11550 "#extension GL_ARB_shader_image_load_store : enable\n"
11551 "\n"
11552 "layout(isolines, point_mode) in;\n"
11553 "\n"
11554 "in vec4 tcs_tes_result[];\n"
11555 "out vec4 tes_gs_result;\n"
11556 "\n"
11557 "#if IMAGES\n"
11558 "UNI_GOKU\n"
11559 "UNI_TRUNKS\n"
11560 "UNI_VEGETA\n"
11561 "#endif\n"
11562 "\n"
11563 "void main()\n"
11564 "{\n"
11565 " vec4 result = vec4(0, 1, 0, 1);\n"
11566 "\n"
11567 "#if IMAGES\n"
11568 "VERIFICATION else\n"
11569 "#endif\n"
11570 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11571 " {\n"
11572 " result = vec4(1, 0, 0, 1);\n"
11573 " }\n"
11574 "\n"
11575 " tes_gs_result = result;\n"
11576 "}\n"
11577 "\n";
11578
11579 static const GLchar *vertex_shader_template = "VERSION\n"
11580 "#extension GL_ARB_shader_image_load_store : enable\n"
11581 "\n"
11582 "out vec4 vs_tcs_result;\n"
11583 "\n"
11584 "#if IMAGES\n"
11585 "UNI_TRUNKS\n"
11586 "UNI_VEGETA\n"
11587 "UNI_GOKU\n"
11588 "#endif\n"
11589 "\n"
11590 "void main()\n"
11591 "{\n"
11592 " vec4 result = vec4(0, 1, 0, 1);\n"
11593 "\n"
11594 "#if IMAGES\n"
11595 "VERIFICATION"
11596 "#endif\n"
11597 "\n"
11598 " vs_tcs_result = result;\n"
11599 "}\n"
11600 "\n";
11601
11602 const GLchar *coordinates_read = 0;
11603 const GLchar *coordinates_write = 0;
11604 const GLchar *image_type = Utils::getImageType(m_test_case);
11605 GLuint n_coordinates = Utils::getNumberOfCoordinates(m_test_case);
11606 const GLchar *shader_template = 0;
11607 const GLchar *tex_coord_type = Utils::getTypeName(Utils::INT, 1 /* n_columns */, n_coordinates);
11608
11609 switch (in_stage)
11610 {
11611 case Utils::COMPUTE_SHADER:
11612 shader_template = compute_shader_template;
11613 break;
11614 case Utils::FRAGMENT_SHADER:
11615 shader_template = fragment_shader_template;
11616 break;
11617 case Utils::GEOMETRY_SHADER:
11618 shader_template = geometry_shader_template;
11619 break;
11620 case Utils::TESS_CTRL_SHADER:
11621 shader_template = tess_ctrl_shader_template;
11622 break;
11623 case Utils::TESS_EVAL_SHADER:
11624 shader_template = tess_eval_shader_template;
11625 break;
11626 case Utils::VERTEX_SHADER:
11627 shader_template = vertex_shader_template;
11628 break;
11629 default:
11630 TCU_FAIL("Invalid enum");
11631 }
11632
11633 switch (n_coordinates)
11634 {
11635 case 1:
11636 coordinates_read = "1";
11637 coordinates_write = "0";
11638 break;
11639 case 2:
11640 coordinates_read = "1, 0";
11641 coordinates_write = "0, 0";
11642 break;
11643 case 3:
11644 coordinates_read = "1, 0, 0";
11645 coordinates_write = "0, 0, 0";
11646 break;
11647 case 4:
11648 coordinates_read = "1, 0, 0, 0";
11649 coordinates_write = "0, 0, 0, 0";
11650 break;
11651 }
11652
11653 out_source.m_parts[0].m_code = shader_template;
11654
11655 size_t position = 0;
11656
11657 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11658 out_source.m_parts[0].m_code);
11659
11660 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11661
11662 position -= strlen(verification_snippet);
11663
11664 Utils::replaceToken("COORDINATES", position, coordinates_read, out_source.m_parts[0].m_code);
11665
11666 Utils::replaceToken("COORDINATES", position, coordinates_write, out_source.m_parts[0].m_code);
11667
11668 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
11669
11670 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11671
11672 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
11673
11674 Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
11675
11676 Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
11677
11678 Utils::replaceAllTokens("TYPE", image_type, out_source.m_parts[0].m_code);
11679 }
11680
11681 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11682 *
11683 * @param program Current program
11684 **/
prepareUniforms(Utils::program & program)11685 void BindingImagesTest::prepareUniforms(Utils::program &program)
11686 {
11687 (void)program;
11688 prepareBuffer(m_goku_buffer, m_goku_data);
11689 prepareBuffer(m_vegeta_buffer, m_vegeta_data);
11690 prepareBuffer(m_trunks_buffer, m_trunks_data);
11691
11692 prepareTexture(m_goku_texture, m_goku_buffer, m_test_case, m_goku_data, 1);
11693 prepareTexture(m_vegeta_texture, m_vegeta_buffer, m_test_case, m_vegeta_data, 2);
11694 prepareTexture(m_trunks_texture, m_trunks_buffer, m_test_case, m_trunks_data, 4);
11695 }
11696
11697 /** Overwrite of releaseResource method, release extra buffers and textures
11698 *
11699 * @param ignored
11700 **/
releaseResource()11701 void BindingImagesTest::releaseResource()
11702 {
11703 m_goku_texture.release();
11704 m_vegeta_texture.release();
11705 m_trunks_texture.release();
11706 if (m_test_case != Utils::TEX_BUFFER)
11707 {
11708 m_goku_buffer.release();
11709 m_vegeta_buffer.release();
11710 m_trunks_buffer.release();
11711 }
11712 }
11713
11714 /** Verify that all images have green texel at [0,0,0,0]
11715 *
11716 * @return true texel is green, false otherwise
11717 **/
verifyAdditionalResults() const11718 bool BindingImagesTest::verifyAdditionalResults() const
11719 {
11720 if (Utils::TEX_BUFFER != m_test_case)
11721 {
11722 return (verifyTexture(m_goku_texture) && verifyTexture(m_vegeta_texture) && verifyTexture(m_trunks_texture));
11723 }
11724 else
11725 {
11726 return (verifyBuffer(m_goku_buffer) && verifyBuffer(m_vegeta_buffer) && verifyBuffer(m_trunks_buffer));
11727 }
11728 }
11729
11730 /** Constructor
11731 *
11732 * @param context Test context
11733 **/
BindingImageSingleTest(deqp::Context & context,Utils::SHADER_STAGES test_stage)11734 BindingImageSingleTest::BindingImageSingleTest(deqp::Context &context, Utils::SHADER_STAGES test_stage)
11735 : BindingImageTest(context, "binding_image_single", "Test verifies single binding of image used in multiple stages")
11736 , m_goku_texture(context)
11737 , m_test_stage(test_stage)
11738 {
11739 std::string name = "binding_image_single_stage_" + std::string(Utils::getShaderStageName(m_test_stage));
11740
11741 TestCase::m_name = name;
11742 }
11743
11744 /** Set up next test case
11745 *
11746 * @param test_case_index Index of next test case
11747 *
11748 * @return false if there is no more test cases, true otherwise
11749 **/
prepareNextTestCase(glw::GLuint test_case_index)11750 bool BindingImageSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
11751 {
11752 if (test_case_index > 0)
11753 {
11754 return false;
11755 }
11756
11757 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
11758 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
11759 << tcu::TestLog::EndMessage;
11760
11761 return true;
11762 }
11763
11764 /** Prepare source for given shader stage
11765 *
11766 * @param in_stage Shader stage, compute shader will use 430
11767 * @param in_use_version_400 Select if 400 or 420 should be used
11768 * @param out_source Prepared shader source instance
11769 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11770 void BindingImageSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11771 Utils::shaderSource &out_source)
11772 {
11773 static const GLchar *uni_goku_with_binding = "layout(binding = 2, rgba8) uniform image2D goku;\n";
11774
11775 static const GLchar *uni_goku_no_binding = "layout(rgba8) uniform image2D goku;\n";
11776
11777 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,1));\n"
11778 "\n"
11779 " imageStore(goku, ivec2(0,0), vec4(0, 1, 0, 1));\n"
11780 "\n"
11781 " if (vec4(1, 0, 0, 0) != goku_color)\n"
11782 " {\n"
11783 " result = vec4(1, 0, 0, 1);\n"
11784 " }\n";
11785
11786 static const GLchar *compute_shader_template =
11787 "VERSION\n"
11788 "#extension GL_ARB_shader_image_load_store : enable\n"
11789 "\n"
11790 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11791 "\n"
11792 "writeonly uniform image2D uni_image;\n"
11793 "\n"
11794 "UNI_GOKU\n"
11795 "\n"
11796 "void main()\n"
11797 "{\n"
11798 " vec4 result = vec4(0, 1, 0, 1);\n"
11799 "\n"
11800 "VERIFICATION"
11801 "\n"
11802 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11803 "}\n"
11804 "\n";
11805
11806 static const GLchar *fragment_shader_template = "VERSION\n"
11807 "#extension GL_ARB_shader_image_load_store : enable\n"
11808 "\n"
11809 "in vec4 gs_fs_result;\n"
11810 "out vec4 fs_out_result;\n"
11811 "\n"
11812 "UNI_GOKU\n"
11813 "\n"
11814 "void main()\n"
11815 "{\n"
11816 " vec4 result = vec4(0, 1, 0, 1);\n"
11817 "\n"
11818 "VERIFICATION"
11819 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11820 " {\n"
11821 " result = vec4(1, 0, 0, 1);\n"
11822 " }\n"
11823 "\n"
11824 " fs_out_result = result;\n"
11825 "}\n"
11826 "\n";
11827
11828 static const GLchar *geometry_shader_template = "VERSION\n"
11829 "#extension GL_ARB_shader_image_load_store : enable\n"
11830 "\n"
11831 "layout(points) in;\n"
11832 "layout(triangle_strip, max_vertices = 4) out;\n"
11833 "\n"
11834 "in vec4 tes_gs_result[];\n"
11835 "out vec4 gs_fs_result;\n"
11836 "\n"
11837 "#if IMAGES\n"
11838 "UNI_GOKU\n"
11839 "#endif\n"
11840 "\n"
11841 "void main()\n"
11842 "{\n"
11843 " vec4 result = vec4(0, 1, 0, 1);\n"
11844 "\n"
11845 "#if IMAGES\n"
11846 "VERIFICATION else\n"
11847 "#endif\n"
11848 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11849 " {\n"
11850 " result = vec4(1, 0, 0, 1);\n"
11851 " }\n"
11852 "\n"
11853 " gs_fs_result = result;\n"
11854 " gl_Position = vec4(-1, -1, 0, 1);\n"
11855 " EmitVertex();\n"
11856 " gs_fs_result = result;\n"
11857 " gl_Position = vec4(-1, 1, 0, 1);\n"
11858 " EmitVertex();\n"
11859 " gs_fs_result = result;\n"
11860 " gl_Position = vec4(1, -1, 0, 1);\n"
11861 " EmitVertex();\n"
11862 " gs_fs_result = result;\n"
11863 " gl_Position = vec4(1, 1, 0, 1);\n"
11864 " EmitVertex();\n"
11865 "}\n"
11866 "\n";
11867
11868 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
11869 "#extension GL_ARB_shader_image_load_store : enable\n"
11870 "\n"
11871 "layout(vertices = 1) out;\n"
11872 "\n"
11873 "in vec4 vs_tcs_result[];\n"
11874 "out vec4 tcs_tes_result[];\n"
11875 "\n"
11876 "#if IMAGES\n"
11877 "UNI_GOKU\n"
11878 "#endif\n"
11879 "\n"
11880 "void main()\n"
11881 "{\n"
11882 " vec4 result = vec4(0, 1, 0, 1);\n"
11883 "\n"
11884 "#if IMAGES\n"
11885 "VERIFICATION else\n"
11886 "#endif\n"
11887 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11888 " {\n"
11889 " result = vec4(1, 0, 0, 1);\n"
11890 " }\n"
11891 "\n"
11892 " tcs_tes_result[gl_InvocationID] = result;\n"
11893 "\n"
11894 " gl_TessLevelOuter[0] = 1.0;\n"
11895 " gl_TessLevelOuter[1] = 1.0;\n"
11896 " gl_TessLevelOuter[2] = 1.0;\n"
11897 " gl_TessLevelOuter[3] = 1.0;\n"
11898 " gl_TessLevelInner[0] = 1.0;\n"
11899 " gl_TessLevelInner[1] = 1.0;\n"
11900 "}\n"
11901 "\n";
11902
11903 static const GLchar *tess_eval_shader_template = "VERSION\n"
11904 "#extension GL_ARB_shader_image_load_store : enable\n"
11905 "\n"
11906 "layout(isolines, point_mode) in;\n"
11907 "\n"
11908 "in vec4 tcs_tes_result[];\n"
11909 "out vec4 tes_gs_result;\n"
11910 "\n"
11911 "#if IMAGES\n"
11912 "UNI_GOKU\n"
11913 "#endif\n"
11914 "\n"
11915 "void main()\n"
11916 "{\n"
11917 " vec4 result = vec4(0, 1, 0, 1);\n"
11918 "\n"
11919 "#if IMAGES\n"
11920 "VERIFICATION else\n"
11921 "#endif\n"
11922 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11923 " {\n"
11924 " result = vec4(1, 0, 0, 1);\n"
11925 " }\n"
11926 "\n"
11927 " tes_gs_result = result;\n"
11928 "}\n"
11929 "\n";
11930
11931 static const GLchar *vertex_shader_template = "VERSION\n"
11932 "#extension GL_ARB_shader_image_load_store : enable\n"
11933 "\n"
11934 "out vec4 vs_tcs_result;\n"
11935 "\n"
11936 "#if IMAGES\n"
11937 "UNI_GOKU\n"
11938 "#endif\n"
11939 "\n"
11940 "void main()\n"
11941 "{\n"
11942 " vec4 result = vec4(0, 1, 0, 1);\n"
11943 "\n"
11944 "#if IMAGES\n"
11945 "VERIFICATION"
11946 "#endif\n"
11947 "\n"
11948 " vs_tcs_result = result;\n"
11949 "}\n"
11950 "\n";
11951
11952 const GLchar *shader_template = 0;
11953 const GLchar *uniform_definition = uni_goku_no_binding;
11954
11955 switch (in_stage)
11956 {
11957 case Utils::COMPUTE_SHADER:
11958 shader_template = compute_shader_template;
11959 uniform_definition = uni_goku_with_binding;
11960 break;
11961 case Utils::FRAGMENT_SHADER:
11962 shader_template = fragment_shader_template;
11963 /* We can't rely on the binding qualifier being present in m_test_stage
11964 * if images are unsupported in that stage.
11965 */
11966 if (maxImageUniforms(m_test_stage) == 0)
11967 uniform_definition = uni_goku_with_binding;
11968 break;
11969 case Utils::GEOMETRY_SHADER:
11970 shader_template = geometry_shader_template;
11971 break;
11972 case Utils::TESS_CTRL_SHADER:
11973 shader_template = tess_ctrl_shader_template;
11974 break;
11975 case Utils::TESS_EVAL_SHADER:
11976 shader_template = tess_eval_shader_template;
11977 break;
11978 case Utils::VERTEX_SHADER:
11979 shader_template = vertex_shader_template;
11980 break;
11981 default:
11982 TCU_FAIL("Invalid enum");
11983 }
11984
11985 if (in_stage == m_test_stage)
11986 {
11987 uniform_definition = uni_goku_with_binding;
11988 }
11989
11990 out_source.m_parts[0].m_code = shader_template;
11991
11992 size_t position = 0;
11993
11994 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11995 out_source.m_parts[0].m_code);
11996
11997 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11998
11999 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12000
12001 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
12002 }
12003
12004 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12005 *
12006 * @param program Current program
12007 **/
prepareUniforms(Utils::program & program)12008 void BindingImageSingleTest::prepareUniforms(Utils::program &program)
12009 {
12010 (void)program;
12011 static const GLuint goku_data = 0x000000ff;
12012
12013 prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, 2 /* unit */);
12014 }
12015
12016 /** Overwrite of releaseResource method, release extra texture
12017 *
12018 * @param ignored
12019 **/
releaseResource()12020 void BindingImageSingleTest::releaseResource()
12021 {
12022 m_goku_texture.release();
12023 }
12024
12025 /** Verify that all images have green texel at [0,0,0,0]
12026 *
12027 * @return true texel is green, false otherwise
12028 **/
verifyAdditionalResults() const12029 bool BindingImageSingleTest::verifyAdditionalResults() const
12030 {
12031 return verifyTexture(m_goku_texture);
12032 }
12033
12034 /** Constructor
12035 *
12036 * @param context Test context
12037 **/
BindingImageArrayTest(deqp::Context & context)12038 BindingImageArrayTest::BindingImageArrayTest(deqp::Context &context)
12039 : BindingImageTest(context, "binding_image_array", "Test verifies binding of image array")
12040 , m_goku_00_texture(context)
12041 , m_goku_01_texture(context)
12042 , m_goku_02_texture(context)
12043 , m_goku_03_texture(context)
12044 , m_goku_04_texture(context)
12045 , m_goku_05_texture(context)
12046 , m_goku_06_texture(context)
12047 {
12048 /* Nothing to be done here */
12049 }
12050
12051 /** Prepare source for given shader stage
12052 *
12053 * @param in_stage Shader stage, compute shader will use 430
12054 * @param in_use_version_400 Select if 400 or 420 should be used
12055 * @param out_source Prepared shader source instance
12056 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12057 void BindingImageArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12058 Utils::shaderSource &out_source)
12059 {
12060 static const GLchar *uni_goku = "layout(binding = 1, rgba8) uniform image2D goku[7];\n";
12061
12062 static const GLchar *verification_snippet = " vec4 color[7];\n"
12063 "\n"
12064 " for (uint i = 0u; i < 7; ++i)\n"
12065 " {\n"
12066 " color[i] = imageLoad(goku[i], ivec2(0,0));\n"
12067 " }\n"
12068 "\n"
12069 " if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
12070 " (vec4(0, 0, 0, 1) != color[1]) ||\n"
12071 " (vec4(0, 0, 1, 0) != color[2]) ||\n"
12072 " (vec4(0, 0, 1, 1) != color[3]) ||\n"
12073 " (vec4(0, 1, 0, 0) != color[4]) ||\n"
12074 " (vec4(0, 1, 0, 1) != color[5]) ||\n"
12075 " (vec4(0, 1, 1, 0) != color[6]) )\n"
12076 " {\n"
12077 " result = vec4(1, 0, 0, 1);\n"
12078 " }\n";
12079
12080 static const GLchar *compute_shader_template =
12081 "VERSION\n"
12082 "#extension GL_ARB_shader_image_load_store : enable\n"
12083 "\n"
12084 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12085 "\n"
12086 "writeonly uniform image2D uni_image;\n"
12087 "\n"
12088 "UNI_GOKU\n"
12089 "\n"
12090 "void main()\n"
12091 "{\n"
12092 " vec4 result = vec4(0, 1, 0, 1);\n"
12093 "\n"
12094 "VERIFICATION"
12095 "\n"
12096 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12097 "}\n"
12098 "\n";
12099
12100 static const GLchar *fragment_shader_template = "VERSION\n"
12101 "#extension GL_ARB_shader_image_load_store : enable\n"
12102 "\n"
12103 "in vec4 gs_fs_result;\n"
12104 "out vec4 fs_out_result;\n"
12105 "\n"
12106 "UNI_GOKU\n"
12107 "\n"
12108 "void main()\n"
12109 "{\n"
12110 " vec4 result = vec4(0, 1, 0, 1);\n"
12111 "\n"
12112 "VERIFICATION"
12113 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12114 " {\n"
12115 " result = vec4(1, 0, 0, 1);\n"
12116 " }\n"
12117 "\n"
12118 " fs_out_result = result;\n"
12119 "}\n"
12120 "\n";
12121
12122 static const GLchar *geometry_shader_template = "VERSION\n"
12123 "#extension GL_ARB_shader_image_load_store : enable\n"
12124 "\n"
12125 "layout(points) in;\n"
12126 "layout(triangle_strip, max_vertices = 4) out;\n"
12127 "\n"
12128 "in vec4 tes_gs_result[];\n"
12129 "out vec4 gs_fs_result;\n"
12130 "\n"
12131 "#if IMAGES\n"
12132 "UNI_GOKU\n"
12133 "#endif\n"
12134 "\n"
12135 "void main()\n"
12136 "{\n"
12137 " vec4 result = vec4(0, 1, 0, 1);\n"
12138 "\n"
12139 "#if IMAGES\n"
12140 "VERIFICATION else\n"
12141 "#endif\n"
12142 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12143 " {\n"
12144 " result = vec4(1, 0, 0, 1);\n"
12145 " }\n"
12146 "\n"
12147 " gs_fs_result = result;\n"
12148 " gl_Position = vec4(-1, -1, 0, 1);\n"
12149 " EmitVertex();\n"
12150 " gs_fs_result = result;\n"
12151 " gl_Position = vec4(-1, 1, 0, 1);\n"
12152 " EmitVertex();\n"
12153 " gs_fs_result = result;\n"
12154 " gl_Position = vec4(1, -1, 0, 1);\n"
12155 " EmitVertex();\n"
12156 " gs_fs_result = result;\n"
12157 " gl_Position = vec4(1, 1, 0, 1);\n"
12158 " EmitVertex();\n"
12159 "}\n"
12160 "\n";
12161
12162 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12163 "#extension GL_ARB_shader_image_load_store : enable\n"
12164 "\n"
12165 "layout(vertices = 1) out;\n"
12166 "\n"
12167 "in vec4 vs_tcs_result[];\n"
12168 "out vec4 tcs_tes_result[];\n"
12169 "\n"
12170 "#if IMAGES\n"
12171 "UNI_GOKU\n"
12172 "#endif\n"
12173 "\n"
12174 "void main()\n"
12175 "{\n"
12176 " vec4 result = vec4(0, 1, 0, 1);\n"
12177 "\n"
12178 "#if IMAGES\n"
12179 "VERIFICATION else\n"
12180 "#endif\n"
12181 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12182 " {\n"
12183 " result = vec4(1, 0, 0, 1);\n"
12184 " }\n"
12185 "\n"
12186 " tcs_tes_result[gl_InvocationID] = result;\n"
12187 "\n"
12188 " gl_TessLevelOuter[0] = 1.0;\n"
12189 " gl_TessLevelOuter[1] = 1.0;\n"
12190 " gl_TessLevelOuter[2] = 1.0;\n"
12191 " gl_TessLevelOuter[3] = 1.0;\n"
12192 " gl_TessLevelInner[0] = 1.0;\n"
12193 " gl_TessLevelInner[1] = 1.0;\n"
12194 "}\n"
12195 "\n";
12196
12197 static const GLchar *tess_eval_shader_template = "VERSION\n"
12198 "#extension GL_ARB_shader_image_load_store : enable\n"
12199 "\n"
12200 "layout(isolines, point_mode) in;\n"
12201 "\n"
12202 "in vec4 tcs_tes_result[];\n"
12203 "out vec4 tes_gs_result;\n"
12204 "\n"
12205 "#if IMAGES\n"
12206 "UNI_GOKU\n"
12207 "#endif\n"
12208 "\n"
12209 "void main()\n"
12210 "{\n"
12211 " vec4 result = vec4(0, 1, 0, 1);\n"
12212 "\n"
12213 "#if IMAGES\n"
12214 "VERIFICATION else\n"
12215 "#endif\n"
12216 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12217 " {\n"
12218 " result = vec4(1, 0, 0, 1);\n"
12219 " }\n"
12220 "\n"
12221 " tes_gs_result = result;\n"
12222 "}\n"
12223 "\n";
12224
12225 static const GLchar *vertex_shader_template = "VERSION\n"
12226 "#extension GL_ARB_shader_image_load_store : enable\n"
12227 "\n"
12228 "out vec4 vs_tcs_result;\n"
12229 "\n"
12230 "#if IMAGES\n"
12231 "UNI_GOKU\n"
12232 "#endif\n"
12233 "\n"
12234 "void main()\n"
12235 "{\n"
12236 " vec4 result = vec4(0, 1, 0, 1);\n"
12237 "\n"
12238 "#if IMAGES\n"
12239 "VERIFICATION"
12240 "#endif\n"
12241 "\n"
12242 " vs_tcs_result = result;\n"
12243 "}\n"
12244 "\n";
12245
12246 const GLchar *shader_template = 0;
12247
12248 switch (in_stage)
12249 {
12250 case Utils::COMPUTE_SHADER:
12251 shader_template = compute_shader_template;
12252 break;
12253 case Utils::FRAGMENT_SHADER:
12254 shader_template = fragment_shader_template;
12255 break;
12256 case Utils::GEOMETRY_SHADER:
12257 shader_template = geometry_shader_template;
12258 break;
12259 case Utils::TESS_CTRL_SHADER:
12260 shader_template = tess_ctrl_shader_template;
12261 break;
12262 case Utils::TESS_EVAL_SHADER:
12263 shader_template = tess_eval_shader_template;
12264 break;
12265 case Utils::VERTEX_SHADER:
12266 shader_template = vertex_shader_template;
12267 break;
12268 default:
12269 TCU_FAIL("Invalid enum");
12270 }
12271
12272 out_source.m_parts[0].m_code = shader_template;
12273
12274 size_t position = 0;
12275
12276 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12277 out_source.m_parts[0].m_code);
12278
12279 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12280
12281 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12282
12283 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12284 }
12285
12286 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12287 *
12288 * @param program Current program
12289 **/
prepareUniforms(Utils::program & program)12290 void BindingImageArrayTest::prepareUniforms(Utils::program &program)
12291 {
12292 static const GLuint goku_data[7] = {
12293 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
12294 };
12295
12296 Utils::texture *textures[7] = {
12297 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12298 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12299 };
12300
12301 for (GLuint i = 0; i < 7; ++i)
12302 {
12303 GLint expected_binding = i + 1;
12304
12305 checkBinding(program, i, expected_binding);
12306
12307 prepareTexture(*textures[i], Utils::buffer(m_context), Utils::TEX_2D, goku_data[i], expected_binding);
12308 }
12309 }
12310
12311 /** Overwrite of releaseResource method, release extra textures
12312 *
12313 * @param ignored
12314 **/
releaseResource()12315 void BindingImageArrayTest::releaseResource()
12316 {
12317 Utils::texture *textures[7] = {
12318 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12319 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12320 };
12321
12322 for (GLuint i = 0; i < 7; ++i)
12323 {
12324 textures[i]->release();
12325 }
12326 }
12327
12328 /** Verifies that API reports correct uniform binding
12329 *
12330 * @param program Program
12331 * @param index Index of array element
12332 * @param expected_binding Expected binding
12333 **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)12334 void BindingImageArrayTest::checkBinding(Utils::program &program, GLuint index, GLint expected_binding)
12335 {
12336 if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
12337 {
12338 TCU_FAIL("Wrong binding reported by API");
12339 }
12340 }
12341
12342 /** Constructor
12343 *
12344 * @param context Test context
12345 **/
BindingImageDefaultTest(deqp::Context & context)12346 BindingImageDefaultTest::BindingImageDefaultTest(deqp::Context &context)
12347 : APITestBase(context, "binding_image_default", "Test verifies default image binding")
12348 {
12349 /* Nothing to be done here */
12350 }
12351
12352 /** Execute API call and verifies results
12353 *
12354 * @return true when results are positive, false otherwise
12355 **/
checkResults(Utils::program & program)12356 bool BindingImageDefaultTest::checkResults(Utils::program &program)
12357 {
12358 return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
12359 }
12360
12361 /** Prepare source for given shader stage
12362 *
12363 * @param in_stage Shader stage, compute shader will use 430
12364 * @param in_use_version_400 Select if 400 or 420 should be used
12365 * @param out_source Prepared shader source instance
12366 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12367 void BindingImageDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12368 Utils::shaderSource &out_source)
12369 {
12370 static const GLchar *uni_goku = "layout(rgba8) uniform image2D goku;\n";
12371
12372 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12373 "\n"
12374 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12375 " {\n"
12376 " result = vec4(1, 0, 0, 1);\n"
12377 " }\n";
12378
12379 static const GLchar *compute_shader_template =
12380 "VERSION\n"
12381 "#extension GL_ARB_shader_image_load_store : enable\n"
12382 "\n"
12383 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12384 "\n"
12385 "writeonly uniform image2D uni_image;\n"
12386 "\n"
12387 "UNI_GOKU\n"
12388 "\n"
12389 "void main()\n"
12390 "{\n"
12391 " vec4 result = vec4(0, 1, 0, 1);\n"
12392 "\n"
12393 "VERIFICATION"
12394 "\n"
12395 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12396 "}\n"
12397 "\n";
12398
12399 static const GLchar *fragment_shader_template = "VERSION\n"
12400 "#extension GL_ARB_shader_image_load_store : enable\n"
12401 "\n"
12402 "in vec4 gs_fs_result;\n"
12403 "out vec4 fs_out_result;\n"
12404 "\n"
12405 "UNI_GOKU\n"
12406 "\n"
12407 "void main()\n"
12408 "{\n"
12409 " vec4 result = vec4(0, 1, 0, 1);\n"
12410 "\n"
12411 "VERIFICATION"
12412 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12413 " {\n"
12414 " result = vec4(1, 0, 0, 1);\n"
12415 " }\n"
12416 "\n"
12417 " fs_out_result = result;\n"
12418 "}\n"
12419 "\n";
12420
12421 static const GLchar *geometry_shader_template = "VERSION\n"
12422 "#extension GL_ARB_shader_image_load_store : enable\n"
12423 "\n"
12424 "layout(points) in;\n"
12425 "layout(triangle_strip, max_vertices = 4) out;\n"
12426 "\n"
12427 "in vec4 tes_gs_result[];\n"
12428 "out vec4 gs_fs_result;\n"
12429 "\n"
12430 "#if IMAGES\n"
12431 "UNI_GOKU\n"
12432 "#endif\n"
12433 "\n"
12434 "void main()\n"
12435 "{\n"
12436 " vec4 result = vec4(0, 1, 0, 1);\n"
12437 "\n"
12438 "#if IMAGES\n"
12439 "VERIFICATION else\n"
12440 "#endif\n"
12441 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12442 " {\n"
12443 " result = vec4(1, 0, 0, 1);\n"
12444 " }\n"
12445 "\n"
12446 " gs_fs_result = result;\n"
12447 " gl_Position = vec4(-1, -1, 0, 1);\n"
12448 " EmitVertex();\n"
12449 " gs_fs_result = result;\n"
12450 " gl_Position = vec4(-1, 1, 0, 1);\n"
12451 " EmitVertex();\n"
12452 " gs_fs_result = result;\n"
12453 " gl_Position = vec4(1, -1, 0, 1);\n"
12454 " EmitVertex();\n"
12455 " gs_fs_result = result;\n"
12456 " gl_Position = vec4(1, 1, 0, 1);\n"
12457 " EmitVertex();\n"
12458 "}\n"
12459 "\n";
12460
12461 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12462 "#extension GL_ARB_shader_image_load_store : enable\n"
12463 "\n"
12464 "layout(vertices = 1) out;\n"
12465 "\n"
12466 "in vec4 vs_tcs_result[];\n"
12467 "out vec4 tcs_tes_result[];\n"
12468 "\n"
12469 "#if IMAGES\n"
12470 "UNI_GOKU\n"
12471 "#endif\n"
12472 "\n"
12473 "void main()\n"
12474 "{\n"
12475 " vec4 result = vec4(0, 1, 0, 1);\n"
12476 "\n"
12477 "#if IMAGES\n"
12478 "VERIFICATION else\n"
12479 "#endif\n"
12480 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12481 " {\n"
12482 " result = vec4(1, 0, 0, 1);\n"
12483 " }\n"
12484 "\n"
12485 " tcs_tes_result[gl_InvocationID] = result;\n"
12486 "\n"
12487 " gl_TessLevelOuter[0] = 1.0;\n"
12488 " gl_TessLevelOuter[1] = 1.0;\n"
12489 " gl_TessLevelOuter[2] = 1.0;\n"
12490 " gl_TessLevelOuter[3] = 1.0;\n"
12491 " gl_TessLevelInner[0] = 1.0;\n"
12492 " gl_TessLevelInner[1] = 1.0;\n"
12493 "}\n"
12494 "\n";
12495
12496 static const GLchar *tess_eval_shader_template = "VERSION\n"
12497 "#extension GL_ARB_shader_image_load_store : enable\n"
12498 "\n"
12499 "layout(isolines, point_mode) in;\n"
12500 "\n"
12501 "in vec4 tcs_tes_result[];\n"
12502 "out vec4 tes_gs_result;\n"
12503 "\n"
12504 "#if IMAGES\n"
12505 "UNI_GOKU\n"
12506 "#endif\n"
12507 "\n"
12508 "void main()\n"
12509 "{\n"
12510 " vec4 result = vec4(0, 1, 0, 1);\n"
12511 "\n"
12512 "#if IMAGES\n"
12513 "VERIFICATION else\n"
12514 "#endif\n"
12515 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12516 " {\n"
12517 " result = vec4(1, 0, 0, 1);\n"
12518 " }\n"
12519 "\n"
12520 " tes_gs_result = result;\n"
12521 "}\n"
12522 "\n";
12523
12524 static const GLchar *vertex_shader_template = "VERSION\n"
12525 "#extension GL_ARB_shader_image_load_store : enable\n"
12526 "\n"
12527 "out vec4 vs_tcs_result;\n"
12528 "\n"
12529 "#if IMAGES\n"
12530 "UNI_GOKU\n"
12531 "#endif\n"
12532 "\n"
12533 "void main()\n"
12534 "{\n"
12535 " vec4 result = vec4(0, 1, 0, 1);\n"
12536 "\n"
12537 "#if IMAGES\n"
12538 "VERIFICATION"
12539 "#endif\n"
12540 "\n"
12541 " vs_tcs_result = result;\n"
12542 "}\n"
12543 "\n";
12544
12545 const GLchar *shader_template = 0;
12546
12547 switch (in_stage)
12548 {
12549 case Utils::COMPUTE_SHADER:
12550 shader_template = compute_shader_template;
12551 break;
12552 case Utils::FRAGMENT_SHADER:
12553 shader_template = fragment_shader_template;
12554 break;
12555 case Utils::GEOMETRY_SHADER:
12556 shader_template = geometry_shader_template;
12557 break;
12558 case Utils::TESS_CTRL_SHADER:
12559 shader_template = tess_ctrl_shader_template;
12560 break;
12561 case Utils::TESS_EVAL_SHADER:
12562 shader_template = tess_eval_shader_template;
12563 break;
12564 case Utils::VERTEX_SHADER:
12565 shader_template = vertex_shader_template;
12566 break;
12567 default:
12568 TCU_FAIL("Invalid enum");
12569 }
12570
12571 out_source.m_parts[0].m_code = shader_template;
12572
12573 size_t position = 0;
12574
12575 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12576 out_source.m_parts[0].m_code);
12577
12578 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12579
12580 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12581
12582 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12583 }
12584
12585 /** Constructor
12586 *
12587 * @param context Test context
12588 **/
BindingImageAPIOverrideTest(deqp::Context & context)12589 BindingImageAPIOverrideTest::BindingImageAPIOverrideTest(deqp::Context &context)
12590 : BindingImageTest(context, "binding_image_api_override", "Verifies that API can override image binding")
12591 , m_goku_texture(context)
12592 {
12593 /* Nothing to be done here */
12594 }
12595
12596 /** Prepare source for given shader stage
12597 *
12598 * @param in_stage Shader stage, compute shader will use 430
12599 * @param in_use_version_400 Select if 400 or 420 should be used
12600 * @param out_source Prepared shader source instance
12601 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12602 void BindingImageAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12603 Utils::shaderSource &out_source)
12604 {
12605 static const GLchar *uni_goku = "layout(binding = 3, rgba8) uniform image2D goku;\n";
12606
12607 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12608 "\n"
12609 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12610 " {\n"
12611 " result = vec4(1, 0, 0, 1);\n"
12612 " }\n";
12613
12614 static const GLchar *compute_shader_template =
12615 "VERSION\n"
12616 "#extension GL_ARB_shader_image_load_store : enable\n"
12617 "\n"
12618 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12619 "\n"
12620 "writeonly uniform image2D uni_image;\n"
12621 "\n"
12622 "UNI_GOKU\n"
12623 "\n"
12624 "void main()\n"
12625 "{\n"
12626 " vec4 result = vec4(0, 1, 0, 1);\n"
12627 "\n"
12628 "VERIFICATION"
12629 "\n"
12630 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12631 "}\n"
12632 "\n";
12633
12634 static const GLchar *fragment_shader_template = "VERSION\n"
12635 "#extension GL_ARB_shader_image_load_store : enable\n"
12636 "\n"
12637 "in vec4 gs_fs_result;\n"
12638 "out vec4 fs_out_result;\n"
12639 "\n"
12640 "UNI_GOKU\n"
12641 "\n"
12642 "void main()\n"
12643 "{\n"
12644 " vec4 result = vec4(0, 1, 0, 1);\n"
12645 "\n"
12646 "VERIFICATION"
12647 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12648 " {\n"
12649 " result = vec4(1, 0, 0, 1);\n"
12650 " }\n"
12651 "\n"
12652 " fs_out_result = result;\n"
12653 "}\n"
12654 "\n";
12655
12656 static const GLchar *geometry_shader_template = "VERSION\n"
12657 "#extension GL_ARB_shader_image_load_store : enable\n"
12658 "\n"
12659 "layout(points) in;\n"
12660 "layout(triangle_strip, max_vertices = 4) out;\n"
12661 "\n"
12662 "in vec4 tes_gs_result[];\n"
12663 "out vec4 gs_fs_result;\n"
12664 "\n"
12665 "#if IMAGES\n"
12666 "UNI_GOKU\n"
12667 "#endif\n"
12668 "\n"
12669 "void main()\n"
12670 "{\n"
12671 " vec4 result = vec4(0, 1, 0, 1);\n"
12672 "\n"
12673 "#if IMAGES\n"
12674 "VERIFICATION else\n"
12675 "#endif\n"
12676 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12677 " {\n"
12678 " result = vec4(1, 0, 0, 1);\n"
12679 " }\n"
12680 "\n"
12681 " gs_fs_result = result;\n"
12682 " gl_Position = vec4(-1, -1, 0, 1);\n"
12683 " EmitVertex();\n"
12684 " gs_fs_result = result;\n"
12685 " gl_Position = vec4(-1, 1, 0, 1);\n"
12686 " EmitVertex();\n"
12687 " gs_fs_result = result;\n"
12688 " gl_Position = vec4(1, -1, 0, 1);\n"
12689 " EmitVertex();\n"
12690 " gs_fs_result = result;\n"
12691 " gl_Position = vec4(1, 1, 0, 1);\n"
12692 " EmitVertex();\n"
12693 "}\n"
12694 "\n";
12695
12696 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12697 "#extension GL_ARB_shader_image_load_store : enable\n"
12698 "\n"
12699 "layout(vertices = 1) out;\n"
12700 "\n"
12701 "in vec4 vs_tcs_result[];\n"
12702 "out vec4 tcs_tes_result[];\n"
12703 "\n"
12704 "#if IMAGES\n"
12705 "UNI_GOKU\n"
12706 "#endif\n"
12707 "\n"
12708 "void main()\n"
12709 "{\n"
12710 " vec4 result = vec4(0, 1, 0, 1);\n"
12711 "\n"
12712 "#if IMAGES\n"
12713 "VERIFICATION else\n"
12714 "#endif\n"
12715 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12716 " {\n"
12717 " result = vec4(1, 0, 0, 1);\n"
12718 " }\n"
12719 "\n"
12720 " tcs_tes_result[gl_InvocationID] = result;\n"
12721 "\n"
12722 " gl_TessLevelOuter[0] = 1.0;\n"
12723 " gl_TessLevelOuter[1] = 1.0;\n"
12724 " gl_TessLevelOuter[2] = 1.0;\n"
12725 " gl_TessLevelOuter[3] = 1.0;\n"
12726 " gl_TessLevelInner[0] = 1.0;\n"
12727 " gl_TessLevelInner[1] = 1.0;\n"
12728 "}\n"
12729 "\n";
12730
12731 static const GLchar *tess_eval_shader_template = "VERSION\n"
12732 "#extension GL_ARB_shader_image_load_store : enable\n"
12733 "\n"
12734 "layout(isolines, point_mode) in;\n"
12735 "\n"
12736 "in vec4 tcs_tes_result[];\n"
12737 "out vec4 tes_gs_result;\n"
12738 "\n"
12739 "#if IMAGES\n"
12740 "UNI_GOKU\n"
12741 "#endif\n"
12742 "\n"
12743 "void main()\n"
12744 "{\n"
12745 " vec4 result = vec4(0, 1, 0, 1);\n"
12746 "\n"
12747 "#if IMAGES\n"
12748 "VERIFICATION else\n"
12749 "#endif\n"
12750 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12751 " {\n"
12752 " result = vec4(1, 0, 0, 1);\n"
12753 " }\n"
12754 "\n"
12755 " tes_gs_result = result;\n"
12756 "}\n"
12757 "\n";
12758
12759 static const GLchar *vertex_shader_template = "VERSION\n"
12760 "#extension GL_ARB_shader_image_load_store : enable\n"
12761 "\n"
12762 "out vec4 vs_tcs_result;\n"
12763 "\n"
12764 "#if IMAGES\n"
12765 "UNI_GOKU\n"
12766 "#endif\n"
12767 "\n"
12768 "void main()\n"
12769 "{\n"
12770 " vec4 result = vec4(0, 1, 0, 1);\n"
12771 "\n"
12772 "#if IMAGES\n"
12773 "VERIFICATION"
12774 "#endif\n"
12775 "\n"
12776 " vs_tcs_result = result;\n"
12777 "}\n"
12778 "\n";
12779
12780 const GLchar *shader_template = 0;
12781
12782 switch (in_stage)
12783 {
12784 case Utils::COMPUTE_SHADER:
12785 shader_template = compute_shader_template;
12786 break;
12787 case Utils::FRAGMENT_SHADER:
12788 shader_template = fragment_shader_template;
12789 break;
12790 case Utils::GEOMETRY_SHADER:
12791 shader_template = geometry_shader_template;
12792 break;
12793 case Utils::TESS_CTRL_SHADER:
12794 shader_template = tess_ctrl_shader_template;
12795 break;
12796 case Utils::TESS_EVAL_SHADER:
12797 shader_template = tess_eval_shader_template;
12798 break;
12799 case Utils::VERTEX_SHADER:
12800 shader_template = vertex_shader_template;
12801 break;
12802 default:
12803 TCU_FAIL("Invalid enum");
12804 }
12805
12806 out_source.m_parts[0].m_code = shader_template;
12807
12808 size_t position = 0;
12809
12810 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12811 out_source.m_parts[0].m_code);
12812
12813 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12814
12815 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12816
12817 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12818 }
12819
12820 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12821 *
12822 * @param program Current program
12823 **/
prepareUniforms(Utils::program & program)12824 void BindingImageAPIOverrideTest::prepareUniforms(Utils::program &program)
12825 {
12826 static const GLuint goku_data = 0x000000ff;
12827 static const GLint new_binding = 7;
12828
12829 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
12830
12831 const GLint uniform_location = program.getUniformLocation("goku");
12832 if (-1 == uniform_location)
12833 {
12834 TCU_FAIL("Uniform is inactive");
12835 }
12836
12837 gl.uniform1i(uniform_location, new_binding);
12838
12839 GLint binding = -1;
12840
12841 gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
12842 GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
12843
12844 if (new_binding != binding)
12845 {
12846 TCU_FAIL("Wrong binding value");
12847 return;
12848 }
12849
12850 prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, new_binding);
12851 }
12852
12853 /** Overwrite of releaseResource method, release extra texture
12854 *
12855 * @param ignored
12856 **/
releaseResource()12857 void BindingImageAPIOverrideTest::releaseResource()
12858 {
12859 m_goku_texture.release();
12860 }
12861
12862 /** Constructor
12863 *
12864 * @param context Test context
12865 **/
BindingImageInvalidTest(deqp::Context & context,TESTCASES test_case_idx)12866 BindingImageInvalidTest::BindingImageInvalidTest(deqp::Context &context, TESTCASES test_case_idx)
12867 : NegativeTestBase(context, "binding_image_invalid", "Test verifies invalid binding values")
12868 , m_test_case_idx(test_case_idx)
12869 {
12870 std::string name = "binding_image_invalid_case_" + std::string(getTestCaseString(m_test_case_idx));
12871
12872 TestCase::m_name = name;
12873 }
12874
getTestCaseString(TESTCASES test_case)12875 const GLchar *BindingImageInvalidTest::getTestCaseString(TESTCASES test_case)
12876 {
12877 const GLchar *name = 0;
12878
12879 switch (test_case)
12880 {
12881 case NEGATIVE_VALUE:
12882 name = "-1";
12883 break;
12884 case VARIABLE_NAME:
12885 name = "goku";
12886 break;
12887 case STD140:
12888 name = "std140";
12889 break;
12890 case MISSING:
12891 name = "";
12892 break;
12893 case TEST_CASES_MAX:
12894 name = "0";
12895 break;
12896 default:
12897 TCU_FAIL("Invalid enum");
12898 }
12899
12900 return name;
12901 }
12902
12903 /** Set up next test case
12904 *
12905 * @param test_case_index Index of next test case
12906 *
12907 * @return false if there is no more test cases, true otherwise
12908 **/
prepareNextTestCase(glw::GLuint test_case_index)12909 bool BindingImageInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
12910 {
12911 if (test_case_index > 0)
12912 {
12913 return false;
12914 }
12915 switch (m_test_case_idx)
12916 {
12917 // case (glw::GLuint)-1:
12918 // m_case = TEST_CASES_MAX;
12919 // break;
12920 case NEGATIVE_VALUE:
12921 case VARIABLE_NAME:
12922 case STD140:
12923 case MISSING:
12924 m_case = (TESTCASES)m_test_case_idx;
12925 break;
12926 default:
12927 return false;
12928 }
12929
12930 return true;
12931 }
12932
12933 /** Prepare source for given shader stage
12934 *
12935 * @param in_stage Shader stage, compute shader will use 430
12936 * @param in_use_version_400 Select if 400 or 420 should be used
12937 * @param out_source Prepared shader source instance
12938 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12939 void BindingImageInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12940 Utils::shaderSource &out_source)
12941 {
12942 static const GLchar *uni_goku = "layout(binding BINDING, rgba8) uniform image2D goku;\n";
12943
12944 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12945 "\n"
12946 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12947 " {\n"
12948 " result = vec4(1, 0, 0, 1);\n"
12949 " }\n";
12950
12951 static const GLchar *compute_shader_template =
12952 "VERSION\n"
12953 "#extension GL_ARB_shader_image_load_store : enable\n"
12954 "\n"
12955 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12956 "\n"
12957 "writeonly uniform image2D uni_image;\n"
12958 "\n"
12959 "UNI_GOKU\n"
12960 "\n"
12961 "void main()\n"
12962 "{\n"
12963 " vec4 result = vec4(0, 1, 0, 1);\n"
12964 "\n"
12965 "VERIFICATION"
12966 "\n"
12967 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12968 "}\n"
12969 "\n";
12970
12971 static const GLchar *fragment_shader_template = "VERSION\n"
12972 "#extension GL_ARB_shader_image_load_store : enable\n"
12973 "\n"
12974 "in vec4 gs_fs_result;\n"
12975 "out vec4 fs_out_result;\n"
12976 "\n"
12977 "UNI_GOKU\n"
12978 "\n"
12979 "void main()\n"
12980 "{\n"
12981 " vec4 result = vec4(0, 1, 0, 1);\n"
12982 "\n"
12983 "VERIFICATION"
12984 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12985 " {\n"
12986 " result = vec4(1, 0, 0, 1);\n"
12987 " }\n"
12988 "\n"
12989 " fs_out_result = result;\n"
12990 "}\n"
12991 "\n";
12992
12993 static const GLchar *geometry_shader_template = "VERSION\n"
12994 "#extension GL_ARB_shader_image_load_store : enable\n"
12995 "\n"
12996 "layout(points) in;\n"
12997 "layout(triangle_strip, max_vertices = 4) out;\n"
12998 "\n"
12999 "in vec4 tes_gs_result[];\n"
13000 "out vec4 gs_fs_result;\n"
13001 "\n"
13002 "UNI_GOKU\n"
13003 "\n"
13004 "void main()\n"
13005 "{\n"
13006 " vec4 result = vec4(0, 1, 0, 1);\n"
13007 "\n"
13008 "VERIFICATION"
13009 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13010 " {\n"
13011 " result = vec4(1, 0, 0, 1);\n"
13012 " }\n"
13013 "\n"
13014 " gs_fs_result = result;\n"
13015 " gl_Position = vec4(-1, -1, 0, 1);\n"
13016 " EmitVertex();\n"
13017 " gs_fs_result = result;\n"
13018 " gl_Position = vec4(-1, 1, 0, 1);\n"
13019 " EmitVertex();\n"
13020 " gs_fs_result = result;\n"
13021 " gl_Position = vec4(1, -1, 0, 1);\n"
13022 " EmitVertex();\n"
13023 " gs_fs_result = result;\n"
13024 " gl_Position = vec4(1, 1, 0, 1);\n"
13025 " EmitVertex();\n"
13026 "}\n"
13027 "\n";
13028
13029 static const GLchar *tess_ctrl_shader_template =
13030 "VERSION\n"
13031 "#extension GL_ARB_shader_image_load_store : enable\n"
13032 "\n"
13033 "layout(vertices = 1) out;\n"
13034 "\n"
13035 "in vec4 vs_tcs_result[];\n"
13036 "out vec4 tcs_tes_result[];\n"
13037 "\n"
13038 "UNI_GOKU\n"
13039 "\n"
13040 "void main()\n"
13041 "{\n"
13042 " vec4 result = vec4(0, 1, 0, 1);\n"
13043 "\n"
13044 "VERIFICATION"
13045 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13046 " {\n"
13047 " result = vec4(1, 0, 0, 1);\n"
13048 " }\n"
13049 "\n"
13050 " tcs_tes_result[gl_InvocationID] = result;\n"
13051 "\n"
13052 " gl_TessLevelOuter[0] = 1.0;\n"
13053 " gl_TessLevelOuter[1] = 1.0;\n"
13054 " gl_TessLevelOuter[2] = 1.0;\n"
13055 " gl_TessLevelOuter[3] = 1.0;\n"
13056 " gl_TessLevelInner[0] = 1.0;\n"
13057 " gl_TessLevelInner[1] = 1.0;\n"
13058 "}\n"
13059 "\n";
13060
13061 static const GLchar *tess_eval_shader_template = "VERSION\n"
13062 "#extension GL_ARB_shader_image_load_store : enable\n"
13063 "\n"
13064 "layout(isolines, point_mode) in;\n"
13065 "\n"
13066 "in vec4 tcs_tes_result[];\n"
13067 "out vec4 tes_gs_result;\n"
13068 "\n"
13069 "UNI_GOKU\n"
13070 "\n"
13071 "void main()\n"
13072 "{\n"
13073 " vec4 result = vec4(0, 1, 0, 1);\n"
13074 "\n"
13075 "VERIFICATION"
13076 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13077 " {\n"
13078 " result = vec4(1, 0, 0, 1);\n"
13079 " }\n"
13080 "\n"
13081 " tes_gs_result = result;\n"
13082 "}\n"
13083 "\n";
13084
13085 static const GLchar *vertex_shader_template = "VERSION\n"
13086 "#extension GL_ARB_shader_image_load_store : enable\n"
13087 "\n"
13088 "out vec4 vs_tcs_result;\n"
13089 "\n"
13090 "UNI_GOKU\n"
13091 "\n"
13092 "void main()\n"
13093 "{\n"
13094 " vec4 result = vec4(0, 1, 0, 1);\n"
13095 "\n"
13096 "VERIFICATION"
13097 "\n"
13098 " vs_tcs_result = result;\n"
13099 "}\n"
13100 "\n";
13101
13102 const GLchar *shader_template = 0;
13103
13104 switch (in_stage)
13105 {
13106 case Utils::COMPUTE_SHADER:
13107 shader_template = compute_shader_template;
13108 break;
13109 case Utils::FRAGMENT_SHADER:
13110 shader_template = fragment_shader_template;
13111 break;
13112 case Utils::GEOMETRY_SHADER:
13113 shader_template = geometry_shader_template;
13114 break;
13115 case Utils::TESS_CTRL_SHADER:
13116 shader_template = tess_ctrl_shader_template;
13117 break;
13118 case Utils::TESS_EVAL_SHADER:
13119 shader_template = tess_eval_shader_template;
13120 break;
13121 case Utils::VERTEX_SHADER:
13122 shader_template = vertex_shader_template;
13123 break;
13124 default:
13125 TCU_FAIL("Invalid enum");
13126 }
13127
13128 out_source.m_parts[0].m_code = shader_template;
13129
13130 size_t position = 0;
13131
13132 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13133 out_source.m_parts[0].m_code);
13134
13135 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13136
13137 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13138
13139 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
13140 }
13141
getCaseString(TESTCASES test_case)13142 const GLchar *BindingImageInvalidTest::getCaseString(TESTCASES test_case)
13143 {
13144 (void)test_case;
13145 const GLchar *binding = 0;
13146
13147 switch (m_case)
13148 {
13149 case NEGATIVE_VALUE:
13150 binding = "= -1";
13151 break;
13152 case VARIABLE_NAME:
13153 binding = "= goku";
13154 break;
13155 case STD140:
13156 binding = "= std140";
13157 break;
13158 case MISSING:
13159 binding = "";
13160 break;
13161 case TEST_CASES_MAX:
13162 binding = "= 0";
13163 break;
13164 default:
13165 TCU_FAIL("Invalid enum");
13166 }
13167
13168 return binding;
13169 }
13170
13171 /* Constants used by InitializerListTest */
13172 const GLfloat InitializerListTest::m_value = 0.0625f;
13173
13174 /** Constructor
13175 *
13176 * @param context Test context
13177 **/
InitializerListTest(deqp::Context & context,testCase test_case)13178 InitializerListTest::InitializerListTest(deqp::Context &context, testCase test_case)
13179 : GLSLTestBase(context, "initializer_list", "Test verifies initializer lists")
13180 , m_current_test_case_index(0)
13181 {
13182 m_test_cases.push_back(test_case);
13183
13184 std::string name = "initializer_list_initializer_" + getInitializerName(test_case.m_initializer) + "_cols_" +
13185 std::to_string(test_case.m_n_cols) + "_rows_" + std::to_string(test_case.m_n_rows);
13186
13187 TestCase::m_name = name;
13188 }
13189
getInitializerName(TESTED_INITIALIZERS initializer)13190 std::string InitializerListTest::getInitializerName(TESTED_INITIALIZERS initializer)
13191 {
13192 switch (initializer)
13193 {
13194 case VECTOR:
13195 return std::string("vector");
13196 case MATRIX:
13197 return std::string("matrix");
13198 case MATRIX_ROWS:
13199 return std::string("matrix_rows");
13200 case STRUCT:
13201 return std::string("struct");
13202 case ARRAY_SCALAR:
13203 return std::string("array_scalar");
13204 case ARRAY_VECTOR_CTR:
13205 return std::string("array_vector_ctr");
13206 case ARRAY_VECTOR_LIST:
13207 return std::string("array_vector_list");
13208 case ARRAY_MATRIX_CTR:
13209 return std::string("array_matrix_ctr");
13210 case ARRAY_MATRIX_LIST:
13211 return std::string("array_matrix_list");
13212 case ARRAY_STRUCT:
13213 return std::string("array_struct");
13214 case NESTED_STRUCT_CTR:
13215 return std::string("nested_struct_ctr");
13216 case NESTED_STRUCT_LIST:
13217 return std::string("nested_struct_list");
13218 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13219 return std::string("nested_struct_arrays_struct_list");
13220 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13221 return std::string("nested_struct_arrays_struct_mix");
13222 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13223 return std::string("nested_array_struct_struct_list");
13224 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13225 return std::string("nested_array_struct_struct_mix");
13226 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13227 return std::string("nested_struct_struct_array_list");
13228 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13229 return std::string("nested_struct_struct_array_mix");
13230 case UNSIZED_ARRAY_SCALAR:
13231 return std::string("unsized_array_scalar");
13232 case UNSIZED_ARRAY_VECTOR:
13233 return std::string("unsized_array_vector");
13234 case UNSIZED_ARRAY_MATRIX:
13235 return std::string("unsized_array_matrix");
13236 case UNSIZED_ARRAY_STRUCT:
13237 return std::string("unsized_array_struct");
13238 default:
13239 return std::string("default");
13240 }
13241 }
13242
13243 /** Set up next test case
13244 *
13245 * @param test_case_index Index of next test case
13246 *
13247 * @return false if there is no more test cases, true otherwise
13248 **/
prepareNextTestCase(glw::GLuint test_case_index)13249 bool InitializerListTest::prepareNextTestCase(glw::GLuint test_case_index)
13250 {
13251 m_current_test_case_index = test_case_index;
13252
13253 if ((glw::GLuint)-1 == test_case_index)
13254 {
13255 m_current_test_case_index = 0;
13256 return true;
13257 }
13258 else if (m_test_cases.size() <= test_case_index)
13259 {
13260 return false;
13261 }
13262
13263 logTestCaseName();
13264
13265 return true;
13266 }
13267
13268 /** Overwritte of prepareUniforms method
13269 *
13270 * @param program Current program
13271 **/
prepareUniforms(Utils::program & program)13272 void InitializerListTest::prepareUniforms(Utils::program &program)
13273 {
13274 static const GLfloat float_data[16] = {m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value,
13275 m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value};
13276
13277 program.uniform("uni_matrix", Utils::FLOAT, 4, 4, float_data);
13278 }
13279
13280 /** Prepare source for given shader stage
13281 *
13282 * @param in_stage Shader stage, compute shader will use 430
13283 * @param in_use_version_400 Select if 400 or 420 should be used
13284 * @param out_source Prepared shader source instance
13285 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13286 void InitializerListTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13287 Utils::shaderSource &out_source)
13288 {
13289 static const GLchar *verification_snippet = " TYPE_NAME variableARRAY_DEFINITION = INITIALIZATION;\n"
13290 "\n"
13291 " float sum = SUM;\n"
13292 "\n"
13293 " if (EXPECTED_VALUE != sum)\n"
13294 " {\n"
13295 " result = vec4(1, 0, 0, 1);\n"
13296 " }\n";
13297
13298 static const GLchar *compute_shader_template =
13299 "VERSION\n"
13300 "\n"
13301 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13302 "\n"
13303 "writeonly uniform image2D uni_image;\n"
13304 " uniform mat4 uni_matrix;\n"
13305 "\n"
13306 "TYPE_DEFINITION\n"
13307 "\n"
13308 "void main()\n"
13309 "{\n"
13310 " vec4 result = vec4(0, 1, 0, 1);\n"
13311 "\n"
13312 "VERIFICATION"
13313 "\n"
13314 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13315 "}\n"
13316 "\n";
13317
13318 static const GLchar *fragment_shader_template = "VERSION\n"
13319 "\n"
13320 "in vec4 gs_fs_result;\n"
13321 "out vec4 fs_out_result;\n"
13322 "\n"
13323 "uniform mat4 uni_matrix;\n"
13324 "\n"
13325 "TYPE_DEFINITION\n"
13326 "\n"
13327 "void main()\n"
13328 "{\n"
13329 " vec4 result = vec4(0, 1, 0, 1);\n"
13330 "\n"
13331 "VERIFICATION"
13332 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13333 " {\n"
13334 " result = vec4(1, 0, 0, 1);\n"
13335 " }\n"
13336 "\n"
13337 " fs_out_result = result;\n"
13338 "}\n"
13339 "\n";
13340
13341 static const GLchar *geometry_shader_template = "VERSION\n"
13342 "\n"
13343 "layout(points) in;\n"
13344 "layout(triangle_strip, max_vertices = 4) out;\n"
13345 "\n"
13346 "in vec4 tes_gs_result[];\n"
13347 "out vec4 gs_fs_result;\n"
13348 "\n"
13349 "uniform mat4 uni_matrix;\n"
13350 "\n"
13351 "TYPE_DEFINITION\n"
13352 "\n"
13353 "void main()\n"
13354 "{\n"
13355 " vec4 result = vec4(0, 1, 0, 1);\n"
13356 "\n"
13357 "VERIFICATION"
13358 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13359 " {\n"
13360 " result = vec4(1, 0, 0, 1);\n"
13361 " }\n"
13362 "\n"
13363 " gs_fs_result = result;\n"
13364 " gl_Position = vec4(-1, -1, 0, 1);\n"
13365 " EmitVertex();\n"
13366 " gs_fs_result = result;\n"
13367 " gl_Position = vec4(-1, 1, 0, 1);\n"
13368 " EmitVertex();\n"
13369 " gs_fs_result = result;\n"
13370 " gl_Position = vec4(1, -1, 0, 1);\n"
13371 " EmitVertex();\n"
13372 " gs_fs_result = result;\n"
13373 " gl_Position = vec4(1, 1, 0, 1);\n"
13374 " EmitVertex();\n"
13375 "}\n"
13376 "\n";
13377
13378 static const GLchar *tess_ctrl_shader_template =
13379 "VERSION\n"
13380 "\n"
13381 "layout(vertices = 1) out;\n"
13382 "\n"
13383 "in vec4 vs_tcs_result[];\n"
13384 "out vec4 tcs_tes_result[];\n"
13385 "\n"
13386 "uniform mat4 uni_matrix;\n"
13387 "\n"
13388 "TYPE_DEFINITION\n"
13389 "\n"
13390 "void main()\n"
13391 "{\n"
13392 " vec4 result = vec4(0, 1, 0, 1);\n"
13393 "\n"
13394 "VERIFICATION"
13395 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13396 " {\n"
13397 " result = vec4(1, 0, 0, 1);\n"
13398 " }\n"
13399 "\n"
13400 " tcs_tes_result[gl_InvocationID] = result;\n"
13401 "\n"
13402 " gl_TessLevelOuter[0] = 1.0;\n"
13403 " gl_TessLevelOuter[1] = 1.0;\n"
13404 " gl_TessLevelOuter[2] = 1.0;\n"
13405 " gl_TessLevelOuter[3] = 1.0;\n"
13406 " gl_TessLevelInner[0] = 1.0;\n"
13407 " gl_TessLevelInner[1] = 1.0;\n"
13408 "}\n"
13409 "\n";
13410
13411 static const GLchar *tess_eval_shader_template = "VERSION\n"
13412 "\n"
13413 "layout(isolines, point_mode) in;\n"
13414 "\n"
13415 "in vec4 tcs_tes_result[];\n"
13416 "out vec4 tes_gs_result;\n"
13417 "\n"
13418 "uniform mat4 uni_matrix;\n"
13419 "\n"
13420 "TYPE_DEFINITION\n"
13421 "\n"
13422 "void main()\n"
13423 "{\n"
13424 " vec4 result = vec4(0, 1, 0, 1);\n"
13425 "\n"
13426 "VERIFICATION"
13427 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13428 " {\n"
13429 " result = vec4(1, 0, 0, 1);\n"
13430 " }\n"
13431 "\n"
13432 " tes_gs_result = result;\n"
13433 "}\n"
13434 "\n";
13435
13436 static const GLchar *vertex_shader_template = "VERSION\n"
13437 "\n"
13438 "out vec4 vs_tcs_result;\n"
13439 "\n"
13440 "uniform mat4 uni_matrix;\n"
13441 "\n"
13442 "TYPE_DEFINITION\n"
13443 "\n"
13444 "void main()\n"
13445 "{\n"
13446 " vec4 result = vec4(0, 1, 0, 1);\n"
13447 "\n"
13448 "VERIFICATION"
13449 "\n"
13450 " vs_tcs_result = result;\n"
13451 "}\n"
13452 "\n";
13453
13454 const std::string &array_definition = getArrayDefinition();
13455 const std::string &expected_value = getExpectedValue();
13456 const std::string &initialization = getInitialization();
13457 const GLchar *shader_template = 0;
13458 const std::string &sum = getSum();
13459 const std::string &type_definition = getTypeDefinition();
13460 const std::string &type_name = getTypeName();
13461
13462 switch (in_stage)
13463 {
13464 case Utils::COMPUTE_SHADER:
13465 shader_template = compute_shader_template;
13466 break;
13467 case Utils::FRAGMENT_SHADER:
13468 shader_template = fragment_shader_template;
13469 break;
13470 case Utils::GEOMETRY_SHADER:
13471 shader_template = geometry_shader_template;
13472 break;
13473 case Utils::TESS_CTRL_SHADER:
13474 shader_template = tess_ctrl_shader_template;
13475 break;
13476 case Utils::TESS_EVAL_SHADER:
13477 shader_template = tess_eval_shader_template;
13478 break;
13479 case Utils::VERTEX_SHADER:
13480 shader_template = vertex_shader_template;
13481 break;
13482 default:
13483 TCU_FAIL("Invalid enum");
13484 }
13485
13486 out_source.m_parts[0].m_code = shader_template;
13487
13488 size_t position = 0;
13489 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13490 out_source.m_parts[0].m_code);
13491
13492 Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
13493
13494 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13495
13496 position -= strlen(verification_snippet);
13497
13498 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
13499
13500 Utils::replaceToken("ARRAY_DEFINITION", position, array_definition.c_str(), out_source.m_parts[0].m_code);
13501
13502 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
13503
13504 Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
13505
13506 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
13507 }
13508
13509 /** Get string representing "[SIZE]" for current test case
13510 *
13511 * @return String
13512 **/
getArrayDefinition()13513 std::string InitializerListTest::getArrayDefinition()
13514 {
13515 const testCase &test_case = m_test_cases[m_current_test_case_index];
13516
13517 std::string array_definition;
13518
13519 switch (test_case.m_initializer)
13520 {
13521 case VECTOR:
13522 case MATRIX:
13523 case MATRIX_ROWS:
13524 case STRUCT:
13525 case NESTED_STRUCT_CTR:
13526 case NESTED_STRUCT_LIST:
13527 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13528 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13529 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13530 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13531 array_definition = "";
13532 break;
13533 case ARRAY_SCALAR:
13534 case ARRAY_VECTOR_CTR:
13535 case ARRAY_VECTOR_LIST:
13536 case ARRAY_MATRIX_CTR:
13537 case ARRAY_MATRIX_LIST:
13538 case ARRAY_STRUCT:
13539 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13540 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13541 array_definition = "[4]";
13542 break;
13543 case UNSIZED_ARRAY_SCALAR:
13544 case UNSIZED_ARRAY_VECTOR:
13545 case UNSIZED_ARRAY_MATRIX:
13546 case UNSIZED_ARRAY_STRUCT:
13547 array_definition = "[]";
13548 break;
13549 default:
13550 TCU_FAIL("Invalid enum");
13551 }
13552
13553 return array_definition;
13554 }
13555
13556 /** Get string representing expected value of sum for current test case
13557 *
13558 * @return String
13559 **/
getExpectedValue()13560 std::string InitializerListTest::getExpectedValue()
13561 {
13562 const testCase &test_case = m_test_cases[m_current_test_case_index];
13563
13564 GLfloat value = 0.0f;
13565
13566 switch (test_case.m_initializer)
13567 {
13568 case VECTOR:
13569 case MATRIX:
13570 case MATRIX_ROWS:
13571 value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows);
13572 break;
13573 case ARRAY_VECTOR_CTR:
13574 case ARRAY_VECTOR_LIST:
13575 case ARRAY_MATRIX_CTR:
13576 case ARRAY_MATRIX_LIST:
13577 case UNSIZED_ARRAY_VECTOR:
13578 case UNSIZED_ARRAY_MATRIX:
13579 value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows) * 4.0f;
13580 break;
13581 case ARRAY_SCALAR:
13582 case UNSIZED_ARRAY_SCALAR:
13583 value = 4.0f;
13584 break;
13585 case STRUCT:
13586 value = 8.0f;
13587 break;
13588 case NESTED_STRUCT_CTR:
13589 case NESTED_STRUCT_LIST:
13590 value = 12.0f;
13591 break;
13592 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13593 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13594 value = 16.0f;
13595 break;
13596 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13597 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13598 value = 28.0f;
13599 break;
13600 case ARRAY_STRUCT:
13601 case UNSIZED_ARRAY_STRUCT:
13602 value = 32.0f;
13603 break;
13604 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13605 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13606 value = 48.0f;
13607 break;
13608 default:
13609 TCU_FAIL("Invalid enum");
13610 }
13611
13612 value *= m_value;
13613
13614 std::string expected_value;
13615 expected_value.resize(64, 0);
13616
13617 sprintf(&expected_value[0], "%f", value);
13618
13619 return expected_value;
13620 }
13621
13622 /** Get string representing initialization list for current test case
13623 *
13624 * @return String
13625 **/
getInitialization()13626 std::string InitializerListTest::getInitialization()
13627 {
13628 const testCase &test_case = m_test_cases[m_current_test_case_index];
13629
13630 std::string initialization;
13631
13632 switch (test_case.m_initializer)
13633 {
13634 case VECTOR:
13635 initialization.append(getVectorInitializer(0 /*column*/, test_case.m_n_rows));
13636
13637 break;
13638
13639 case MATRIX:
13640 initialization = "{ ";
13641 initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13642 initialization.append(" }");
13643
13644 break;
13645
13646 case MATRIX_ROWS:
13647 {
13648 initialization = "{ ";
13649 initialization.append(getVectorArrayCtr(test_case.m_n_cols, test_case.m_n_rows));
13650 initialization.append(" }");
13651 }
13652 break;
13653
13654 case STRUCT:
13655 initialization = "{ ";
13656 initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
13657 initialization.append(", ");
13658 initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
13659 initialization.append(" }");
13660
13661 break;
13662
13663 case ARRAY_SCALAR:
13664 case UNSIZED_ARRAY_SCALAR:
13665 initialization = "{ ";
13666 initialization.append(getVectorValues(0 /* column */, 4 /* size */));
13667 initialization.append(" }");
13668
13669 break;
13670
13671 case ARRAY_VECTOR_LIST:
13672 case UNSIZED_ARRAY_VECTOR:
13673 initialization = "{ ";
13674 initialization.append(getVectorArrayList(4 /* columns */, test_case.m_n_rows));
13675 initialization.append(" }");
13676
13677 break;
13678
13679 case ARRAY_VECTOR_CTR:
13680 initialization = "{ ";
13681 initialization.append(getVectorArrayCtr(4 /* columns */, test_case.m_n_rows));
13682 initialization.append(" }");
13683
13684 break;
13685
13686 case ARRAY_MATRIX_LIST:
13687 case UNSIZED_ARRAY_MATRIX:
13688 initialization = "{ ";
13689
13690 for (GLuint i = 0; i < 4; ++i)
13691 {
13692 initialization.append("{ ");
13693 initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13694 initialization.append(" }");
13695
13696 if (i + 1 < 4)
13697 {
13698 initialization.append(", ");
13699 }
13700 }
13701
13702 initialization.append(" }");
13703
13704 break;
13705
13706 case ARRAY_MATRIX_CTR:
13707 {
13708 const std::string &type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
13709
13710 initialization = "{ ";
13711
13712 for (GLuint i = 0; i < 4; ++i)
13713 {
13714 initialization.append(type_name);
13715 initialization.append("(");
13716 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
13717 {
13718 initialization.append(getVectorValues(col, test_case.m_n_rows));
13719
13720 if (col + 1 < test_case.m_n_cols)
13721 {
13722 initialization.append(", ");
13723 }
13724 }
13725 initialization.append(")");
13726
13727 if (i + 1 < 4)
13728 {
13729 initialization.append(", ");
13730 }
13731 }
13732
13733 initialization.append(" }");
13734 }
13735 break;
13736
13737 case ARRAY_STRUCT:
13738 case UNSIZED_ARRAY_STRUCT:
13739 initialization = "{ ";
13740
13741 for (GLuint i = 0; i < 4; ++i)
13742 {
13743 initialization.append("{ ");
13744 initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
13745 initialization.append(", ");
13746 initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
13747 initialization.append(" }");
13748
13749 if (i + 1 < 4)
13750 {
13751 initialization.append(", ");
13752 }
13753 }
13754
13755 initialization.append(" }");
13756
13757 break;
13758
13759 case NESTED_STRUCT_CTR:
13760 initialization = "StructureWithStructure(BasicStructure(";
13761 initialization.append(getVectorConstructor(0 /* column */, 4));
13762 initialization.append(", ");
13763 initialization.append(getVectorConstructor(2 /* column */, 4));
13764 initialization.append("), ");
13765 initialization.append(getVectorConstructor(3 /* column */, 4));
13766 initialization.append(")");
13767
13768 break;
13769
13770 case NESTED_STRUCT_LIST:
13771 initialization = "{ { ";
13772 initialization.append(getVectorInitializer(0 /* column */, 4));
13773 initialization.append(", ");
13774 initialization.append(getVectorInitializer(2 /* column */, 4));
13775 initialization.append(" }, ");
13776 initialization.append(getVectorInitializer(3 /* column */, 4));
13777 initialization.append(" }");
13778
13779 break;
13780
13781 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13782 initialization = "{ ";
13783 initialization.append(getVectorInitializer(0 /* column */, 4));
13784 initialization.append(", { ");
13785
13786 for (GLuint i = 0; i < 3; ++i)
13787 {
13788 initialization.append("{ ");
13789 initialization.append(getVectorInitializer(2 /* column */, 4));
13790 initialization.append(", ");
13791 initialization.append(getVectorInitializer(3 /* column */, 4));
13792 initialization.append(" }");
13793
13794 if (i + 1 < 3)
13795 {
13796 initialization.append(", ");
13797 }
13798 }
13799
13800 initialization.append(" } }");
13801
13802 break;
13803
13804 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13805 initialization = "{ ";
13806 initialization.append(getVectorConstructor(0 /* column */, 4));
13807 initialization.append(", { ");
13808
13809 for (GLuint i = 0; i < 3; ++i)
13810 {
13811 initialization.append("{ ");
13812 initialization.append(getVectorInitializer(2 /* column */, 4));
13813 initialization.append(", ");
13814 initialization.append(getVectorConstructor(3 /* column */, 4));
13815 initialization.append(" }");
13816
13817 if (i + 1 < 3)
13818 {
13819 initialization.append(", ");
13820 }
13821 }
13822
13823 initialization.append(" } }");
13824
13825 break;
13826
13827 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13828 initialization = "{ ";
13829
13830 for (GLuint i = 0; i < 4; ++i)
13831 {
13832 initialization.append("{ { ");
13833
13834 initialization.append(getVectorInitializer(0 /* column */, 4));
13835 initialization.append(", ");
13836 initialization.append(getVectorInitializer(1 /* column */, 4));
13837
13838 initialization.append(" }, ");
13839
13840 initialization.append(getVectorInitializer(2 /* column */, 4));
13841
13842 initialization.append(" }");
13843
13844 if (i + 1 < 4)
13845 {
13846 initialization.append(", ");
13847 }
13848 }
13849
13850 initialization.append(" }");
13851
13852 break;
13853
13854 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13855 initialization = "{\n";
13856
13857 for (GLuint i = 0; i < 2; ++i)
13858 {
13859 initialization.append("StructureWithStructure(\n");
13860 initialization.append("BasicStructure(");
13861
13862 initialization.append(getVectorConstructor(0 /* column */, 4));
13863 initialization.append(" , ");
13864 initialization.append(getVectorConstructor(1 /* column */, 4));
13865
13866 initialization.append("), ");
13867
13868 initialization.append(getVectorConstructor(2 /* column */, 4));
13869
13870 initialization.append(")");
13871
13872 initialization.append(" , ");
13873
13874 initialization.append("{ { ");
13875
13876 initialization.append(getVectorInitializer(0 /* column */, 4));
13877 initialization.append(", ");
13878 initialization.append(getVectorInitializer(1 /* column */, 4));
13879
13880 initialization.append(" }, ");
13881
13882 initialization.append(getVectorInitializer(2 /* column */, 4));
13883
13884 initialization.append(" }");
13885
13886 if (i + 1 < 2)
13887 {
13888 initialization.append(" , ");
13889 }
13890 }
13891
13892 initialization.append(" }");
13893
13894 break;
13895
13896 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13897 initialization = "{ ";
13898 initialization.append("{ ");
13899 initialization.append(getVectorInitializer(0 /* column */, 4));
13900 initialization.append(", ");
13901 initialization.append("{ ");
13902 initialization.append(getVectorInitializer(1 /* column */, 4));
13903 initialization.append(", ");
13904 initialization.append(getVectorInitializer(2 /* column */, 4));
13905 initialization.append(" }");
13906 initialization.append(" }");
13907 initialization.append(", ");
13908 initialization.append(getVectorInitializer(3 /* column */, 4));
13909 initialization.append(" }");
13910
13911 break;
13912
13913 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13914 initialization = "StructureWithStructureWithArray(";
13915 initialization.append("StructureWithArray(");
13916 initialization.append(getVectorConstructor(0 /* column */, 4));
13917 initialization.append(" , vec4[2]( ");
13918 initialization.append(getVectorConstructor(1 /* column */, 4));
13919 initialization.append(" , ");
13920 initialization.append(getVectorConstructor(2 /* column */, 4));
13921 initialization.append(" )");
13922 initialization.append(")");
13923 initialization.append(" , ");
13924 initialization.append(getVectorConstructor(3 /* column */, 4));
13925 initialization.append(")");
13926
13927 break;
13928
13929 default:
13930 TCU_FAIL("Invalid enum");
13931 }
13932
13933 return initialization;
13934 }
13935
13936 /** Logs description of current test case
13937 *
13938 **/
logTestCaseName()13939 void InitializerListTest::logTestCaseName()
13940 {
13941 const testCase &test_case = m_test_cases[m_current_test_case_index];
13942
13943 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
13944
13945 switch (test_case.m_initializer)
13946 {
13947 case VECTOR:
13948 message << "List. Single vec" << test_case.m_n_rows;
13949 break;
13950 case MATRIX:
13951 message << "List. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
13952 break;
13953 case MATRIX_ROWS:
13954 message << "Ctr. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
13955 break;
13956 case STRUCT:
13957 message << "List. Structure";
13958 break;
13959 case NESTED_STRUCT_CTR:
13960 message << "Ctr. Nested structure";
13961 break;
13962 case NESTED_STRUCT_LIST:
13963 message << "List. Nested structure";
13964 break;
13965 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13966 message << "List. Structure with structure array";
13967 break;
13968 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13969 message << "Mix. Structure with structure array";
13970 break;
13971 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13972 message << "List. Structure with structure with array";
13973 break;
13974 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13975 message << "Mix. Structure with structure with array";
13976 break;
13977 case ARRAY_SCALAR:
13978 message << "List. Array of scalars";
13979 break;
13980 case ARRAY_VECTOR_CTR:
13981 message << "Ctr. Array of vec" << test_case.m_n_rows;
13982 break;
13983 case ARRAY_VECTOR_LIST:
13984 message << "List. Array of vec" << test_case.m_n_rows;
13985 break;
13986 case ARRAY_MATRIX_CTR:
13987 message << "Ctr. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
13988 break;
13989 case ARRAY_MATRIX_LIST:
13990 message << "List. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
13991 break;
13992 case ARRAY_STRUCT:
13993 message << "List. Array of structures";
13994 break;
13995 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13996 message << "List. Array of structures with structures";
13997 break;
13998 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13999 message << "Mix. Array of structures with structures";
14000 break;
14001 case UNSIZED_ARRAY_SCALAR:
14002 message << "List. Unsized array of scalars";
14003 break;
14004 case UNSIZED_ARRAY_VECTOR:
14005 message << "List. Unsized array of vec" << test_case.m_n_rows;
14006 break;
14007 case UNSIZED_ARRAY_MATRIX:
14008 message << "List. Unsized array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14009 break;
14010 case UNSIZED_ARRAY_STRUCT:
14011 message << "List. Unsized array of structures";
14012 break;
14013 default:
14014 TCU_FAIL("Invalid enum");
14015 }
14016
14017 message << tcu::TestLog::EndMessage;
14018 }
14019
14020 /** Get string representing sum for current test case
14021 *
14022 * @return String
14023 **/
getSum()14024 std::string InitializerListTest::getSum()
14025 {
14026 static const GLchar *var = "variable";
14027
14028 const testCase &test_case = m_test_cases[m_current_test_case_index];
14029
14030 std::string sum;
14031
14032 switch (test_case.m_initializer)
14033 {
14034 case VECTOR:
14035 sum = getVectorSum(var, test_case.m_n_rows);
14036
14037 break;
14038
14039 case MATRIX:
14040 case MATRIX_ROWS:
14041 sum = getVectorArraySum("variable[INDEX]", test_case.m_n_cols, test_case.m_n_rows);
14042
14043 break;
14044
14045 case STRUCT:
14046 sum = getVectorSum("variable.member_a", test_case.m_n_rows);
14047 sum.append(" + ");
14048 sum.append(getVectorSum("variable.member_b", test_case.m_n_rows));
14049
14050 break;
14051
14052 case ARRAY_SCALAR:
14053 case UNSIZED_ARRAY_SCALAR:
14054 sum = "variable[0] + variable[1] + variable[2] + variable[3]";
14055
14056 break;
14057
14058 case ARRAY_VECTOR_LIST:
14059 case ARRAY_VECTOR_CTR:
14060 case UNSIZED_ARRAY_VECTOR:
14061 sum = getVectorArraySum("variable[INDEX]", 4 /* columns */, test_case.m_n_rows);
14062
14063 break;
14064
14065 case ARRAY_MATRIX_LIST:
14066 case ARRAY_MATRIX_CTR:
14067 case UNSIZED_ARRAY_MATRIX:
14068 sum.append(getVectorArraySum("variable[0][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14069 sum.append(" + ");
14070 sum.append(getVectorArraySum("variable[1][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14071 sum.append(" + ");
14072 sum.append(getVectorArraySum("variable[2][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14073 sum.append(" + ");
14074 sum.append(getVectorArraySum("variable[3][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14075
14076 break;
14077
14078 case ARRAY_STRUCT:
14079 case UNSIZED_ARRAY_STRUCT:
14080 sum.append(getVectorArraySum("variable[INDEX].member_a", 4, test_case.m_n_rows));
14081 sum.append(" + ");
14082 sum.append(getVectorArraySum("variable[INDEX].member_b", 4, test_case.m_n_rows));
14083
14084 break;
14085
14086 case NESTED_STRUCT_CTR:
14087 case NESTED_STRUCT_LIST:
14088 sum.append(getVectorSum("variable.member_a.member_a", 4));
14089 sum.append(" + ");
14090 sum.append(getVectorSum("variable.member_a.member_b", 4));
14091 sum.append(" + ");
14092 sum.append(getVectorSum("variable.member_b", 4));
14093
14094 break;
14095
14096 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14097 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14098 sum.append(getVectorSum("variable.member_a", 4));
14099 sum.append(" + ");
14100 sum.append(getVectorArraySum("variable.member_b[INDEX].member_a", 3, 4));
14101 sum.append(" + ");
14102 sum.append(getVectorArraySum("variable.member_b[INDEX].member_b", 3, 4));
14103
14104 break;
14105
14106 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14107 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14108 sum.append(getVectorArraySum("variable[INDEX].member_a.member_a", 4, 4));
14109 sum.append(" + ");
14110 sum.append(getVectorArraySum("variable[INDEX].member_a.member_b", 4, 4));
14111 sum.append(" + ");
14112 sum.append(getVectorArraySum("variable[INDEX].member_b", 4, 4));
14113
14114 break;
14115
14116 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14117 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14118 sum.append(getVectorSum("variable.member_a.member_a", 4));
14119 sum.append(" + ");
14120 sum.append(getVectorArraySum("variable.member_a.member_b[INDEX]", 2, 4));
14121 sum.append(" + ");
14122 sum.append(getVectorSum("variable.member_b", 4));
14123
14124 break;
14125
14126 default:
14127 TCU_FAIL("Invalid enum");
14128 }
14129
14130 return sum;
14131 }
14132
14133 /** Get string representing types definition for current test case
14134 *
14135 * @return String
14136 **/
getTypeDefinition()14137 std::string InitializerListTest::getTypeDefinition()
14138 {
14139 const testCase &test_case = m_test_cases[m_current_test_case_index];
14140
14141 static const GLchar *basic_struct = "struct BasicStructure {\n"
14142 " vec4 member_a;\n"
14143 " vec4 member_b;\n"
14144 "};\n";
14145
14146 static const GLchar *struct_with_array = "struct StructureWithArray {\n"
14147 " vec4 member_a;\n"
14148 " vec4 member_b[2];\n"
14149 "};\n";
14150
14151 static const GLchar *struct_with_struct = "struct StructureWithStructure {\n"
14152 " BasicStructure member_a;\n"
14153 " vec4 member_b;\n"
14154 "};\n";
14155
14156 static const GLchar *struct_with_struct_array = "struct StructureWithStructArray {\n"
14157 " vec4 member_a;\n"
14158 " BasicStructure member_b[3];\n"
14159 "};\n";
14160
14161 static const GLchar *struct_with_struct_with_array = "struct StructureWithStructureWithArray {\n"
14162 " StructureWithArray member_a;\n"
14163 " vec4 member_b;\n"
14164 "};\n";
14165
14166 std::string type_definition;
14167
14168 switch (test_case.m_initializer)
14169 {
14170 case VECTOR:
14171 case MATRIX:
14172 case MATRIX_ROWS:
14173 case ARRAY_SCALAR:
14174 case ARRAY_VECTOR_CTR:
14175 case ARRAY_VECTOR_LIST:
14176 case ARRAY_MATRIX_CTR:
14177 case ARRAY_MATRIX_LIST:
14178 case UNSIZED_ARRAY_SCALAR:
14179 case UNSIZED_ARRAY_VECTOR:
14180 case UNSIZED_ARRAY_MATRIX:
14181 type_definition = "";
14182 break;
14183 case STRUCT:
14184 case ARRAY_STRUCT:
14185 case UNSIZED_ARRAY_STRUCT:
14186 type_definition = basic_struct;
14187 break;
14188 case NESTED_STRUCT_CTR:
14189 case NESTED_STRUCT_LIST:
14190 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14191 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14192 type_definition = basic_struct;
14193 type_definition.append(struct_with_struct);
14194 break;
14195 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14196 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14197 type_definition = basic_struct;
14198 type_definition.append(struct_with_struct_array);
14199 break;
14200 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14201 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14202 type_definition = struct_with_array;
14203 type_definition.append(struct_with_struct_with_array);
14204 break;
14205 default:
14206 TCU_FAIL("Invalid enum");
14207 }
14208
14209 return type_definition;
14210 }
14211
14212 /** Get string representing name of variable's type for current test case
14213 *
14214 * @return String
14215 **/
getTypeName()14216 std::string InitializerListTest::getTypeName()
14217 {
14218 const testCase &test_case = m_test_cases[m_current_test_case_index];
14219
14220 static const GLchar *basic_struct = "BasicStructure";
14221
14222 static const GLchar *struct_with_struct = "StructureWithStructure";
14223
14224 static const GLchar *struct_with_struct_array = "StructureWithStructArray";
14225
14226 static const GLchar *struct_with_struct_with_array = "StructureWithStructureWithArray";
14227
14228 std::string type_name;
14229
14230 switch (test_case.m_initializer)
14231 {
14232 case VECTOR:
14233 case MATRIX:
14234 case MATRIX_ROWS:
14235 case ARRAY_VECTOR_CTR:
14236 case ARRAY_VECTOR_LIST:
14237 case ARRAY_MATRIX_CTR:
14238 case ARRAY_MATRIX_LIST:
14239 case UNSIZED_ARRAY_VECTOR:
14240 case UNSIZED_ARRAY_MATRIX:
14241 type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
14242 break;
14243 case STRUCT:
14244 case ARRAY_STRUCT:
14245 case UNSIZED_ARRAY_STRUCT:
14246 type_name = basic_struct;
14247 break;
14248 case NESTED_STRUCT_CTR:
14249 case NESTED_STRUCT_LIST:
14250 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14251 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14252 type_name = struct_with_struct;
14253 break;
14254 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14255 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14256 type_name = struct_with_struct_array;
14257 break;
14258 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14259 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14260 type_name = struct_with_struct_with_array;
14261 break;
14262 case ARRAY_SCALAR:
14263 case UNSIZED_ARRAY_SCALAR:
14264 type_name = "float";
14265 break;
14266 default:
14267 TCU_FAIL("Invalid enum");
14268 }
14269
14270 return type_name;
14271 }
14272
14273 /** Get string representing array of vector constructors
14274 *
14275 * @param columns Number of columns
14276 * @param size Size of vector
14277 *
14278 * @return String
14279 **/
getVectorArrayCtr(GLuint columns,GLuint size)14280 std::string InitializerListTest::getVectorArrayCtr(GLuint columns, GLuint size)
14281 {
14282 std::string result;
14283
14284 for (GLuint col = 0; col < columns; ++col)
14285 {
14286 result.append(getVectorConstructor(col, size));
14287
14288 if (col + 1 < columns)
14289 {
14290 result.append(", ");
14291 }
14292 }
14293
14294 return result;
14295 }
14296
14297 /** Get string representing array of vector initializers
14298 *
14299 * @param columns Number of columns
14300 * @param size Size of vector
14301 *
14302 * @return String
14303 **/
getVectorArrayList(GLuint columns,GLuint size)14304 std::string InitializerListTest::getVectorArrayList(GLuint columns, GLuint size)
14305 {
14306 std::string result;
14307
14308 for (GLuint col = 0; col < columns; ++col)
14309 {
14310 result.append(getVectorInitializer(col, size));
14311
14312 if (col + 1 < columns)
14313 {
14314 result.append(", ");
14315 }
14316 }
14317
14318 return result;
14319 }
14320
14321 /** Get string representing vector constructor
14322 *
14323 * @param column Index of column of uni_matrix to use as data source
14324 * @param size Size of vector
14325 *
14326 * @return String
14327 **/
getVectorConstructor(GLuint column,GLuint size)14328 std::string InitializerListTest::getVectorConstructor(GLuint column, GLuint size)
14329 {
14330 const std::string &type_name = Utils::getTypeName(Utils::FLOAT, 1 /*n_cols*/, size);
14331
14332 std::string result;
14333
14334 result.append(type_name);
14335 result.append("(");
14336 result.append(getVectorValues(column, size));
14337 result.append(")");
14338
14339 return result;
14340 }
14341
14342 /** Get string representing vector initializer
14343 *
14344 * @param column Index of column of uni_matrix to use as data source
14345 * @param size Size of vector
14346 *
14347 * @return String
14348 **/
getVectorInitializer(GLuint column,GLuint size)14349 std::string InitializerListTest::getVectorInitializer(GLuint column, GLuint size)
14350 {
14351 std::string result;
14352
14353 result.append("{");
14354 result.append(getVectorValues(column, size));
14355 result.append("}");
14356
14357 return result;
14358 }
14359
14360 /** Get string representing sum of vector array. Token INDEX in name will be replaced with element index.
14361 *
14362 * @param array_name Name of array variable
14363 * @param columns Number of columns to sum
14364 * @param size Size of vector
14365 *
14366 * @return String
14367 **/
getVectorArraySum(const GLchar * array_name,GLuint columns,GLuint size)14368 std::string InitializerListTest::getVectorArraySum(const GLchar *array_name, GLuint columns, GLuint size)
14369 {
14370 static const GLchar *lut[] = {"0", "1", "2", "3"};
14371
14372 std::string sum;
14373
14374 for (GLuint i = 0; i < columns; ++i)
14375 {
14376 size_t position = 0;
14377 std::string name = array_name;
14378
14379 Utils::replaceToken("INDEX", position, lut[i], name);
14380
14381 sum.append(getVectorSum(name.c_str(), size));
14382
14383 if (i + 1 < columns)
14384 {
14385 sum.append(" + ");
14386 }
14387 }
14388
14389 return sum;
14390 }
14391
14392 /** Get string representing sum of vectors' elements
14393 *
14394 * @param vector_name Name of vector variable
14395 * @param size Size of vector
14396 *
14397 * @return String
14398 **/
getVectorSum(const GLchar * vector_name,GLuint size)14399 std::string InitializerListTest::getVectorSum(const GLchar *vector_name, GLuint size)
14400 {
14401 static const GLchar *lut[] = {
14402 ".x",
14403 ".y",
14404 ".z",
14405 ".w",
14406 };
14407
14408 std::string sum;
14409
14410 for (GLuint i = 0; i < size; ++i)
14411 {
14412 sum.append(vector_name);
14413 sum.append(lut[i]);
14414
14415 if (i + 1 < size)
14416 {
14417 sum.append(" + ");
14418 }
14419 }
14420
14421 return sum;
14422 }
14423
14424 /** Get string representing vector values
14425 *
14426 * @param column Index of column of uni_matrix to use as data source
14427 * @param size Size of vector
14428 *
14429 * @return String
14430 **/
getVectorValues(GLuint column,GLuint size)14431 std::string InitializerListTest::getVectorValues(GLuint column, GLuint size)
14432 {
14433 const GLchar *init_template = 0;
14434 const GLchar *column_index = 0;
14435
14436 switch (size)
14437 {
14438 case 2:
14439 init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y";
14440 break;
14441 case 3:
14442 init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z";
14443 break;
14444 case 4:
14445 init_template = "uni_matrix[COLUMN].z, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z, uni_matrix[COLUMN].w";
14446 break;
14447 }
14448
14449 switch (column)
14450 {
14451 case 0:
14452 column_index = "0";
14453 break;
14454 case 1:
14455 column_index = "1";
14456 break;
14457 case 2:
14458 column_index = "2";
14459 break;
14460 case 3:
14461 column_index = "3";
14462 break;
14463 }
14464
14465 std::string initializer = init_template;
14466
14467 Utils::replaceAllTokens("COLUMN", column_index, initializer);
14468
14469 return initializer;
14470 }
14471
14472 /** Constructor
14473 *
14474 * @param context Test context
14475 **/
InitializerListNegativeTest(deqp::Context & context,TESTED_ERRORS test_case)14476 InitializerListNegativeTest::InitializerListNegativeTest(deqp::Context &context, TESTED_ERRORS test_case)
14477 : NegativeTestBase(context, "initializer_list_negative", "Verifies invalid initializers")
14478 , m_current_test_case_index(0)
14479 {
14480 m_test_cases.push_back(test_case);
14481
14482 std::string name = "initializer_list_negative_error_" + getTestedErrorName(test_case);
14483
14484 TestCase::m_name = name;
14485 }
14486
getTestedErrorName(TESTED_ERRORS error)14487 std::string InitializerListNegativeTest::getTestedErrorName(TESTED_ERRORS error)
14488 {
14489 switch (error)
14490 {
14491 case TYPE_UIVEC_BOOL:
14492 return std::string("type_uivec_bool");
14493 case TYPE_IVEC_BOOL:
14494 return std::string("type_ivec_bool");
14495 case TYPE_VEC_BOOL:
14496 return std::string("type_vec_bool");
14497 case TYPE_MAT_BOOL:
14498 return std::string("type_mat_bool");
14499 case COMPONENTS_VEC_LESS:
14500 return std::string("components_vec_less");
14501 case COMPONENTS_VEC_MORE:
14502 return std::string("components_vec_more");
14503 case COMPONENTS_MAT_LESS_ROWS:
14504 return std::string("components_mat_less_rows");
14505 case COMPONENTS_MAT_LESS_COLUMNS:
14506 return std::string("components_mat_less_columns");
14507 case COMPONENTS_MAT_MORE_ROWS:
14508 return std::string("components_mat_more_rows");
14509 case COMPONENTS_MAT_MORE_COLUMNS:
14510 return std::string("components_mat_more_columns");
14511 case LIST_IN_CONSTRUCTOR:
14512 return std::string("list_in_constructor");
14513 case STRUCT_LAYOUT_MEMBER_TYPE:
14514 return std::string("struct_layout_member_type");
14515 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
14516 return std::string("struct_layout_member_count_more");
14517 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
14518 return std::string("struct_layout_member_count_less");
14519 case STRUCT_LAYOUT_MEMBER_ORDER:
14520 return std::string("struct_layout_member_order");
14521 default:
14522 return std::string("default");
14523 }
14524 }
14525
14526 /** Set up next test case
14527 *
14528 * @param test_case_index Index of next test case
14529 *
14530 * @return false if there is no more test cases, true otherwise
14531 **/
prepareNextTestCase(glw::GLuint test_case_index)14532 bool InitializerListNegativeTest::prepareNextTestCase(glw::GLuint test_case_index)
14533 {
14534 m_current_test_case_index = test_case_index;
14535
14536 if ((glw::GLuint)-1 == test_case_index)
14537 {
14538 m_current_test_case_index = 0;
14539 return true;
14540 }
14541 else if (m_test_cases.size() <= test_case_index)
14542 {
14543 return false;
14544 }
14545
14546 logTestCaseName();
14547
14548 return true;
14549 }
14550
14551 /** Prepare source for given shader stage
14552 *
14553 * @param in_stage Shader stage, compute shader will use 430
14554 * @param in_use_version_400 Select if 400 or 420 should be used
14555 * @param out_source Prepared shader source instance
14556 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)14557 void InitializerListNegativeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
14558 Utils::shaderSource &out_source)
14559 {
14560 static const GLchar *verification_snippet = " TYPE_NAME variable = INITIALIZATION;\n"
14561 "\n"
14562 " float sum = SUM;\n"
14563 "\n"
14564 " if (0 != sum)\n"
14565 " {\n"
14566 " result = vec4(1, 0, 0, 1);\n"
14567 " }\n";
14568
14569 static const GLchar *compute_shader_template =
14570 "VERSION\n"
14571 "\n"
14572 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
14573 "\n"
14574 "writeonly uniform image2D uni_image;\n"
14575 "\n"
14576 "TYPE_DEFINITION\n"
14577 "\n"
14578 "void main()\n"
14579 "{\n"
14580 " vec4 result = vec4(0, 1, 0, 1);\n"
14581 "\n"
14582 "VERIFICATION"
14583 "\n"
14584 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
14585 "}\n"
14586 "\n";
14587
14588 static const GLchar *fragment_shader_template = "VERSION\n"
14589 "\n"
14590 "in vec4 gs_fs_result;\n"
14591 "out vec4 fs_out_result;\n"
14592 "\n"
14593 "TYPE_DEFINITION\n"
14594 "\n"
14595 "void main()\n"
14596 "{\n"
14597 " vec4 result = vec4(0, 1, 0, 1);\n"
14598 "\n"
14599 "VERIFICATION"
14600 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
14601 " {\n"
14602 " result = vec4(1, 0, 0, 1);\n"
14603 " }\n"
14604 "\n"
14605 " fs_out_result = result;\n"
14606 "}\n"
14607 "\n";
14608
14609 static const GLchar *geometry_shader_template = "VERSION\n"
14610 "\n"
14611 "layout(points) in;\n"
14612 "layout(triangle_strip, max_vertices = 4) out;\n"
14613 "\n"
14614 "in vec4 tes_gs_result[];\n"
14615 "out vec4 gs_fs_result;\n"
14616 "\n"
14617 "TYPE_DEFINITION\n"
14618 "\n"
14619 "void main()\n"
14620 "{\n"
14621 " vec4 result = vec4(0, 1, 0, 1);\n"
14622 "\n"
14623 "VERIFICATION"
14624 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
14625 " {\n"
14626 " result = vec4(1, 0, 0, 1);\n"
14627 " }\n"
14628 "\n"
14629 " gs_fs_result = result;\n"
14630 " gl_Position = vec4(-1, -1, 0, 1);\n"
14631 " EmitVertex();\n"
14632 " gs_fs_result = result;\n"
14633 " gl_Position = vec4(-1, 1, 0, 1);\n"
14634 " EmitVertex();\n"
14635 " gs_fs_result = result;\n"
14636 " gl_Position = vec4(1, -1, 0, 1);\n"
14637 " EmitVertex();\n"
14638 " gs_fs_result = result;\n"
14639 " gl_Position = vec4(1, 1, 0, 1);\n"
14640 " EmitVertex();\n"
14641 "}\n"
14642 "\n";
14643
14644 static const GLchar *tess_ctrl_shader_template =
14645 "VERSION\n"
14646 "\n"
14647 "layout(vertices = 1) out;\n"
14648 "\n"
14649 "in vec4 vs_tcs_result[];\n"
14650 "out vec4 tcs_tes_result[];\n"
14651 "\n"
14652 "TYPE_DEFINITION\n"
14653 "\n"
14654 "void main()\n"
14655 "{\n"
14656 " vec4 result = vec4(0, 1, 0, 1);\n"
14657 "\n"
14658 "VERIFICATION"
14659 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
14660 " {\n"
14661 " result = vec4(1, 0, 0, 1);\n"
14662 " }\n"
14663 "\n"
14664 " tcs_tes_result[gl_InvocationID] = result;\n"
14665 "\n"
14666 " gl_TessLevelOuter[0] = 1.0;\n"
14667 " gl_TessLevelOuter[1] = 1.0;\n"
14668 " gl_TessLevelOuter[2] = 1.0;\n"
14669 " gl_TessLevelOuter[3] = 1.0;\n"
14670 " gl_TessLevelInner[0] = 1.0;\n"
14671 " gl_TessLevelInner[1] = 1.0;\n"
14672 "}\n"
14673 "\n";
14674
14675 static const GLchar *tess_eval_shader_template = "VERSION\n"
14676 "\n"
14677 "layout(isolines, point_mode) in;\n"
14678 "\n"
14679 "in vec4 tcs_tes_result[];\n"
14680 "out vec4 tes_gs_result;\n"
14681 "\n"
14682 "TYPE_DEFINITION\n"
14683 "\n"
14684 "void main()\n"
14685 "{\n"
14686 " vec4 result = vec4(0, 1, 0, 1);\n"
14687 "\n"
14688 "VERIFICATION"
14689 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
14690 " {\n"
14691 " result = vec4(1, 0, 0, 1);\n"
14692 " }\n"
14693 "\n"
14694 " tes_gs_result = result;\n"
14695 "}\n"
14696 "\n";
14697
14698 static const GLchar *vertex_shader_template = "VERSION\n"
14699 "\n"
14700 "out vec4 vs_tcs_result;\n"
14701 "\n"
14702 "TYPE_DEFINITION\n"
14703 "\n"
14704 "void main()\n"
14705 "{\n"
14706 " vec4 result = vec4(0, 1, 0, 1);\n"
14707 "\n"
14708 "VERIFICATION"
14709 "\n"
14710 " vs_tcs_result = result;\n"
14711 "}\n"
14712 "\n";
14713
14714 const std::string &initialization = getInitialization();
14715 const GLchar *shader_template = 0;
14716 const std::string &sum = getSum();
14717 const std::string &type_definition = getTypeDefinition();
14718 const std::string &type_name = getTypeName();
14719
14720 switch (in_stage)
14721 {
14722 case Utils::COMPUTE_SHADER:
14723 shader_template = compute_shader_template;
14724 break;
14725 case Utils::FRAGMENT_SHADER:
14726 shader_template = fragment_shader_template;
14727 break;
14728 case Utils::GEOMETRY_SHADER:
14729 shader_template = geometry_shader_template;
14730 break;
14731 case Utils::TESS_CTRL_SHADER:
14732 shader_template = tess_ctrl_shader_template;
14733 break;
14734 case Utils::TESS_EVAL_SHADER:
14735 shader_template = tess_eval_shader_template;
14736 break;
14737 case Utils::VERTEX_SHADER:
14738 shader_template = vertex_shader_template;
14739 break;
14740 default:
14741 TCU_FAIL("Invalid enum");
14742 }
14743
14744 out_source.m_parts[0].m_code = shader_template;
14745
14746 size_t position = 0;
14747 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
14748 out_source.m_parts[0].m_code);
14749
14750 Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
14751
14752 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
14753
14754 position -= strlen(verification_snippet);
14755
14756 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
14757
14758 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
14759
14760 Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
14761 }
14762
14763 /** Get string representing initialization list for current test case
14764 *
14765 * @return String
14766 **/
getInitialization()14767 std::string InitializerListNegativeTest::getInitialization()
14768 {
14769 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
14770
14771 std::string initialization;
14772
14773 switch (error)
14774 {
14775 case TYPE_UIVEC_BOOL:
14776 initialization = "{ true, 0, 1, 2 }";
14777
14778 break;
14779
14780 case TYPE_IVEC_BOOL:
14781 initialization = "{ true, 0, -1, 2 }";
14782
14783 break;
14784
14785 case TYPE_VEC_BOOL:
14786 initialization = "{ true, 0.125, 0.25, 0.375 }";
14787
14788 break;
14789
14790 case TYPE_MAT_BOOL:
14791 initialization = "{ {false, 0, 1, 1}, {0, 1, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
14792
14793 break;
14794
14795 case COMPONENTS_VEC_LESS:
14796 case COMPONENTS_VEC_MORE:
14797 initialization = "{ 0, 0.25, 0.375 }";
14798
14799 break;
14800
14801 case COMPONENTS_MAT_LESS_ROWS:
14802 initialization = "{ {0, 0, 1, 1}, {0, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
14803
14804 break;
14805
14806 case COMPONENTS_MAT_MORE_ROWS:
14807 initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1, 0}, {1, 0, 1} }";
14808
14809 break;
14810
14811 case COMPONENTS_MAT_LESS_COLUMNS:
14812 initialization = "{ {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
14813
14814 break;
14815
14816 case COMPONENTS_MAT_MORE_COLUMNS:
14817 initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1}, {1, 0, 1} }";
14818
14819 break;
14820
14821 case LIST_IN_CONSTRUCTOR:
14822 initialization = "Struct( { vec4(0, 1, 0, 1), vec3(0, 1, 0) }, vec4(1, 0, 1, 0) )";
14823
14824 break;
14825
14826 case STRUCT_LAYOUT_MEMBER_TYPE:
14827 initialization = "{ { {0, 1, 0, 1}, vec4(0, 1, 0, 1) }, vec4(1, 0, 1, 0) }";
14828
14829 break;
14830
14831 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
14832 initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } , vec4(1, 0, 1, 0), vec4(1, 0, 1, 0) }";
14833
14834 break;
14835
14836 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
14837 initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } }";
14838
14839 break;
14840
14841 case STRUCT_LAYOUT_MEMBER_ORDER:
14842 initialization = "{ vec4(1, 0, 1, 0), { vec3(0, 1, 0) , {0, 1, 0, 1} } }";
14843
14844 break;
14845
14846 default:
14847 TCU_FAIL("Invalid enum");
14848 }
14849
14850 return initialization;
14851 }
14852
14853 /** Logs description of current test case
14854 *
14855 **/
logTestCaseName()14856 void InitializerListNegativeTest::logTestCaseName()
14857 {
14858 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
14859
14860 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
14861
14862 switch (error)
14863 {
14864 case TYPE_UIVEC_BOOL:
14865 message << "Wrong type in uvec initializer list";
14866 break;
14867 case TYPE_IVEC_BOOL:
14868 message << "Wrong type in ivec initializer list";
14869 break;
14870 case TYPE_VEC_BOOL:
14871 message << "Wrong type in vec initializer list";
14872 break;
14873 case TYPE_MAT_BOOL:
14874 message << "Wrong type in mat initializer list";
14875 break;
14876 case COMPONENTS_VEC_LESS:
14877 message << "Wrong number of componenets in vec initialize list - less";
14878 break;
14879 case COMPONENTS_VEC_MORE:
14880 message << "Wrong number of componenets in vec initialize list - more";
14881 break;
14882 case COMPONENTS_MAT_LESS_ROWS:
14883 message << "Wrong number of componenets in mat initialize list - less rows";
14884 break;
14885 case COMPONENTS_MAT_LESS_COLUMNS:
14886 message << "Wrong number of componenets in mat initialize list - less columns";
14887 break;
14888 case COMPONENTS_MAT_MORE_ROWS:
14889 message << "Wrong number of componenets in mat initialize list - more rows";
14890 break;
14891 case COMPONENTS_MAT_MORE_COLUMNS:
14892 message << "Wrong number of componenets in mat initialize list - more columns";
14893 break;
14894 case LIST_IN_CONSTRUCTOR:
14895 message << "Initializer list in constructor";
14896 break;
14897 case STRUCT_LAYOUT_MEMBER_TYPE:
14898 message << "Wrong type of structure member";
14899 break;
14900 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
14901 message << "Wrong number of structure members - more";
14902 break;
14903 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
14904 message << "Wrong number of structure members - less";
14905 break;
14906 case STRUCT_LAYOUT_MEMBER_ORDER:
14907 message << "Wrong order of structure members";
14908 break;
14909 default:
14910 TCU_FAIL("Invalid enum");
14911 }
14912
14913 message << tcu::TestLog::EndMessage;
14914 }
14915
14916 /** Get string representing sum for current test case
14917 *
14918 * @return String
14919 **/
getSum()14920 std::string InitializerListNegativeTest::getSum()
14921 {
14922 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
14923
14924 std::string sum;
14925
14926 switch (error)
14927 {
14928 case TYPE_UIVEC_BOOL:
14929 case TYPE_IVEC_BOOL:
14930 case TYPE_VEC_BOOL:
14931 case COMPONENTS_VEC_LESS:
14932 sum = "variable.x + variable.y + variable.z + variable.w";
14933 break;
14934 case TYPE_MAT_BOOL:
14935 case COMPONENTS_MAT_LESS_ROWS:
14936 case COMPONENTS_MAT_LESS_COLUMNS:
14937 sum = "variable[0].x + variable[0].y + variable[0].z + variable[0].w + "
14938 "variable[1].x + variable[1].y + variable[1].z + variable[1].w + "
14939 "variable[2].x + variable[2].y + variable[2].z + variable[2].w + "
14940 "variable[3].x + variable[3].y + variable[3].z + variable[3].w";
14941 break;
14942 case COMPONENTS_VEC_MORE:
14943 sum = "variable.x + variable.y + variable.z";
14944 break;
14945 case COMPONENTS_MAT_MORE_ROWS:
14946 case COMPONENTS_MAT_MORE_COLUMNS:
14947 sum = "variable[0].x + variable[0].y + variable[0].z"
14948 "variable[1].x + variable[1].y + variable[1].z"
14949 "variable[2].x + variable[2].y + variable[2].z";
14950 break;
14951 case LIST_IN_CONSTRUCTOR:
14952 case STRUCT_LAYOUT_MEMBER_TYPE:
14953 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
14954 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
14955 case STRUCT_LAYOUT_MEMBER_ORDER:
14956 sum = "variable.member_a.member_a.x + variable.member_a.member_a.y + variable.member_a.member_a.z + "
14957 "variable.member_a.member_a.w + "
14958 "variable.member_a.member_b.x + variable.member_a.member_b.y + variable.member_a.member_b.z + "
14959 "variable.member_b.x + variable.member_b.y + variable.member_b.z + variable.member_b.w";
14960 break;
14961 default:
14962 TCU_FAIL("Invalid enum");
14963 }
14964
14965 return sum;
14966 }
14967
14968 /** Get string representing types definition for current test case
14969 *
14970 * @return String
14971 **/
getTypeDefinition()14972 std::string InitializerListNegativeTest::getTypeDefinition()
14973 {
14974 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
14975
14976 static const GLchar *struct_def = "struct BasicStructure {\n"
14977 " vec4 member_a;\n"
14978 " vec3 member_b;\n"
14979 "};\n"
14980 "\n"
14981 "struct StructureWithStructure {\n"
14982 " BasicStructure member_a;\n"
14983 " vec4 member_b;\n"
14984 "};\n";
14985
14986 std::string type_definition;
14987
14988 switch (error)
14989 {
14990 case TYPE_UIVEC_BOOL:
14991 case TYPE_IVEC_BOOL:
14992 case TYPE_VEC_BOOL:
14993 case TYPE_MAT_BOOL:
14994 case COMPONENTS_VEC_LESS:
14995 case COMPONENTS_VEC_MORE:
14996 case COMPONENTS_MAT_LESS_ROWS:
14997 case COMPONENTS_MAT_LESS_COLUMNS:
14998 case COMPONENTS_MAT_MORE_ROWS:
14999 case COMPONENTS_MAT_MORE_COLUMNS:
15000 type_definition = "";
15001 break;
15002 case LIST_IN_CONSTRUCTOR:
15003 case STRUCT_LAYOUT_MEMBER_TYPE:
15004 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15005 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15006 case STRUCT_LAYOUT_MEMBER_ORDER:
15007 type_definition = struct_def;
15008 break;
15009 default:
15010 TCU_FAIL("Invalid enum");
15011 }
15012
15013 return type_definition;
15014 }
15015
15016 /** Get string representing name of variable's type for current test case
15017 *
15018 * @return String
15019 **/
getTypeName()15020 std::string InitializerListNegativeTest::getTypeName()
15021 {
15022 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
15023
15024 static const GLchar *struct_with_struct = "StructureWithStructure";
15025
15026 std::string type_name;
15027
15028 switch (error)
15029 {
15030 case TYPE_UIVEC_BOOL:
15031 type_name = "uvec4";
15032 break;
15033 case TYPE_IVEC_BOOL:
15034 type_name = "ivec4";
15035 break;
15036 case TYPE_VEC_BOOL:
15037 case COMPONENTS_VEC_LESS:
15038 type_name = "vec4";
15039 break;
15040 case COMPONENTS_VEC_MORE:
15041 type_name = "vec2";
15042 break;
15043 case TYPE_MAT_BOOL:
15044 case COMPONENTS_MAT_LESS_ROWS:
15045 case COMPONENTS_MAT_LESS_COLUMNS:
15046 type_name = "mat4";
15047 break;
15048 case COMPONENTS_MAT_MORE_ROWS:
15049 case COMPONENTS_MAT_MORE_COLUMNS:
15050 type_name = "mat3";
15051 break;
15052 case LIST_IN_CONSTRUCTOR:
15053 case STRUCT_LAYOUT_MEMBER_TYPE:
15054 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15055 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15056 case STRUCT_LAYOUT_MEMBER_ORDER:
15057 type_name = struct_with_struct;
15058 break;
15059 default:
15060 TCU_FAIL("Invalid enum");
15061 }
15062
15063 return type_name;
15064 }
15065
15066 /** Constructor
15067 *
15068 * @param context Test context
15069 **/
LengthOfVectorAndMatrixTest(deqp::Context & context,testCase test_case)15070 LengthOfVectorAndMatrixTest::LengthOfVectorAndMatrixTest(deqp::Context &context, testCase test_case)
15071 : GLSLTestBase(context, "length_of_vector_and_matrix", "Test verifies .length() for vectors and matrices")
15072 {
15073 m_test_cases.push_back(test_case);
15074
15075 std::string name = "length_of_vector_and_matrix_type_" + getTypeName(test_case.m_type) + "_cols_" +
15076 std::to_string(test_case.m_n_cols) + "_rows_" + std::to_string(test_case.m_n_rows);
15077
15078 TestCase::m_name = name;
15079 }
15080
getTypeName(Utils::TYPES type)15081 std::string LengthOfVectorAndMatrixTest::getTypeName(Utils::TYPES type)
15082 {
15083 switch (type)
15084 {
15085 case Utils::TYPES::FLOAT:
15086 return std::string("float");
15087 case Utils::TYPES::DOUBLE:
15088 return std::string("double");
15089 case Utils::TYPES::INT:
15090 return std::string("int");
15091 case Utils::TYPES::UINT:
15092 return std::string("uint");
15093 default:
15094 return std::string("default");
15095 }
15096 }
15097
15098 /** Set up next test case
15099 *
15100 * @param test_case_index Index of next test case
15101 *
15102 * @return false if there is no more test cases, true otherwise
15103 **/
prepareNextTestCase(glw::GLuint test_case_index)15104 bool LengthOfVectorAndMatrixTest::prepareNextTestCase(glw::GLuint test_case_index)
15105 {
15106 m_current_test_case_index = test_case_index;
15107
15108 if ((glw::GLuint)-1 == test_case_index)
15109 {
15110 m_current_test_case_index = 0;
15111 return true;
15112 }
15113 else if (m_test_cases.size() <= test_case_index)
15114 {
15115 return false;
15116 }
15117
15118 const testCase &test_case = m_test_cases[m_current_test_case_index];
15119
15120 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested type: "
15121 << Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows)
15122 << tcu::TestLog::EndMessage;
15123
15124 return true;
15125 }
15126
15127 /** Prepare source for given shader stage
15128 *
15129 * @param in_stage Shader stage, compute shader will use 430
15130 * @param in_use_version_400 Select if 400 or 420 should be used
15131 * @param out_source Prepared shader source instance
15132 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15133 void LengthOfVectorAndMatrixTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15134 Utils::shaderSource &out_source)
15135 {
15136 if (Utils::COMPUTE_SHADER == in_stage)
15137 {
15138 m_is_compute_program = true;
15139 prepareComputeShaderSource(out_source);
15140 }
15141 else
15142 {
15143 m_is_compute_program = false;
15144 prepareDrawShaderSource(in_stage, in_use_version_400, out_source);
15145 }
15146 }
15147
15148 /** Overwritte of prepareUniforms method
15149 *
15150 * @param program Current program
15151 **/
prepareUniforms(Utils::program & program)15152 void LengthOfVectorAndMatrixTest::prepareUniforms(Utils::program &program)
15153 {
15154 static const GLfloat float_value = 0.125;
15155 static const GLint int_value = -1;
15156 static const GLuint uint_value = 1;
15157
15158 static const GLfloat float_data[16] = {float_value, float_value, float_value, float_value, float_value, float_value,
15159 float_value, float_value, float_value, float_value, float_value, float_value,
15160 float_value, float_value, float_value, float_value};
15161
15162 static const GLint int_data[4] = {int_value, int_value, int_value, int_value};
15163
15164 static const GLuint uint_data[4] = {uint_value, uint_value, uint_value, uint_value};
15165
15166 if (false == m_is_compute_program)
15167 {
15168 return;
15169 }
15170
15171 const testCase &test_case = m_test_cases[m_current_test_case_index];
15172
15173 switch (test_case.m_type)
15174 {
15175 case Utils::FLOAT:
15176 program.uniform("uni_variable", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
15177 break;
15178 case Utils::INT:
15179 program.uniform("uni_variable", Utils::INT, 1 /* columns */, test_case.m_n_rows, int_data);
15180 break;
15181 case Utils::UINT:
15182 program.uniform("uni_variable", Utils::UINT, 1 /* columns */, test_case.m_n_rows, uint_data);
15183 break;
15184 default:
15185 TCU_FAIL("Invalid enum");
15186 }
15187 }
15188
15189 /** Prepare vertex buffer
15190 *
15191 * @param program Program object
15192 * @param buffer Vertex buffer
15193 * @param vao Vertex array object
15194 *
15195 * @return 0
15196 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)15197 void LengthOfVectorAndMatrixTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
15198 Utils::vertexArray &vao)
15199 {
15200 static const GLfloat float_value = 0.125f;
15201 static const GLint int_value = -1;
15202 static const GLuint uint_value = 1;
15203
15204 static const GLfloat float_data[16] = {float_value, float_value, float_value, float_value, float_value, float_value,
15205 float_value, float_value, float_value, float_value, float_value, float_value,
15206 float_value, float_value, float_value, float_value};
15207
15208 static const GLint int_data[4] = {int_value, int_value, int_value, int_value};
15209
15210 static const GLuint uint_data[4] = {uint_value, uint_value, uint_value, uint_value};
15211
15212 const testCase &test_case = m_test_cases[m_current_test_case_index];
15213
15214 std::string variable_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "variable");
15215 GLint variable_loc = program.getAttribLocation(variable_name.c_str());
15216
15217 if (-1 == variable_loc)
15218 {
15219 TCU_FAIL("Vertex attribute location is invalid");
15220 }
15221
15222 vao.generate();
15223 vao.bind();
15224
15225 buffer.generate(GL_ARRAY_BUFFER);
15226
15227 GLvoid *data_ptr = 0;
15228 GLsizeiptr data_size = 0;
15229
15230 switch (test_case.m_type)
15231 {
15232 case Utils::FLOAT:
15233 data_ptr = (GLvoid *)float_data;
15234 data_size = sizeof(float_data);
15235 break;
15236 case Utils::INT:
15237 data_ptr = (GLvoid *)int_data;
15238 data_size = sizeof(int_data);
15239 break;
15240 case Utils::UINT:
15241 data_ptr = (GLvoid *)uint_data;
15242 data_size = sizeof(uint_data);
15243 break;
15244 default:
15245 TCU_FAIL("Invalid enum");
15246 }
15247
15248 buffer.update(data_size, data_ptr, GL_STATIC_DRAW);
15249
15250 /* GL entry points */
15251 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
15252
15253 /* Set up vao */
15254 switch (test_case.m_type)
15255 {
15256 case Utils::FLOAT:
15257 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15258 {
15259 const GLuint index = variable_loc + col;
15260 const GLint size = test_case.m_n_rows;
15261 const GLvoid *offset = (const GLvoid *)(test_case.m_n_rows * sizeof(GLfloat) * col);
15262
15263 gl.vertexAttribPointer(index, size, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0, offset);
15264 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
15265 }
15266 break;
15267 case Utils::INT:
15268 gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_INT /* type */, 0 /* stride */,
15269 0 /* offset */);
15270 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15271 break;
15272 case Utils::UINT:
15273 gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_UNSIGNED_INT /* type */, 0 /* stride */,
15274 0 /* offset */);
15275 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15276 break;
15277 default:
15278 DE_ASSERT(0);
15279 break;
15280 }
15281
15282 /* Enable attribute */
15283 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15284 {
15285 gl.enableVertexAttribArray(variable_loc + col);
15286 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
15287 }
15288 }
15289
15290 /** Get string representing value that should be placed at token EXPECTED_VALUE
15291 *
15292 * @param in_stage Shader stage
15293 *
15294 * @return String with value
15295 **/
getExpectedValue(Utils::SHADER_STAGES in_stage)15296 std::string LengthOfVectorAndMatrixTest::getExpectedValue(Utils::SHADER_STAGES in_stage)
15297 {
15298 const testCase &test_case = m_test_cases[m_current_test_case_index];
15299
15300 GLuint count = 0;
15301
15302 switch (in_stage)
15303 {
15304 case Utils::FRAGMENT_SHADER:
15305 count = 3;
15306 break;
15307 case Utils::COMPUTE_SHADER:
15308 count = 2;
15309 break;
15310 default:
15311 count = 4;
15312 }
15313
15314 if (1 == test_case.m_n_cols)
15315 {
15316 count *= test_case.m_n_rows;
15317 }
15318 else
15319 {
15320 count *= test_case.m_n_cols;
15321 }
15322
15323 std::string expected_value;
15324 expected_value.resize(64, 0);
15325
15326 switch (test_case.m_type)
15327 {
15328 case Utils::FLOAT:
15329 {
15330 GLfloat value = 0.125f * (GLfloat)count;
15331 sprintf(&expected_value[0], "%f", value);
15332 }
15333 break;
15334 case Utils::INT:
15335 {
15336 GLint value = -1 * (GLint)count;
15337 sprintf(&expected_value[0], "%d", value);
15338 }
15339 break;
15340 case Utils::UINT:
15341 {
15342 GLuint value = 1 * (GLuint)count;
15343 sprintf(&expected_value[0], "%d", value);
15344 }
15345 break;
15346 default:
15347 DE_ASSERT(0);
15348 break;
15349 }
15350
15351 return expected_value;
15352 }
15353
15354 /** Get string reresenting initialization of local variables for current test case
15355 *
15356 * @return String with initialization
15357 **/
getInitialization()15358 std::string LengthOfVectorAndMatrixTest::getInitialization()
15359 {
15360 const testCase &test_case = m_test_cases[m_current_test_case_index];
15361
15362 std::string initialization;
15363
15364 if (1 == test_case.m_n_cols)
15365 {
15366 initialization = getVectorInitializer(test_case.m_type, test_case.m_n_rows);
15367 }
15368 else
15369 {
15370 initialization = getMatrixInitializer(test_case.m_n_cols, test_case.m_n_rows);
15371 }
15372
15373 return initialization;
15374 }
15375
15376 /** Get string reresenting initialization of local matrix variables
15377 *
15378 * @param n_cols Number of columns
15379 * @param n_rows Number of rows
15380 *
15381 * @return String with initialization
15382 **/
getMatrixInitializer(GLuint n_cols,GLuint n_rows)15383 std::string LengthOfVectorAndMatrixTest::getMatrixInitializer(GLuint n_cols, GLuint n_rows)
15384 {
15385 std::string result;
15386
15387 result.append("{ ");
15388
15389 for (GLuint col = 0; col < n_cols; ++col)
15390 {
15391 result.append(getVectorInitializer(Utils::FLOAT, n_rows));
15392
15393 if (col + 1 < n_cols)
15394 {
15395 result.append(", ");
15396 }
15397 }
15398
15399 result.append(" }");
15400
15401 return result;
15402 }
15403
15404 /** Get string reresenting initialization of local vector variables
15405 *
15406 * @param type Basic type of vector
15407 * @param n_rows Number of rows
15408 *
15409 * @return String with initialization
15410 **/
getVectorInitializer(Utils::TYPES type,glw::GLuint n_rows)15411 std::string LengthOfVectorAndMatrixTest::getVectorInitializer(Utils::TYPES type, glw::GLuint n_rows)
15412 {
15413 std::string result;
15414 const GLchar *value = 0;
15415
15416 switch (type)
15417 {
15418 case Utils::FLOAT:
15419 value = "0.125";
15420 break;
15421 case Utils::UINT:
15422 value = "1";
15423 break;
15424 case Utils::INT:
15425 value = "-1";
15426 break;
15427 default:
15428 TCU_FAIL("Invalid enum");
15429 }
15430
15431 result.append("{");
15432
15433 for (GLuint row = 0; row < n_rows; ++row)
15434 {
15435 result.append(value);
15436
15437 if (row + 1 < n_rows)
15438 {
15439 result.append(", ");
15440 }
15441 }
15442
15443 result.append("}");
15444
15445 return result;
15446 }
15447
15448 /** Prepare source for given shader stage
15449 *
15450 * @param in_stage Shader stage, compute shader will use 430
15451 * @param in_use_version_400 Select if 400 or 420 should be used
15452 * @param out_source Prepared shader source instance
15453 **/
prepareDrawShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15454 void LengthOfVectorAndMatrixTest::prepareDrawShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15455 Utils::shaderSource &out_source)
15456 {
15457 static const GLchar *verification_snippet =
15458 " VARIABLE_TYPE variable = INITIALIZATION;\n"
15459 " Structure structure = { { 0, 1, 0, 1 } , INITIALIZATION };\n"
15460 "\n"
15461 " const uint variable_length = variable.length();\n"
15462 " const uint structure_member_b_length = structure.member_b.length();\n"
15463 " const uint input_member_length = INPUT_VARIABLE_NAME.length();\n"
15464 "#ifndef FRAGMENT\n"
15465 " const uint output_member_length = OUTPUT_VARIABLE_NAME.length();\n"
15466 "#endif // FRAGMENT\n"
15467 "\n"
15468 " BASE_TYPE array_var[variable.length()];\n"
15469 " BASE_TYPE array_str[structure.member_b.length()];\n"
15470 " BASE_TYPE array_in [INPUT_VARIABLE_NAME.length()];\n"
15471 "#ifndef FRAGMENT\n"
15472 " BASE_TYPE array_out[OUTPUT_VARIABLE_NAME.length()];\n"
15473 "#endif // FRAGMENT\n"
15474 "\n"
15475 " BASE_TYPE sum = 0;\n"
15476 "\n"
15477 " for (uint i = 0; i < variable_length; ++i)\n"
15478 " {\n"
15479 " array_var[i] = variableARRAY_INDEX.x;\n"
15480 " }\n"
15481 "\n"
15482 " for (uint i = 0; i < structure_member_b_length; ++i)\n"
15483 " {\n"
15484 " array_str[i] = structure.member_bARRAY_INDEX.y;\n"
15485 " }\n"
15486 "\n"
15487 " for (uint i = 0; i < input_member_length; ++i)\n"
15488 " {\n"
15489 " array_in[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.x;\n"
15490 " }\n"
15491 "\n"
15492 "#ifndef FRAGMENT\n"
15493 " for (uint i = 0; i < output_member_length; ++i)\n"
15494 " {\n"
15495 " array_out[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.y;\n"
15496 " }\n"
15497 "#endif // FRAGMENT\n"
15498 "\n"
15499 " for (uint i = 0; i < array_var.length(); ++i)\n"
15500 " {\n"
15501 " sum += array_var[i];\n"
15502 " }\n"
15503 "\n"
15504 " for (uint i = 0; i < array_str.length(); ++i)\n"
15505 " {\n"
15506 " sum += array_str[i];\n"
15507 " }\n"
15508 "\n"
15509 " for (uint i = 0; i < array_in.length(); ++i)\n"
15510 " {\n"
15511 " sum += array_in[i];\n"
15512 " }\n"
15513 "\n"
15514 "#ifndef FRAGMENT\n"
15515 " for (uint i = 0; i < array_out.length(); ++i)\n"
15516 " {\n"
15517 " sum += array_out[i];\n"
15518 " }\n"
15519 "#endif // FRAGMENT\n"
15520 "\n"
15521 " if (EXPECTED_VALUE != sum)\n"
15522 " {\n"
15523 " result = vec4(1, 0, 0, 1);\n"
15524 " }\n";
15525
15526 static const GLchar *fragment_shader_template = "VERSION\n"
15527 "\n"
15528 "#define FRAGMENT\n"
15529 "\n"
15530 "in vec4 gs_fs_result;\n"
15531 "out vec4 fs_out_result;\n"
15532 "\n"
15533 "in GSOutputBlock {\n"
15534 " VARIABLE_DECLARATION;\n"
15535 "} input_block;\n"
15536 "\n"
15537 "struct Structure {\n"
15538 " vec4 member_a;\n"
15539 " TYPE_NAME member_b;\n"
15540 "};\n"
15541 "\n"
15542 "void main()\n"
15543 "{\n"
15544 " vec4 result = vec4(0, 1, 0, 1);\n"
15545 "\n"
15546 "VERIFICATION"
15547 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
15548 " {\n"
15549 " result = vec4(1, 0, 0, 1);\n"
15550 " }\n"
15551 "\n"
15552 " fs_out_result = result;\n"
15553 "}\n"
15554 "\n";
15555
15556 static const GLchar *geometry_shader_template = "VERSION\n"
15557 "\n"
15558 "layout(points) in;\n"
15559 "layout(triangle_strip, max_vertices = 4) out;\n"
15560 "\n"
15561 "in vec4 tes_gs_result[];\n"
15562 "out vec4 gs_fs_result;\n"
15563 "\n"
15564 "in TCSOutputBlock {\n"
15565 " VARIABLE_DECLARATION;\n"
15566 "} input_block[];\n"
15567 "out GSOutputBlock {\n"
15568 " VARIABLE_DECLARATION;\n"
15569 "} output_block;\n"
15570 "\n"
15571 "struct Structure {\n"
15572 " vec4 member_a;\n"
15573 " TYPE_NAME member_b;\n"
15574 "};\n"
15575 "\n"
15576 "void main()\n"
15577 "{\n"
15578 " vec4 result = vec4(0, 1, 0, 1);\n"
15579 "\n"
15580 "VERIFICATION"
15581 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
15582 " {\n"
15583 " result = vec4(1, 0, 0, 1);\n"
15584 " }\n"
15585 "\n"
15586 " gs_fs_result = result;\n"
15587 " gl_Position = vec4(-1, -1, 0, 1);\n"
15588 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15589 " EmitVertex();\n"
15590 " gs_fs_result = result;\n"
15591 " gl_Position = vec4(-1, 1, 0, 1);\n"
15592 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15593 " EmitVertex();\n"
15594 " gs_fs_result = result;\n"
15595 " gl_Position = vec4(1, -1, 0, 1);\n"
15596 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15597 " EmitVertex();\n"
15598 " gs_fs_result = result;\n"
15599 " gl_Position = vec4(1, 1, 0, 1);\n"
15600 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15601 " EmitVertex();\n"
15602 "}\n"
15603 "\n";
15604
15605 static const GLchar *tess_ctrl_shader_template =
15606 "VERSION\n"
15607 "\n"
15608 "layout(vertices = 1) out;\n"
15609 "\n"
15610 "in vec4 vs_tcs_result[];\n"
15611 "out vec4 tcs_tes_result[];\n"
15612 "\n"
15613 "in VSOutputBlock {\n"
15614 " VARIABLE_DECLARATION;\n"
15615 "} input_block[];\n"
15616 "out TCSOutputBlock {\n"
15617 " VARIABLE_DECLARATION;\n"
15618 "} output_block[];\n"
15619 "\n"
15620 "struct Structure {\n"
15621 " vec4 member_a;\n"
15622 " TYPE_NAME member_b;\n"
15623 "};\n"
15624 "\n"
15625 "void main()\n"
15626 "{\n"
15627 " vec4 result = vec4(0, 1, 0, 1);\n"
15628 "\n"
15629 "VERIFICATION"
15630 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
15631 " {\n"
15632 " result = vec4(1, 0, 0, 1);\n"
15633 " }\n"
15634 "\n"
15635 " tcs_tes_result[gl_InvocationID] = result;\n"
15636 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15637 "\n"
15638 " gl_TessLevelOuter[0] = 1.0;\n"
15639 " gl_TessLevelOuter[1] = 1.0;\n"
15640 " gl_TessLevelOuter[2] = 1.0;\n"
15641 " gl_TessLevelOuter[3] = 1.0;\n"
15642 " gl_TessLevelInner[0] = 1.0;\n"
15643 " gl_TessLevelInner[1] = 1.0;\n"
15644 "}\n"
15645 "\n";
15646
15647 static const GLchar *tess_eval_shader_template = "VERSION\n"
15648 "\n"
15649 "layout(isolines, point_mode) in;\n"
15650 "\n"
15651 "in vec4 tcs_tes_result[];\n"
15652 "out vec4 tes_gs_result;\n"
15653 "\n"
15654 "in TCSOutputBlock {\n"
15655 " VARIABLE_DECLARATION;\n"
15656 "} input_block[];\n"
15657 "out TCSOutputBlock {\n"
15658 " VARIABLE_DECLARATION;\n"
15659 "} output_block;\n"
15660 "\n"
15661 "struct Structure {\n"
15662 " vec4 member_a;\n"
15663 " TYPE_NAME member_b;\n"
15664 "};\n"
15665 "\n"
15666 "void main()\n"
15667 "{\n"
15668 " vec4 result = vec4(0, 1, 0, 1);\n"
15669 "\n"
15670 "VERIFICATION"
15671 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
15672 " {\n"
15673 " result = vec4(1, 0, 0, 1);\n"
15674 " }\n"
15675 "\n"
15676 " tes_gs_result = result;\n"
15677 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15678 "}\n"
15679 "\n";
15680
15681 static const GLchar *vertex_shader_template = "VERSION\n"
15682 "\n"
15683 "out vec4 vs_tcs_result;\n"
15684 "\n"
15685 "in VARIABLE_DECLARATION;\n"
15686 "out VSOutputBlock {\n"
15687 " VARIABLE_DECLARATION;\n"
15688 "} output_block;\n"
15689 "\n"
15690 "struct Structure {\n"
15691 " vec4 member_a;\n"
15692 " TYPE_NAME member_b;\n"
15693 "};\n"
15694 "\n"
15695 "void main()\n"
15696 "{\n"
15697 " vec4 result = vec4(0, 1, 0, 1);\n"
15698 "\n"
15699 "VERIFICATION"
15700 "\n"
15701 " vs_tcs_result = result;\n"
15702 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15703 "}\n"
15704 "\n";
15705
15706 const GLchar *array_index = "";
15707 const testCase &test_case = m_test_cases[m_current_test_case_index];
15708 const GLchar *shader_template = 0;
15709 const GLchar *input_block_name = "input_block";
15710 const GLchar *output_block_name = "output_block";
15711
15712 const std::string &base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
15713 const std::string &expected_value = getExpectedValue(in_stage);
15714 const std::string &initialization = getInitialization();
15715 const std::string &type_name = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
15716
15717 std::string input_decl;
15718 std::string input_ref;
15719 std::string output_decl;
15720 std::string output_ref;
15721
15722 Utils::qualifierSet in_qualifiers;
15723 Utils::qualifierSet out_qualifiers;
15724
15725 if ((Utils::UINT == test_case.m_type) || (Utils::INT == test_case.m_type))
15726 {
15727 if (Utils::VERTEX_SHADER != in_stage)
15728 {
15729 in_qualifiers.push_back(Utils::QUAL_FLAT);
15730 }
15731
15732 out_qualifiers.push_back(Utils::QUAL_FLAT);
15733 }
15734
15735 switch (in_stage)
15736 {
15737 case Utils::COMPUTE_SHADER:
15738 shader_template = 0;
15739 break;
15740 case Utils::FRAGMENT_SHADER:
15741 shader_template = fragment_shader_template;
15742 break;
15743 case Utils::GEOMETRY_SHADER:
15744 shader_template = geometry_shader_template;
15745 break;
15746 case Utils::TESS_CTRL_SHADER:
15747 shader_template = tess_ctrl_shader_template;
15748 break;
15749 case Utils::TESS_EVAL_SHADER:
15750 shader_template = tess_eval_shader_template;
15751 break;
15752 case Utils::VERTEX_SHADER:
15753 shader_template = vertex_shader_template;
15754 break;
15755 default:
15756 TCU_FAIL("Invalid enum");
15757 }
15758
15759 if (Utils::VERTEX_SHADER != in_stage)
15760 {
15761 Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable",
15762 input_block_name, input_decl, input_ref);
15763 }
15764 else
15765 {
15766 Utils::prepareVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable", input_decl,
15767 input_ref);
15768 }
15769 if (Utils::FRAGMENT_SHADER != in_stage)
15770 {
15771 Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
15772 output_block_name, output_decl, output_ref);
15773 }
15774 else
15775 {
15776 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
15777 output_decl, output_ref);
15778 }
15779
15780 if (1 != test_case.m_n_cols)
15781 {
15782 array_index = "[i]";
15783 }
15784
15785 out_source.m_parts[0].m_code = shader_template;
15786
15787 size_t position = 0;
15788 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
15789 out_source.m_parts[0].m_code);
15790
15791 Utils::replaceToken("VARIABLE_DECLARATION", position, input_decl.c_str(), out_source.m_parts[0].m_code);
15792
15793 if (Utils::FRAGMENT_SHADER != in_stage)
15794 {
15795 Utils::replaceToken("VARIABLE_DECLARATION", position, output_decl.c_str(), out_source.m_parts[0].m_code);
15796 }
15797
15798 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
15799
15800 size_t temp = position;
15801
15802 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
15803
15804 position = temp;
15805
15806 Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
15807
15808 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
15809
15810 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
15811
15812 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15813
15814 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15815
15816 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15817
15818 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15819
15820 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15821
15822 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
15823
15824 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", input_ref.c_str(), out_source.m_parts[0].m_code);
15825
15826 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", output_ref.c_str(), out_source.m_parts[0].m_code);
15827
15828 Utils::replaceAllTokens("ARRAY_INDEX", array_index, out_source.m_parts[0].m_code);
15829 }
15830
15831 /** Prepare source for compute shader stage
15832 *
15833 * @param out_source Prepared shader source instance
15834 **/
prepareComputeShaderSource(Utils::shaderSource & out_source)15835 void LengthOfVectorAndMatrixTest::prepareComputeShaderSource(Utils::shaderSource &out_source)
15836 {
15837 static const GLchar *verification_snippet =
15838 " VARIABLE_TYPE variable = uni_variable;\n"
15839 " Structure structure = { { 0, 1, 0, 1 } , uni_variable };\n"
15840 "\n"
15841 " const uint variable_length = variable.length();\n"
15842 " const uint structure_member_b_length = structure.member_b.length();\n"
15843 "\n"
15844 " BASE_TYPE array_var[variable.length()];\n"
15845 " BASE_TYPE array_str[structure.member_b.length()];\n"
15846 "\n"
15847 " BASE_TYPE sum = 0;\n"
15848 "\n"
15849 " for (uint i = 0; i < variable_length; ++i)\n"
15850 " {\n"
15851 " array_var[i] = variableARRAY_INDEX.x;\n"
15852 " }\n"
15853 "\n"
15854 " for (uint i = 0; i < structure_member_b_length; ++i)\n"
15855 " {\n"
15856 " array_str[i] = structure.member_bARRAY_INDEX.y;\n"
15857 " }\n"
15858 "\n"
15859 " for (uint i = 0; i < array_var.length(); ++i)\n"
15860 " {\n"
15861 " sum += array_var[i];\n"
15862 " }\n"
15863 "\n"
15864 " for (uint i = 0; i < array_str.length(); ++i)\n"
15865 " {\n"
15866 " sum += array_str[i];\n"
15867 " }\n"
15868 "\n"
15869 " if (EXPECTED_VALUE != sum)\n"
15870 " {\n"
15871 " result = vec4(1, 0, 0, 1);\n"
15872 " }\n";
15873
15874 static const GLchar *compute_shader_template =
15875 "VERSION\n"
15876 "\n"
15877 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
15878 "\n"
15879 "writeonly uniform image2D uni_image;\n"
15880 " uniform TYPE_NAME uni_variable;\n"
15881 "\n"
15882 "struct Structure {\n"
15883 " vec4 member_a;\n"
15884 " TYPE_NAME member_b;\n"
15885 "};\n"
15886 "\n"
15887 "void main()\n"
15888 "{\n"
15889 " vec4 result = vec4(0, 1, 0, 1);\n"
15890 "\n"
15891 "VERIFICATION"
15892 "\n"
15893 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
15894 "}\n"
15895 "\n";
15896
15897 const testCase &test_case = m_test_cases[m_current_test_case_index];
15898 const GLchar *array_index = "";
15899
15900 const std::string &base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
15901 const std::string &expected_value = getExpectedValue(Utils::COMPUTE_SHADER);
15902 const std::string &type_name = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
15903
15904 if (1 != test_case.m_n_cols)
15905 {
15906 array_index = "[i]";
15907 }
15908
15909 out_source.m_parts[0].m_code = compute_shader_template;
15910
15911 size_t position = 0;
15912 Utils::replaceToken("VERSION", position, getVersionString(Utils::COMPUTE_SHADER, false),
15913 out_source.m_parts[0].m_code);
15914
15915 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
15916
15917 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
15918
15919 size_t temp = position;
15920
15921 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
15922
15923 position = temp;
15924
15925 Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
15926
15927 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15928
15929 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15930
15931 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
15932
15933 Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
15934
15935 Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
15936
15937 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
15938 }
15939
15940 /** Constructor
15941 *
15942 * @param context Test context
15943 **/
LengthOfComputeResultTest(deqp::Context & context)15944 LengthOfComputeResultTest::LengthOfComputeResultTest(deqp::Context &context)
15945 : GLSLTestBase(context, "length_of_compute_result", "Test verifies .length() for results of computation")
15946 {
15947 /* Nothing to be done here */
15948 }
15949
15950 /** Prepare source for given shader stage
15951 *
15952 * @param in_stage Shader stage, compute shader will use 430
15953 * @param in_use_version_400 Select if 400 or 420 should be used
15954 * @param out_source Prepared shader source instance
15955 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15956 void LengthOfComputeResultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15957 Utils::shaderSource &out_source)
15958 {
15959 static const GLchar *uniforms = "uniform mat2x4 goten;\n"
15960 "uniform uvec4 indices;\n"
15961 "uniform uvec4 expected_lengths;\n"
15962 "uniform mat4x3 gohan;\n"
15963 "uniform vec3 vegeta;\n"
15964 "uniform vec3 trunks;\n"
15965 "uniform uint variable;\n"
15966 "uniform float expected_sum;\n";
15967
15968 static const GLchar *verification_snippet =
15969 " uint lengths[4];\n"
15970 " float x[(gohan * goten).length()];\n"
15971 " float y[(gohan * goten)[variable - 1].length()];\n"
15972 "\n"
15973 " lengths[indices.x] = gohan[variable].length();\n"
15974 " lengths[indices.y] = (gohan * goten).length();\n"
15975 " lengths[indices.z] = (gohan * goten)[variable].length();\n"
15976 " lengths[indices.w] = (vegeta * trunks).length();\n"
15977 "\n"
15978 " float dot_result = dot(vegeta, trunks);\n"
15979 " mat2x3 mul_result = gohan * goten;\n"
15980 "\n"
15981 "#ifdef TESS_CTRL\n"
15982 " const uint position_length = gl_out[gl_InvocationID].gl_Position.length();\n"
15983 "#endif\n"
15984 "#ifndef COMPUTE\n"
15985 "#ifndef FRAGMENT\n"
15986 "#ifndef TESS_CTRL\n"
15987 " const uint position_length = gl_Position.length();\n"
15988 "#endif /*TESS_CTRL */\n"
15989 "#endif /* FRAGMENT */\n"
15990 "#endif /* COMPUTE */\n"
15991 "#ifdef FRAGMENT\n"
15992 " const uint point_coord_length = gl_PointCoord.length();\n"
15993 " const uint sample_position_length = gl_SamplePosition.length();\n"
15994 "#endif /* FRAGMENT */\n"
15995 " const uint outer_length = outerProduct(vegeta, trunks).length();\n"
15996 "\n"
15997 " for (uint i = 0; i < x.length(); ++i)\n"
15998 " {\n"
15999 " x[i] = mul_result[i].x;\n"
16000 " }\n"
16001 "\n"
16002 " for (uint i = 0; i < y.length(); ++i)\n"
16003 " {\n"
16004 " y[i] = mul_result[0][i];\n"
16005 " }\n"
16006 "\n"
16007 " if ( (expected_lengths.x != lengths[0]) ||\n"
16008 " (expected_lengths.y != lengths[1]) ||\n"
16009 " (expected_lengths.z != lengths[2]) ||\n"
16010 " (expected_lengths.w != lengths[3]) ||\n"
16011 "#ifndef COMPUTE\n"
16012 "#ifndef FRAGMENT\n"
16013 " (4 /* vec4 */ != position_length) ||\n"
16014 "#endif /* FRAGMENT */\n"
16015 "#endif /* COMPUTE */\n"
16016 "#ifdef FRAGMENT\n"
16017 " (2 /* vec2 */ != point_coord_length) ||\n"
16018 " (2 /* vec2 */ != sample_position_length) ||\n"
16019 "#endif /* FRAGMENT */\n"
16020 " (0.5 != dot_result) ||\n"
16021 " (3 /* mat3 */ != outer_length) ||\n"
16022 " (expected_sum != x[variable] + y[variable]) )\n"
16023 " {\n"
16024 " result = vec4(1, 0, 0, 1);\n"
16025 " }\n";
16026
16027 static const GLchar *compute_shader_template =
16028 "VERSION\n"
16029 "\n"
16030 "#define COMPUTE\n"
16031 "\n"
16032 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16033 "\n"
16034 "writeonly uniform image2D uni_image;\n"
16035 "\n"
16036 "UNIFORMS"
16037 "\n"
16038 "void main()\n"
16039 "{\n"
16040 " vec4 result = vec4(0, 1, 0, 1);\n"
16041 "\n"
16042 "VERIFICATION"
16043 "\n"
16044 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16045 "}\n"
16046 "\n";
16047
16048 static const GLchar *fragment_shader_template = "VERSION\n"
16049 "\n"
16050 "#define FRAGMENT\n"
16051 "\n"
16052 "in vec4 gs_fs_result;\n"
16053 "out vec4 fs_out_result;\n"
16054 "\n"
16055 "UNIFORMS"
16056 "\n"
16057 "void main()\n"
16058 "{\n"
16059 " vec4 result = vec4(0, 1, 0, 1);\n"
16060 "\n"
16061 "VERIFICATION"
16062 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16063 " {\n"
16064 " result = vec4(1, 0, 0, 1);\n"
16065 " }\n"
16066 "\n"
16067 " fs_out_result = result;\n"
16068 "}\n"
16069 "\n";
16070
16071 static const GLchar *geometry_shader_template = "VERSION\n"
16072 "\n"
16073 "layout(points) in;\n"
16074 "layout(triangle_strip, max_vertices = 4) out;\n"
16075 "\n"
16076 "in vec4 tes_gs_result[];\n"
16077 "out vec4 gs_fs_result;\n"
16078 "\n"
16079 "UNIFORMS"
16080 "\n"
16081 "void main()\n"
16082 "{\n"
16083 " vec4 result = vec4(0, 1, 0, 1);\n"
16084 "\n"
16085 "VERIFICATION"
16086 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16087 " {\n"
16088 " result = vec4(1, 0, 0, 1);\n"
16089 " }\n"
16090 "\n"
16091 " gs_fs_result = result;\n"
16092 " gl_Position = vec4(-1, -1, 0, 1);\n"
16093 " EmitVertex();\n"
16094 " gs_fs_result = result;\n"
16095 " gl_Position = vec4(-1, 1, 0, 1);\n"
16096 " EmitVertex();\n"
16097 " gs_fs_result = result;\n"
16098 " gl_Position = vec4(1, -1, 0, 1);\n"
16099 " EmitVertex();\n"
16100 " gs_fs_result = result;\n"
16101 " gl_Position = vec4(1, 1, 0, 1);\n"
16102 " EmitVertex();\n"
16103 "}\n"
16104 "\n";
16105
16106 static const GLchar *tess_ctrl_shader_template =
16107 "VERSION\n"
16108 "#define TESS_CTRL\n"
16109 "\n"
16110 "layout(vertices = 1) out;\n"
16111 "\n"
16112 "in vec4 vs_tcs_result[];\n"
16113 "out vec4 tcs_tes_result[];\n"
16114 "\n"
16115 "UNIFORMS"
16116 "\n"
16117 "void main()\n"
16118 "{\n"
16119 " vec4 result = vec4(0, 1, 0, 1);\n"
16120 "\n"
16121 "VERIFICATION"
16122 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16123 " {\n"
16124 " result = vec4(1, 0, 0, 1);\n"
16125 " }\n"
16126 "\n"
16127 " tcs_tes_result[gl_InvocationID] = result;\n"
16128 "\n"
16129 " gl_TessLevelOuter[0] = 1.0;\n"
16130 " gl_TessLevelOuter[1] = 1.0;\n"
16131 " gl_TessLevelOuter[2] = 1.0;\n"
16132 " gl_TessLevelOuter[3] = 1.0;\n"
16133 " gl_TessLevelInner[0] = 1.0;\n"
16134 " gl_TessLevelInner[1] = 1.0;\n"
16135 "}\n"
16136 "\n";
16137
16138 static const GLchar *tess_eval_shader_template = "VERSION\n"
16139 "\n"
16140 "layout(isolines, point_mode) in;\n"
16141 "\n"
16142 "in vec4 tcs_tes_result[];\n"
16143 "out vec4 tes_gs_result;\n"
16144 "\n"
16145 "UNIFORMS"
16146 "\n"
16147 "void main()\n"
16148 "{\n"
16149 " vec4 result = vec4(0, 1, 0, 1);\n"
16150 "\n"
16151 "VERIFICATION"
16152 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16153 " {\n"
16154 " result = vec4(1, 0, 0, 1);\n"
16155 " }\n"
16156 "\n"
16157 " tes_gs_result = result;\n"
16158 "}\n"
16159 "\n";
16160
16161 static const GLchar *vertex_shader_template = "VERSION\n"
16162 "\n"
16163 "out vec4 vs_tcs_result;\n"
16164 "\n"
16165 "UNIFORMS"
16166 "\n"
16167 "void main()\n"
16168 "{\n"
16169 " vec4 result = vec4(0, 1, 0, 1);\n"
16170 "\n"
16171 "VERIFICATION"
16172 "\n"
16173 " vs_tcs_result = result;\n"
16174 "}\n"
16175 "\n";
16176
16177 const GLchar *shader_template = 0;
16178
16179 switch (in_stage)
16180 {
16181 case Utils::COMPUTE_SHADER:
16182 shader_template = compute_shader_template;
16183 break;
16184 case Utils::FRAGMENT_SHADER:
16185 shader_template = fragment_shader_template;
16186 break;
16187 case Utils::GEOMETRY_SHADER:
16188 shader_template = geometry_shader_template;
16189 break;
16190 case Utils::TESS_CTRL_SHADER:
16191 shader_template = tess_ctrl_shader_template;
16192 break;
16193 case Utils::TESS_EVAL_SHADER:
16194 shader_template = tess_eval_shader_template;
16195 break;
16196 case Utils::VERTEX_SHADER:
16197 shader_template = vertex_shader_template;
16198 break;
16199 default:
16200 TCU_FAIL("Invalid enum");
16201 }
16202
16203 out_source.m_parts[0].m_code = shader_template;
16204
16205 size_t position = 0;
16206 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16207 out_source.m_parts[0].m_code);
16208
16209 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16210
16211 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16212 }
16213
16214 /** Overwritte of prepareUniforms method
16215 *
16216 * @param program Current program
16217 **/
prepareUniforms(Utils::program & program)16218 void LengthOfComputeResultTest::prepareUniforms(Utils::program &program)
16219 {
16220 static const GLfloat gohan_data[12] = {0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f,
16221 0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f};
16222
16223 static const GLfloat goten_data[8] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
16224
16225 static const GLfloat vegeta_data[3] = {0.5f, 0.5f, 0.0f};
16226
16227 static const GLfloat trunks_data[3] = {0.5f, 0.5f, 0.0f};
16228
16229 static const GLuint indices_data[4] = {2, 1, 0, 3};
16230
16231 static const GLuint variable_data[1] = {1};
16232
16233 static const GLuint expected_lengths_data[4] = {3, 2, 3, 3};
16234
16235 static const GLfloat expected_sum_data[1] = {1.0f};
16236
16237 program.uniform("gohan", Utils::FLOAT, 4 /* n_cols */, 3 /* n_rows */, gohan_data);
16238 program.uniform("goten", Utils::FLOAT, 2 /* n_cols */, 4 /* n_rows */, goten_data);
16239 program.uniform("vegeta", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, vegeta_data);
16240 program.uniform("trunks", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, trunks_data);
16241 program.uniform("indices", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, indices_data);
16242 program.uniform("variable", Utils::UINT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16243 program.uniform("expected_lengths", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, expected_lengths_data);
16244 program.uniform("expected_sum", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, expected_sum_data);
16245 }
16246
16247 /** Constructor
16248 *
16249 * @param context Test context
16250 **/
ScalarSwizzlersTest(deqp::Context & context)16251 ScalarSwizzlersTest::ScalarSwizzlersTest(deqp::Context &context)
16252 : GLSLTestBase(context, "scalar_swizzlers", "Verifies that swizzlers can be used on scalars")
16253 {
16254 /* Nothing to be done here */
16255 }
16256
16257 /** Prepare source for given shader stage
16258 *
16259 * @param in_stage Shader stage, compute shader will use 430
16260 * @param in_use_version_400 Select if 400 or 420 should be used
16261 * @param out_source Prepared shader source instance
16262 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16263 void ScalarSwizzlersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16264 Utils::shaderSource &out_source)
16265 {
16266 static const GLchar *uniforms = "uniform float variable;\n"
16267 "uniform vec3 expected_values;\n";
16268
16269 static const GLchar *literal = "#define LITERAL 0.375\n";
16270
16271 static const GLchar *structure = "struct Structure {\n"
16272 " vec2 m_xx;\n"
16273 " vec3 m_xxx;\n"
16274 " vec4 m_xxxx;\n"
16275 " vec2 m_nested_xx;\n"
16276 " vec3 m_nested_xxx;\n"
16277 " vec4 m_nested_xxxx;\n"
16278 "};\n";
16279
16280 static const GLchar *function = "bool check_values(in Structure structure, in float value)\n"
16281 "{\n"
16282 " const vec2 xx = vec2(value, value);\n"
16283 " const vec3 xxx = vec3(value, value, value);\n"
16284 " const vec4 xxxx = vec4(value, value, value, value);\n"
16285 "\n"
16286 " bool result = true;\n"
16287 "\n"
16288 " if ((xx != structure.m_xx) ||\n"
16289 " (xxx != structure.m_xxx) ||\n"
16290 " (xxxx != structure.m_xxxx) ||\n"
16291 " (xx != structure.m_nested_xx) ||\n"
16292 " (xxx != structure.m_nested_xxx) ||\n"
16293 " (xxxx != structure.m_nested_xxxx) )\n"
16294 " {\n"
16295 " result = false;\n"
16296 " }\n"
16297 "\n"
16298 " return result;\n"
16299 "}\n";
16300
16301 static const GLchar *verification_snippet =
16302 " Structure literal_result;\n"
16303 " Structure constant_result;\n"
16304 " Structure variable_result;\n"
16305 "\n"
16306 " literal_result.m_xx = LITERAL.xx ;\n"
16307 " literal_result.m_xxx = LITERAL.xxx ;\n"
16308 " literal_result.m_xxxx = LITERAL.xxxx;\n"
16309 " literal_result.m_nested_xx = LITERAL.x.rr.sss.rr ;\n"
16310 " literal_result.m_nested_xxx = LITERAL.s.xx.rrr.xxx ;\n"
16311 " literal_result.m_nested_xxxx = LITERAL.r.ss.xxx.ssss;\n"
16312 "\n"
16313 " const float constant = 0.125;\n"
16314 "\n"
16315 " constant_result.m_xx = constant.xx ;\n"
16316 " constant_result.m_xxx = constant.xxx ;\n"
16317 " constant_result.m_xxxx = constant.xxxx;\n"
16318 " constant_result.m_nested_xx = constant.x.rr.sss.rr ;\n"
16319 " constant_result.m_nested_xxx = constant.s.xx.rrr.xxx ;\n"
16320 " constant_result.m_nested_xxxx = constant.r.ss.xxx.ssss;\n"
16321 "\n"
16322 " variable_result.m_xx = variable.xx ;\n"
16323 " variable_result.m_xxx = variable.xxx ;\n"
16324 " variable_result.m_xxxx = variable.xxxx;\n"
16325 " variable_result.m_nested_xx = variable.x.rr.sss.rr ;\n"
16326 " variable_result.m_nested_xxx = variable.s.xx.rrr.xxx ;\n"
16327 " variable_result.m_nested_xxxx = variable.r.ss.xxx.ssss;\n"
16328 "\n"
16329 " if ((false == check_values(literal_result, expected_values.x)) ||\n"
16330 " (false == check_values(constant_result, expected_values.y)) ||\n"
16331 " (false == check_values(variable_result, expected_values.z)) )\n"
16332 " {\n"
16333 " result = vec4(1, 0, 0, 1);\n"
16334 " }\n";
16335
16336 static const GLchar *compute_shader_template =
16337 "VERSION\n"
16338 "\n"
16339 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16340 "\n"
16341 "writeonly uniform image2D uni_image;\n"
16342 "\n"
16343 "STRUCTURE"
16344 "\n"
16345 "UNIFORMS"
16346 "\n"
16347 "FUNCTION"
16348 "\n"
16349 "LITERAL"
16350 "\n"
16351 "void main()\n"
16352 "{\n"
16353 " vec4 result = vec4(0, 1, 0, 1);\n"
16354 "\n"
16355 "VERIFICATION"
16356 "\n"
16357 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16358 "}\n"
16359 "\n";
16360
16361 static const GLchar *fragment_shader_template = "VERSION\n"
16362 "\n"
16363 "#define FRAGMENT\n"
16364 "\n"
16365 "in vec4 gs_fs_result;\n"
16366 "out vec4 fs_out_result;\n"
16367 "\n"
16368 "STRUCTURE"
16369 "\n"
16370 "UNIFORMS"
16371 "\n"
16372 "FUNCTION"
16373 "\n"
16374 "LITERAL"
16375 "\n"
16376 "void main()\n"
16377 "{\n"
16378 " vec4 result = vec4(0, 1, 0, 1);\n"
16379 "\n"
16380 "VERIFICATION"
16381 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16382 " {\n"
16383 " result = vec4(1, 0, 0, 1);\n"
16384 " }\n"
16385 "\n"
16386 " fs_out_result = result;\n"
16387 "}\n"
16388 "\n";
16389
16390 static const GLchar *geometry_shader_template = "VERSION\n"
16391 "\n"
16392 "layout(points) in;\n"
16393 "layout(triangle_strip, max_vertices = 4) out;\n"
16394 "\n"
16395 "in vec4 tes_gs_result[];\n"
16396 "out vec4 gs_fs_result;\n"
16397 "\n"
16398 "STRUCTURE"
16399 "\n"
16400 "UNIFORMS"
16401 "\n"
16402 "FUNCTION"
16403 "\n"
16404 "LITERAL"
16405 "\n"
16406 "void main()\n"
16407 "{\n"
16408 " vec4 result = vec4(0, 1, 0, 1);\n"
16409 "\n"
16410 "VERIFICATION"
16411 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16412 " {\n"
16413 " result = vec4(1, 0, 0, 1);\n"
16414 " }\n"
16415 "\n"
16416 " gs_fs_result = result;\n"
16417 " gl_Position = vec4(-1, -1, 0, 1);\n"
16418 " EmitVertex();\n"
16419 " gs_fs_result = result;\n"
16420 " gl_Position = vec4(-1, 1, 0, 1);\n"
16421 " EmitVertex();\n"
16422 " gs_fs_result = result;\n"
16423 " gl_Position = vec4(1, -1, 0, 1);\n"
16424 " EmitVertex();\n"
16425 " gs_fs_result = result;\n"
16426 " gl_Position = vec4(1, 1, 0, 1);\n"
16427 " EmitVertex();\n"
16428 "}\n"
16429 "\n";
16430
16431 static const GLchar *tess_ctrl_shader_template =
16432 "VERSION\n"
16433 "\n"
16434 "layout(vertices = 1) out;\n"
16435 "\n"
16436 "in vec4 vs_tcs_result[];\n"
16437 "out vec4 tcs_tes_result[];\n"
16438 "\n"
16439 "STRUCTURE"
16440 "\n"
16441 "UNIFORMS"
16442 "\n"
16443 "FUNCTION"
16444 "\n"
16445 "LITERAL"
16446 "\n"
16447 "void main()\n"
16448 "{\n"
16449 " vec4 result = vec4(0, 1, 0, 1);\n"
16450 "\n"
16451 "VERIFICATION"
16452 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16453 " {\n"
16454 " result = vec4(1, 0, 0, 1);\n"
16455 " }\n"
16456 "\n"
16457 " tcs_tes_result[gl_InvocationID] = result;\n"
16458 "\n"
16459 " gl_TessLevelOuter[0] = 1.0;\n"
16460 " gl_TessLevelOuter[1] = 1.0;\n"
16461 " gl_TessLevelOuter[2] = 1.0;\n"
16462 " gl_TessLevelOuter[3] = 1.0;\n"
16463 " gl_TessLevelInner[0] = 1.0;\n"
16464 " gl_TessLevelInner[1] = 1.0;\n"
16465 "}\n"
16466 "\n";
16467
16468 static const GLchar *tess_eval_shader_template = "VERSION\n"
16469 "\n"
16470 "layout(isolines, point_mode) in;\n"
16471 "\n"
16472 "in vec4 tcs_tes_result[];\n"
16473 "out vec4 tes_gs_result;\n"
16474 "\n"
16475 "STRUCTURE"
16476 "\n"
16477 "UNIFORMS"
16478 "\n"
16479 "FUNCTION"
16480 "\n"
16481 "LITERAL"
16482 "\n"
16483 "void main()\n"
16484 "{\n"
16485 " vec4 result = vec4(0, 1, 0, 1);\n"
16486 "\n"
16487 "VERIFICATION"
16488 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16489 " {\n"
16490 " result = vec4(1, 0, 0, 1);\n"
16491 " }\n"
16492 "\n"
16493 " tes_gs_result = result;\n"
16494 "}\n"
16495 "\n";
16496
16497 static const GLchar *vertex_shader_template = "VERSION\n"
16498 "\n"
16499 "out vec4 vs_tcs_result;\n"
16500 "\n"
16501 "STRUCTURE"
16502 "\n"
16503 "UNIFORMS"
16504 "\n"
16505 "FUNCTION"
16506 "\n"
16507 "LITERAL"
16508 "\n"
16509 "void main()\n"
16510 "{\n"
16511 " vec4 result = vec4(0, 1, 0, 1);\n"
16512 "\n"
16513 "VERIFICATION"
16514 "\n"
16515 " vs_tcs_result = result;\n"
16516 "}\n"
16517 "\n";
16518
16519 const GLchar *shader_template = 0;
16520
16521 switch (in_stage)
16522 {
16523 case Utils::COMPUTE_SHADER:
16524 shader_template = compute_shader_template;
16525 break;
16526 case Utils::FRAGMENT_SHADER:
16527 shader_template = fragment_shader_template;
16528 break;
16529 case Utils::GEOMETRY_SHADER:
16530 shader_template = geometry_shader_template;
16531 break;
16532 case Utils::TESS_CTRL_SHADER:
16533 shader_template = tess_ctrl_shader_template;
16534 break;
16535 case Utils::TESS_EVAL_SHADER:
16536 shader_template = tess_eval_shader_template;
16537 break;
16538 case Utils::VERTEX_SHADER:
16539 shader_template = vertex_shader_template;
16540 break;
16541 default:
16542 TCU_FAIL("Invalid enum");
16543 }
16544
16545 out_source.m_parts[0].m_code = shader_template;
16546
16547 size_t position = 0;
16548 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16549 out_source.m_parts[0].m_code);
16550
16551 Utils::replaceToken("STRUCTURE", position, structure, out_source.m_parts[0].m_code);
16552
16553 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16554
16555 Utils::replaceToken("FUNCTION", position, function, out_source.m_parts[0].m_code);
16556
16557 Utils::replaceToken("LITERAL", position, literal, out_source.m_parts[0].m_code);
16558
16559 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16560 }
16561
16562 /** Overwritte of prepareUniforms method
16563 *
16564 * @param program Current program
16565 **/
prepareUniforms(Utils::program & program)16566 void ScalarSwizzlersTest::prepareUniforms(Utils::program &program)
16567 {
16568 static const GLfloat variable_data[4] = {0.75f};
16569 static const GLfloat expected_values_data[3] = {0.375f, 0.125f, 0.75f};
16570
16571 program.uniform("variable", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16572 program.uniform("expected_values", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, expected_values_data);
16573 }
16574
16575 /** Constructor
16576 *
16577 * @param context Test context
16578 **/
ScalarSwizzlersInvalidTest(deqp::Context & context,TESTED_CASES test_case)16579 ScalarSwizzlersInvalidTest::ScalarSwizzlersInvalidTest(deqp::Context &context, TESTED_CASES test_case)
16580 : NegativeTestBase(context, "scalar_swizzlers_invalid",
16581 "Verifies if invalid use of swizzlers on scalars is reported as error")
16582 , m_test_case_idx(test_case)
16583 {
16584 std::string name = "scalar_swizzlers_invalid_case_" + std::string(getTestCaseString(m_test_case_idx));
16585
16586 TestCase::m_name = name;
16587 }
16588
getTestCaseString(TESTED_CASES test_case)16589 const GLchar *ScalarSwizzlersInvalidTest::getTestCaseString(TESTED_CASES test_case)
16590 {
16591 const GLchar *name = 0;
16592
16593 switch (test_case)
16594 {
16595 case INVALID_Y:
16596 name = "invalid_y";
16597 break;
16598 case INVALID_B:
16599 name = "invalid_b";
16600 break;
16601 case INVALID_Q:
16602 name = "invalid_q";
16603 break;
16604 case INVALID_XY:
16605 name = "invalid_xy";
16606 break;
16607 case INVALID_XRS:
16608 name = "invalid_xrs";
16609 break;
16610 case WRONG:
16611 name = "wrong";
16612 break;
16613 case MISSING_PARENTHESIS:
16614 name = "missing_parenthesis";
16615 break;
16616 default:
16617 TCU_FAIL("Invalid enum");
16618 }
16619
16620 return name;
16621 }
16622
16623 /** Set up next test case
16624 *
16625 * @param test_case_index Index of next test case
16626 *
16627 * @return false if there is no more test cases, true otherwise
16628 **/
prepareNextTestCase(glw::GLuint test_case_index)16629 bool ScalarSwizzlersInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
16630 {
16631 if (test_case_index > 0)
16632 {
16633 return false;
16634 }
16635 switch (m_test_case_idx)
16636 {
16637 // case (glw::GLuint)-1:
16638 case INVALID_Y:
16639 case INVALID_B:
16640 case INVALID_Q:
16641 case INVALID_XY:
16642 case INVALID_XRS:
16643 case WRONG:
16644 case MISSING_PARENTHESIS:
16645 m_case = (TESTED_CASES)m_test_case_idx;
16646 break;
16647 default:
16648 return false;
16649 }
16650
16651 return true;
16652 }
16653
16654 /** Prepare source for given shader stage
16655 *
16656 * @param in_stage Shader stage, compute shader will use 430
16657 * @param in_use_version_400 Select if 400 or 420 should be used
16658 * @param out_source Prepared shader source instance
16659 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16660 void ScalarSwizzlersInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16661 Utils::shaderSource &out_source)
16662 {
16663 static const GLchar *uniforms = "uniform float variable;\n";
16664
16665 static const GLchar *verification_invalid_y = "\n"
16666 " if (0.125 != variable.y) )\n"
16667 " {\n"
16668 " result = vec4(1, 0, 0, 1);\n"
16669 " }\n";
16670
16671 static const GLchar *verification_invalid_b = "\n"
16672 " if (0.125 != variable.b) )\n"
16673 " {\n"
16674 " result = vec4(1, 0, 0, 1);\n"
16675 " }\n";
16676
16677 static const GLchar *verification_invalid_q = "\n"
16678 " if (0.125 != variable.q) )\n"
16679 " {\n"
16680 " result = vec4(1, 0, 0, 1);\n"
16681 " }\n";
16682
16683 static const GLchar *verification_invalid_xy = "\n"
16684 " if (vec2(0.125, 0.25) != variable.xy) )\n"
16685 " {\n"
16686 " result = vec4(1, 0, 0, 1);\n"
16687 " }\n";
16688
16689 static const GLchar *verification_invalid_xrs = "\n"
16690 " if (vec3(0.125, 0.125, 0.25) != variable.xrs) )\n"
16691 " {\n"
16692 " result = vec4(1, 0, 0, 1);\n"
16693 " }\n";
16694
16695 static const GLchar *verification_wrong_u = "\n"
16696 " if (0.125 != variable.u) )\n"
16697 " {\n"
16698 " result = vec4(1, 0, 0, 1);\n"
16699 " }\n";
16700
16701 static const GLchar *verification_missing_parenthesis = "\n"
16702 " if (variable != 1.x) )\n"
16703 " {\n"
16704 " result = vec4(1, 0, 0, 1);\n"
16705 " }\n";
16706
16707 static const GLchar *compute_shader_template =
16708 "VERSION\n"
16709 "\n"
16710 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16711 "\n"
16712 "writeonly uniform image2D uni_image;\n"
16713 "\n"
16714 "UNIFORMS"
16715 "\n"
16716 "void main()\n"
16717 "{\n"
16718 " vec4 result = vec4(0, 1, 0, 1);\n"
16719 "\n"
16720 "VERIFICATION"
16721 "\n"
16722 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16723 "}\n"
16724 "\n";
16725
16726 static const GLchar *fragment_shader_template = "VERSION\n"
16727 "\n"
16728 "#define FRAGMENT\n"
16729 "\n"
16730 "in vec4 gs_fs_result;\n"
16731 "out vec4 fs_out_result;\n"
16732 "\n"
16733 "UNIFORMS"
16734 "\n"
16735 "void main()\n"
16736 "{\n"
16737 " vec4 result = vec4(0, 1, 0, 1);\n"
16738 "\n"
16739 "VERIFICATION"
16740 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16741 " {\n"
16742 " result = vec4(1, 0, 0, 1);\n"
16743 " }\n"
16744 "\n"
16745 " fs_out_result = result;\n"
16746 "}\n"
16747 "\n";
16748
16749 static const GLchar *geometry_shader_template = "VERSION\n"
16750 "\n"
16751 "layout(points) in;\n"
16752 "layout(triangle_strip, max_vertices = 4) out;\n"
16753 "\n"
16754 "in vec4 tes_gs_result[];\n"
16755 "out vec4 gs_fs_result;\n"
16756 "\n"
16757 "UNIFORMS"
16758 "\n"
16759 "void main()\n"
16760 "{\n"
16761 " vec4 result = vec4(0, 1, 0, 1);\n"
16762 "\n"
16763 "VERIFICATION"
16764 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16765 " {\n"
16766 " result = vec4(1, 0, 0, 1);\n"
16767 " }\n"
16768 "\n"
16769 " gs_fs_result = result;\n"
16770 " gl_Position = vec4(-1, -1, 0, 1);\n"
16771 " EmitVertex();\n"
16772 " gs_fs_result = result;\n"
16773 " gl_Position = vec4(-1, 1, 0, 1);\n"
16774 " EmitVertex();\n"
16775 " gs_fs_result = result;\n"
16776 " gl_Position = vec4(1, -1, 0, 1);\n"
16777 " EmitVertex();\n"
16778 " gs_fs_result = result;\n"
16779 " gl_Position = vec4(1, 1, 0, 1);\n"
16780 " EmitVertex();\n"
16781 "}\n"
16782 "\n";
16783
16784 static const GLchar *tess_ctrl_shader_template =
16785 "VERSION\n"
16786 "\n"
16787 "layout(vertices = 1) out;\n"
16788 "\n"
16789 "in vec4 vs_tcs_result[];\n"
16790 "out vec4 tcs_tes_result[];\n"
16791 "\n"
16792 "UNIFORMS"
16793 "\n"
16794 "void main()\n"
16795 "{\n"
16796 " vec4 result = vec4(0, 1, 0, 1);\n"
16797 "\n"
16798 "VERIFICATION"
16799 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16800 " {\n"
16801 " result = vec4(1, 0, 0, 1);\n"
16802 " }\n"
16803 "\n"
16804 " tcs_tes_result[gl_InvocationID] = result;\n"
16805 "\n"
16806 " gl_TessLevelOuter[0] = 1.0;\n"
16807 " gl_TessLevelOuter[1] = 1.0;\n"
16808 " gl_TessLevelOuter[2] = 1.0;\n"
16809 " gl_TessLevelOuter[3] = 1.0;\n"
16810 " gl_TessLevelInner[0] = 1.0;\n"
16811 " gl_TessLevelInner[1] = 1.0;\n"
16812 "}\n"
16813 "\n";
16814
16815 static const GLchar *tess_eval_shader_template = "VERSION\n"
16816 "\n"
16817 "layout(isolines, point_mode) in;\n"
16818 "\n"
16819 "in vec4 tcs_tes_result[];\n"
16820 "out vec4 tes_gs_result;\n"
16821 "\n"
16822 "UNIFORMS"
16823 "\n"
16824 "void main()\n"
16825 "{\n"
16826 " vec4 result = vec4(0, 1, 0, 1);\n"
16827 "\n"
16828 "VERIFICATION"
16829 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16830 " {\n"
16831 " result = vec4(1, 0, 0, 1);\n"
16832 " }\n"
16833 "\n"
16834 " tes_gs_result = result;\n"
16835 "}\n"
16836 "\n";
16837
16838 static const GLchar *vertex_shader_template = "VERSION\n"
16839 "\n"
16840 "out vec4 vs_tcs_result;\n"
16841 "\n"
16842 "UNIFORMS"
16843 "\n"
16844 "void main()\n"
16845 "{\n"
16846 " vec4 result = vec4(0, 1, 0, 1);\n"
16847 "\n"
16848 "VERIFICATION"
16849 "\n"
16850 " vs_tcs_result = result;\n"
16851 "}\n"
16852 "\n";
16853
16854 const GLchar *shader_template = 0;
16855 const GLchar *verification_snippet = 0;
16856
16857 switch (in_stage)
16858 {
16859 case Utils::COMPUTE_SHADER:
16860 shader_template = compute_shader_template;
16861 break;
16862 case Utils::FRAGMENT_SHADER:
16863 shader_template = fragment_shader_template;
16864 break;
16865 case Utils::GEOMETRY_SHADER:
16866 shader_template = geometry_shader_template;
16867 break;
16868 case Utils::TESS_CTRL_SHADER:
16869 shader_template = tess_ctrl_shader_template;
16870 break;
16871 case Utils::TESS_EVAL_SHADER:
16872 shader_template = tess_eval_shader_template;
16873 break;
16874 case Utils::VERTEX_SHADER:
16875 shader_template = vertex_shader_template;
16876 break;
16877 default:
16878 TCU_FAIL("Invalid enum");
16879 }
16880
16881 switch (m_case)
16882 {
16883 case INVALID_Y:
16884 verification_snippet = verification_invalid_y;
16885 break;
16886 case INVALID_B:
16887 verification_snippet = verification_invalid_b;
16888 break;
16889 case INVALID_Q:
16890 verification_snippet = verification_invalid_q;
16891 break;
16892 case INVALID_XY:
16893 verification_snippet = verification_invalid_xy;
16894 break;
16895 case INVALID_XRS:
16896 verification_snippet = verification_invalid_xrs;
16897 break;
16898 case WRONG:
16899 verification_snippet = verification_wrong_u;
16900 break;
16901 case MISSING_PARENTHESIS:
16902 verification_snippet = verification_missing_parenthesis;
16903 break;
16904 default:
16905 TCU_FAIL("Invalid enum");
16906 }
16907
16908 out_source.m_parts[0].m_code = shader_template;
16909
16910 size_t position = 0;
16911 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16912 out_source.m_parts[0].m_code);
16913
16914 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16915
16916 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16917 }
16918
16919 /* Constants used by BuiltInValuesTest */
16920 const GLint BuiltInValuesTest::m_min_program_texel_offset_limit = -8;
16921 const GLint BuiltInValuesTest::m_max_program_texel_offset_limit = 7;
16922
16923 /** Constructor
16924 *
16925 * @param context Test context
16926 **/
BuiltInValuesTest(deqp::Context & context)16927 BuiltInValuesTest::BuiltInValuesTest(deqp::Context &context)
16928 : GLSLTestBase(context, "built_in_values", "Test verifies values of gl_Min/Max_ProgramTexelOffset")
16929 {
16930 /* Nothing to be done here */
16931 }
16932
16933 /** Prepare source for given shader stage
16934 *
16935 * @param in_stage Shader stage, compute shader will use 430
16936 * @param in_use_version_400 Select if 400 or 420 should be used
16937 * @param out_source Prepared shader source instance
16938 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16939 void BuiltInValuesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16940 Utils::shaderSource &out_source)
16941 {
16942 static const GLchar *verification_snippet = " if ((expected_values.x != gl_MinProgramTexelOffset) ||\n"
16943 " (expected_values.y != gl_MaxProgramTexelOffset) )\n"
16944 " {\n"
16945 " result = vec4(1, 0, 0, 1);\n"
16946 " }\n";
16947
16948 static const GLchar *compute_shader_template =
16949 "VERSION\n"
16950 "\n"
16951 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16952 "\n"
16953 "writeonly uniform image2D uni_image;\n"
16954 " uniform ivec2 expected_values;\n"
16955 "\n"
16956 "void main()\n"
16957 "{\n"
16958 " vec4 result = vec4(0, 1, 0, 1);\n"
16959 "\n"
16960 "VERIFICATION"
16961 "\n"
16962 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16963 "}\n"
16964 "\n";
16965
16966 static const GLchar *fragment_shader_template = "VERSION\n"
16967 "\n"
16968 "in vec4 gs_fs_result;\n"
16969 "out vec4 fs_out_result;\n"
16970 "\n"
16971 "uniform ivec2 expected_values;\n"
16972 "\n"
16973 "void main()\n"
16974 "{\n"
16975 " vec4 result = vec4(0, 1, 0, 1);\n"
16976 "\n"
16977 "VERIFICATION"
16978 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16979 " {\n"
16980 " result = vec4(1, 0, 0, 1);\n"
16981 " }\n"
16982 "\n"
16983 " fs_out_result = result;\n"
16984 "}\n"
16985 "\n";
16986
16987 static const GLchar *geometry_shader_template = "VERSION\n"
16988 "\n"
16989 "layout(points) in;\n"
16990 "layout(triangle_strip, max_vertices = 4) out;\n"
16991 "\n"
16992 "in vec4 tes_gs_result[];\n"
16993 "out vec4 gs_fs_result;\n"
16994 "\n"
16995 "uniform ivec2 expected_values;\n"
16996 "\n"
16997 "void main()\n"
16998 "{\n"
16999 " vec4 result = vec4(0, 1, 0, 1);\n"
17000 "\n"
17001 "VERIFICATION"
17002 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17003 " {\n"
17004 " result = vec4(1, 0, 0, 1);\n"
17005 " }\n"
17006 "\n"
17007 " gs_fs_result = result;\n"
17008 " gl_Position = vec4(-1, -1, 0, 1);\n"
17009 " EmitVertex();\n"
17010 " gs_fs_result = result;\n"
17011 " gl_Position = vec4(-1, 1, 0, 1);\n"
17012 " EmitVertex();\n"
17013 " gs_fs_result = result;\n"
17014 " gl_Position = vec4(1, -1, 0, 1);\n"
17015 " EmitVertex();\n"
17016 " gs_fs_result = result;\n"
17017 " gl_Position = vec4(1, 1, 0, 1);\n"
17018 " EmitVertex();\n"
17019 "}\n"
17020 "\n";
17021
17022 static const GLchar *tess_ctrl_shader_template =
17023 "VERSION\n"
17024 "\n"
17025 "layout(vertices = 1) out;\n"
17026 "\n"
17027 "in vec4 vs_tcs_result[];\n"
17028 "out vec4 tcs_tes_result[];\n"
17029 "\n"
17030 "uniform ivec2 expected_values;\n"
17031 "\n"
17032 "void main()\n"
17033 "{\n"
17034 " vec4 result = vec4(0, 1, 0, 1);\n"
17035 "\n"
17036 "VERIFICATION"
17037 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17038 " {\n"
17039 " result = vec4(1, 0, 0, 1);\n"
17040 " }\n"
17041 "\n"
17042 " tcs_tes_result[gl_InvocationID] = result;\n"
17043 "\n"
17044 " gl_TessLevelOuter[0] = 1.0;\n"
17045 " gl_TessLevelOuter[1] = 1.0;\n"
17046 " gl_TessLevelOuter[2] = 1.0;\n"
17047 " gl_TessLevelOuter[3] = 1.0;\n"
17048 " gl_TessLevelInner[0] = 1.0;\n"
17049 " gl_TessLevelInner[1] = 1.0;\n"
17050 "}\n"
17051 "\n";
17052
17053 static const GLchar *tess_eval_shader_template = "VERSION\n"
17054 "\n"
17055 "layout(isolines, point_mode) in;\n"
17056 "\n"
17057 "in vec4 tcs_tes_result[];\n"
17058 "out vec4 tes_gs_result;\n"
17059 "\n"
17060 "uniform ivec2 expected_values;\n"
17061 "\n"
17062 "void main()\n"
17063 "{\n"
17064 " vec4 result = vec4(0, 1, 0, 1);\n"
17065 "\n"
17066 "VERIFICATION"
17067 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17068 " {\n"
17069 " result = vec4(1, 0, 0, 1);\n"
17070 " }\n"
17071 "\n"
17072 " tes_gs_result = result;\n"
17073 "}\n"
17074 "\n";
17075
17076 static const GLchar *vertex_shader_template = "VERSION\n"
17077 "\n"
17078 "out vec4 vs_tcs_result;\n"
17079 "\n"
17080 "uniform ivec2 expected_values;\n"
17081 "\n"
17082 "void main()\n"
17083 "{\n"
17084 " vec4 result = vec4(0, 1, 0, 1);\n"
17085 "\n"
17086 "VERIFICATION"
17087 "\n"
17088 " vs_tcs_result = result;\n"
17089 "}\n"
17090 "\n";
17091
17092 const GLchar *shader_template = 0;
17093
17094 switch (in_stage)
17095 {
17096 case Utils::COMPUTE_SHADER:
17097 shader_template = compute_shader_template;
17098 break;
17099 case Utils::FRAGMENT_SHADER:
17100 shader_template = fragment_shader_template;
17101 break;
17102 case Utils::GEOMETRY_SHADER:
17103 shader_template = geometry_shader_template;
17104 break;
17105 case Utils::TESS_CTRL_SHADER:
17106 shader_template = tess_ctrl_shader_template;
17107 break;
17108 case Utils::TESS_EVAL_SHADER:
17109 shader_template = tess_eval_shader_template;
17110 break;
17111 case Utils::VERTEX_SHADER:
17112 shader_template = vertex_shader_template;
17113 break;
17114 default:
17115 TCU_FAIL("Invalid enum");
17116 }
17117
17118 out_source.m_parts[0].m_code = shader_template;
17119
17120 size_t position = 0;
17121 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17122 out_source.m_parts[0].m_code);
17123
17124 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17125 }
17126
17127 /** Overwritte of prepareUniforms method
17128 *
17129 * @param program Current program
17130 **/
prepareUniforms(Utils::program & program)17131 void BuiltInValuesTest::prepareUniforms(Utils::program &program)
17132 {
17133 const GLint expected_values_data[2] = {m_min_program_texel_offset, m_max_program_texel_offset};
17134
17135 program.uniform("expected_values", Utils::INT, 1 /* n_cols */, 2 /* n_rows */, expected_values_data);
17136 }
17137
17138 /** Prepare test cases
17139 *
17140 * @return true
17141 **/
testInit()17142 bool BuiltInValuesTest::testInit()
17143 {
17144 const Functions &gl = m_context.getRenderContext().getFunctions();
17145
17146 gl.getIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, &m_min_program_texel_offset);
17147 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17148
17149 gl.getIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, &m_max_program_texel_offset);
17150 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17151
17152 if ((m_min_program_texel_offset_limit > m_min_program_texel_offset) ||
17153 (m_max_program_texel_offset_limit > m_max_program_texel_offset))
17154 {
17155 m_context.getTestContext().getLog()
17156 << tcu::TestLog::Message << "Invalid GL_PROGRAM_TEXEL_OFFSET values."
17157 << " Min: " << m_min_program_texel_offset << " expected at top: " << m_min_program_texel_offset_limit
17158 << " Max: " << m_min_program_texel_offset << " expected at least: " << m_max_program_texel_offset_limit
17159 << tcu::TestLog::EndMessage;
17160
17161 return false;
17162 }
17163
17164 return true;
17165 }
17166
17167 /** Constructor
17168 *
17169 * @param context Test context
17170 **/
BuiltInAssignmentTest(deqp::Context & context,GLuint test_case)17171 BuiltInAssignmentTest::BuiltInAssignmentTest(deqp::Context &context, GLuint test_case)
17172 : NegativeTestBase(context, "built_in_assignment",
17173 "Test verifies that built in gl_Min/MaxProgramTexelOffset cannot be assigned")
17174 , m_case(test_case)
17175 {
17176 std::string name = "built_in_assignment_testing_" +
17177 std::string(test_case == 0 ? "gl_MinProgramTexelOffset" : "gl_MaxProgramTexelOffset");
17178
17179 TestCase::m_name = name;
17180 }
17181
17182 /** Set up next test case
17183 *
17184 * @param test_case_index Index of next test case
17185 *
17186 * @return false if there is no more test cases, true otherwise
17187 **/
prepareNextTestCase(glw::GLuint test_case_index)17188 bool BuiltInAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
17189 {
17190 if (test_case_index > 0)
17191 {
17192 return false;
17193 }
17194
17195 const GLchar *description = 0;
17196
17197 switch (m_case)
17198 {
17199 case (glw::GLuint)-1:
17200 case 0:
17201 description = "Testing gl_MinProgramTexelOffset";
17202 break;
17203 case 1:
17204 description = "Testing gl_MaxProgramTexelOffset";
17205 break;
17206 default:
17207 return false;
17208 }
17209
17210 m_context.getTestContext().getLog() << tcu::TestLog::Message << description << tcu::TestLog::EndMessage;
17211
17212 return true;
17213 }
17214
17215 /** Prepare source for given shader stage
17216 *
17217 * @param in_stage Shader stage, compute shader will use 430
17218 * @param in_use_version_400 Select if 400 or 420 should be used
17219 * @param out_source Prepared shader source instance
17220 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17221 void BuiltInAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17222 Utils::shaderSource &out_source)
17223 {
17224 static const GLchar *min_verification_snippet = " gl_MinProgramTexelOffset += gl_MaxProgramTexelOffset\n"
17225 "\n"
17226 " if (expected_value != gl_MinProgramTexelOffset)\n"
17227 " {\n"
17228 " result = vec4(1, 0, 0, 1);\n"
17229 " }\n";
17230
17231 static const GLchar *max_verification_snippet = " gl_MaxProgramTexelOffset += gl_MinProgramTexelOffset\n"
17232 "\n"
17233 " if (expected_value != gl_MaxProgramTexelOffset)\n"
17234 " {\n"
17235 " result = vec4(1, 0, 0, 1);\n"
17236 " }\n";
17237
17238 static const GLchar *compute_shader_template =
17239 "VERSION\n"
17240 "\n"
17241 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17242 "\n"
17243 "writeonly uniform image2D uni_image;\n"
17244 " uniform ivec2 expected_values;\n"
17245 "\n"
17246 "void main()\n"
17247 "{\n"
17248 " vec4 result = vec4(0, 1, 0, 1);\n"
17249 "\n"
17250 "VERIFICATION"
17251 "\n"
17252 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17253 "}\n"
17254 "\n";
17255
17256 static const GLchar *fragment_shader_template = "VERSION\n"
17257 "\n"
17258 "in vec4 gs_fs_result;\n"
17259 "out vec4 fs_out_result;\n"
17260 "\n"
17261 "uniform ivec2 expected_values;\n"
17262 "\n"
17263 "void main()\n"
17264 "{\n"
17265 " vec4 result = vec4(0, 1, 0, 1);\n"
17266 "\n"
17267 "VERIFICATION"
17268 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17269 " {\n"
17270 " result = vec4(1, 0, 0, 1);\n"
17271 " }\n"
17272 "\n"
17273 " fs_out_result = result;\n"
17274 "}\n"
17275 "\n";
17276
17277 static const GLchar *geometry_shader_template = "VERSION\n"
17278 "\n"
17279 "layout(points) in;\n"
17280 "layout(triangle_strip, max_vertices = 4) out;\n"
17281 "\n"
17282 "in vec4 tes_gs_result[];\n"
17283 "out vec4 gs_fs_result;\n"
17284 "\n"
17285 "uniform ivec2 expected_values;\n"
17286 "\n"
17287 "void main()\n"
17288 "{\n"
17289 " vec4 result = vec4(0, 1, 0, 1);\n"
17290 "\n"
17291 "VERIFICATION"
17292 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17293 " {\n"
17294 " result = vec4(1, 0, 0, 1);\n"
17295 " }\n"
17296 "\n"
17297 " gs_fs_result = result;\n"
17298 " gl_Position = vec4(-1, -1, 0, 1);\n"
17299 " EmitVertex();\n"
17300 " gs_fs_result = result;\n"
17301 " gl_Position = vec4(-1, 1, 0, 1);\n"
17302 " EmitVertex();\n"
17303 " gs_fs_result = result;\n"
17304 " gl_Position = vec4(1, -1, 0, 1);\n"
17305 " EmitVertex();\n"
17306 " gs_fs_result = result;\n"
17307 " gl_Position = vec4(1, 1, 0, 1);\n"
17308 " EmitVertex();\n"
17309 "}\n"
17310 "\n";
17311
17312 static const GLchar *tess_ctrl_shader_template =
17313 "VERSION\n"
17314 "\n"
17315 "layout(vertices = 1) out;\n"
17316 "\n"
17317 "in vec4 vs_tcs_result[];\n"
17318 "out vec4 tcs_tes_result[];\n"
17319 "\n"
17320 "uniform ivec2 expected_values;\n"
17321 "\n"
17322 "void main()\n"
17323 "{\n"
17324 " vec4 result = vec4(0, 1, 0, 1);\n"
17325 "\n"
17326 "VERIFICATION"
17327 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17328 " {\n"
17329 " result = vec4(1, 0, 0, 1);\n"
17330 " }\n"
17331 "\n"
17332 " tcs_tes_result[gl_InvocationID] = result;\n"
17333 "\n"
17334 " gl_TessLevelOuter[0] = 1.0;\n"
17335 " gl_TessLevelOuter[1] = 1.0;\n"
17336 " gl_TessLevelOuter[2] = 1.0;\n"
17337 " gl_TessLevelOuter[3] = 1.0;\n"
17338 " gl_TessLevelInner[0] = 1.0;\n"
17339 " gl_TessLevelInner[1] = 1.0;\n"
17340 "}\n"
17341 "\n";
17342
17343 static const GLchar *tess_eval_shader_template = "VERSION\n"
17344 "\n"
17345 "layout(isolines, point_mode) in;\n"
17346 "\n"
17347 "in vec4 tcs_tes_result[];\n"
17348 "out vec4 tes_gs_result;\n"
17349 "\n"
17350 "uniform ivec2 expected_values;\n"
17351 "\n"
17352 "void main()\n"
17353 "{\n"
17354 " vec4 result = vec4(0, 1, 0, 1);\n"
17355 "\n"
17356 "VERIFICATION"
17357 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17358 " {\n"
17359 " result = vec4(1, 0, 0, 1);\n"
17360 " }\n"
17361 "\n"
17362 " tes_gs_result = result;\n"
17363 "}\n"
17364 "\n";
17365
17366 static const GLchar *vertex_shader_template = "VERSION\n"
17367 "\n"
17368 "out vec4 vs_tcs_result;\n"
17369 "\n"
17370 "uniform ivec2 expected_values;\n"
17371 "\n"
17372 "void main()\n"
17373 "{\n"
17374 " vec4 result = vec4(0, 1, 0, 1);\n"
17375 "\n"
17376 "VERIFICATION"
17377 "\n"
17378 " vs_tcs_result = result;\n"
17379 "}\n"
17380 "\n";
17381
17382 const GLchar *shader_template = 0;
17383 const GLchar *verification_snippet = 0;
17384
17385 switch (in_stage)
17386 {
17387 case Utils::COMPUTE_SHADER:
17388 shader_template = compute_shader_template;
17389 break;
17390 case Utils::FRAGMENT_SHADER:
17391 shader_template = fragment_shader_template;
17392 break;
17393 case Utils::GEOMETRY_SHADER:
17394 shader_template = geometry_shader_template;
17395 break;
17396 case Utils::TESS_CTRL_SHADER:
17397 shader_template = tess_ctrl_shader_template;
17398 break;
17399 case Utils::TESS_EVAL_SHADER:
17400 shader_template = tess_eval_shader_template;
17401 break;
17402 case Utils::VERTEX_SHADER:
17403 shader_template = vertex_shader_template;
17404 break;
17405 default:
17406 TCU_FAIL("Invalid enum");
17407 }
17408
17409 switch (m_case)
17410 {
17411 case (glw::GLuint)-1:
17412 case 0:
17413 verification_snippet = min_verification_snippet;
17414 break;
17415 case 1:
17416 verification_snippet = max_verification_snippet;
17417 break;
17418 }
17419
17420 out_source.m_parts[0].m_code = shader_template;
17421
17422 size_t position = 0;
17423 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17424 out_source.m_parts[0].m_code);
17425
17426 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17427 }
17428
17429 /** Constructor.
17430 *
17431 * @param context CTS context.
17432 **/
buffer(deqp::Context & context)17433 Utils::buffer::buffer(deqp::Context &context) : m_id(0), m_context(context), m_target(0)
17434 {
17435 }
17436
17437 /** Destructor
17438 *
17439 **/
~buffer()17440 Utils::buffer::~buffer()
17441 {
17442 release();
17443 }
17444
17445 /** Execute BindBuffer
17446 *
17447 **/
bind() const17448 void Utils::buffer::bind() const
17449 {
17450 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17451
17452 gl.bindBuffer(m_target, m_id);
17453 GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
17454 }
17455
17456 /** Execute BindBufferRange
17457 *
17458 * @param index <index> parameter
17459 * @param offset <offset> parameter
17460 * @param size <size> parameter
17461 **/
bindRange(glw::GLuint index,glw::GLintptr offset,glw::GLsizeiptr size)17462 void Utils::buffer::bindRange(glw::GLuint index, glw::GLintptr offset, glw::GLsizeiptr size)
17463 {
17464 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17465
17466 gl.bindBufferRange(m_target, index, m_id, offset, size);
17467 GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
17468 }
17469
17470 /** Execute GenBuffer
17471 *
17472 * @param target Target that will be used by this buffer
17473 **/
generate(glw::GLenum target)17474 void Utils::buffer::generate(glw::GLenum target)
17475 {
17476 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17477
17478 m_target = target;
17479
17480 gl.genBuffers(1, &m_id);
17481 GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
17482 }
17483
17484 /** Maps buffer content
17485 *
17486 * @param access Access rights for mapped region
17487 *
17488 * @return Mapped memory
17489 **/
map(GLenum access) const17490 void *Utils::buffer::map(GLenum access) const
17491 {
17492 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17493
17494 gl.bindBuffer(m_target, m_id);
17495 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17496
17497 void *result = gl.mapBuffer(m_target, access);
17498 GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
17499
17500 return result;
17501 }
17502
17503 /** Unmaps buffer
17504 *
17505 **/
unmap() const17506 void Utils::buffer::unmap() const
17507 {
17508 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17509
17510 gl.bindBuffer(m_target, m_id);
17511 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17512
17513 gl.unmapBuffer(m_target);
17514 GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
17515 }
17516
17517 /** Execute BufferData
17518 *
17519 * @param size <size> parameter
17520 * @param data <data> parameter
17521 * @param usage <usage> parameter
17522 **/
update(glw::GLsizeiptr size,glw::GLvoid * data,glw::GLenum usage)17523 void Utils::buffer::update(glw::GLsizeiptr size, glw::GLvoid *data, glw::GLenum usage)
17524 {
17525 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17526
17527 gl.bindBuffer(m_target, m_id);
17528 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17529
17530 gl.bufferData(m_target, size, data, usage);
17531 GLU_EXPECT_NO_ERROR(gl.getError(), "bufferData");
17532 }
17533
17534 /** Release buffer
17535 *
17536 **/
release()17537 void Utils::buffer::release()
17538 {
17539 if (0 != m_id)
17540 {
17541 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17542
17543 gl.deleteBuffers(1, &m_id);
17544 m_id = 0;
17545 }
17546 }
17547
17548 /** Constructor
17549 *
17550 * @param context CTS context
17551 **/
framebuffer(deqp::Context & context)17552 Utils::framebuffer::framebuffer(deqp::Context &context) : m_id(0), m_context(context)
17553 {
17554 /* Nothing to be done here */
17555 }
17556
17557 /** Destructor
17558 *
17559 **/
~framebuffer()17560 Utils::framebuffer::~framebuffer()
17561 {
17562 if (0 != m_id)
17563 {
17564 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17565
17566 gl.deleteFramebuffers(1, &m_id);
17567 m_id = 0;
17568 }
17569 }
17570
17571 /** Attach texture to specified attachment
17572 *
17573 * @param attachment Attachment
17574 * @param texture_id Texture id
17575 * @param width Texture width
17576 * @param height Texture height
17577 **/
attachTexture(glw::GLenum attachment,glw::GLuint texture_id,glw::GLuint width,glw::GLuint height)17578 void Utils::framebuffer::attachTexture(glw::GLenum attachment, glw::GLuint texture_id, glw::GLuint width,
17579 glw::GLuint height)
17580 {
17581 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17582
17583 bind();
17584
17585 gl.bindTexture(GL_TEXTURE_2D, texture_id);
17586 GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
17587
17588 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture_id, 0 /* level */);
17589 GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture2D");
17590
17591 gl.viewport(0 /* x */, 0 /* y */, width, height);
17592 GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
17593 }
17594
17595 /** Binds framebuffer to DRAW_FRAMEBUFFER
17596 *
17597 **/
bind()17598 void Utils::framebuffer::bind()
17599 {
17600 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17601
17602 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_id);
17603 GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
17604 }
17605
17606 /** Clear framebuffer
17607 *
17608 * @param mask <mask> parameter of glClear. Decides which shall be cleared
17609 **/
clear(glw::GLenum mask)17610 void Utils::framebuffer::clear(glw::GLenum mask)
17611 {
17612 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17613
17614 gl.clear(mask);
17615 GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
17616 }
17617
17618 /** Specifies clear color
17619 *
17620 * @param red Red channel
17621 * @param green Green channel
17622 * @param blue Blue channel
17623 * @param alpha Alpha channel
17624 **/
clearColor(GLfloat red,GLfloat green,GLfloat blue,GLfloat alpha)17625 void Utils::framebuffer::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
17626 {
17627 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17628
17629 gl.clearColor(red, green, blue, alpha);
17630 GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
17631 }
17632
17633 /** Generate framebuffer
17634 *
17635 **/
generate()17636 void Utils::framebuffer::generate()
17637 {
17638 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17639
17640 gl.genFramebuffers(1, &m_id);
17641 GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
17642 }
17643
shaderSource()17644 Utils::shaderSource::shaderSource()
17645 {
17646 }
17647
shaderSource(const shaderSource & source)17648 Utils::shaderSource::shaderSource(const shaderSource &source) : m_parts(source.m_parts), m_use_lengths(false)
17649 {
17650 }
17651
shaderSource(const glw::GLchar * source_code)17652 Utils::shaderSource::shaderSource(const glw::GLchar *source_code) : m_use_lengths(false)
17653 {
17654 if (0 != source_code)
17655 {
17656 m_parts.resize(1);
17657
17658 m_parts[0].m_code = source_code;
17659 }
17660 }
17661
shaderCompilationException(const shaderSource & source,const glw::GLchar * message)17662 Utils::shaderCompilationException::shaderCompilationException(const shaderSource &source, const glw::GLchar *message)
17663 : m_shader_source(source)
17664 , m_error_message(message)
17665 {
17666 /* Nothing to be done */
17667 }
17668
what() const17669 const char *Utils::shaderCompilationException::what() const throw()
17670 {
17671 return "Shader compilation failed";
17672 }
17673
programLinkageException(const glw::GLchar * message)17674 Utils::programLinkageException::programLinkageException(const glw::GLchar *message) : m_error_message(message)
17675 {
17676 /* Nothing to be done */
17677 }
17678
what() const17679 const char *Utils::programLinkageException::what() const throw()
17680 {
17681 return "Program linking failed";
17682 }
17683
17684 const glw::GLenum Utils::program::ARB_COMPUTE_SHADER = 0x91B9;
17685
17686 /** Constructor.
17687 *
17688 * @param context CTS context.
17689 **/
program(deqp::Context & context)17690 Utils::program::program(deqp::Context &context)
17691 : m_compute_shader_id(0)
17692 , m_fragment_shader_id(0)
17693 , m_geometry_shader_id(0)
17694 , m_program_object_id(0)
17695 , m_tesselation_control_shader_id(0)
17696 , m_tesselation_evaluation_shader_id(0)
17697 , m_vertex_shader_id(0)
17698 , m_context(context)
17699 {
17700 /* Nothing to be done here */
17701 }
17702
17703 /** Destructor
17704 *
17705 **/
~program()17706 Utils::program::~program()
17707 {
17708 remove();
17709 }
17710
17711 /** Build program
17712 *
17713 * @param compute_shader_code Compute shader source code
17714 * @param fragment_shader_code Fragment shader source code
17715 * @param geometry_shader_code Geometry shader source code
17716 * @param tesselation_control_shader_code Tesselation control shader source code
17717 * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17718 * @param vertex_shader_code Vertex shader source code
17719 * @param varying_names Array of strings containing names of varyings to be captured with transfrom feedback
17720 * @param n_varying_names Number of varyings to be captured with transfrom feedback
17721 * @param is_separable Selects if monolithis or separable program should be built. Defaults to false
17722 **/
build(const glw::GLchar * compute_shader_code,const glw::GLchar * fragment_shader_code,const glw::GLchar * geometry_shader_code,const glw::GLchar * tesselation_control_shader_code,const glw::GLchar * tesselation_evaluation_shader_code,const glw::GLchar * vertex_shader_code,const glw::GLchar * const * varying_names,glw::GLuint n_varying_names,bool is_separable)17723 void Utils::program::build(const glw::GLchar *compute_shader_code, const glw::GLchar *fragment_shader_code,
17724 const glw::GLchar *geometry_shader_code, const glw::GLchar *tesselation_control_shader_code,
17725 const glw::GLchar *tesselation_evaluation_shader_code, const glw::GLchar *vertex_shader_code,
17726 const glw::GLchar *const *varying_names, glw::GLuint n_varying_names, bool is_separable)
17727 {
17728 const shaderSource compute_shader(compute_shader_code);
17729 const shaderSource fragment_shader(fragment_shader_code);
17730 const shaderSource geometry_shader(geometry_shader_code);
17731 const shaderSource tesselation_control_shader(tesselation_control_shader_code);
17732 const shaderSource tesselation_evaluation_shader(tesselation_evaluation_shader_code);
17733 const shaderSource vertex_shader(vertex_shader_code);
17734
17735 build(compute_shader, fragment_shader, geometry_shader, tesselation_control_shader, tesselation_evaluation_shader,
17736 vertex_shader, varying_names, n_varying_names, is_separable);
17737 }
17738
17739 /** Build program
17740 *
17741 * @param compute_shader_code Compute shader source code
17742 * @param fragment_shader_code Fragment shader source code
17743 * @param geometry_shader_code Geometry shader source code
17744 * @param tesselation_control_shader_code Tesselation control shader source code
17745 * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17746 * @param vertex_shader_code Vertex shader source code
17747 * @param varying_names Array of strings containing names of varyings to be captured with transfrom feedback
17748 * @param n_varying_names Number of varyings to be captured with transfrom feedback
17749 * @param is_separable Selects if monolithis or separable program should be built. Defaults to false
17750 **/
build(const shaderSource & compute_shader,const shaderSource & fragment_shader,const shaderSource & geometry_shader,const shaderSource & tesselation_control_shader,const shaderSource & tesselation_evaluation_shader,const shaderSource & vertex_shader,const glw::GLchar * const * varying_names,glw::GLuint n_varying_names,bool is_separable)17751 void Utils::program::build(const shaderSource &compute_shader, const shaderSource &fragment_shader,
17752 const shaderSource &geometry_shader, const shaderSource &tesselation_control_shader,
17753 const shaderSource &tesselation_evaluation_shader, const shaderSource &vertex_shader,
17754 const glw::GLchar *const *varying_names, glw::GLuint n_varying_names, bool is_separable)
17755 {
17756 /* GL entry points */
17757 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17758
17759 /* Create shader objects and compile */
17760 if (false == compute_shader.m_parts.empty())
17761 {
17762 m_compute_shader_id = gl.createShader(ARB_COMPUTE_SHADER);
17763 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17764
17765 compile(m_compute_shader_id, compute_shader);
17766 }
17767
17768 if (false == fragment_shader.m_parts.empty())
17769 {
17770 m_fragment_shader_id = gl.createShader(GL_FRAGMENT_SHADER);
17771 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17772
17773 compile(m_fragment_shader_id, fragment_shader);
17774 }
17775
17776 if (false == geometry_shader.m_parts.empty())
17777 {
17778 m_geometry_shader_id = gl.createShader(GL_GEOMETRY_SHADER);
17779 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17780
17781 compile(m_geometry_shader_id, geometry_shader);
17782 }
17783
17784 if (false == tesselation_control_shader.m_parts.empty())
17785 {
17786 m_tesselation_control_shader_id = gl.createShader(GL_TESS_CONTROL_SHADER);
17787 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17788
17789 compile(m_tesselation_control_shader_id, tesselation_control_shader);
17790 }
17791
17792 if (false == tesselation_evaluation_shader.m_parts.empty())
17793 {
17794 m_tesselation_evaluation_shader_id = gl.createShader(GL_TESS_EVALUATION_SHADER);
17795 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17796
17797 compile(m_tesselation_evaluation_shader_id, tesselation_evaluation_shader);
17798 }
17799
17800 if (false == vertex_shader.m_parts.empty())
17801 {
17802 m_vertex_shader_id = gl.createShader(GL_VERTEX_SHADER);
17803 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17804
17805 compile(m_vertex_shader_id, vertex_shader);
17806 }
17807
17808 /* Create program object */
17809 m_program_object_id = gl.createProgram();
17810 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
17811
17812 /* Set up captyured varyings' names */
17813 if (0 != n_varying_names)
17814 {
17815 gl.transformFeedbackVaryings(m_program_object_id, n_varying_names, varying_names, GL_INTERLEAVED_ATTRIBS);
17816 GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
17817 }
17818
17819 /* Set separable parameter */
17820 if (true == is_separable)
17821 {
17822 gl.programParameteri(m_program_object_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
17823 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
17824 }
17825
17826 /* Link program */
17827 link();
17828 }
17829
compile(glw::GLuint shader_id,const Utils::shaderSource & source) const17830 void Utils::program::compile(glw::GLuint shader_id, const Utils::shaderSource &source) const
17831 {
17832 /* GL entry points */
17833 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17834
17835 /* Compilation status */
17836 glw::GLint status = GL_FALSE;
17837
17838 /* Source parts and lengths vectors */
17839 std::vector<const GLchar *> parts;
17840 std::vector<GLint> lengths_vector;
17841 GLint *lengths = 0;
17842
17843 /* Prepare storage */
17844 parts.resize(source.m_parts.size());
17845
17846 /* Prepare arrays */
17847 for (GLuint i = 0; i < source.m_parts.size(); ++i)
17848 {
17849 parts[i] = source.m_parts[i].m_code.c_str();
17850 }
17851
17852 if (true == source.m_use_lengths)
17853 {
17854 lengths_vector.resize(source.m_parts.size());
17855
17856 for (GLuint i = 0; i < source.m_parts.size(); ++i)
17857 {
17858 lengths_vector[i] = source.m_parts[i].m_length;
17859 }
17860
17861 lengths = &lengths_vector[0];
17862 }
17863
17864 /* Set source code */
17865 gl.shaderSource(shader_id, static_cast<GLsizei>(source.m_parts.size()), &parts[0], lengths);
17866 GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
17867
17868 /* Compile */
17869 gl.compileShader(shader_id);
17870 GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
17871
17872 /* Get compilation status */
17873 gl.getShaderiv(shader_id, GL_COMPILE_STATUS, &status);
17874 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
17875
17876 /* Log compilation error */
17877 if (GL_TRUE != status)
17878 {
17879 glw::GLint length = 0;
17880 std::vector<glw::GLchar> message;
17881
17882 /* Error log length */
17883 gl.getShaderiv(shader_id, GL_INFO_LOG_LENGTH, &length);
17884 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
17885
17886 /* Prepare storage */
17887 message.resize(length);
17888
17889 /* Get error log */
17890 gl.getShaderInfoLog(shader_id, length, 0, &message[0]);
17891 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
17892
17893 throw shaderCompilationException(source, &message[0]);
17894 }
17895 }
17896
17897 /** Create program from provided binary
17898 *
17899 * @param binary Buffer with binary form of program
17900 * @param binary_format Format of <binary> data
17901 **/
createFromBinary(const std::vector<GLubyte> & binary,GLenum binary_format)17902 void Utils::program::createFromBinary(const std::vector<GLubyte> &binary, GLenum binary_format)
17903 {
17904 /* GL entry points */
17905 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17906
17907 /* Create program object */
17908 m_program_object_id = gl.createProgram();
17909 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
17910
17911 gl.programBinary(m_program_object_id, binary_format, &binary[0], static_cast<GLsizei>(binary.size()));
17912 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramBinary");
17913 }
17914
getAttribLocation(const glw::GLchar * name) const17915 glw::GLint Utils::program::getAttribLocation(const glw::GLchar *name) const
17916 {
17917 /* GL entry points */
17918 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17919
17920 GLint location = gl.getAttribLocation(m_program_object_id, name);
17921 GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
17922
17923 return location;
17924 }
17925
17926 /** Get binary form of program
17927 *
17928 * @param binary Buffer for binary data
17929 * @param binary_format Format of binary data
17930 **/
getBinary(std::vector<GLubyte> & binary,GLenum & binary_format) const17931 void Utils::program::getBinary(std::vector<GLubyte> &binary, GLenum &binary_format) const
17932 {
17933 /* GL entry points */
17934 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17935
17936 /* Get binary size */
17937 GLint length = 0;
17938 gl.getProgramiv(m_program_object_id, GL_PROGRAM_BINARY_LENGTH, &length);
17939 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
17940
17941 /* Allocate storage */
17942 binary.resize(length);
17943
17944 /* Get binary */
17945 gl.getProgramBinary(m_program_object_id, static_cast<GLsizei>(binary.size()), &length, &binary_format, &binary[0]);
17946 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramBinary");
17947 }
17948
17949 /** Get subroutine index
17950 *
17951 * @param subroutine_name Subroutine name
17952 *
17953 * @return Index of subroutine
17954 **/
getSubroutineIndex(const glw::GLchar * subroutine_name,glw::GLenum shader_stage) const17955 GLuint Utils::program::getSubroutineIndex(const glw::GLchar *subroutine_name, glw::GLenum shader_stage) const
17956 {
17957 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17958 GLuint index = -1;
17959
17960 index = gl.getSubroutineIndex(m_program_object_id, shader_stage, subroutine_name);
17961 GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineIndex");
17962
17963 if (GL_INVALID_INDEX == index)
17964 {
17965 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine: " << subroutine_name
17966 << " is not available" << tcu::TestLog::EndMessage;
17967
17968 TCU_FAIL("Subroutine is not available");
17969 }
17970
17971 return index;
17972 }
17973
17974 /** Get subroutine uniform location
17975 *
17976 * @param uniform_name Subroutine uniform name
17977 *
17978 * @return Location of subroutine uniform
17979 **/
getSubroutineUniformLocation(const glw::GLchar * uniform_name,glw::GLenum shader_stage) const17980 GLint Utils::program::getSubroutineUniformLocation(const glw::GLchar *uniform_name, glw::GLenum shader_stage) const
17981 {
17982 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17983 GLint location = -1;
17984
17985 location = gl.getSubroutineUniformLocation(m_program_object_id, shader_stage, uniform_name);
17986 GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineUniformLocation");
17987
17988 if (-1 == location)
17989 {
17990 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine uniform: " << uniform_name
17991 << " is not available" << tcu::TestLog::EndMessage;
17992
17993 TCU_FAIL("Subroutine uniform is not available");
17994 }
17995
17996 return location;
17997 }
17998
17999 /** Get integer uniform at given location
18000 *
18001 * @param location Uniform location
18002 *
18003 * @return Value
18004 **/
getUniform1i(GLuint location) const18005 GLint Utils::program::getUniform1i(GLuint location) const
18006 {
18007 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18008
18009 GLint result;
18010
18011 gl.getUniformiv(m_program_object_id, location, &result);
18012 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformiv");
18013
18014 return result;
18015 }
18016
18017 /** Get uniform location
18018 *
18019 * @param uniform_name Subroutine uniform name
18020 *
18021 * @return Location of uniform
18022 **/
getUniformLocation(const glw::GLchar * uniform_name) const18023 GLint Utils::program::getUniformLocation(const glw::GLchar *uniform_name) const
18024 {
18025 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18026 GLint location = -1;
18027
18028 location = gl.getUniformLocation(m_program_object_id, uniform_name);
18029 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
18030
18031 if (-1 == location)
18032 {
18033 m_context.getTestContext().getLog()
18034 << tcu::TestLog::Message << "Uniform: " << uniform_name << " is not available" << tcu::TestLog::EndMessage;
18035
18036 TCU_FAIL("Uniform is not available");
18037 }
18038
18039 return location;
18040 }
18041
18042 /** Attach shaders and link program
18043 *
18044 **/
link() const18045 void Utils::program::link() const
18046 {
18047 /* GL entry points */
18048 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18049
18050 /* Link status */
18051 glw::GLint status = GL_FALSE;
18052
18053 /* Attach shaders */
18054 if (0 != m_compute_shader_id)
18055 {
18056 gl.attachShader(m_program_object_id, m_compute_shader_id);
18057 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18058 }
18059
18060 if (0 != m_fragment_shader_id)
18061 {
18062 gl.attachShader(m_program_object_id, m_fragment_shader_id);
18063 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18064 }
18065
18066 if (0 != m_geometry_shader_id)
18067 {
18068 gl.attachShader(m_program_object_id, m_geometry_shader_id);
18069 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18070 }
18071
18072 if (0 != m_tesselation_control_shader_id)
18073 {
18074 gl.attachShader(m_program_object_id, m_tesselation_control_shader_id);
18075 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18076 }
18077
18078 if (0 != m_tesselation_evaluation_shader_id)
18079 {
18080 gl.attachShader(m_program_object_id, m_tesselation_evaluation_shader_id);
18081 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18082 }
18083
18084 if (0 != m_vertex_shader_id)
18085 {
18086 gl.attachShader(m_program_object_id, m_vertex_shader_id);
18087 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18088 }
18089
18090 /* Link */
18091 gl.linkProgram(m_program_object_id);
18092 GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
18093
18094 /* Get link status */
18095 gl.getProgramiv(m_program_object_id, GL_LINK_STATUS, &status);
18096 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18097
18098 /* Log link error */
18099 if (GL_TRUE != status)
18100 {
18101 glw::GLint length = 0;
18102 std::vector<glw::GLchar> message;
18103
18104 /* Get error log length */
18105 gl.getProgramiv(m_program_object_id, GL_INFO_LOG_LENGTH, &length);
18106 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18107
18108 message.resize(length);
18109
18110 /* Get error log */
18111 gl.getProgramInfoLog(m_program_object_id, length, 0, &message[0]);
18112 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
18113
18114 throw programLinkageException(&message[0]);
18115 }
18116 }
18117
18118 /** Delete program object and all attached shaders
18119 *
18120 **/
remove()18121 void Utils::program::remove()
18122 {
18123 /* GL entry points */
18124 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18125
18126 /* Make sure program object is no longer used by GL */
18127 gl.useProgram(0);
18128
18129 /* Clean program object */
18130 if (0 != m_program_object_id)
18131 {
18132 gl.deleteProgram(m_program_object_id);
18133 m_program_object_id = 0;
18134 }
18135
18136 /* Clean shaders */
18137 if (0 != m_compute_shader_id)
18138 {
18139 gl.deleteShader(m_compute_shader_id);
18140 m_compute_shader_id = 0;
18141 }
18142
18143 if (0 != m_fragment_shader_id)
18144 {
18145 gl.deleteShader(m_fragment_shader_id);
18146 m_fragment_shader_id = 0;
18147 }
18148
18149 if (0 != m_geometry_shader_id)
18150 {
18151 gl.deleteShader(m_geometry_shader_id);
18152 m_geometry_shader_id = 0;
18153 }
18154
18155 if (0 != m_tesselation_control_shader_id)
18156 {
18157 gl.deleteShader(m_tesselation_control_shader_id);
18158 m_tesselation_control_shader_id = 0;
18159 }
18160
18161 if (0 != m_tesselation_evaluation_shader_id)
18162 {
18163 gl.deleteShader(m_tesselation_evaluation_shader_id);
18164 m_tesselation_evaluation_shader_id = 0;
18165 }
18166
18167 if (0 != m_vertex_shader_id)
18168 {
18169 gl.deleteShader(m_vertex_shader_id);
18170 m_vertex_shader_id = 0;
18171 }
18172 }
18173
uniform(const glw::GLchar * uniform_name,TYPES type,glw::GLuint n_columns,glw::GLuint n_rows,const void * data) const18174 void Utils::program::uniform(const glw::GLchar *uniform_name, TYPES type, glw::GLuint n_columns, glw::GLuint n_rows,
18175 const void *data) const
18176 {
18177 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18178
18179 GLuint location = getUniformLocation(uniform_name);
18180
18181 if ((glw::GLuint)-1 == location)
18182 {
18183 TCU_FAIL("Uniform is inactive");
18184 }
18185
18186 switch (type)
18187 {
18188 case DOUBLE:
18189 if (1 == n_columns)
18190 {
18191 getUniformNdv(gl, n_rows)(location, 1 /* count */, (const GLdouble *)data);
18192 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
18193 }
18194 else
18195 {
18196 getUniformMatrixNdv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLdouble *)data);
18197 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
18198 }
18199 break;
18200 case FLOAT:
18201 if (1 == n_columns)
18202 {
18203 getUniformNfv(gl, n_rows)(location, 1 /* count */, (const GLfloat *)data);
18204 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
18205 }
18206 else
18207 {
18208 getUniformMatrixNfv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLfloat *)data);
18209 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
18210 }
18211 break;
18212 case INT:
18213 getUniformNiv(gl, n_rows)(location, 1 /* count */, (const GLint *)data);
18214 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
18215 break;
18216 case UINT:
18217 getUniformNuiv(gl, n_rows)(location, 1 /* count */, (const GLuint *)data);
18218 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
18219 break;
18220 default:
18221 TCU_FAIL("Invalid enum");
18222 }
18223 }
18224
18225 /** Execute UseProgram
18226 *
18227 **/
use() const18228 void Utils::program::use() const
18229 {
18230 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18231
18232 gl.useProgram(m_program_object_id);
18233 GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
18234 }
18235
printShaderSource(const shaderSource & source,tcu::MessageBuilder & log)18236 void Utils::program::printShaderSource(const shaderSource &source, tcu::MessageBuilder &log)
18237 {
18238 GLuint line_number = 0;
18239
18240 log << "Shader source.";
18241
18242 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18243 {
18244 log << "\nLine||Part: " << (i + 1) << "/" << source.m_parts.size();
18245
18246 if (true == source.m_use_lengths)
18247 {
18248 log << " Length: " << source.m_parts[i].m_length;
18249 }
18250
18251 log << "\n";
18252
18253 const GLchar *part = source.m_parts[i].m_code.c_str();
18254
18255 while (0 != part)
18256 {
18257 std::string line;
18258 const GLchar *next_line = strchr(part, '\n');
18259
18260 if (0 != next_line)
18261 {
18262 next_line += 1;
18263 line.assign(part, next_line - part);
18264 }
18265 else
18266 {
18267 line = part;
18268 }
18269
18270 if (0 != *part)
18271 {
18272 log << std::setw(4) << line_number << "||" << line;
18273 }
18274
18275 part = next_line;
18276 line_number += 1;
18277 }
18278 }
18279 }
18280
18281 /** Constructor.
18282 *
18283 * @param context CTS context.
18284 **/
texture(deqp::Context & context)18285 Utils::texture::texture(deqp::Context &context) : m_id(0), m_buffer_id(0), m_context(context), m_texture_type(TEX_2D)
18286 {
18287 /* Nothing to done here */
18288 }
18289
18290 /** Destructor
18291 *
18292 **/
~texture()18293 Utils::texture::~texture()
18294 {
18295 release();
18296 }
18297
18298 /** Bind texture to GL_TEXTURE_2D
18299 *
18300 **/
bind() const18301 void Utils::texture::bind() const
18302 {
18303 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18304
18305 GLenum target = getTextureTartet(m_texture_type);
18306
18307 gl.bindTexture(target, m_id);
18308 GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
18309 }
18310
18311 /** Create 2d texture
18312 *
18313 * @param width Width of texture
18314 * @param height Height of texture
18315 * @param internal_format Internal format of texture
18316 **/
create(glw::GLuint width,glw::GLuint height,glw::GLenum internal_format)18317 void Utils::texture::create(glw::GLuint width, glw::GLuint height, glw::GLenum internal_format)
18318 {
18319 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18320
18321 release();
18322
18323 m_texture_type = TEX_2D;
18324
18325 gl.genTextures(1, &m_id);
18326 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18327
18328 bind();
18329
18330 gl.texStorage2D(GL_TEXTURE_2D, 1 /* levels */, internal_format, width, height);
18331 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18332 }
18333
18334 /** Create texture of given type
18335 *
18336 * @param width Width of texture
18337 * @param height Height of texture
18338 * @param depth Depth of texture
18339 * @param internal_format Internal format of texture
18340 * @param texture_type Type of texture
18341 **/
create(GLuint width,GLuint height,GLuint depth,GLenum internal_format,TEXTURE_TYPES texture_type)18342 void Utils::texture::create(GLuint width, GLuint height, GLuint depth, GLenum internal_format,
18343 TEXTURE_TYPES texture_type)
18344 {
18345 static const GLuint levels = 1;
18346
18347 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18348
18349 release();
18350
18351 m_texture_type = texture_type;
18352
18353 GLenum target = getTextureTartet(m_texture_type);
18354
18355 gl.genTextures(1, &m_id);
18356 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18357
18358 bind();
18359
18360 switch (m_texture_type)
18361 {
18362 case TEX_1D:
18363 gl.texStorage1D(target, levels, internal_format, width);
18364 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18365 break;
18366 case TEX_2D:
18367 case TEX_1D_ARRAY:
18368 case TEX_2D_RECT:
18369 case TEX_CUBE:
18370 gl.texStorage2D(target, levels, internal_format, width, height);
18371 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18372 break;
18373 case TEX_3D:
18374 case TEX_2D_ARRAY:
18375 gl.texStorage3D(target, levels, internal_format, width, height, depth);
18376 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18377 break;
18378 default:
18379 TCU_FAIL("Invliad enum");
18380 }
18381 }
18382
18383 /** Create buffer texture
18384 *
18385 * @param internal_format Internal format of texture
18386 * @param buffer_id Id of buffer that will be used as data source
18387 **/
createBuffer(GLenum internal_format,GLuint buffer_id)18388 void Utils::texture::createBuffer(GLenum internal_format, GLuint buffer_id)
18389 {
18390 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18391
18392 release();
18393
18394 m_texture_type = TEX_BUFFER;
18395 m_buffer_id = buffer_id;
18396
18397 gl.genTextures(1, &m_id);
18398 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18399
18400 bind();
18401
18402 gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
18403 GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
18404 }
18405
18406 /** Get contents of texture
18407 *
18408 * @param format Format of image
18409 * @param type Type of image
18410 * @param out_data Buffer for image
18411 **/
get(glw::GLenum format,glw::GLenum type,glw::GLvoid * out_data) const18412 void Utils::texture::get(glw::GLenum format, glw::GLenum type, glw::GLvoid *out_data) const
18413 {
18414 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18415
18416 GLenum target = getTextureTartet(m_texture_type);
18417
18418 bind();
18419
18420 gl.memoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
18421 GLU_EXPECT_NO_ERROR(gl.getError(), "MemoryBarrier");
18422
18423 if (TEX_CUBE != m_texture_type)
18424 {
18425 gl.getTexImage(target, 0 /* level */, format, type, out_data);
18426 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18427 }
18428 else
18429 {
18430 GLint width;
18431 GLint height;
18432
18433 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
18434 {
18435 TCU_FAIL("Not implemented");
18436 }
18437
18438 GLuint texel_size = 4;
18439
18440 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
18441 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18442
18443 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
18444 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18445
18446 const GLuint image_size = width * height * texel_size;
18447
18448 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
18449 (GLvoid *)((GLchar *)out_data + (image_size * 0)));
18450 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
18451 (GLvoid *)((GLchar *)out_data + (image_size * 1)));
18452 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
18453 (GLvoid *)((GLchar *)out_data + (image_size * 2)));
18454 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
18455 (GLvoid *)((GLchar *)out_data + (image_size * 3)));
18456 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
18457 (GLvoid *)((GLchar *)out_data + (image_size * 4)));
18458 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
18459 (GLvoid *)((GLchar *)out_data + (image_size * 5)));
18460 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18461 }
18462 }
18463
18464 /** Delete texture
18465 *
18466 **/
release()18467 void Utils::texture::release()
18468 {
18469 if (0 != m_id)
18470 {
18471 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18472
18473 gl.deleteTextures(1, &m_id);
18474 m_id = 0;
18475
18476 if ((m_texture_type == TEX_BUFFER) && (0 != m_buffer_id))
18477 {
18478 gl.deleteBuffers(1, &m_buffer_id);
18479 m_buffer_id = 0;
18480 }
18481 }
18482 }
18483
18484 /** Update contents of texture
18485 *
18486 * @param width Width of texture
18487 * @param height Height of texture
18488 * @param format Format of data
18489 * @param type Type of data
18490 * @param data Buffer with image
18491 **/
update(glw::GLuint width,glw::GLuint height,glw::GLuint depth,glw::GLenum format,glw::GLenum type,glw::GLvoid * data)18492 void Utils::texture::update(glw::GLuint width, glw::GLuint height, glw::GLuint depth, glw::GLenum format,
18493 glw::GLenum type, glw::GLvoid *data)
18494 {
18495 static const GLuint level = 0;
18496
18497 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18498
18499 GLenum target = getTextureTartet(m_texture_type);
18500
18501 bind();
18502
18503 switch (m_texture_type)
18504 {
18505 case TEX_1D:
18506 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
18507 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18508 break;
18509 case TEX_2D:
18510 case TEX_1D_ARRAY:
18511 case TEX_2D_RECT:
18512 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
18513 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18514 break;
18515 case TEX_CUBE:
18516 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18517 data);
18518 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18519 data);
18520 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18521 data);
18522 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18523 data);
18524 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18525 data);
18526 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18527 data);
18528 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18529 break;
18530 case TEX_3D:
18531 case TEX_2D_ARRAY:
18532 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
18533 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18534 break;
18535 default:
18536 TCU_FAIL("Invliad enum");
18537 }
18538 }
18539
18540 /** Constructor.
18541 *
18542 * @param context CTS context.
18543 **/
vertexArray(deqp::Context & context)18544 Utils::vertexArray::vertexArray(deqp::Context &context) : m_id(0), m_context(context)
18545 {
18546 }
18547
18548 /** Destructor
18549 *
18550 **/
~vertexArray()18551 Utils::vertexArray::~vertexArray()
18552 {
18553 if (0 != m_id)
18554 {
18555 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18556
18557 gl.deleteVertexArrays(1, &m_id);
18558
18559 m_id = 0;
18560 }
18561 }
18562
18563 /** Execute BindVertexArray
18564 *
18565 **/
bind()18566 void Utils::vertexArray::bind()
18567 {
18568 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18569
18570 gl.bindVertexArray(m_id);
18571 GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
18572 }
18573
18574 /** Execute GenVertexArrays
18575 *
18576 **/
generate()18577 void Utils::vertexArray::generate()
18578 {
18579 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18580
18581 gl.genVertexArrays(1, &m_id);
18582 GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
18583 }
18584 } // namespace GLSL420Pack
18585
18586 /** Constructor.
18587 *
18588 * @param context Rendering context.
18589 **/
ShadingLanguage420PackTests(deqp::Context & context)18590 ShadingLanguage420PackTests::ShadingLanguage420PackTests(deqp::Context &context)
18591 : TestCaseGroup(context, "shading_language_420pack", "Verifies \"shading_language_420pack\" functionality")
18592 {
18593 /* Left blank on purpose */
18594 }
18595
18596 /** Initializes a texture_storage_multisample test group.
18597 *
18598 **/
init(void)18599 void ShadingLanguage420PackTests::init(void)
18600 {
18601 addBindingSamplerSingleTest();
18602 addBindingImageSingleTest();
18603 addUTF8CharactersTest();
18604 addUTF8InSourceTest();
18605 addQualifierOrderTest();
18606 addQualifierOrderBlockTest();
18607 addLineContinuationTest();
18608 addChild(new GLSL420Pack::LineNumberingTest(m_context));
18609 addImplicitConversionsValidTest();
18610 addChild(new GLSL420Pack::ImplicitConversionsInvalidTest(m_context));
18611 addChild(new GLSL420Pack::ConstDynamicValueTest(m_context));
18612 addChild(new GLSL420Pack::ConstAssignmentTest(m_context));
18613 addChild(new GLSL420Pack::ConstDynamicValueAsConstExprTest(m_context));
18614 addQualifierOrderUniformTest();
18615 addQualifierOrderFunctionInoutTest();
18616 addQualifierOrderFunctionInputTest();
18617 addQualifierOrderFunctionOutputTest();
18618 addChild(new GLSL420Pack::QualifierOverrideLayoutTest(m_context));
18619 addChild(new GLSL420Pack::BindingUniformBlocksTest(m_context));
18620 addBindingUniformSingleBlockTest();
18621 addChild(new GLSL420Pack::BindingUniformBlockArrayTest(m_context));
18622 addChild(new GLSL420Pack::BindingUniformDefaultTest(m_context));
18623 addChild(new GLSL420Pack::BindingUniformAPIOverirdeTest(m_context));
18624 addChild(new GLSL420Pack::BindingUniformGlobalBlockTest(m_context));
18625 addBindingUniformInvalidTest();
18626 addBindingSamplersTest();
18627 addChild(new GLSL420Pack::BindingSamplerArrayTest(m_context));
18628 addChild(new GLSL420Pack::BindingSamplerDefaultTest(m_context));
18629 addChild(new GLSL420Pack::BindingSamplerAPIOverrideTest(m_context));
18630 addBindingSamplerInvalidTest();
18631 addBindingImagesTest();
18632 addChild(new GLSL420Pack::BindingImageArrayTest(m_context));
18633 addChild(new GLSL420Pack::BindingImageDefaultTest(m_context));
18634 addChild(new GLSL420Pack::BindingImageAPIOverrideTest(m_context));
18635 addBindingImageInvalidTest();
18636 addInitializerListTest();
18637 addInitializerListNegativeTest();
18638 addLengthOfVectorAndMatrixTest();
18639 addChild(new GLSL420Pack::LengthOfComputeResultTest(m_context));
18640 addChild(new GLSL420Pack::ScalarSwizzlersTest(m_context));
18641 addScalarSwizzlersInvalidTest();
18642 addChild(new GLSL420Pack::BuiltInValuesTest(m_context));
18643 addBuiltInAssignmentTest();
18644 }
18645
addBindingSamplerSingleTest()18646 void ShadingLanguage420PackTests::addBindingSamplerSingleTest()
18647 {
18648 std::vector<GLSL420Pack::Utils::SHADER_STAGES> stages{
18649 GLSL420Pack::Utils::VERTEX_SHADER, GLSL420Pack::Utils::TESS_CTRL_SHADER, GLSL420Pack::Utils::TESS_EVAL_SHADER,
18650 GLSL420Pack::Utils::GEOMETRY_SHADER, GLSL420Pack::Utils::FRAGMENT_SHADER};
18651
18652 for (GLSL420Pack::Utils::SHADER_STAGES &stage : stages)
18653 {
18654 addChild(new GLSL420Pack::BindingSamplerSingleTest(m_context, stage));
18655 }
18656 }
18657
addBindingImageSingleTest()18658 void ShadingLanguage420PackTests::addBindingImageSingleTest()
18659 {
18660 std::vector<GLSL420Pack::Utils::SHADER_STAGES> stages{
18661 GLSL420Pack::Utils::VERTEX_SHADER, GLSL420Pack::Utils::TESS_CTRL_SHADER, GLSL420Pack::Utils::TESS_EVAL_SHADER,
18662 GLSL420Pack::Utils::GEOMETRY_SHADER, GLSL420Pack::Utils::FRAGMENT_SHADER};
18663
18664 for (GLSL420Pack::Utils::SHADER_STAGES &stage : stages)
18665 {
18666 addChild(new GLSL420Pack::BindingImageSingleTest(m_context, stage));
18667 }
18668 }
18669
addUTF8CharactersTest()18670 void ShadingLanguage420PackTests::addUTF8CharactersTest()
18671 {
18672 std::vector<GLSL420Pack::UTF8CharactersTest::testCase> test_cases = {
18673 {GLSL420Pack::UTF8CharactersTest::IN_COMMENT, GLSL420Pack::Utils::TWO_BYTES},
18674 {GLSL420Pack::UTF8CharactersTest::IN_COMMENT, GLSL420Pack::Utils::THREE_BYTES},
18675 {GLSL420Pack::UTF8CharactersTest::IN_COMMENT, GLSL420Pack::Utils::FOUR_BYTES},
18676 {GLSL420Pack::UTF8CharactersTest::IN_COMMENT, GLSL420Pack::Utils::FIVE_BYTES},
18677 {GLSL420Pack::UTF8CharactersTest::IN_COMMENT, GLSL420Pack::Utils::SIX_BYTES},
18678 {GLSL420Pack::UTF8CharactersTest::IN_COMMENT, GLSL420Pack::Utils::REDUNDANT_ASCII},
18679 {GLSL420Pack::UTF8CharactersTest::IN_PREPROCESSOR, GLSL420Pack::Utils::TWO_BYTES},
18680 {GLSL420Pack::UTF8CharactersTest::IN_PREPROCESSOR, GLSL420Pack::Utils::THREE_BYTES},
18681 {GLSL420Pack::UTF8CharactersTest::IN_PREPROCESSOR, GLSL420Pack::Utils::FOUR_BYTES},
18682 {GLSL420Pack::UTF8CharactersTest::IN_PREPROCESSOR, GLSL420Pack::Utils::FIVE_BYTES},
18683 {GLSL420Pack::UTF8CharactersTest::IN_PREPROCESSOR, GLSL420Pack::Utils::SIX_BYTES},
18684 {GLSL420Pack::UTF8CharactersTest::IN_PREPROCESSOR, GLSL420Pack::Utils::REDUNDANT_ASCII},
18685 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NULL_TERMINATED, GLSL420Pack::Utils::TWO_BYTES},
18686 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NULL_TERMINATED, GLSL420Pack::Utils::THREE_BYTES},
18687 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NULL_TERMINATED, GLSL420Pack::Utils::FOUR_BYTES},
18688 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NULL_TERMINATED, GLSL420Pack::Utils::FIVE_BYTES},
18689 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NULL_TERMINATED, GLSL420Pack::Utils::SIX_BYTES},
18690 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NULL_TERMINATED, GLSL420Pack::Utils::REDUNDANT_ASCII},
18691 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NON_NULL_TERMINATED, GLSL420Pack::Utils::TWO_BYTES},
18692 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NON_NULL_TERMINATED, GLSL420Pack::Utils::THREE_BYTES},
18693 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NON_NULL_TERMINATED, GLSL420Pack::Utils::FOUR_BYTES},
18694 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NON_NULL_TERMINATED, GLSL420Pack::Utils::FIVE_BYTES},
18695 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NON_NULL_TERMINATED, GLSL420Pack::Utils::SIX_BYTES},
18696 {GLSL420Pack::UTF8CharactersTest::AS_LAST_CHARACTER_NON_NULL_TERMINATED, GLSL420Pack::Utils::REDUNDANT_ASCII},
18697 };
18698
18699 for (size_t test_case = 0; test_case < test_cases.size(); ++test_case)
18700 {
18701 addChild(new GLSL420Pack::UTF8CharactersTest(m_context, test_cases[test_case]));
18702 }
18703 }
18704
addUTF8InSourceTest()18705 void ShadingLanguage420PackTests::addUTF8InSourceTest()
18706 {
18707 std::vector<GLSL420Pack::Utils::UTF8_CHARACTERS> test_cases = {
18708 GLSL420Pack::Utils::TWO_BYTES, GLSL420Pack::Utils::THREE_BYTES, GLSL420Pack::Utils::FOUR_BYTES,
18709 GLSL420Pack::Utils::FIVE_BYTES, GLSL420Pack::Utils::SIX_BYTES, GLSL420Pack::Utils::REDUNDANT_ASCII};
18710
18711 for (GLSL420Pack::Utils::UTF8_CHARACTERS &character : test_cases)
18712 {
18713 addChild(new GLSL420Pack::UTF8InSourceTest(m_context, character));
18714 }
18715 }
18716
addQualifierOrderTest()18717 void ShadingLanguage420PackTests::addQualifierOrderTest()
18718 {
18719 std::vector<GLSL420Pack::Utils::qualifierSet> test_cases(5);
18720 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18721 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_IN);
18722 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18723 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_SMOOTH);
18724 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18725
18726 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_LOWP);
18727 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_IN);
18728 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_SAMPLE);
18729 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18730 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_NOPERSPECTIVE);
18731 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18732
18733 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18734 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_IN);
18735 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18736 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_SMOOTH);
18737 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18738 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18739
18740 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOWP);
18741 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_IN);
18742 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18743 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_SAMPLE);
18744 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18745 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_NOPERSPECTIVE);
18746 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18747
18748 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18749 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_IN);
18750 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_PATCH);
18751 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18752 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18753
18754 for (size_t i = 0; i < test_cases.size(); ++i)
18755 {
18756 addChild(new GLSL420Pack::QualifierOrderTest(m_context, test_cases[i], i));
18757 }
18758 }
18759
addQualifierOrderBlockTest()18760 void ShadingLanguage420PackTests::addQualifierOrderBlockTest()
18761 {
18762 std::vector<GLSL420Pack::Utils::qualifierSet> test_cases(4);
18763
18764 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18765 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_FLAT);
18766 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18767
18768 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_LOWP);
18769 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_SAMPLE);
18770 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_NOPERSPECTIVE);
18771 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18772
18773 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18774 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_SMOOTH);
18775 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18776
18777 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOWP);
18778 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_SAMPLE);
18779 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_NOPERSPECTIVE);
18780 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_INVARIANT);
18781
18782 for (size_t i = 0; i < test_cases.size(); ++i)
18783 {
18784 addChild(new GLSL420Pack::QualifierOrderBlockTest(m_context, test_cases[i], i));
18785 }
18786 }
18787
addLineContinuationTest()18788 void ShadingLanguage420PackTests::addLineContinuationTest()
18789 {
18790 std::vector<GLSL420Pack::LineContinuationTest::testCase> test_cases = {
18791 {{GLSL420Pack::LineContinuationTest::ASSIGNMENT_BEFORE_OPERATOR, GLSL420Pack::LineContinuationTest::ONCE,
18792 GLSL420Pack::LineContinuationTest::UNIX},
18793 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_BEFORE_OPERATOR, GLSL420Pack::LineContinuationTest::ONCE,
18794 GLSL420Pack::LineContinuationTest::DOS},
18795 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_BEFORE_OPERATOR,
18796 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18797 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_BEFORE_OPERATOR,
18798 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18799 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_AFTER_OPERATOR, GLSL420Pack::LineContinuationTest::ONCE,
18800 GLSL420Pack::LineContinuationTest::UNIX},
18801 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_AFTER_OPERATOR, GLSL420Pack::LineContinuationTest::ONCE,
18802 GLSL420Pack::LineContinuationTest::DOS},
18803 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_AFTER_OPERATOR,
18804 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18805 {GLSL420Pack::LineContinuationTest::ASSIGNMENT_AFTER_OPERATOR,
18806 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18807 {GLSL420Pack::LineContinuationTest::VECTOR_VARIABLE_INITIALIZER, GLSL420Pack::LineContinuationTest::ONCE,
18808 GLSL420Pack::LineContinuationTest::UNIX},
18809 {GLSL420Pack::LineContinuationTest::VECTOR_VARIABLE_INITIALIZER, GLSL420Pack::LineContinuationTest::ONCE,
18810 GLSL420Pack::LineContinuationTest::DOS},
18811 {GLSL420Pack::LineContinuationTest::VECTOR_VARIABLE_INITIALIZER,
18812 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18813 {GLSL420Pack::LineContinuationTest::VECTOR_VARIABLE_INITIALIZER,
18814 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18815 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_FUNCTION_NAME, GLSL420Pack::LineContinuationTest::ONCE,
18816 GLSL420Pack::LineContinuationTest::UNIX},
18817 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_FUNCTION_NAME, GLSL420Pack::LineContinuationTest::ONCE,
18818 GLSL420Pack::LineContinuationTest::DOS},
18819 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_FUNCTION_NAME,
18820 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18821 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_FUNCTION_NAME,
18822 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18823 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_TYPE_NAME, GLSL420Pack::LineContinuationTest::ONCE,
18824 GLSL420Pack::LineContinuationTest::UNIX},
18825 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_TYPE_NAME, GLSL420Pack::LineContinuationTest::ONCE,
18826 GLSL420Pack::LineContinuationTest::DOS},
18827 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_TYPE_NAME, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18828 GLSL420Pack::LineContinuationTest::UNIX},
18829 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_TYPE_NAME, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18830 GLSL420Pack::LineContinuationTest::DOS},
18831 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_VARIABLE_NAME, GLSL420Pack::LineContinuationTest::ONCE,
18832 GLSL420Pack::LineContinuationTest::UNIX},
18833 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_VARIABLE_NAME, GLSL420Pack::LineContinuationTest::ONCE,
18834 GLSL420Pack::LineContinuationTest::DOS},
18835 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_VARIABLE_NAME,
18836 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18837 {GLSL420Pack::LineContinuationTest::TOKEN_INSIDE_VARIABLE_NAME,
18838 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18839 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_INSIDE, GLSL420Pack::LineContinuationTest::ONCE,
18840 GLSL420Pack::LineContinuationTest::UNIX},
18841 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_INSIDE, GLSL420Pack::LineContinuationTest::ONCE,
18842 GLSL420Pack::LineContinuationTest::DOS},
18843 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_INSIDE,
18844 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18845 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_INSIDE,
18846 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18847 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_BETWEEN, GLSL420Pack::LineContinuationTest::ONCE,
18848 GLSL420Pack::LineContinuationTest::UNIX},
18849 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_BETWEEN, GLSL420Pack::LineContinuationTest::ONCE,
18850 GLSL420Pack::LineContinuationTest::DOS},
18851 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_BETWEEN,
18852 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18853 {GLSL420Pack::LineContinuationTest::PREPROCESSOR_TOKEN_BETWEEN,
18854 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18855 {GLSL420Pack::LineContinuationTest::COMMENT, GLSL420Pack::LineContinuationTest::ONCE,
18856 GLSL420Pack::LineContinuationTest::UNIX},
18857 {GLSL420Pack::LineContinuationTest::COMMENT, GLSL420Pack::LineContinuationTest::ONCE,
18858 GLSL420Pack::LineContinuationTest::DOS},
18859 {GLSL420Pack::LineContinuationTest::COMMENT, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18860 GLSL420Pack::LineContinuationTest::UNIX},
18861 {GLSL420Pack::LineContinuationTest::COMMENT, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18862 GLSL420Pack::LineContinuationTest::DOS},
18863 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18864 GLSL420Pack::LineContinuationTest::UNIX},
18865 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18866 GLSL420Pack::LineContinuationTest::DOS},
18867 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18868 GLSL420Pack::LineContinuationTest::UNIX},
18869 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18870 GLSL420Pack::LineContinuationTest::DOS},
18871 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NON_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18872 GLSL420Pack::LineContinuationTest::UNIX},
18873 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NON_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18874 GLSL420Pack::LineContinuationTest::DOS},
18875 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NON_NULL,
18876 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18877 {GLSL420Pack::LineContinuationTest::SOURCE_TERMINATION_NON_NULL,
18878 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18879 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18880 GLSL420Pack::LineContinuationTest::UNIX},
18881 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18882 GLSL420Pack::LineContinuationTest::DOS},
18883 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18884 GLSL420Pack::LineContinuationTest::UNIX},
18885 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES,
18886 GLSL420Pack::LineContinuationTest::DOS},
18887 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18888 GLSL420Pack::LineContinuationTest::UNIX},
18889 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18890 GLSL420Pack::LineContinuationTest::DOS},
18891 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NULL,
18892 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18893 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NULL,
18894 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18895 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NON_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18896 GLSL420Pack::LineContinuationTest::UNIX},
18897 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NON_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18898 GLSL420Pack::LineContinuationTest::DOS},
18899 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NON_NULL,
18900 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18901 {GLSL420Pack::LineContinuationTest::PART_TERMINATION_NON_NULL,
18902 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS},
18903 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NON_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18904 GLSL420Pack::LineContinuationTest::UNIX},
18905 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NON_NULL, GLSL420Pack::LineContinuationTest::ONCE,
18906 GLSL420Pack::LineContinuationTest::DOS},
18907 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NON_NULL,
18908 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::UNIX},
18909 {GLSL420Pack::LineContinuationTest::PART_NEXT_TO_TERMINATION_NON_NULL,
18910 GLSL420Pack::LineContinuationTest::MULTIPLE_TIMES, GLSL420Pack::LineContinuationTest::DOS}}};
18911
18912 for (size_t test_case = 0; test_case < test_cases.size(); ++test_case)
18913 {
18914 addChild(new GLSL420Pack::LineContinuationTest(m_context, test_cases[test_case]));
18915 }
18916 }
18917
addImplicitConversionsValidTest()18918 void ShadingLanguage420PackTests::addImplicitConversionsValidTest()
18919 {
18920 static const GLSL420Pack::ImplicitConversionsValidTest::typesPair allowed_conversions[] = {
18921 {GLSL420Pack::Utils::UINT, GLSL420Pack::Utils::INT}, {GLSL420Pack::Utils::FLOAT, GLSL420Pack::Utils::INT},
18922 {GLSL420Pack::Utils::DOUBLE, GLSL420Pack::Utils::INT}, {GLSL420Pack::Utils::FLOAT, GLSL420Pack::Utils::UINT},
18923 {GLSL420Pack::Utils::DOUBLE, GLSL420Pack::Utils::UINT}, {GLSL420Pack::Utils::FLOAT, GLSL420Pack::Utils::FLOAT},
18924 };
18925
18926 static GLuint n_allowed_conversions =
18927 sizeof(allowed_conversions) / sizeof(GLSL420Pack::ImplicitConversionsValidTest::typesPair);
18928
18929 for (GLuint i = 0; i < n_allowed_conversions; ++i)
18930 {
18931 const GLSL420Pack::ImplicitConversionsValidTest::typesPair &types = allowed_conversions[i];
18932
18933 GLuint allowed_columns = 1;
18934 if ((true == GLSL420Pack::Utils::doesTypeSupportMatrix(types.m_t1)) &&
18935 (true == GLSL420Pack::Utils::doesTypeSupportMatrix(types.m_t2)))
18936 {
18937 allowed_columns = 4;
18938 }
18939
18940 {
18941 GLSL420Pack::ImplicitConversionsValidTest::testCase test_case = {types, 1, 1};
18942
18943 addChild(new GLSL420Pack::ImplicitConversionsValidTest(m_context, test_case));
18944 }
18945
18946 for (GLuint row = 2; row <= 4; ++row)
18947 {
18948 for (GLuint col = 1; col <= allowed_columns; ++col)
18949 {
18950 GLSL420Pack::ImplicitConversionsValidTest::testCase test_case = {types, col, row};
18951
18952 addChild(new GLSL420Pack::ImplicitConversionsValidTest(m_context, test_case));
18953 }
18954 }
18955 }
18956 }
18957
addQualifierOrderUniformTest()18958 void ShadingLanguage420PackTests::addQualifierOrderUniformTest()
18959 {
18960 std::vector<GLSL420Pack::Utils::qualifierSet> test_cases(4);
18961
18962 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18963 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_UNIFORM);
18964 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18965
18966 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_LOWP);
18967 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_UNIFORM);
18968 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18969
18970 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18971 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18972 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_UNIFORM);
18973 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18974
18975 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18976 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOWP);
18977 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_UNIFORM);
18978 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_LOCATION);
18979
18980 for (size_t i = 0; i < test_cases.size(); ++i)
18981 {
18982 addChild(new GLSL420Pack::QualifierOrderUniformTest(m_context, test_cases[i], i));
18983 }
18984 }
18985
addQualifierOrderFunctionInoutTest()18986 void ShadingLanguage420PackTests::addQualifierOrderFunctionInoutTest()
18987 {
18988 std::vector<GLSL420Pack::Utils::qualifierSet> test_cases(6);
18989
18990 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18991 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
18992 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_INOUT);
18993
18994 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_INOUT);
18995 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
18996 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
18997
18998 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_MEDIUMP);
18999 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19000 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_INOUT);
19001
19002 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_INOUT);
19003 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19004 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_MEDIUMP);
19005
19006 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_LOWP);
19007 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19008 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_INOUT);
19009
19010 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_INOUT);
19011 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19012 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_LOWP);
19013
19014 for (size_t i = 0; i < test_cases.size(); ++i)
19015 {
19016 addChild(new GLSL420Pack::QualifierOrderFunctionInoutTest(m_context, test_cases[i], i));
19017 }
19018 }
19019
addQualifierOrderFunctionInputTest()19020 void ShadingLanguage420PackTests::addQualifierOrderFunctionInputTest()
19021 {
19022 std::vector<GLSL420Pack::Utils::qualifierSet> test_cases(6);
19023
19024 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_CONST);
19025 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
19026 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19027 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_IN);
19028
19029 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_IN);
19030 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_CONST);
19031 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19032 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
19033
19034 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19035 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_MEDIUMP);
19036 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_CONST);
19037 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_IN);
19038
19039 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_IN);
19040 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19041 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_MEDIUMP);
19042 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_CONST);
19043
19044 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_LOWP);
19045 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_CONST);
19046 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_IN);
19047 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19048
19049 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_IN);
19050 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19051 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_CONST);
19052 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_LOWP);
19053
19054 for (size_t i = 0; i < test_cases.size(); ++i)
19055 {
19056 addChild(new GLSL420Pack::QualifierOrderFunctionInputTest(m_context, test_cases[i], i));
19057 }
19058 }
19059
addQualifierOrderFunctionOutputTest()19060 void ShadingLanguage420PackTests::addQualifierOrderFunctionOutputTest()
19061 {
19062 std::vector<GLSL420Pack::Utils::qualifierSet> test_cases(6);
19063
19064 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
19065 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19066 test_cases[0].push_back(GLSL420Pack::Utils::QUAL_OUT);
19067
19068 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_OUT);
19069 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19070 test_cases[1].push_back(GLSL420Pack::Utils::QUAL_HIGHP);
19071
19072 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19073 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_MEDIUMP);
19074 test_cases[2].push_back(GLSL420Pack::Utils::QUAL_OUT);
19075
19076 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_OUT);
19077 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19078 test_cases[3].push_back(GLSL420Pack::Utils::QUAL_MEDIUMP);
19079
19080 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_LOWP);
19081 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_OUT);
19082 test_cases[4].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19083
19084 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_OUT);
19085 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_PRECISE);
19086 test_cases[5].push_back(GLSL420Pack::Utils::QUAL_LOWP);
19087
19088 for (size_t i = 0; i < test_cases.size(); ++i)
19089 {
19090 addChild(new GLSL420Pack::QualifierOrderFunctionOutputTest(m_context, test_cases[i], i));
19091 }
19092 }
19093
addBindingUniformSingleBlockTest()19094 void ShadingLanguage420PackTests::addBindingUniformSingleBlockTest()
19095 {
19096 std::vector<GLSL420Pack::Utils::SHADER_STAGES> stages{
19097 GLSL420Pack::Utils::VERTEX_SHADER, GLSL420Pack::Utils::TESS_CTRL_SHADER, GLSL420Pack::Utils::TESS_EVAL_SHADER,
19098 GLSL420Pack::Utils::GEOMETRY_SHADER, GLSL420Pack::Utils::FRAGMENT_SHADER};
19099
19100 for (GLSL420Pack::Utils::SHADER_STAGES &stage : stages)
19101 {
19102 addChild(new GLSL420Pack::BindingUniformSingleBlockTest(m_context, stage));
19103 }
19104 }
19105
addBindingUniformInvalidTest()19106 void ShadingLanguage420PackTests::addBindingUniformInvalidTest()
19107 {
19108 std::vector<GLSL420Pack::BindingUniformInvalidTest::TESTCASES> cases{
19109 GLSL420Pack::BindingUniformInvalidTest::NEGATIVE_VALUE,
19110 GLSL420Pack::BindingUniformInvalidTest::VARIABLE_NAME,
19111 GLSL420Pack::BindingUniformInvalidTest::STD140,
19112 GLSL420Pack::BindingUniformInvalidTest::MISSING,
19113 };
19114
19115 for (GLuint test_case_idx = 0; test_case_idx < cases.size(); ++test_case_idx)
19116 {
19117 addChild(new GLSL420Pack::BindingUniformInvalidTest(m_context, cases[test_case_idx]));
19118 }
19119 }
19120
addBindingSamplersTest()19121 void ShadingLanguage420PackTests::addBindingSamplersTest()
19122 {
19123 std::vector<GLSL420Pack::Utils::TEXTURE_TYPES> tex_types{
19124 GLSL420Pack::Utils::TEX_2D, GLSL420Pack::Utils::TEX_BUFFER, GLSL420Pack::Utils::TEX_2D_RECT,
19125 GLSL420Pack::Utils::TEX_2D_ARRAY, GLSL420Pack::Utils::TEX_3D, GLSL420Pack::Utils::TEX_CUBE,
19126 GLSL420Pack::Utils::TEX_1D, GLSL420Pack::Utils::TEX_1D_ARRAY};
19127
19128 for (GLSL420Pack::Utils::TEXTURE_TYPES &tex_type : tex_types)
19129 {
19130 addChild(new GLSL420Pack::BindingSamplersTest(m_context, tex_type));
19131 }
19132 }
19133
addBindingSamplerInvalidTest()19134 void ShadingLanguage420PackTests::addBindingSamplerInvalidTest()
19135 {
19136 std::vector<GLSL420Pack::BindingSamplerInvalidTest::TESTCASES> cases{
19137 GLSL420Pack::BindingSamplerInvalidTest::NEGATIVE_VALUE,
19138 GLSL420Pack::BindingSamplerInvalidTest::VARIABLE_NAME,
19139 GLSL420Pack::BindingSamplerInvalidTest::STD140,
19140 GLSL420Pack::BindingSamplerInvalidTest::MISSING,
19141 };
19142
19143 for (GLuint test_case_idx = 0; test_case_idx < cases.size(); ++test_case_idx)
19144 {
19145 addChild(new GLSL420Pack::BindingSamplerInvalidTest(m_context, cases[test_case_idx]));
19146 }
19147 }
19148
addBindingImagesTest()19149 void ShadingLanguage420PackTests::addBindingImagesTest()
19150 {
19151 std::vector<GLSL420Pack::Utils::TEXTURE_TYPES> tex_types{
19152 GLSL420Pack::Utils::TEX_2D, GLSL420Pack::Utils::TEX_BUFFER, GLSL420Pack::Utils::TEX_2D_RECT,
19153 GLSL420Pack::Utils::TEX_2D_ARRAY, GLSL420Pack::Utils::TEX_3D, GLSL420Pack::Utils::TEX_CUBE,
19154 GLSL420Pack::Utils::TEX_1D, GLSL420Pack::Utils::TEX_1D_ARRAY};
19155
19156 for (GLSL420Pack::Utils::TEXTURE_TYPES &tex_type : tex_types)
19157 {
19158 addChild(new GLSL420Pack::BindingImagesTest(m_context, tex_type));
19159 }
19160 }
19161
addBindingImageInvalidTest()19162 void ShadingLanguage420PackTests::addBindingImageInvalidTest()
19163 {
19164 std::vector<GLSL420Pack::BindingImageInvalidTest::TESTCASES> cases{
19165 GLSL420Pack::BindingImageInvalidTest::NEGATIVE_VALUE,
19166 GLSL420Pack::BindingImageInvalidTest::VARIABLE_NAME,
19167 GLSL420Pack::BindingImageInvalidTest::STD140,
19168 GLSL420Pack::BindingImageInvalidTest::MISSING,
19169 };
19170
19171 for (GLuint test_case_idx = 0; test_case_idx < cases.size(); ++test_case_idx)
19172 {
19173 addChild(new GLSL420Pack::BindingImageInvalidTest(m_context, cases[test_case_idx]));
19174 }
19175 }
19176
addInitializerListTest()19177 void ShadingLanguage420PackTests::addInitializerListTest()
19178 {
19179 for (GLuint i = 0; i < GLSL420Pack::InitializerListTest::TESTED_INITIALIZERS_MAX; ++i)
19180 {
19181 const GLSL420Pack::InitializerListTest::TESTED_INITIALIZERS l_init =
19182 (GLSL420Pack::InitializerListTest::TESTED_INITIALIZERS)i;
19183
19184 GLSL420Pack::InitializerListTest::testCase test_case = {l_init, 1, 1};
19185
19186 switch (l_init)
19187 {
19188 case GLSL420Pack::InitializerListTest::VECTOR:
19189 case GLSL420Pack::InitializerListTest::ARRAY_VECTOR_CTR:
19190 case GLSL420Pack::InitializerListTest::ARRAY_VECTOR_LIST:
19191 case GLSL420Pack::InitializerListTest::UNSIZED_ARRAY_VECTOR:
19192 {
19193 for (GLuint row = 2; row <= 4; ++row)
19194 {
19195 test_case.m_n_rows = row;
19196
19197 addChild(new GLSL420Pack::InitializerListTest(m_context, test_case));
19198 }
19199
19200 break;
19201 }
19202 case GLSL420Pack::InitializerListTest::MATRIX:
19203 case GLSL420Pack::InitializerListTest::MATRIX_ROWS:
19204 case GLSL420Pack::InitializerListTest::ARRAY_MATRIX_CTR:
19205 case GLSL420Pack::InitializerListTest::ARRAY_MATRIX_LIST:
19206 case GLSL420Pack::InitializerListTest::UNSIZED_ARRAY_MATRIX:
19207 {
19208 for (GLuint col = 2; col <= 4; ++col)
19209 {
19210 for (GLuint row = 2; row <= 4; ++row)
19211 {
19212 test_case.m_n_cols = col;
19213 test_case.m_n_rows = row;
19214
19215 addChild(new GLSL420Pack::InitializerListTest(m_context, test_case));
19216 }
19217 }
19218
19219 break;
19220 }
19221 case GLSL420Pack::InitializerListTest::ARRAY_SCALAR:
19222 case GLSL420Pack::InitializerListTest::UNSIZED_ARRAY_SCALAR:
19223 {
19224 addChild(new GLSL420Pack::InitializerListTest(m_context, test_case));
19225
19226 break;
19227 }
19228 case GLSL420Pack::InitializerListTest::STRUCT:
19229 case GLSL420Pack::InitializerListTest::ARRAY_STRUCT:
19230 case GLSL420Pack::InitializerListTest::NESTED_STRUCT_CTR:
19231 case GLSL420Pack::InitializerListTest::NESTED_STRUCT_LIST:
19232 case GLSL420Pack::InitializerListTest::NESTED_STURCT_ARRAYS_STRUCT_LIST:
19233 case GLSL420Pack::InitializerListTest::NESTED_STURCT_ARRAYS_STRUCT_MIX:
19234 case GLSL420Pack::InitializerListTest::NESTED_ARRAY_STRUCT_STRUCT_LIST:
19235 case GLSL420Pack::InitializerListTest::NESTED_ARRAY_STRUCT_STRUCT_MIX:
19236 case GLSL420Pack::InitializerListTest::NESTED_STRUCT_STRUCT_ARRAY_LIST:
19237 case GLSL420Pack::InitializerListTest::NESTED_STRUCT_STRUCT_ARRAY_MIX:
19238 case GLSL420Pack::InitializerListTest::UNSIZED_ARRAY_STRUCT:
19239 {
19240 test_case.m_n_rows = 4;
19241 addChild(new GLSL420Pack::InitializerListTest(m_context, test_case));
19242
19243 break;
19244 }
19245 default:
19246 DE_ASSERT(0);
19247 break;
19248 }
19249 }
19250 }
19251
addInitializerListNegativeTest()19252 void ShadingLanguage420PackTests::addInitializerListNegativeTest()
19253 {
19254 for (GLuint i = 0; i < GLSL420Pack::InitializerListNegativeTest::TESTED_ERRORS_MAX; ++i)
19255 {
19256 const GLSL420Pack::InitializerListNegativeTest::TESTED_ERRORS error =
19257 (GLSL420Pack::InitializerListNegativeTest::TESTED_ERRORS)i;
19258
19259 addChild(new GLSL420Pack::InitializerListNegativeTest(m_context, error));
19260 }
19261 }
19262
addLengthOfVectorAndMatrixTest()19263 void ShadingLanguage420PackTests::addLengthOfVectorAndMatrixTest()
19264 {
19265 /* Vectors */
19266 for (GLuint row = 2; row <= 4; ++row)
19267 {
19268 GLSL420Pack::LengthOfVectorAndMatrixTest::testCase test_case = {GLSL420Pack::Utils::UINT, 1 /* n_cols */, row};
19269
19270 addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context, test_case));
19271 }
19272
19273 for (GLuint row = 2; row <= 4; ++row)
19274 {
19275 GLSL420Pack::LengthOfVectorAndMatrixTest::testCase test_case = {GLSL420Pack::Utils::INT, 1 /* n_cols */, row};
19276
19277 addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context, test_case));
19278 }
19279
19280 for (GLuint row = 2; row <= 4; ++row)
19281 {
19282 GLSL420Pack::LengthOfVectorAndMatrixTest::testCase test_case = {GLSL420Pack::Utils::FLOAT, 1 /* n_cols */, row};
19283
19284 addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context, test_case));
19285 }
19286
19287 /* Matrices */
19288 for (GLuint col = 2; col <= 4; ++col)
19289 {
19290 for (GLuint row = 2; row <= 4; ++row)
19291 {
19292 GLSL420Pack::LengthOfVectorAndMatrixTest::testCase test_case = {GLSL420Pack::Utils::FLOAT, col, row};
19293
19294 addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context, test_case));
19295 }
19296 }
19297 }
19298
addScalarSwizzlersInvalidTest()19299 void ShadingLanguage420PackTests::addScalarSwizzlersInvalidTest()
19300 {
19301 std::vector<GLSL420Pack::ScalarSwizzlersInvalidTest::TESTED_CASES> cases{
19302 GLSL420Pack::ScalarSwizzlersInvalidTest::INVALID_Y,
19303 GLSL420Pack::ScalarSwizzlersInvalidTest::INVALID_B,
19304 GLSL420Pack::ScalarSwizzlersInvalidTest::INVALID_Q,
19305 GLSL420Pack::ScalarSwizzlersInvalidTest::INVALID_XY,
19306 GLSL420Pack::ScalarSwizzlersInvalidTest::INVALID_XRS,
19307 GLSL420Pack::ScalarSwizzlersInvalidTest::WRONG,
19308 GLSL420Pack::ScalarSwizzlersInvalidTest::MISSING_PARENTHESIS,
19309 };
19310
19311 for (GLuint test_case_idx = 0; test_case_idx < cases.size(); ++test_case_idx)
19312 {
19313 addChild(new GLSL420Pack::ScalarSwizzlersInvalidTest(m_context, cases[test_case_idx]));
19314 }
19315 }
19316
addBuiltInAssignmentTest()19317 void ShadingLanguage420PackTests::addBuiltInAssignmentTest()
19318 {
19319 for (GLuint test_case_idx = 0; test_case_idx < 2; ++test_case_idx)
19320 {
19321 addChild(new GLSL420Pack::BuiltInAssignmentTest(m_context, test_case_idx));
19322 }
19323 }
19324
19325 } // namespace gl4cts
19326