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 = "geomtery";
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)2464 LineContinuationTest::LineContinuationTest(deqp::Context &context) : GLSLTestBase(context, "line_continuation", "desc")
2465 {
2466 /* Nothing to be done here */
2467 }
2468
2469 /** Overwrite getShaderSourceConfig method
2470 *
2471 * @param out_n_parts Number of source parts used by this test case
2472 * @param out_use_lengths If source lengths shall be provided to compiler
2473 **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)2474 void LineContinuationTest::getShaderSourceConfig(GLuint &out_n_parts, bool &out_use_lengths)
2475 {
2476 out_n_parts = (true == isShaderMultipart()) ? 2 : 1;
2477 out_use_lengths = useSourceLengths();
2478 }
2479
2480 /** Set up next test case
2481 *
2482 * @param test_case_index Index of next test case
2483 *
2484 * @return false if there is no more test cases, true otherwise
2485 **/
prepareNextTestCase(glw::GLuint test_case_index)2486 bool LineContinuationTest::prepareNextTestCase(glw::GLuint test_case_index)
2487 {
2488 static const testCase test_cases[] = {{ASSIGNMENT_BEFORE_OPERATOR, ONCE, UNIX},
2489 {ASSIGNMENT_BEFORE_OPERATOR, ONCE, DOS},
2490 {ASSIGNMENT_BEFORE_OPERATOR, MULTIPLE_TIMES, UNIX},
2491 {ASSIGNMENT_BEFORE_OPERATOR, MULTIPLE_TIMES, DOS},
2492 {ASSIGNMENT_AFTER_OPERATOR, ONCE, UNIX},
2493 {ASSIGNMENT_AFTER_OPERATOR, ONCE, DOS},
2494 {ASSIGNMENT_AFTER_OPERATOR, MULTIPLE_TIMES, UNIX},
2495 {ASSIGNMENT_AFTER_OPERATOR, MULTIPLE_TIMES, DOS},
2496 {VECTOR_VARIABLE_INITIALIZER, ONCE, UNIX},
2497 {VECTOR_VARIABLE_INITIALIZER, ONCE, DOS},
2498 {VECTOR_VARIABLE_INITIALIZER, MULTIPLE_TIMES, UNIX},
2499 {VECTOR_VARIABLE_INITIALIZER, MULTIPLE_TIMES, DOS},
2500 {TOKEN_INSIDE_FUNCTION_NAME, ONCE, UNIX},
2501 {TOKEN_INSIDE_FUNCTION_NAME, ONCE, DOS},
2502 {TOKEN_INSIDE_FUNCTION_NAME, MULTIPLE_TIMES, UNIX},
2503 {TOKEN_INSIDE_FUNCTION_NAME, MULTIPLE_TIMES, DOS},
2504 {TOKEN_INSIDE_TYPE_NAME, ONCE, UNIX},
2505 {TOKEN_INSIDE_TYPE_NAME, ONCE, DOS},
2506 {TOKEN_INSIDE_TYPE_NAME, MULTIPLE_TIMES, UNIX},
2507 {TOKEN_INSIDE_TYPE_NAME, MULTIPLE_TIMES, DOS},
2508 {TOKEN_INSIDE_VARIABLE_NAME, ONCE, UNIX},
2509 {TOKEN_INSIDE_VARIABLE_NAME, ONCE, DOS},
2510 {TOKEN_INSIDE_VARIABLE_NAME, MULTIPLE_TIMES, UNIX},
2511 {TOKEN_INSIDE_VARIABLE_NAME, MULTIPLE_TIMES, DOS},
2512 {PREPROCESSOR_TOKEN_INSIDE, ONCE, UNIX},
2513 {PREPROCESSOR_TOKEN_INSIDE, ONCE, DOS},
2514 {PREPROCESSOR_TOKEN_INSIDE, MULTIPLE_TIMES, UNIX},
2515 {PREPROCESSOR_TOKEN_INSIDE, MULTIPLE_TIMES, DOS},
2516 {PREPROCESSOR_TOKEN_BETWEEN, ONCE, UNIX},
2517 {PREPROCESSOR_TOKEN_BETWEEN, ONCE, DOS},
2518 {PREPROCESSOR_TOKEN_BETWEEN, MULTIPLE_TIMES, UNIX},
2519 {PREPROCESSOR_TOKEN_BETWEEN, MULTIPLE_TIMES, DOS},
2520 {COMMENT, ONCE, UNIX},
2521 {COMMENT, ONCE, DOS},
2522 {COMMENT, MULTIPLE_TIMES, UNIX},
2523 {COMMENT, MULTIPLE_TIMES, DOS},
2524 {SOURCE_TERMINATION_NULL, ONCE, UNIX},
2525 {SOURCE_TERMINATION_NULL, ONCE, DOS},
2526 {SOURCE_TERMINATION_NULL, MULTIPLE_TIMES, UNIX},
2527 {SOURCE_TERMINATION_NULL, MULTIPLE_TIMES, DOS},
2528 {SOURCE_TERMINATION_NON_NULL, ONCE, UNIX},
2529 {SOURCE_TERMINATION_NON_NULL, ONCE, DOS},
2530 {SOURCE_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX},
2531 {SOURCE_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS},
2532 {PART_TERMINATION_NULL, ONCE, UNIX},
2533 {PART_TERMINATION_NULL, ONCE, DOS},
2534 {PART_TERMINATION_NULL, MULTIPLE_TIMES, UNIX},
2535 {PART_TERMINATION_NULL, MULTIPLE_TIMES, DOS},
2536 {PART_NEXT_TO_TERMINATION_NULL, ONCE, UNIX},
2537 {PART_NEXT_TO_TERMINATION_NULL, ONCE, DOS},
2538 {PART_NEXT_TO_TERMINATION_NULL, MULTIPLE_TIMES, UNIX},
2539 {PART_NEXT_TO_TERMINATION_NULL, MULTIPLE_TIMES, DOS},
2540 {PART_TERMINATION_NON_NULL, ONCE, UNIX},
2541 {PART_TERMINATION_NON_NULL, ONCE, DOS},
2542 {PART_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX},
2543 {PART_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS},
2544 {PART_NEXT_TO_TERMINATION_NON_NULL, ONCE, UNIX},
2545 {PART_NEXT_TO_TERMINATION_NON_NULL, ONCE, DOS},
2546 {PART_NEXT_TO_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX},
2547 {PART_NEXT_TO_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS}};
2548
2549 static const GLuint max_test_cases = sizeof(test_cases) / sizeof(testCase);
2550
2551 if ((GLuint)-1 == test_case_index)
2552 {
2553 m_test_case.m_case = DEBUG_CASE;
2554 }
2555 else if (max_test_cases <= test_case_index)
2556 {
2557 return false;
2558 }
2559 else
2560 {
2561 m_test_case = test_cases[test_case_index];
2562 }
2563
2564 m_context.getTestContext().getLog() << tcu::TestLog::Message
2565 << "Test case: " << repetitionsToStr((REPETITIONS)m_test_case.m_repetitions)
2566 << " line continuation, with "
2567 << lineEndingsToStr((LINE_ENDINGS)m_test_case.m_line_endings)
2568 << " line endings, is placed " << casesToStr((CASES)m_test_case.m_case)
2569 << tcu::TestLog::EndMessage;
2570
2571 return true;
2572 }
2573
2574 /** Prepare source for given shader stage
2575 *
2576 * @param in_stage Shader stage, compute shader will use 430
2577 * @param in_use_version_400 Select if 400 or 420 should be used
2578 * @param out_source Prepared shader source instance
2579 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)2580 void LineContinuationTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
2581 Utils::shaderSource &out_source)
2582 {
2583 if (Utils::COMPUTE_SHADER == in_stage)
2584 {
2585 prepareComputShaderSource(out_source);
2586 }
2587 else
2588 {
2589 prepareShaderSourceForDraw(in_stage, in_use_version_400, out_source);
2590 }
2591 }
2592
2593 /** Prepare compute shader source
2594 *
2595 * @param source Result shader source
2596 **/
prepareComputShaderSource(Utils::shaderSource & source)2597 void LineContinuationTest::prepareComputShaderSource(Utils::shaderSource &source)
2598 {
2599 static const GLchar *shader_template_part_0 =
2600 "#version 430\n"
2601 "\n"
2602 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2603 "\n"
2604 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
2605 "\n"
2606 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2607 "\n"
2608 "writeonly uniform image2D uni_image;\n"
2609 " uniform sampler2D uni_sampler;\n"
2610 "\n"
2611 "void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2612 "{\n"
2613 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), inVARIABLE_CASE_value);\n"
2614 "}\n"
2615 "\n"
2616 "#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2617 "PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2618 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2619
2620 static const GLchar *shader_template_part_1 =
2621 "void main()\n"
2622 "{\n"
2623 " ivec2 coordinates ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE "
2624 "ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
2625 " vec4 sampled_color = texelFetch(uni_sampler, coordinates, 0 /* lod */);\n"
2626 " vec4 result = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2627 "\n"
2628 " if (vec4(0, 0, 1, 1) == sampled_color)\n"
2629 " {\n"
2630 " result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2631 " }\n"
2632 " else\n"
2633 " {\n"
2634 " result = vec4(coordinates.xy, sampled_color.rg);\n"
2635 " }\n"
2636 "\n"
2637 " SET_RESULT(result);"
2638 "}\n";
2639
2640 /* Init strings with templates and replace all CASE tokens */
2641 if (true == isShaderMultipart())
2642 {
2643 source.m_parts[0].m_code = shader_template_part_0;
2644 source.m_parts[1].m_code = shader_template_part_1;
2645
2646 replaceAllCaseTokens(source.m_parts[0].m_code);
2647 replaceAllCaseTokens(source.m_parts[1].m_code);
2648 }
2649 else
2650 {
2651 source.m_parts[0].m_code = shader_template_part_0;
2652 source.m_parts[0].m_code.append(shader_template_part_1);
2653
2654 replaceAllCaseTokens(source.m_parts[0].m_code);
2655 }
2656 }
2657
2658 /** Prepare source for given shader stage
2659 *
2660 * @param stage Shader stage, compute shader will use 430
2661 * @param use_version_400 Select if 400 or 420 should be used
2662 * @param source Result shader sources
2663 **/
prepareShaderSourceForDraw(Utils::SHADER_STAGES stage,bool use_version_400,Utils::shaderSource & source)2664 void LineContinuationTest::prepareShaderSourceForDraw(Utils::SHADER_STAGES stage, bool use_version_400,
2665 Utils::shaderSource &source)
2666 {
2667 /* Templates */
2668 static const GLchar *shader_template_part_0 =
2669 "VERSION\n"
2670 "\n"
2671 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2672 "\n"
2673 "STAGE_SPECIFIC\n"
2674 "\n"
2675 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2676 "\n"
2677 "IN_COLOR_DEFINITION\n"
2678 "IN_TEXTURE_COORDINATES_DEFINITION\n"
2679 "OUT_COLOR_DEFINITION\n"
2680 "OUT_TEXTURE_COORDINATES_DEFINITION\n"
2681 "uniform sampler2D uni_sampler;\n"
2682 "\n"
2683 "void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2684 "{\n"
2685 " OUT_COLOR ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE inVARIABLE_CASE_value;\n"
2686 "}\n"
2687 "\n"
2688 "#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2689 "PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2690 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2691
2692 static const GLchar *shader_template_part_1 =
2693 "void main()\n"
2694 "{\n"
2695 " vec2 coordinates = TEXTURE_COORDINATES;\n"
2696 " vec4 sampled_color = texture(uni_sampler, coordinates);\n"
2697 " vec4 result = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2698 "\n"
2699 " if (PASS_CONDITION)\n"
2700 " {\n"
2701 " result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2702 " }\n"
2703 " else\n"
2704 " {\n"
2705 " result = vec4(coordinates.xy, sampled_color.rg);\n"
2706 " }\n"
2707 "\n"
2708 "STORE_RESULTS"
2709 "}\n"
2710 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2711
2712 static const GLchar *store_results_template = " SET_RESULT(result);\n"
2713 " TEXTURE_COORDINATES = coordinates;\n";
2714
2715 static const GLchar *store_results_tcs_template = " SET_RESULT(result);\n"
2716 " TEXTURE_COORDINATES = coordinates;\n"
2717 " gl_TessLevelOuter[0] = 1.0;\n"
2718 " gl_TessLevelOuter[1] = 1.0;\n"
2719 " gl_TessLevelOuter[2] = 1.0;\n"
2720 " gl_TessLevelOuter[3] = 1.0;\n"
2721 " gl_TessLevelInner[0] = 1.0;\n"
2722 " gl_TessLevelInner[1] = 1.0;\n";
2723
2724 static const GLchar *store_results_fs_template = " SET_RESULT(result);\n";
2725
2726 static const GLchar *store_results_gs_template = " gl_Position = vec4(-1, -1, 0, 1);\n"
2727 " SET_RESULT(result);\n"
2728 " TEXTURE_COORDINATES = coordinates + vec2(-0.25, -0.25);\n"
2729 " EmitVertex();\n"
2730 " gl_Position = vec4(-1, 1, 0, 1);\n"
2731 " SET_RESULT(result);\n"
2732 " TEXTURE_COORDINATES = coordinates + vec2(-0.25, 0.25);\n"
2733 " EmitVertex();\n"
2734 " gl_Position = vec4(1, -1, 0, 1);\n"
2735 " SET_RESULT(result);\n"
2736 " TEXTURE_COORDINATES = coordinates + vec2(0.25, -0.25);\n"
2737 " EmitVertex();\n"
2738 " gl_Position = vec4(1, 1, 0, 1);\n"
2739 " SET_RESULT(result);\n"
2740 " TEXTURE_COORDINATES = coordinates + vec2(0.25, 0.25);\n"
2741 " EmitVertex();\n";
2742
2743 static const GLchar *pass_condition_template = "(EXPECTED_VALUE == sampled_color) &&\n"
2744 " (vec4(0, 1, 0, 1) == IN_COLOR) ";
2745
2746 static const GLchar *pass_condition_vs_template = "EXPECTED_VALUE == sampled_color";
2747
2748 /* Tokens to be replaced with GLSL stuff */
2749 static const GLchar *token_version = "VERSION";
2750 static const GLchar *token_stage_specific = "STAGE_SPECIFIC";
2751
2752 static const GLchar *token_in_color_definition = "IN_COLOR_DEFINITION";
2753 static const GLchar *token_in_tex_coord_definition = "IN_TEXTURE_COORDINATES_DEFINITION";
2754 static const GLchar *token_out_color_definition = "OUT_COLOR_DEFINITION";
2755 static const GLchar *token_out_tex_coord_definition = "OUT_TEXTURE_COORDINATES_DEFINITION";
2756
2757 static const GLchar *token_expected_value = "EXPECTED_VALUE";
2758 static const GLchar *token_texture_coordinates = "TEXTURE_COORDINATES";
2759 static const GLchar *token_in_color = "IN_COLOR";
2760 static const GLchar *token_out_color = "OUT_COLOR";
2761
2762 static const GLchar *token_store_results = "STORE_RESULTS";
2763 static const GLchar *token_pass_condition = "PASS_CONDITION";
2764
2765 /* Name of variable and empty string*/
2766 static const GLchar *color_name = "color";
2767 static const GLchar *empty = "";
2768
2769 /* GLSL stuff */
2770 const GLchar *version = getVersionString(stage, use_version_400);
2771 const GLchar *stage_specific_layout = getStageSpecificLayout(stage);
2772 const GLchar *expected_value = getExpectedValueString();
2773
2774 /* Qualifiers */
2775 Utils::qualifierSet in;
2776 Utils::qualifierSet out;
2777 in.push_back(Utils::QUAL_IN);
2778 out.push_back(Utils::QUAL_OUT);
2779
2780 /* In/Out variables definitions and references */
2781 std::string in_tex_coord_reference;
2782 std::string out_tex_coord_reference;
2783 std::string in_color_reference;
2784 std::string out_color_reference;
2785 std::string in_tex_coord_definition;
2786 std::string out_tex_coord_definition;
2787 std::string in_color_definition;
2788 std::string out_color_definition;
2789
2790 Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec2", m_texture_coordinates_name, in_tex_coord_definition,
2791 in_tex_coord_reference);
2792 Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec2", m_texture_coordinates_name,
2793 out_tex_coord_definition, out_tex_coord_reference);
2794 Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec4", color_name, in_color_definition, in_color_reference);
2795 Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec4", color_name, out_color_definition,
2796 out_color_reference);
2797
2798 in_tex_coord_definition.append(";");
2799 out_tex_coord_definition.append(";");
2800 in_color_definition.append(";");
2801 out_color_definition.append(";");
2802
2803 /* Select pass condition and store results tempaltes */
2804 const GLchar *store_results = store_results_template;
2805 const GLchar *pass_condition = pass_condition_template;
2806
2807 switch (stage)
2808 {
2809 case Utils::FRAGMENT_SHADER:
2810 store_results = store_results_fs_template;
2811 break;
2812 case Utils::GEOMETRY_SHADER:
2813 store_results = store_results_gs_template;
2814 break;
2815 case Utils::TESS_CTRL_SHADER:
2816 store_results = store_results_tcs_template;
2817 break;
2818 case Utils::VERTEX_SHADER:
2819 pass_condition = pass_condition_vs_template;
2820 break;
2821 default:
2822 break;
2823 }
2824 const GLuint store_results_length = static_cast<GLuint>(strlen(store_results));
2825 const GLuint pass_condition_length = static_cast<GLuint>(strlen(pass_condition));
2826
2827 /* Init strings with templates and replace all CASE tokens */
2828 if (true == isShaderMultipart())
2829 {
2830 source.m_parts[0].m_code = shader_template_part_0;
2831 source.m_parts[1].m_code = shader_template_part_1;
2832
2833 replaceAllCaseTokens(source.m_parts[0].m_code);
2834 replaceAllCaseTokens(source.m_parts[1].m_code);
2835 }
2836 else
2837 {
2838 source.m_parts[0].m_code = shader_template_part_0;
2839 source.m_parts[0].m_code.append(shader_template_part_1);
2840
2841 replaceAllCaseTokens(source.m_parts[0].m_code);
2842 }
2843
2844 /* Get memory for shader source parts */
2845 const bool is_multipart = isShaderMultipart();
2846 size_t position = 0;
2847 std::string &shader_source_part_0 = source.m_parts[0].m_code;
2848 std::string &shader_source_part_1 = (true == is_multipart) ? source.m_parts[1].m_code : source.m_parts[0].m_code;
2849
2850 /* Replace tokens */
2851 /* Part 0 */
2852 Utils::replaceToken(token_version, position, version, shader_source_part_0);
2853
2854 Utils::replaceToken(token_stage_specific, position, stage_specific_layout, shader_source_part_0);
2855
2856 if (Utils::VERTEX_SHADER != stage)
2857 {
2858 Utils::replaceToken(token_in_color_definition, position, in_color_definition.c_str(), shader_source_part_0);
2859 }
2860 else
2861 {
2862 Utils::replaceToken(token_in_color_definition, position, empty, shader_source_part_0);
2863 }
2864 Utils::replaceToken(token_in_tex_coord_definition, position, in_tex_coord_definition.c_str(), shader_source_part_0);
2865 Utils::replaceToken(token_out_color_definition, position, out_color_definition.c_str(), shader_source_part_0);
2866 if (Utils::FRAGMENT_SHADER == stage)
2867 {
2868 Utils::replaceToken(token_out_tex_coord_definition, position, empty, shader_source_part_0);
2869 }
2870 else
2871 {
2872 Utils::replaceToken(token_out_tex_coord_definition, position, out_tex_coord_definition.c_str(),
2873 shader_source_part_0);
2874 }
2875
2876 Utils::replaceToken(token_out_color, position, out_color_reference.c_str(), shader_source_part_0);
2877
2878 /* Part 1 */
2879 if (true == is_multipart)
2880 {
2881 position = 0;
2882 }
2883
2884 Utils::replaceToken(token_texture_coordinates, position, in_tex_coord_reference.c_str(), shader_source_part_1);
2885
2886 Utils::replaceToken(token_pass_condition, position, pass_condition, shader_source_part_1);
2887 position -= pass_condition_length;
2888
2889 Utils::replaceToken(token_expected_value, position, expected_value, shader_source_part_1);
2890 if (Utils::VERTEX_SHADER != stage)
2891 {
2892 Utils::replaceToken(token_in_color, position, in_color_reference.c_str(), shader_source_part_1);
2893 }
2894
2895 Utils::replaceToken(token_store_results, position, store_results, shader_source_part_1);
2896 position -= store_results_length;
2897
2898 if (Utils::GEOMETRY_SHADER == stage)
2899 {
2900 for (GLuint i = 0; i < 4; ++i)
2901 {
2902 Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(),
2903 shader_source_part_1);
2904 }
2905 }
2906 else if (Utils::FRAGMENT_SHADER == stage)
2907 {
2908 /* Nothing to be done */
2909 }
2910 else
2911 {
2912 Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(), shader_source_part_1);
2913 }
2914 }
2915
2916 /** Prepare texture
2917 *
2918 * @param texture Texutre to be created and filled with content
2919 *
2920 * @return Name of sampler uniform that should be used for the texture
2921 **/
prepareSourceTexture(Utils::texture & texture)2922 const GLchar *LineContinuationTest::prepareSourceTexture(Utils::texture &texture)
2923 {
2924 std::vector<GLuint> data;
2925 static const GLuint width = 64;
2926 static const GLuint height = 64;
2927 static const GLuint data_size = width * height;
2928 static const GLuint blue_color = 0xffff0000;
2929 static const GLuint grey_color = 0xaaaaaaaa;
2930
2931 data.resize(data_size);
2932
2933 for (GLuint i = 0; i < data_size; ++i)
2934 {
2935 data[i] = grey_color;
2936 }
2937
2938 for (GLuint y = 16; y < 48; ++y)
2939 {
2940 const GLuint line_offset = y * 64;
2941
2942 for (GLuint x = 16; x < 48; ++x)
2943 {
2944 const GLuint pixel_offset = x + line_offset;
2945
2946 data[pixel_offset] = blue_color;
2947 }
2948 }
2949
2950 texture.create(width, height, GL_RGBA8);
2951
2952 texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
2953
2954 return "uni_sampler";
2955 }
2956
2957 /** Prepare vertex buffer, vec2 tex_coord
2958 *
2959 * @param program Program object
2960 * @param buffer Vertex buffer
2961 * @param vao Vertex array object
2962 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)2963 void LineContinuationTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
2964 Utils::vertexArray &vao)
2965 {
2966 std::string tex_coord_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, m_texture_coordinates_name);
2967 GLint tex_coord_loc = program.getAttribLocation(tex_coord_name.c_str());
2968
2969 if (-1 == tex_coord_loc)
2970 {
2971 TCU_FAIL("Vertex attribute location is invalid");
2972 }
2973
2974 vao.generate();
2975 vao.bind();
2976
2977 buffer.generate(GL_ARRAY_BUFFER);
2978
2979 GLfloat data[] = {0.5f, 0.5f, 0.5f, 0.5f};
2980 GLsizeiptr data_size = sizeof(data);
2981
2982 buffer.update(data_size, data, GL_STATIC_DRAW);
2983
2984 /* GL entry points */
2985 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
2986
2987 /* Set up vao */
2988 gl.vertexAttribPointer(tex_coord_loc, 2 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
2989 0 /* offset */);
2990 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
2991
2992 /* Enable attribute */
2993 gl.enableVertexAttribArray(tex_coord_loc);
2994 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
2995 }
2996
2997 /** Get string describing test cases
2998 *
2999 * @param cases Test case
3000 *
3001 * @return String describing current test case
3002 **/
casesToStr(CASES cases) const3003 const GLchar *LineContinuationTest::casesToStr(CASES cases) const
3004 {
3005 const GLchar *result = 0;
3006 switch (cases)
3007 {
3008 case ASSIGNMENT_BEFORE_OPERATOR:
3009 result = "just before assignment operator";
3010 break;
3011 case ASSIGNMENT_AFTER_OPERATOR:
3012 result = "just after assignment operator";
3013 break;
3014 case VECTOR_VARIABLE_INITIALIZER:
3015 result = "inside vector variable initializer";
3016 break;
3017 case TOKEN_INSIDE_FUNCTION_NAME:
3018 result = "inside function name";
3019 break;
3020 case TOKEN_INSIDE_TYPE_NAME:
3021 result = "inside type name";
3022 break;
3023 case TOKEN_INSIDE_VARIABLE_NAME:
3024 result = "inside variable name";
3025 break;
3026 case PREPROCESSOR_TOKEN_INSIDE:
3027 result = "inside preprocessor token";
3028 break;
3029 case PREPROCESSOR_TOKEN_BETWEEN:
3030 result = "between preprocessor token";
3031 break;
3032 case COMMENT:
3033 result = "inside comment";
3034 break;
3035 case SOURCE_TERMINATION_NULL:
3036 result = "just before null terminating source";
3037 break;
3038 case SOURCE_TERMINATION_NON_NULL:
3039 result = "as last character in source string, without null termination";
3040 break;
3041 case PART_TERMINATION_NULL:
3042 result = "just before null terminating part of source";
3043 break;
3044 case PART_NEXT_TO_TERMINATION_NULL:
3045 result = "just before last character in part of source";
3046 break;
3047 case PART_TERMINATION_NON_NULL:
3048 result = "as last character in part string, without null termination";
3049 break;
3050 case PART_NEXT_TO_TERMINATION_NON_NULL:
3051 result = "just before last character in part string, without null termination";
3052 break;
3053 case DEBUG_CASE: /* intended fall through */
3054 default:
3055 result = "nowhere at all. This is debug!";
3056 break;
3057 }
3058
3059 return result;
3060 }
3061
3062 /** Get expected value, blue color as vec4
3063 *
3064 * @return blue color
3065 **/
getExpectedValueString() const3066 const GLchar *LineContinuationTest::getExpectedValueString() const
3067 {
3068 return "vec4(0, 0, 1, 1)";
3069 }
3070
3071 /** Get line continuation string, single or multiple \
3072 *
3073 * @return String
3074 **/
getLineContinuationString() const3075 std::string LineContinuationTest::getLineContinuationString() const
3076 {
3077 static const GLchar line_continuation_ending_dos[] = {'\\', 0x0d, 0x0a, 0x00};
3078 static const GLchar line_continuation_ending_unix[] = {'\\', 0x0a, 0x00};
3079
3080 std::string result;
3081 const GLchar *selected_string;
3082
3083 if (DOS == m_test_case.m_line_endings)
3084 {
3085 selected_string = line_continuation_ending_dos;
3086 }
3087 else
3088 {
3089 selected_string = line_continuation_ending_unix;
3090 }
3091
3092 GLuint n_repetitions = (ONCE == m_test_case.m_repetitions) ? 1 : m_n_repetitions;
3093
3094 for (GLuint i = 0; i < n_repetitions; ++i)
3095 {
3096 result.append(selected_string);
3097 }
3098
3099 return result;
3100 }
3101
3102 /** Decides if shader should consist of multiple parts for the current test case
3103 *
3104 * @return true if test case requires multiple parts, false otherwise
3105 **/
isShaderMultipart() const3106 bool LineContinuationTest::isShaderMultipart() const
3107 {
3108 bool result;
3109
3110 switch (m_test_case.m_case)
3111 {
3112 case ASSIGNMENT_BEFORE_OPERATOR:
3113 case ASSIGNMENT_AFTER_OPERATOR:
3114 case VECTOR_VARIABLE_INITIALIZER:
3115 case TOKEN_INSIDE_FUNCTION_NAME:
3116 case TOKEN_INSIDE_TYPE_NAME:
3117 case TOKEN_INSIDE_VARIABLE_NAME:
3118 case PREPROCESSOR_TOKEN_INSIDE:
3119 case PREPROCESSOR_TOKEN_BETWEEN:
3120 case COMMENT:
3121 case SOURCE_TERMINATION_NULL:
3122 case SOURCE_TERMINATION_NON_NULL:
3123 default:
3124 result = false;
3125 break;
3126 case PART_TERMINATION_NULL:
3127 case PART_NEXT_TO_TERMINATION_NULL:
3128 case PART_TERMINATION_NON_NULL:
3129 case PART_NEXT_TO_TERMINATION_NON_NULL:
3130 result = true;
3131 break;
3132 }
3133
3134 return result;
3135 }
3136
3137 /** String describing line endings
3138 *
3139 * @param line_ending Line ending enum
3140 *
3141 * @return "unix" or "dos" strings
3142 **/
lineEndingsToStr(LINE_ENDINGS line_ending) const3143 const GLchar *LineContinuationTest::lineEndingsToStr(LINE_ENDINGS line_ending) const
3144 {
3145 const GLchar *result = 0;
3146
3147 if (UNIX == line_ending)
3148 {
3149 result = "unix";
3150 }
3151 else
3152 {
3153 result = "dos";
3154 }
3155
3156 return result;
3157 }
3158
3159 /** String describing number of repetitions
3160 *
3161 * @param repetitions Repetitions enum
3162 *
3163 * @return "single" or "multiple" strings
3164 **/
repetitionsToStr(REPETITIONS repetitions) const3165 const GLchar *LineContinuationTest::repetitionsToStr(REPETITIONS repetitions) const
3166 {
3167 const GLchar *result = 0;
3168
3169 if (ONCE == repetitions)
3170 {
3171 result = "single";
3172 }
3173 else
3174 {
3175 result = "multiple";
3176 }
3177
3178 return result;
3179 }
3180
3181 /** Replace all CASES tokens
3182 *
3183 * @param source String with shader template
3184 **/
replaceAllCaseTokens(std::string & source) const3185 void LineContinuationTest::replaceAllCaseTokens(std::string &source) const
3186 {
3187
3188 /* Tokens to be replaced with line continuation */
3189 static const GLchar *token_assignment_before_operator_case = "ASSIGNMENT_BEFORE_OPERATOR_CASE";
3190 static const GLchar *token_assignment_after_operator_case = "ASSIGNMENT_AFTER_OPERATOR_CASE";
3191 static const GLchar *token_vector_initializer = "VECTOR_VARIABLE_INITIALIZER_CASE";
3192 static const GLchar *token_function_case = "FUNCTION_CASE";
3193 static const GLchar *token_type_case = "TYPE_CASE";
3194 static const GLchar *token_variable_case = "VARIABLE_CASE";
3195 static const GLchar *token_preprocessor_inside_case = "PREPROCESSOR_INSIDE_CASE";
3196 static const GLchar *token_preprocessor_between_case = "PREPROCESSOR_BETWEEN_CASE";
3197 static const GLchar *token_comment = "COMMENT_CASE";
3198 static const GLchar *token_termination = "TERMINATION_CASE";
3199 static const GLchar *token_next_to_termination = "NEXT_TO_TERMINATION_CASE";
3200
3201 /* Line continuation and empty string*/
3202 static const GLchar *empty = "";
3203 const std::string &line_continuation = getLineContinuationString();
3204
3205 /* These strings will used to replace "CASE" tokens */
3206 const GLchar *assignment_before_operator_case = empty;
3207 const GLchar *assignment_after_operator_case = empty;
3208 const GLchar *vector_variable_initializer_case = empty;
3209 const GLchar *function_case = empty;
3210 const GLchar *type_case = empty;
3211 const GLchar *variable_case = empty;
3212 const GLchar *preprocessor_inside_case = empty;
3213 const GLchar *preprocessor_between_case = empty;
3214 const GLchar *comment_case = empty;
3215 const GLchar *source_termination_case = empty;
3216 const GLchar *part_termination_case = empty;
3217 const GLchar *next_to_part_termination_case = empty;
3218
3219 /* Configuration of test case */
3220 switch (m_test_case.m_case)
3221 {
3222 case ASSIGNMENT_BEFORE_OPERATOR:
3223 assignment_before_operator_case = line_continuation.c_str();
3224 break;
3225 case ASSIGNMENT_AFTER_OPERATOR:
3226 assignment_after_operator_case = line_continuation.c_str();
3227 break;
3228 case VECTOR_VARIABLE_INITIALIZER:
3229 vector_variable_initializer_case = line_continuation.c_str();
3230 break;
3231 case TOKEN_INSIDE_FUNCTION_NAME:
3232 function_case = line_continuation.c_str();
3233 break;
3234 case TOKEN_INSIDE_TYPE_NAME:
3235 type_case = line_continuation.c_str();
3236 break;
3237 case TOKEN_INSIDE_VARIABLE_NAME:
3238 variable_case = line_continuation.c_str();
3239 break;
3240 case PREPROCESSOR_TOKEN_INSIDE:
3241 preprocessor_inside_case = line_continuation.c_str();
3242 break;
3243 case PREPROCESSOR_TOKEN_BETWEEN:
3244 preprocessor_between_case = line_continuation.c_str();
3245 break;
3246 case COMMENT:
3247 comment_case = line_continuation.c_str();
3248 break;
3249 case SOURCE_TERMINATION_NULL: /* intended fall through */
3250 case SOURCE_TERMINATION_NON_NULL:
3251 source_termination_case = line_continuation.c_str();
3252 break;
3253 case PART_TERMINATION_NULL: /* intended fall through */
3254 case PART_TERMINATION_NON_NULL:
3255 part_termination_case = line_continuation.c_str();
3256 source_termination_case = line_continuation.c_str();
3257 break;
3258 case PART_NEXT_TO_TERMINATION_NULL: /* intended fall through */
3259 case PART_NEXT_TO_TERMINATION_NON_NULL:
3260 next_to_part_termination_case = line_continuation.c_str();
3261 break;
3262 case DEBUG_CASE: /* intended fall through */
3263 default:
3264 break; /* no line continuations */
3265 }
3266
3267 Utils::replaceAllTokens(token_assignment_after_operator_case, assignment_after_operator_case, source);
3268 Utils::replaceAllTokens(token_assignment_before_operator_case, assignment_before_operator_case, source);
3269 Utils::replaceAllTokens(token_comment, comment_case, source);
3270 Utils::replaceAllTokens(token_function_case, function_case, source);
3271 Utils::replaceAllTokens(token_next_to_termination, next_to_part_termination_case, source);
3272 Utils::replaceAllTokens(token_termination, part_termination_case, source);
3273 Utils::replaceAllTokens(token_preprocessor_between_case, preprocessor_between_case, source);
3274 Utils::replaceAllTokens(token_preprocessor_inside_case, preprocessor_inside_case, source);
3275 Utils::replaceAllTokens(token_termination, source_termination_case, source);
3276 Utils::replaceAllTokens(token_type_case, type_case, source);
3277 Utils::replaceAllTokens(token_variable_case, variable_case, source);
3278 Utils::replaceAllTokens(token_vector_initializer, vector_variable_initializer_case, source);
3279 }
3280
3281 /** Decides if the current test case requires source lengths
3282 *
3283 * @return true if test requires lengths, false otherwise
3284 **/
useSourceLengths() const3285 bool LineContinuationTest::useSourceLengths() const
3286 {
3287 bool result;
3288
3289 switch (m_test_case.m_case)
3290 {
3291 case ASSIGNMENT_BEFORE_OPERATOR:
3292 case ASSIGNMENT_AFTER_OPERATOR:
3293 case VECTOR_VARIABLE_INITIALIZER:
3294 case TOKEN_INSIDE_FUNCTION_NAME:
3295 case TOKEN_INSIDE_TYPE_NAME:
3296 case TOKEN_INSIDE_VARIABLE_NAME:
3297 case PREPROCESSOR_TOKEN_INSIDE:
3298 case PREPROCESSOR_TOKEN_BETWEEN:
3299 case COMMENT:
3300 case SOURCE_TERMINATION_NULL:
3301 case PART_TERMINATION_NULL:
3302 case PART_NEXT_TO_TERMINATION_NULL:
3303 default:
3304 result = false;
3305 break;
3306 case SOURCE_TERMINATION_NON_NULL:
3307 case PART_TERMINATION_NON_NULL:
3308 case PART_NEXT_TO_TERMINATION_NON_NULL:
3309 result = true;
3310 break;
3311 }
3312
3313 return result;
3314 }
3315
3316 /** Constructor
3317 *
3318 * @param context Test context
3319 **/
LineNumberingTest(deqp::Context & context)3320 LineNumberingTest::LineNumberingTest(deqp::Context &context)
3321 : GLSLTestBase(context, "line_numbering", "Verify if line numbering is correct after line continuation")
3322 {
3323 /* Nothing to be done here */
3324 }
3325
3326 /** Prepare source for given shader stage
3327 *
3328 * @param in_stage Shader stage, compute shader will use 430
3329 * @param in_use_version_400 Select if 400 or 420 should be used
3330 * @param out_source Prepared shader source instance
3331 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3332 void LineNumberingTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3333 Utils::shaderSource &out_source)
3334 {
3335 static const GLchar *test_result_snippet_normal[6] = {/* Utils::COMPUTE_SHADER */
3336 "ivec4(11, 1, 2, 3)",
3337 /* Utils::VERTEX_SHADER */
3338 "ivec4(9, 1, 2, 3)",
3339 /* Utils::TESS_CTRL_SHADER */
3340 "ivec4(12, 1, 2, 3)",
3341 /* Utils::TESS_EVAL_SHADER */
3342 "ivec4(12, 1, 2, 3)",
3343 /* Utils::GEOMETRY_SHADER */
3344 "ivec4(13, 1, 2, 3)",
3345 /* Utils::FRAGMENT_SHADER */
3346 "ivec4(10, 1, 2, 3)"};
3347
3348 static const GLchar *test_result_snippet_400[6] = {/* Utils::COMPUTE_SHADER */
3349 "ivec4(13, 1, 2, 3)",
3350 /* Utils::VERTEX_SHADER */
3351 "ivec4(11, 1, 2, 3)",
3352 /* Utils::TESS_CTRL_SHADER */
3353 "ivec4(14, 1, 2, 3)",
3354 /* Utils::TESS_EVAL_SHADER */
3355 "ivec4(14, 1, 2, 3)",
3356 /* Utils::GEOMETRY_SHADER */
3357 "ivec4(15, 1, 2, 3)",
3358 /* Utils::FRAGMENT_SHADER */
3359 "ivec4(12, 1, 2, 3)"};
3360
3361 static const GLchar *line_numbering_snippet = "ivec4 glsl\\\n"
3362 "Test\\\n"
3363 "Function(in ivec3 arg)\n"
3364 "{\n"
3365 " return ivec4(__LINE__, arg.xyz);\n"
3366 "}\n";
3367
3368 static const GLchar *compute_shader_template =
3369 "VERSION\n"
3370 "\n"
3371 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3372 "\n"
3373 "writeonly uniform image2D uni_image;\n"
3374 "\n"
3375 "GLSL_TEST_FUNCTION"
3376 "\n"
3377 "void main()\n"
3378 "{\n"
3379 " vec4 result = vec4(1, 0, 0, 1);\n"
3380 "\n"
3381 " if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3382 " {\n"
3383 " result = vec4(0, 1, 0, 1);\n"
3384 " }\n"
3385 "\n"
3386 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3387 "}\n"
3388 "\n";
3389
3390 static const GLchar *fragment_shader_template =
3391 "VERSION\n"
3392 "\n"
3393 "in vec4 gs_fs_result;\n"
3394 "out vec4 fs_out_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) == gs_fs_result) )\n"
3404 " {\n"
3405 " result = vec4(0, 1, 0, 1);\n"
3406 " }\n"
3407 "\n"
3408 " fs_out_result = result;\n"
3409 "}\n"
3410 "\n";
3411
3412 static const GLchar *geometry_shader_template =
3413 "VERSION\n"
3414 "\n"
3415 "layout(points) in;\n"
3416 "layout(triangle_strip, max_vertices = 4) out;\n"
3417 "\n"
3418 "in vec4 tes_gs_result[];\n"
3419 "out vec4 gs_fs_result;\n"
3420 "\n"
3421 "GLSL_TEST_FUNCTION"
3422 "\n"
3423 "void main()\n"
3424 "{\n"
3425 " vec4 result = vec4(1, 0, 0, 1);\n"
3426 "\n"
3427 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3428 " (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3429 " {\n"
3430 " result = vec4(0, 1, 0, 1);\n"
3431 " }\n"
3432 "\n"
3433 " gs_fs_result = result;\n"
3434 " gl_Position = vec4(-1, -1, 0, 1);\n"
3435 " EmitVertex();\n"
3436 " gs_fs_result = result;\n"
3437 " gl_Position = vec4(-1, 1, 0, 1);\n"
3438 " EmitVertex();\n"
3439 " gs_fs_result = result;\n"
3440 " gl_Position = vec4(1, -1, 0, 1);\n"
3441 " EmitVertex();\n"
3442 " gs_fs_result = result;\n"
3443 " gl_Position = vec4(1, 1, 0, 1);\n"
3444 " EmitVertex();\n"
3445 "}\n"
3446 "\n";
3447
3448 static const GLchar *tess_ctrl_shader_template =
3449 "VERSION\n"
3450 "\n"
3451 "layout(vertices = 1) out;\n"
3452 "\n"
3453 "in vec4 vs_tcs_result[];\n"
3454 "out vec4 tcs_tes_result[];\n"
3455 "\n"
3456 "GLSL_TEST_FUNCTION"
3457 "\n"
3458 "void main()\n"
3459 "{\n"
3460 " vec4 result = vec4(1, 0, 0, 1);\n"
3461 "\n"
3462 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3463 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3464 " {\n"
3465 " result = vec4(0, 1, 0, 1);\n"
3466 " }\n"
3467 "\n"
3468 " tcs_tes_result[gl_InvocationID] = result;\n"
3469 "\n"
3470 " gl_TessLevelOuter[0] = 1.0;\n"
3471 " gl_TessLevelOuter[1] = 1.0;\n"
3472 " gl_TessLevelOuter[2] = 1.0;\n"
3473 " gl_TessLevelOuter[3] = 1.0;\n"
3474 " gl_TessLevelInner[0] = 1.0;\n"
3475 " gl_TessLevelInner[1] = 1.0;\n"
3476 "}\n"
3477 "\n";
3478
3479 static const GLchar *tess_eval_shader_template =
3480 "VERSION\n"
3481 "\n"
3482 "layout(isolines, point_mode) in;\n"
3483 "\n"
3484 "in vec4 tcs_tes_result[];\n"
3485 "out vec4 tes_gs_result;\n"
3486 "\n"
3487 "GLSL_TEST_FUNCTION"
3488 "\n"
3489 "void main()\n"
3490 "{\n"
3491 " vec4 result = vec4(1, 0, 0, 1);\n"
3492 "\n"
3493 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3494 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3495 " {\n"
3496 " result = vec4(0, 1, 0, 1);\n"
3497 " }\n"
3498 "\n"
3499 " tes_gs_result = result;\n"
3500 "}\n"
3501 "\n";
3502
3503 static const GLchar *vertex_shader_template = "VERSION\n"
3504 "\n"
3505 "out vec4 vs_tcs_result;\n"
3506 "\n"
3507 "GLSL_TEST_FUNCTION"
3508 "\n"
3509 "void main()\n"
3510 "{\n"
3511 " vec4 result = vec4(1, 0, 0, 1);\n"
3512 "\n"
3513 " if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3514 " {\n"
3515 " result = vec4(0, 1, 0, 1);\n"
3516 " }\n"
3517 "\n"
3518 " vs_tcs_result = result;\n"
3519 "}\n"
3520 "\n";
3521
3522 const GLchar *shader_template = 0;
3523
3524 switch (in_stage)
3525 {
3526 case Utils::COMPUTE_SHADER:
3527 shader_template = compute_shader_template;
3528 break;
3529 case Utils::FRAGMENT_SHADER:
3530 shader_template = fragment_shader_template;
3531 break;
3532 case Utils::GEOMETRY_SHADER:
3533 shader_template = geometry_shader_template;
3534 break;
3535 case Utils::TESS_CTRL_SHADER:
3536 shader_template = tess_ctrl_shader_template;
3537 break;
3538 case Utils::TESS_EVAL_SHADER:
3539 shader_template = tess_eval_shader_template;
3540 break;
3541 case Utils::VERTEX_SHADER:
3542 shader_template = vertex_shader_template;
3543 break;
3544 default:
3545 TCU_FAIL("Invalid enum");
3546 }
3547
3548 out_source.m_parts[0].m_code = shader_template;
3549
3550 size_t position = 0;
3551 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3552 out_source.m_parts[0].m_code);
3553
3554 Utils::replaceToken("GLSL_TEST_FUNCTION", position, line_numbering_snippet, out_source.m_parts[0].m_code);
3555
3556 Utils::replaceToken("GLSL_TEST_RESULT", position,
3557 in_use_version_400 ? test_result_snippet_400[in_stage] : test_result_snippet_normal[in_stage],
3558 out_source.m_parts[0].m_code);
3559 }
3560
3561 /** Constructor
3562 *
3563 * @param context Test context
3564 **/
UTF8CharactersTest(deqp::Context & context)3565 UTF8CharactersTest::UTF8CharactersTest(deqp::Context &context)
3566 : GLSLTestBase(context, "utf8_characters", "UTF8 character used in comment or preprocessor")
3567 {
3568 /* Nothing to be done here */
3569 }
3570
3571 /** Overwrite getShaderSourceConfig method
3572 *
3573 * @param out_n_parts Number of source parts used by this test case
3574 * @param out_use_lengths If source lengths shall be provided to compiler
3575 **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)3576 void UTF8CharactersTest::getShaderSourceConfig(GLuint &out_n_parts, bool &out_use_lengths)
3577 {
3578 out_n_parts = 1;
3579 out_use_lengths = (AS_LAST_CHARACTER_NON_NULL_TERMINATED == m_test_case.m_case) ? true : false;
3580 }
3581
3582 /** Set up next test case
3583 *
3584 * @param test_case_index Index of next test case
3585 *
3586 * @return false if there is no more test cases, true otherwise
3587 **/
prepareNextTestCase(glw::GLuint test_case_index)3588 bool UTF8CharactersTest::prepareNextTestCase(glw::GLuint test_case_index)
3589 {
3590 static const testCase test_cases[] = {
3591 {IN_COMMENT, Utils::TWO_BYTES},
3592 {IN_COMMENT, Utils::THREE_BYTES},
3593 {IN_COMMENT, Utils::FOUR_BYTES},
3594 {IN_COMMENT, Utils::FIVE_BYTES},
3595 {IN_COMMENT, Utils::SIX_BYTES},
3596 {IN_COMMENT, Utils::REDUNDANT_ASCII},
3597 {IN_PREPROCESSOR, Utils::TWO_BYTES},
3598 {IN_PREPROCESSOR, Utils::THREE_BYTES},
3599 {IN_PREPROCESSOR, Utils::FOUR_BYTES},
3600 {IN_PREPROCESSOR, Utils::FIVE_BYTES},
3601 {IN_PREPROCESSOR, Utils::SIX_BYTES},
3602 {IN_PREPROCESSOR, Utils::REDUNDANT_ASCII},
3603 {AS_LAST_CHARACTER_NULL_TERMINATED, Utils::TWO_BYTES},
3604 {AS_LAST_CHARACTER_NULL_TERMINATED, Utils::THREE_BYTES},
3605 {AS_LAST_CHARACTER_NULL_TERMINATED, Utils::FOUR_BYTES},
3606 {AS_LAST_CHARACTER_NULL_TERMINATED, Utils::FIVE_BYTES},
3607 {AS_LAST_CHARACTER_NULL_TERMINATED, Utils::SIX_BYTES},
3608 {AS_LAST_CHARACTER_NULL_TERMINATED, Utils::REDUNDANT_ASCII},
3609 {AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::TWO_BYTES},
3610 {AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::THREE_BYTES},
3611 {AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::FOUR_BYTES},
3612 {AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::FIVE_BYTES},
3613 {AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::SIX_BYTES},
3614 {AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::REDUNDANT_ASCII},
3615 };
3616
3617 static const GLuint max_test_cases = sizeof(test_cases) / sizeof(testCase);
3618
3619 if ((GLuint)-1 == test_case_index)
3620 {
3621 m_test_case.m_case = DEBUG_CASE;
3622 m_test_case.m_character = Utils::EMPTY;
3623 }
3624 else if (max_test_cases <= test_case_index)
3625 {
3626 return false;
3627 }
3628 else
3629 {
3630 m_test_case = test_cases[test_case_index];
3631 }
3632
3633 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case: utf8 character: "
3634 << Utils::getUtf8Character(m_test_case.m_character) << " is placed "
3635 << casesToStr() << tcu::TestLog::EndMessage;
3636
3637 return true;
3638 }
3639
3640 /** Prepare source for given shader stage
3641 *
3642 * @param in_stage Shader stage, compute shader will use 430
3643 * @param in_use_version_400 Select if 400 or 420 should be used
3644 * @param out_source Prepared shader source instance
3645 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3646 void UTF8CharactersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3647 Utils::shaderSource &out_source)
3648 {
3649 static const GLchar *compute_shader_template =
3650 "VERSION\n"
3651 "\n"
3652 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3653 "\n"
3654 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3655 "\n"
3656 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3657 "\n"
3658 "writeonly uniform image2D uni_image;\n"
3659 " uniform sampler2D uni_sampler;\n"
3660 "\n"
3661 "#if 0\n"
3662 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3663 "#else\n"
3664 " #define SET_RESULT(XX) result = XX\n"
3665 "#endif\n"
3666 "\n"
3667 "void main()\n"
3668 "{\n"
3669 " ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
3670 " vec4 result = vec4(1, 0, 0, 1);\n"
3671 "\n"
3672 " if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
3673 " {\n"
3674 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3675 " }\n"
3676 "\n"
3677 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3678 "}\n"
3679 "// Lorem ipsum LAST_CHARACTER_CASE";
3680
3681 static const GLchar *fragment_shader_template =
3682 "VERSION\n"
3683 "\n"
3684 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3685 "\n"
3686 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3687 "\n"
3688 "in vec4 gs_fs_result;\n"
3689 "in vec2 gs_fs_tex_coord;\n"
3690 "out vec4 fs_out_result;\n"
3691 "uniform sampler2D uni_sampler;\n"
3692 "\n"
3693 "#if 0\n"
3694 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3695 "#else\n"
3696 " #define SET_RESULT(XX) result = XX\n"
3697 "#endif\n"
3698 "\n"
3699 "void main()\n"
3700 "{\n"
3701 " vec4 result = vec4(1, 0, 0, 1);\n"
3702 "\n"
3703 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
3704 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3705 " {\n"
3706 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3707 " }\n"
3708 "\n"
3709 " fs_out_result = result;\n"
3710 "}\n"
3711 "// Lorem ipsum LAST_CHARACTER_CASE";
3712
3713 static const GLchar *geometry_shader_template =
3714 "VERSION\n"
3715 "\n"
3716 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3717 "\n"
3718 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3719 "\n"
3720 "layout(points) in;\n"
3721 "layout(triangle_strip, max_vertices = 4) out;\n"
3722 "\n"
3723 "in vec4 tes_gs_result[];\n"
3724 "out vec2 gs_fs_tex_coord;\n"
3725 "out vec4 gs_fs_result;\n"
3726 "uniform sampler2D uni_sampler;\n"
3727 "\n"
3728 "#if 0\n"
3729 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3730 "#else\n"
3731 " #define SET_RESULT(XX) result = XX\n"
3732 "#endif\n"
3733 "\n"
3734 "void main()\n"
3735 "{\n"
3736 " vec4 result = vec4(1, 0, 0, 1);\n"
3737 "\n"
3738 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
3739 " (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3740 " {\n"
3741 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3742 " }\n"
3743 "\n"
3744 " gs_fs_tex_coord = vec2(0.25, 0.25);\n"
3745 " gs_fs_result = result;\n"
3746 " gl_Position = vec4(-1, -1, 0, 1);\n"
3747 " EmitVertex();\n"
3748 " gs_fs_tex_coord = vec2(0.25, 0.75);\n"
3749 " gs_fs_result = result;\n"
3750 " gl_Position = vec4(-1, 1, 0, 1);\n"
3751 " EmitVertex();\n"
3752 " gs_fs_tex_coord = vec2(0.75, 0.25);\n"
3753 " gs_fs_result = result;\n"
3754 " gl_Position = vec4(1, -1, 0, 1);\n"
3755 " EmitVertex();\n"
3756 " gs_fs_tex_coord = vec2(0.75, 0.75);\n"
3757 " gs_fs_result = result;\n"
3758 " gl_Position = vec4(1, 1, 0, 1);\n"
3759 " EmitVertex();\n"
3760 "}\n"
3761 "// Lorem ipsum LAST_CHARACTER_CASE";
3762
3763 static const GLchar *tess_ctrl_shader_template =
3764 "VERSION\n"
3765 "\n"
3766 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3767 "\n"
3768 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3769 "\n"
3770 "layout(vertices = 1) out;\n"
3771 "\n"
3772 "in vec4 vs_tcs_result[];\n"
3773 "out vec4 tcs_tes_result[];\n"
3774 "uniform sampler2D uni_sampler;\n"
3775 "\n"
3776 "#if 0\n"
3777 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3778 "#else\n"
3779 " #define SET_RESULT(XX) result = XX\n"
3780 "#endif\n"
3781 "\n"
3782 "void main()\n"
3783 "{\n"
3784 " vec4 result = vec4(1, 0, 0, 1);\n"
3785 "\n"
3786 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
3787 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3788 " {\n"
3789 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3790 " }\n"
3791 "\n"
3792 " tcs_tes_result[gl_InvocationID] = result;\n"
3793 "\n"
3794 " gl_TessLevelOuter[0] = 1.0;\n"
3795 " gl_TessLevelOuter[1] = 1.0;\n"
3796 " gl_TessLevelOuter[2] = 1.0;\n"
3797 " gl_TessLevelOuter[3] = 1.0;\n"
3798 " gl_TessLevelInner[0] = 1.0;\n"
3799 " gl_TessLevelInner[1] = 1.0;\n"
3800 "}\n"
3801 "// Lorem ipsum LAST_CHARACTER_CASE";
3802
3803 static const GLchar *tess_eval_shader_template =
3804 "VERSION\n"
3805 "\n"
3806 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3807 "\n"
3808 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3809 "\n"
3810 "layout(isolines, point_mode) in;\n"
3811 "\n"
3812 "in vec4 tcs_tes_result[];\n"
3813 "out vec4 tes_gs_result;\n"
3814 "uniform sampler2D uni_sampler;\n"
3815 "\n"
3816 "#if 0\n"
3817 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3818 "#else\n"
3819 " #define SET_RESULT(XX) result = XX\n"
3820 "#endif\n"
3821 "\n"
3822 "void main()\n"
3823 "{\n"
3824 " vec4 result = vec4(1, 0, 0, 1);\n"
3825 "\n"
3826 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
3827 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3828 " {\n"
3829 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3830 " }\n"
3831 "\n"
3832 " tes_gs_result = result;\n"
3833 "}\n"
3834 "// Lorem ipsum LAST_CHARACTER_CASE";
3835
3836 static const GLchar *vertex_shader_template =
3837 "VERSION\n"
3838 "\n"
3839 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3840 "\n"
3841 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3842 "\n"
3843 "out vec4 vs_tcs_result;\n"
3844 "uniform sampler2D uni_sampler;\n"
3845 "\n"
3846 "#if 0\n"
3847 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3848 "#else\n"
3849 " #define SET_RESULT(XX) result = XX\n"
3850 "#endif\n"
3851 "\n"
3852 "void main()\n"
3853 "{\n"
3854 " vec4 result = vec4(1, 0, 0, 1);\n"
3855 "\n"
3856 " if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
3857 " {\n"
3858 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3859 " }\n"
3860 "\n"
3861 " vs_tcs_result = result;\n"
3862 "}\n"
3863 "// Lorem ipsum LAST_CHARACTER_CASE";
3864
3865 const GLchar *shader_template = 0;
3866 const GLchar *comment_case = "";
3867 const GLchar *preprocessor_case = "";
3868 const GLchar *last_character_case = "";
3869 const GLchar *utf8_character = Utils::getUtf8Character(m_test_case.m_character);
3870
3871 switch (in_stage)
3872 {
3873 case Utils::COMPUTE_SHADER:
3874 shader_template = compute_shader_template;
3875 break;
3876 case Utils::FRAGMENT_SHADER:
3877 shader_template = fragment_shader_template;
3878 break;
3879 case Utils::GEOMETRY_SHADER:
3880 shader_template = geometry_shader_template;
3881 break;
3882 case Utils::TESS_CTRL_SHADER:
3883 shader_template = tess_ctrl_shader_template;
3884 break;
3885 case Utils::TESS_EVAL_SHADER:
3886 shader_template = tess_eval_shader_template;
3887 break;
3888 case Utils::VERTEX_SHADER:
3889 shader_template = vertex_shader_template;
3890 break;
3891 default:
3892 TCU_FAIL("Invalid enum");
3893 }
3894
3895 switch (m_test_case.m_case)
3896 {
3897 case IN_COMMENT:
3898 comment_case = utf8_character;
3899 break;
3900 case IN_PREPROCESSOR:
3901 preprocessor_case = utf8_character;
3902 break;
3903 case AS_LAST_CHARACTER_NULL_TERMINATED:
3904 last_character_case = utf8_character;
3905 break;
3906 case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
3907 last_character_case = utf8_character;
3908 break;
3909 case DEBUG_CASE:
3910 break;
3911 default:
3912 TCU_FAIL("Invalid enum");
3913 }
3914
3915 out_source.m_parts[0].m_code = shader_template;
3916
3917 size_t position = 0;
3918 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3919 out_source.m_parts[0].m_code);
3920
3921 Utils::replaceAllTokens("COMMENT_CASE", comment_case, out_source.m_parts[0].m_code);
3922
3923 Utils::replaceAllTokens("PREPROCESSOR_CASE", preprocessor_case, out_source.m_parts[0].m_code);
3924
3925 Utils::replaceAllTokens("LAST_CHARACTER_CASE", last_character_case, out_source.m_parts[0].m_code);
3926 }
3927
3928 /** Prepare texture
3929 *
3930 * @param texture Texutre to be created and filled with content
3931 *
3932 * @return Name of sampler uniform that should be used for the texture
3933 **/
prepareSourceTexture(Utils::texture & texture)3934 const GLchar *UTF8CharactersTest::prepareSourceTexture(Utils::texture &texture)
3935 {
3936 std::vector<GLuint> data;
3937 static const GLuint width = 64;
3938 static const GLuint height = 64;
3939 static const GLuint data_size = width * height;
3940 static const GLuint blue_color = 0xffff0000;
3941 static const GLuint grey_color = 0xaaaaaaaa;
3942
3943 data.resize(data_size);
3944
3945 for (GLuint i = 0; i < data_size; ++i)
3946 {
3947 data[i] = grey_color;
3948 }
3949
3950 for (GLuint y = 16; y < 48; ++y)
3951 {
3952 const GLuint line_offset = y * 64;
3953
3954 for (GLuint x = 16; x < 48; ++x)
3955 {
3956 const GLuint pixel_offset = x + line_offset;
3957
3958 data[pixel_offset] = blue_color;
3959 }
3960 }
3961
3962 texture.create(width, height, GL_RGBA8);
3963
3964 texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
3965
3966 return "uni_sampler";
3967 }
3968
3969 /** Returns description of current test case
3970 *
3971 * @return String with description
3972 **/
casesToStr() const3973 const GLchar *UTF8CharactersTest::casesToStr() const
3974 {
3975 const GLchar *result = 0;
3976
3977 switch (m_test_case.m_case)
3978 {
3979 case IN_COMMENT:
3980 result = "in comment";
3981 break;
3982 case IN_PREPROCESSOR:
3983 result = "in preprocessor";
3984 break;
3985 case AS_LAST_CHARACTER_NULL_TERMINATED:
3986 result = "just before null";
3987 break;
3988 case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
3989 result = "as last character";
3990 break;
3991 case DEBUG_CASE:
3992 result = "nowhere. This is debug!";
3993 break;
3994 default:
3995 TCU_FAIL("Invalid enum");
3996 }
3997
3998 return result;
3999 }
4000
4001 /** Constructor
4002 *
4003 * @param context Test context
4004 **/
UTF8InSourceTest(deqp::Context & context)4005 UTF8InSourceTest::UTF8InSourceTest(deqp::Context &context)
4006 : NegativeTestBase(context, "utf8_in_source", "UTF8 characters used in shader source")
4007 {
4008 /* Nothing to be done here */
4009 }
4010
4011 /** Set up next test case
4012 *
4013 * @param test_case_index Index of next test case
4014 *
4015 * @return false if there is no more test cases, true otherwise
4016 **/
prepareNextTestCase(glw::GLuint test_case_index)4017 bool UTF8InSourceTest::prepareNextTestCase(glw::GLuint test_case_index)
4018 {
4019 static const Utils::UTF8_CHARACTERS test_cases[] = {Utils::TWO_BYTES, Utils::THREE_BYTES, Utils::FOUR_BYTES,
4020 Utils::FIVE_BYTES, Utils::SIX_BYTES, Utils::REDUNDANT_ASCII};
4021
4022 static const GLuint max_test_cases = sizeof(test_cases) / sizeof(Utils::UTF8_CHARACTERS);
4023
4024 if ((GLuint)-1 == test_case_index)
4025 {
4026 m_character = Utils::EMPTY;
4027 }
4028 else if (max_test_cases <= test_case_index)
4029 {
4030 return false;
4031 }
4032 else
4033 {
4034 m_character = test_cases[test_case_index];
4035 }
4036
4037 m_context.getTestContext().getLog() << tcu::TestLog::Message
4038 << "Test case: utf8 character: " << Utils::getUtf8Character(m_character)
4039 << tcu::TestLog::EndMessage;
4040
4041 return true;
4042 }
4043
4044 /** Prepare source for given shader stage
4045 *
4046 * @param in_stage Shader stage, compute shader will use 430
4047 * @param in_use_version_400 Select if 400 or 420 should be used
4048 * @param out_source Prepared shader source instance
4049 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4050 void UTF8InSourceTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4051 Utils::shaderSource &out_source)
4052 {
4053 static const GLchar *compute_shader_template =
4054 "VERSION\n"
4055 "\n"
4056 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4057 "\n"
4058 "writeonly uniform image2D uni_image;\n"
4059 " uniform sampler2D uni_sampler;\n"
4060 "\n"
4061 "#define SET_RESULT(XX) resHEREult = XX\n"
4062 "\n"
4063 "void main()\n"
4064 "{\n"
4065 " ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
4066 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4067 "\n"
4068 " if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
4069 " {\n"
4070 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4071 " }\n"
4072 "\n"
4073 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), resHEREult);\n"
4074 "}\n"
4075 "";
4076
4077 static const GLchar *fragment_shader_template =
4078 "VERSION\n"
4079 "\n"
4080 "in vec4 gs_fs_result;\n"
4081 "in vec2 gs_fs_tex_coord;\n"
4082 "out vec4 fs_out_result;\n"
4083 "uniform sampler2D uni_sampler;\n"
4084 "\n"
4085 "#define SET_RESULT(XX) resHEREult = XX\n"
4086 "\n"
4087 "void main()\n"
4088 "{\n"
4089 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4090 "\n"
4091 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
4092 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
4093 " {\n"
4094 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4095 " }\n"
4096 "\n"
4097 " fs_out_result = resHEREult;\n"
4098 "}\n"
4099 "\n";
4100
4101 static const GLchar *geometry_shader_template =
4102 "VERSION\n"
4103 "\n"
4104 "layout(points) in;\n"
4105 "layout(triangle_strip, max_vertices = 4) out;\n"
4106 "\n"
4107 "in vec4 tes_gHEREs_result[];\n"
4108 "out vec2 gs_fs_tex_coord;\n"
4109 "out vec4 gs_fs_result;\n"
4110 "uniform sampler2D uni_sampler;\n"
4111 "\n"
4112 "#define SET_RESULT(XX) result = XX\n"
4113 "\n"
4114 "void main()\n"
4115 "{\n"
4116 " vec4 result = vec4(1, 0, 0, 1);\n"
4117 "\n"
4118 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
4119 " (vec4(0, 1, 0, 1) == tes_gHEREs_result[0]) )\n"
4120 " {\n"
4121 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4122 " }\n"
4123 "\n"
4124 " gs_fs_tex_coord = vec2(0.25, 0.25);\n"
4125 " gs_fs_result = result;\n"
4126 " gl_Position = vec4(-1, -1, 0, 1);\n"
4127 " EmitVertex();\n"
4128 " gs_fs_tex_coord = vec2(0.25, 0.75);\n"
4129 " gs_fs_result = result;\n"
4130 " gl_Position = vec4(-1, 1, 0, 1);\n"
4131 " EmitVertex();\n"
4132 " gs_fs_tex_coord = vec2(0.75, 0.25);\n"
4133 " gs_fs_result = result;\n"
4134 " gl_Position = vec4(1, -1, 0, 1);\n"
4135 " EmitVertex();\n"
4136 " gs_fs_tex_coord = vec2(0.75, 0.75);\n"
4137 " gs_fs_result = result;\n"
4138 " gl_Position = vec4(1, 1, 0, 1);\n"
4139 " EmitVertex();\n"
4140 "}\n"
4141 "\n";
4142
4143 static const GLchar *tess_ctrl_shader_template =
4144 "VERSION\n"
4145 "\n"
4146 "layout(vertices = 1) out;\n"
4147 "\n"
4148 "in vec4 vs_tcs_result[];\n"
4149 "out vec4 tcHEREs_tes_result[];\n"
4150 "uniform sampler2D uni_sampler;\n"
4151 "\n"
4152 "#define SET_RESULT(XX) resulHEREt = XX\n"
4153 "\n"
4154 "void main()\n"
4155 "{\n"
4156 " vec4 resulHEREt = vec4(1, 0, 0, 1);\n"
4157 "\n"
4158 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
4159 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
4160 " {\n"
4161 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4162 " }\n"
4163 "\n"
4164 " tcHEREs_tes_result[gl_InvocationID] = resulHEREt;\n"
4165 "\n"
4166 " gl_TessLevelOuter[0] = 1.0;\n"
4167 " gl_TessLevelOuter[1] = 1.0;\n"
4168 " gl_TessLevelOuter[2] = 1.0;\n"
4169 " gl_TessLevelOuter[3] = 1.0;\n"
4170 " gl_TessLevelInner[0] = 1.0;\n"
4171 " gl_TessLevelInner[1] = 1.0;\n"
4172 "}\n"
4173 "\n";
4174
4175 static const GLchar *tess_eval_shader_template =
4176 "VERSION\n"
4177 "\n"
4178 "layout(isolines, point_mode) in;\n"
4179 "\n"
4180 "in vec4 tcs_tes_result[];\n"
4181 "out vec4 teHEREs_gs_result;\n"
4182 "uniform sampler2D uni_sampler;\n"
4183 "\n"
4184 "#define SET_RESULT(XX) reHEREsult = XX\n"
4185 "\n"
4186 "void main()\n"
4187 "{\n"
4188 " vec4 reHEREsult = vec4(1, 0, 0, 1);\n"
4189 "\n"
4190 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
4191 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
4192 " {\n"
4193 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4194 " }\n"
4195 "\n"
4196 " teHEREs_gs_result = reHEREsult;\n"
4197 "}\n"
4198 "\n";
4199
4200 static const GLchar *vertex_shader_template = "VERSION\n"
4201 "\n"
4202 "out vec4 vs_tcs_HEREresult;\n"
4203 "uniform sampler2D uni_sampler;\n"
4204 "\n"
4205 "#define SET_RHEREESULT(XX) resHEREult = XX\n"
4206 "\n"
4207 "void main()\n"
4208 "{\n"
4209 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4210 "\n"
4211 " if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
4212 " {\n"
4213 " SET_RHEREESULT(vec4(0, 1, 0, 1));\n"
4214 " }\n"
4215 "\n"
4216 " vs_tcs_HEREresult = resHEREult;\n"
4217 "}\n"
4218 "\n";
4219
4220 const GLchar *shader_template = 0;
4221 const GLchar *utf8_character = Utils::getUtf8Character(m_character);
4222
4223 switch (in_stage)
4224 {
4225 case Utils::COMPUTE_SHADER:
4226 shader_template = compute_shader_template;
4227 break;
4228 case Utils::FRAGMENT_SHADER:
4229 shader_template = fragment_shader_template;
4230 break;
4231 case Utils::GEOMETRY_SHADER:
4232 shader_template = geometry_shader_template;
4233 break;
4234 case Utils::TESS_CTRL_SHADER:
4235 shader_template = tess_ctrl_shader_template;
4236 break;
4237 case Utils::TESS_EVAL_SHADER:
4238 shader_template = tess_eval_shader_template;
4239 break;
4240 case Utils::VERTEX_SHADER:
4241 shader_template = vertex_shader_template;
4242 break;
4243 default:
4244 TCU_FAIL("Invalid enum");
4245 }
4246
4247 out_source.m_parts[0].m_code = shader_template;
4248
4249 size_t position = 0;
4250 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4251 out_source.m_parts[0].m_code);
4252
4253 Utils::replaceAllTokens("HERE", utf8_character, out_source.m_parts[0].m_code);
4254 }
4255
4256 /** Constructor
4257 *
4258 * @param context Test context
4259 **/
ImplicitConversionsValidTest(deqp::Context & context)4260 ImplicitConversionsValidTest::ImplicitConversionsValidTest(deqp::Context &context)
4261 : GLSLTestBase(context, "implicit_conversions", "Verifies that implicit conversions are allowed")
4262 {
4263 /* Nothing to be done */
4264 }
4265
4266 /** Set up next test case
4267 *
4268 * @param test_case_index Index of next test case
4269 *
4270 * @return false if there is no more test cases, true otherwise
4271 **/
prepareNextTestCase(glw::GLuint test_case_index)4272 bool ImplicitConversionsValidTest::prepareNextTestCase(glw::GLuint test_case_index)
4273 {
4274 m_current_test_case_index = test_case_index;
4275
4276 if ((glw::GLuint)-1 == test_case_index)
4277 {
4278 return true;
4279 }
4280 else if (m_test_cases.size() <= test_case_index)
4281 {
4282 return false;
4283 }
4284
4285 const testCase &test_case = m_test_cases[test_case_index];
4286
4287 m_context.getTestContext().getLog() << tcu::TestLog::Message << "T1:"
4288 << Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols,
4289 test_case.m_n_rows)
4290 << " T2:"
4291 << Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols,
4292 test_case.m_n_rows)
4293 << tcu::TestLog::EndMessage;
4294
4295 return true;
4296 }
4297
4298 /** Prepare source for given shader stage
4299 *
4300 * @param in_stage Shader stage, compute shader will use 430
4301 * @param in_use_version_400 Select if 400 or 420 should be used
4302 * @param out_source Prepared shader source instance
4303 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4304 void ImplicitConversionsValidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4305 Utils::shaderSource &out_source)
4306 {
4307 static const GLchar *function_definition = "T1 function(in T2 left, in T2 right)\n"
4308 "{\n"
4309 " return left + right;\n"
4310 "}\n";
4311
4312 static const GLchar *verification_snippet = " const T2 const_left = T2(VALUE_LIST);\n"
4313 " const T2 const_right = T2(VALUE_LIST);\n"
4314 "\n"
4315 " T1 const_result = function(const_left, const_right);\n"
4316 "\n"
4317 " T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4318 "\n"
4319 " T2 var_left = uni_left;\n"
4320 " T2 var_right = uni_right;\n"
4321 "\n"
4322 " T1 var_result = function(var_left, var_right);\n"
4323 "\n"
4324 " if ((literal_result != const_result) ||\n"
4325 " (const_result != var_result) )\n"
4326 " {\n"
4327 " result = vec4(1, 0, 0, 1);\n"
4328 " }\n";
4329
4330 static const GLchar *compute_shader_template =
4331 "VERSION\n"
4332 "\n"
4333 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4334 "\n"
4335 "writeonly uniform image2D uni_image;\n"
4336 " uniform T2 uni_left;\n"
4337 " uniform T2 uni_right;\n"
4338 "\n"
4339 "FUNCTION_DEFINITION"
4340 "\n"
4341 "void main()\n"
4342 "{\n"
4343 " vec4 result = vec4(0, 1, 0, 1);\n"
4344 "\n"
4345 "VERIFICATION"
4346 "\n"
4347 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4348 "}\n"
4349 "\n";
4350
4351 static const GLchar *fragment_shader_template = "VERSION\n"
4352 "\n"
4353 "in vec4 gs_fs_result;\n"
4354 "out vec4 fs_out_result;\n"
4355 "uniform T2 uni_left;\n"
4356 "uniform T2 uni_right;\n"
4357 "\n"
4358 "FUNCTION_DEFINITION"
4359 "\n"
4360 "void main()\n"
4361 "{\n"
4362 " vec4 result = vec4(0, 1, 0, 1);\n"
4363 "\n"
4364 "VERIFICATION"
4365 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4366 " {\n"
4367 " result = vec4(1, 0, 0, 1);\n"
4368 " }\n"
4369 "\n"
4370 " fs_out_result = result;\n"
4371 "}\n"
4372 "\n";
4373
4374 static const GLchar *geometry_shader_template = "VERSION\n"
4375 "\n"
4376 "layout(points) in;\n"
4377 "layout(triangle_strip, max_vertices = 4) out;\n"
4378 "\n"
4379 "in vec4 tes_gs_result[];\n"
4380 "out vec4 gs_fs_result;\n"
4381 "uniform T2 uni_left;\n"
4382 "uniform T2 uni_right;\n"
4383 "\n"
4384 "FUNCTION_DEFINITION"
4385 "\n"
4386 "void main()\n"
4387 "{\n"
4388 " vec4 result = vec4(0, 1, 0, 1);\n"
4389 "\n"
4390 "VERIFICATION"
4391 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4392 " {\n"
4393 " result = vec4(1, 0, 0, 1);\n"
4394 " }\n"
4395 "\n"
4396 " gs_fs_result = result;\n"
4397 " gl_Position = vec4(-1, -1, 0, 1);\n"
4398 " EmitVertex();\n"
4399 " gs_fs_result = result;\n"
4400 " gl_Position = vec4(-1, 1, 0, 1);\n"
4401 " EmitVertex();\n"
4402 " gs_fs_result = result;\n"
4403 " gl_Position = vec4(1, -1, 0, 1);\n"
4404 " EmitVertex();\n"
4405 " gs_fs_result = result;\n"
4406 " gl_Position = vec4(1, 1, 0, 1);\n"
4407 " EmitVertex();\n"
4408 "}\n"
4409 "\n";
4410
4411 static const GLchar *tess_ctrl_shader_template =
4412 "VERSION\n"
4413 "\n"
4414 "layout(vertices = 1) out;\n"
4415 "\n"
4416 "in vec4 vs_tcs_result[];\n"
4417 "out vec4 tcs_tes_result[];\n"
4418 "uniform T2 uni_left;\n"
4419 "uniform T2 uni_right;\n"
4420 "\n"
4421 "FUNCTION_DEFINITION"
4422 "\n"
4423 "void main()\n"
4424 "{\n"
4425 " vec4 result = vec4(0, 1, 0, 1);\n"
4426 "\n"
4427 "VERIFICATION"
4428 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4429 " {\n"
4430 " result = vec4(1, 0, 0, 1);\n"
4431 " }\n"
4432 "\n"
4433 " tcs_tes_result[gl_InvocationID] = result;\n"
4434 "\n"
4435 " gl_TessLevelOuter[0] = 1.0;\n"
4436 " gl_TessLevelOuter[1] = 1.0;\n"
4437 " gl_TessLevelOuter[2] = 1.0;\n"
4438 " gl_TessLevelOuter[3] = 1.0;\n"
4439 " gl_TessLevelInner[0] = 1.0;\n"
4440 " gl_TessLevelInner[1] = 1.0;\n"
4441 "}\n"
4442 "\n";
4443
4444 static const GLchar *tess_eval_shader_template = "VERSION\n"
4445 "\n"
4446 "layout(isolines, point_mode) in;\n"
4447 "\n"
4448 "in vec4 tcs_tes_result[];\n"
4449 "out vec4 tes_gs_result;\n"
4450 "uniform T2 uni_left;\n"
4451 "uniform T2 uni_right;\n"
4452 "\n"
4453 "FUNCTION_DEFINITION"
4454 "\n"
4455 "void main()\n"
4456 "{\n"
4457 " vec4 result = vec4(0, 1, 0, 1);\n"
4458 "\n"
4459 "VERIFICATION"
4460 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4461 " {\n"
4462 " result = vec4(1, 0, 0, 1);\n"
4463 " }\n"
4464 "\n"
4465 " tes_gs_result = result;\n"
4466 "}\n"
4467 "\n";
4468
4469 static const GLchar *vertex_shader_template = "VERSION\n"
4470 "\n"
4471 "out vec4 vs_tcs_result;\n"
4472 "uniform T2 uni_left;\n"
4473 "uniform T2 uni_right;\n"
4474 "\n"
4475 "FUNCTION_DEFINITION"
4476 "\n"
4477 "void main()\n"
4478 "{\n"
4479 " vec4 result = vec4(0, 1, 0, 1);\n"
4480 "\n"
4481 "VERIFICATION"
4482 "\n"
4483 " vs_tcs_result = result;\n"
4484 "}\n"
4485 "\n";
4486
4487 const testCase &test_case = getCurrentTestCase();
4488 const GLchar *t1 = Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols, test_case.m_n_rows);
4489 const GLchar *t2 = Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols, test_case.m_n_rows);
4490 const std::string &value_list = getValueList(test_case.m_n_cols, test_case.m_n_rows);
4491 const GLchar *shader_template = 0;
4492
4493 switch (in_stage)
4494 {
4495 case Utils::COMPUTE_SHADER:
4496 shader_template = compute_shader_template;
4497 break;
4498 case Utils::FRAGMENT_SHADER:
4499 shader_template = fragment_shader_template;
4500 break;
4501 case Utils::GEOMETRY_SHADER:
4502 shader_template = geometry_shader_template;
4503 break;
4504 case Utils::TESS_CTRL_SHADER:
4505 shader_template = tess_ctrl_shader_template;
4506 break;
4507 case Utils::TESS_EVAL_SHADER:
4508 shader_template = tess_eval_shader_template;
4509 break;
4510 case Utils::VERTEX_SHADER:
4511 shader_template = vertex_shader_template;
4512 break;
4513 default:
4514 TCU_FAIL("Invalid enum");
4515 }
4516
4517 out_source.m_parts[0].m_code = shader_template;
4518
4519 size_t position = 0;
4520 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4521 out_source.m_parts[0].m_code);
4522
4523 Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4524
4525 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4526
4527 Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4528
4529 Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4530
4531 Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4532 }
4533
4534 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
4535 *
4536 * @param program Current program
4537 **/
prepareUniforms(Utils::program & program)4538 void ImplicitConversionsValidTest::prepareUniforms(Utils::program &program)
4539 {
4540 static const GLdouble double_data[16] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
4541 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
4542 static const GLfloat float_data[16] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
4543 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
4544 static const GLint int_data[4] = {1, 1, 1, 1};
4545 static const GLuint uint_data[4] = {1u, 1u, 1u, 1u};
4546
4547 const testCase &test_case = getCurrentTestCase();
4548
4549 switch (test_case.m_types.m_t2)
4550 {
4551 case Utils::DOUBLE:
4552 program.uniform("uni_left", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4553 program.uniform("uni_right", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4554 break;
4555 case Utils::FLOAT:
4556 program.uniform("uni_left", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4557 program.uniform("uni_right", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4558 break;
4559 case Utils::INT:
4560 program.uniform("uni_left", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4561 program.uniform("uni_right", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4562 break;
4563 case Utils::UINT:
4564 program.uniform("uni_left", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4565 program.uniform("uni_right", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4566 break;
4567 default:
4568 TCU_FAIL("Invalid enum");
4569 }
4570 }
4571
4572 /** Prepare test cases
4573 *
4574 * @return true
4575 **/
testInit()4576 bool ImplicitConversionsValidTest::testInit()
4577 {
4578 static const typesPair allowed_conversions[] = {
4579 {Utils::UINT, Utils::INT}, {Utils::FLOAT, Utils::INT}, {Utils::DOUBLE, Utils::INT},
4580 {Utils::FLOAT, Utils::UINT}, {Utils::DOUBLE, Utils::UINT}, {Utils::FLOAT, Utils::FLOAT},
4581 };
4582
4583 static GLuint n_allowed_conversions = sizeof(allowed_conversions) / sizeof(typesPair);
4584
4585 m_debug_test_case.m_types.m_t1 = Utils::FLOAT;
4586 m_debug_test_case.m_types.m_t2 = Utils::FLOAT;
4587 m_debug_test_case.m_n_cols = 4;
4588 m_debug_test_case.m_n_rows = 4;
4589
4590 for (GLuint i = 0; i < n_allowed_conversions; ++i)
4591 {
4592 const typesPair &types = allowed_conversions[i];
4593
4594 GLuint allowed_columns = 1;
4595 if ((true == Utils::doesTypeSupportMatrix(types.m_t1)) && (true == Utils::doesTypeSupportMatrix(types.m_t2)))
4596 {
4597 allowed_columns = 4;
4598 }
4599
4600 {
4601 testCase test_case = {types, 1, 1};
4602
4603 m_test_cases.push_back(test_case);
4604 }
4605
4606 for (GLuint row = 2; row <= 4; ++row)
4607 {
4608 for (GLuint col = 1; col <= allowed_columns; ++col)
4609 {
4610 testCase test_case = {types, col, row};
4611
4612 m_test_cases.push_back(test_case);
4613 }
4614 }
4615 }
4616
4617 return true;
4618 }
4619
4620 /** Returns reference to current test case
4621 *
4622 * @return Reference to testCase
4623 **/
getCurrentTestCase()4624 const ImplicitConversionsValidTest::testCase &ImplicitConversionsValidTest::getCurrentTestCase()
4625 {
4626 if ((glw::GLuint)-1 == m_current_test_case_index)
4627 {
4628 return m_debug_test_case;
4629 }
4630 else
4631 {
4632 return m_test_cases[m_current_test_case_index];
4633 }
4634 }
4635
4636 /** Get list of values to for glsl constants
4637 *
4638 * @param n_columns Number of columns
4639 * @param n_rows Number of rows
4640 *
4641 * @return String with list of values separated with comma
4642 **/
getValueList(glw::GLuint n_columns,glw::GLuint n_rows)4643 std::string ImplicitConversionsValidTest::getValueList(glw::GLuint n_columns, glw::GLuint n_rows)
4644 {
4645 std::string result;
4646
4647 for (GLuint i = 0; i < n_columns * n_rows; ++i)
4648 {
4649 if (i != n_columns * n_rows - 1)
4650 {
4651 result.append("1, ");
4652 }
4653 else
4654 {
4655 result.append("1");
4656 }
4657 }
4658
4659 return result;
4660 }
4661
4662 /** Constructor
4663 *
4664 * @param context Test context
4665 **/
ImplicitConversionsInvalidTest(deqp::Context & context)4666 ImplicitConversionsInvalidTest::ImplicitConversionsInvalidTest(deqp::Context &context)
4667 : NegativeTestBase(context, "implicit_conversions_invalid",
4668 "Verifies that implicit conversions from uint to int are forbidden")
4669 , m_current_test_case_index(0)
4670 {
4671 /* Nothing to be done here */
4672 }
4673
4674 /** Set up next test case
4675 *
4676 * @param test_case_index Index of next test case
4677 *
4678 * @return false if there is no more test cases, true otherwise
4679 **/
prepareNextTestCase(glw::GLuint test_case_index)4680 bool ImplicitConversionsInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
4681 {
4682 m_current_test_case_index = test_case_index;
4683
4684 if ((glw::GLuint)-1 == test_case_index)
4685 {
4686 return false;
4687 }
4688 else if (4 <= test_case_index)
4689 {
4690 return false;
4691 }
4692
4693 m_context.getTestContext().getLog() << tcu::TestLog::Message
4694 << "T1:" << Utils::getTypeName(Utils::UINT, 1, test_case_index + 1)
4695 << " T2:" << Utils::getTypeName(Utils::INT, 1, test_case_index + 1)
4696 << tcu::TestLog::EndMessage;
4697
4698 return true;
4699 }
4700
4701 /** Prepare source for given shader stage
4702 *
4703 * @param in_stage Shader stage, compute shader will use 430
4704 * @param in_use_version_400 Select if 400 or 420 should be used
4705 * @param out_source Prepared shader source instance
4706 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4707 void ImplicitConversionsInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4708 Utils::shaderSource &out_source)
4709 {
4710 static const GLchar *function_definition = "T1 function(in T2 left, in T2 right)\n"
4711 "{\n"
4712 " return left + right;\n"
4713 "}\n";
4714
4715 static const GLchar *verification_snippet = " const T2 const_left = T2(VALUE_LIST);\n"
4716 " const T2 const_right = T2(VALUE_LIST);\n"
4717 "\n"
4718 " T1 const_result = function(const_left, const_right);\n"
4719 "\n"
4720 " T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4721 "\n"
4722 " T2 var_left = uni_left;\n"
4723 " T2 var_right = uni_right;\n"
4724 "\n"
4725 " T1 var_result = function(var_left, var_right);\n"
4726 "\n"
4727 " if ((literal_result != const_result) ||\n"
4728 " (const_result != var_result) )\n"
4729 " {\n"
4730 " result = vec4(1, 0, 0, 1);\n"
4731 " }\n";
4732
4733 static const GLchar *compute_shader_template =
4734 "VERSION\n"
4735 "\n"
4736 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4737 "\n"
4738 "writeonly uniform image2D uni_image;\n"
4739 " uniform T2 uni_left;\n"
4740 " uniform T2 uni_right;\n"
4741 "\n"
4742 "FUNCTION_DEFINITION"
4743 "\n"
4744 "void main()\n"
4745 "{\n"
4746 " vec4 result = vec4(0, 1, 0, 1);\n"
4747 "\n"
4748 "VERIFICATION"
4749 "\n"
4750 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4751 "}\n"
4752 "\n";
4753
4754 static const GLchar *fragment_shader_template = "VERSION\n"
4755 "\n"
4756 "in vec4 gs_fs_result;\n"
4757 "out vec4 fs_out_result;\n"
4758 "uniform T2 uni_left;\n"
4759 "uniform T2 uni_right;\n"
4760 "\n"
4761 "FUNCTION_DEFINITION"
4762 "\n"
4763 "void main()\n"
4764 "{\n"
4765 " vec4 result = vec4(0, 1, 0, 1);\n"
4766 "\n"
4767 "VERIFICATION"
4768 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4769 " {\n"
4770 " result = vec4(1, 0, 0, 1);\n"
4771 " }\n"
4772 "\n"
4773 " fs_out_result = result;\n"
4774 "}\n"
4775 "\n";
4776
4777 static const GLchar *geometry_shader_template = "VERSION\n"
4778 "\n"
4779 "layout(points) in;\n"
4780 "layout(triangle_strip, max_vertices = 4) out;\n"
4781 "\n"
4782 "in vec4 tes_gs_result[];\n"
4783 "out vec4 gs_fs_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) != tes_gs_result[0])\n"
4795 " {\n"
4796 " result = vec4(1, 0, 0, 1);\n"
4797 " }\n"
4798 "\n"
4799 " gs_fs_result = result;\n"
4800 " gl_Position = vec4(-1, -1, 0, 1);\n"
4801 " EmitVertex();\n"
4802 " gs_fs_result = result;\n"
4803 " gl_Position = vec4(-1, 1, 0, 1);\n"
4804 " EmitVertex();\n"
4805 " gs_fs_result = result;\n"
4806 " gl_Position = vec4(1, -1, 0, 1);\n"
4807 " EmitVertex();\n"
4808 " gs_fs_result = result;\n"
4809 " gl_Position = vec4(1, 1, 0, 1);\n"
4810 " EmitVertex();\n"
4811 "}\n"
4812 "\n";
4813
4814 static const GLchar *tess_ctrl_shader_template =
4815 "VERSION\n"
4816 "\n"
4817 "layout(vertices = 1) out;\n"
4818 "\n"
4819 "in vec4 vs_tcs_result[];\n"
4820 "out vec4 tcs_tes_result[];\n"
4821 "uniform T2 uni_left;\n"
4822 "uniform T2 uni_right;\n"
4823 "\n"
4824 "FUNCTION_DEFINITION"
4825 "\n"
4826 "void main()\n"
4827 "{\n"
4828 " vec4 result = vec4(0, 1, 0, 1);\n"
4829 "\n"
4830 "VERIFICATION"
4831 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4832 " {\n"
4833 " result = vec4(1, 0, 0, 1);\n"
4834 " }\n"
4835 "\n"
4836 " tcs_tes_result[gl_InvocationID] = result;\n"
4837 "\n"
4838 " gl_TessLevelOuter[0] = 1.0;\n"
4839 " gl_TessLevelOuter[1] = 1.0;\n"
4840 " gl_TessLevelOuter[2] = 1.0;\n"
4841 " gl_TessLevelOuter[3] = 1.0;\n"
4842 " gl_TessLevelInner[0] = 1.0;\n"
4843 " gl_TessLevelInner[1] = 1.0;\n"
4844 "}\n"
4845 "\n";
4846
4847 static const GLchar *tess_eval_shader_template = "VERSION\n"
4848 "\n"
4849 "layout(isolines, point_mode) in;\n"
4850 "\n"
4851 "in vec4 tcs_tes_result[];\n"
4852 "out vec4 tes_gs_result;\n"
4853 "uniform T2 uni_left;\n"
4854 "uniform T2 uni_right;\n"
4855 "\n"
4856 "FUNCTION_DEFINITION"
4857 "\n"
4858 "void main()\n"
4859 "{\n"
4860 " vec4 result = vec4(0, 1, 0, 1);\n"
4861 "\n"
4862 "VERIFICATION"
4863 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4864 " {\n"
4865 " result = vec4(1, 0, 0, 1);\n"
4866 " }\n"
4867 "\n"
4868 " tes_gs_result = result;\n"
4869 "}\n"
4870 "\n";
4871
4872 static const GLchar *vertex_shader_template = "VERSION\n"
4873 "\n"
4874 "out vec4 vs_tcs_result;\n"
4875 "uniform T2 uni_left;\n"
4876 "uniform T2 uni_right;\n"
4877 "\n"
4878 "FUNCTION_DEFINITION"
4879 "\n"
4880 "void main()\n"
4881 "{\n"
4882 " vec4 result = vec4(0, 1, 0, 1);\n"
4883 "\n"
4884 "VERIFICATION"
4885 "\n"
4886 " vs_tcs_result = result;\n"
4887 "}\n"
4888 "\n";
4889
4890 GLuint n_rows = m_current_test_case_index + 1;
4891 const GLchar *t1 = Utils::getTypeName(Utils::INT, 1, n_rows);
4892 const GLchar *t2 = Utils::getTypeName(Utils::UINT, 1, n_rows);
4893 const std::string &value_list = getValueList(n_rows);
4894 const GLchar *shader_template = 0;
4895
4896 switch (in_stage)
4897 {
4898 case Utils::COMPUTE_SHADER:
4899 shader_template = compute_shader_template;
4900 break;
4901 case Utils::FRAGMENT_SHADER:
4902 shader_template = fragment_shader_template;
4903 break;
4904 case Utils::GEOMETRY_SHADER:
4905 shader_template = geometry_shader_template;
4906 break;
4907 case Utils::TESS_CTRL_SHADER:
4908 shader_template = tess_ctrl_shader_template;
4909 break;
4910 case Utils::TESS_EVAL_SHADER:
4911 shader_template = tess_eval_shader_template;
4912 break;
4913 case Utils::VERTEX_SHADER:
4914 shader_template = vertex_shader_template;
4915 break;
4916 default:
4917 TCU_FAIL("Invalid enum");
4918 }
4919
4920 out_source.m_parts[0].m_code = shader_template;
4921
4922 size_t position = 0;
4923 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4924 out_source.m_parts[0].m_code);
4925
4926 Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4927
4928 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4929
4930 Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4931
4932 Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4933
4934 Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4935 }
4936
4937 /** Get list of values to for glsl constants
4938 *
4939 * @return String with list of values separated with comma
4940 **/
getValueList(glw::GLuint n_rows)4941 std::string ImplicitConversionsInvalidTest::getValueList(glw::GLuint n_rows)
4942 {
4943 std::string result;
4944
4945 for (GLuint i = 0; i < n_rows; ++i)
4946 {
4947 if (i != n_rows - 1)
4948 {
4949 result.append("1, ");
4950 }
4951 else
4952 {
4953 result.append("1");
4954 }
4955 }
4956
4957 return result;
4958 }
4959
4960 /** Constructor
4961 *
4962 * @param context Test context
4963 **/
ConstDynamicValueTest(deqp::Context & context)4964 ConstDynamicValueTest::ConstDynamicValueTest(deqp::Context &context)
4965 : GLSLTestBase(context, "const_dynamic_value", "Test if constants can be initialized with dynamic values")
4966 {
4967 /* Nothing to be done here */
4968 }
4969
4970 /** Prepare source for given shader stage
4971 *
4972 * @param in_stage Shader stage, compute shader will use 430
4973 * @param in_use_version_400 Select if 400 or 420 should be used
4974 * @param out_source Prepared shader source instance
4975 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4976 void ConstDynamicValueTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4977 Utils::shaderSource &out_source)
4978 {
4979 static const GLchar *struct_definition = "struct S {\n"
4980 " float scalar;\n"
4981 " vec4 vector;\n"
4982 " mat2 matrix;\n"
4983 "};\n";
4984
4985 static const GLchar *verification_snippet = " const float c1 = uni_scalar;\n"
4986 " const vec4 c2 = uni_vector;\n"
4987 " const mat2 c3 = uni_matrix;\n"
4988 " const S c4 = { uni_scalar, uni_vector, uni_matrix };\n"
4989 " const vec4 c5[15] = { uni_vector,\n"
4990 " uni_vector,\n"
4991 " uni_vector,\n"
4992 " uni_vector,\n"
4993 " uni_vector,\n"
4994 " uni_vector,\n"
4995 " uni_vector,\n"
4996 " uni_vector,\n"
4997 " uni_vector,\n"
4998 " uni_vector,\n"
4999 " uni_vector,\n"
5000 " uni_vector,\n"
5001 " uni_vector,\n"
5002 " uni_vector,\n"
5003 " uni_vector };\n"
5004 " if ((SCALAR != c1) ||\n"
5005 " (VECTOR != c2) ||\n"
5006 " (MATRIX != c3) ||\n"
5007 " (SCALAR != c4.scalar) ||\n"
5008 " (VECTOR != c4.vector) ||\n"
5009 " (MATRIX != c4.matrix) ||\n"
5010 " (VECTOR != c5[0]) ||\n"
5011 " (VECTOR != c5[1]) ||\n"
5012 " (VECTOR != c5[2]) ||\n"
5013 " (VECTOR != c5[3]) ||\n"
5014 " (VECTOR != c5[4]) ||\n"
5015 " (VECTOR != c5[5]) ||\n"
5016 " (VECTOR != c5[6]) ||\n"
5017 " (VECTOR != c5[7]) ||\n"
5018 " (VECTOR != c5[8]) ||\n"
5019 " (VECTOR != c5[9]) ||\n"
5020 " (VECTOR != c5[10]) ||\n"
5021 " (VECTOR != c5[11]) ||\n"
5022 " (VECTOR != c5[12]) ||\n"
5023 " (VECTOR != c5[13]) ||\n"
5024 " (VECTOR != c5[14]) )\n"
5025 " {\n"
5026 " result = vec4(1, 0, 0, 1);\n"
5027 " }\n";
5028
5029 static const GLchar *compute_shader_template =
5030 "VERSION\n"
5031 "\n"
5032 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5033 "\n"
5034 "writeonly uniform image2D uni_image;\n"
5035 " uniform float uni_scalar;\n"
5036 " uniform vec4 uni_vector;\n"
5037 " uniform mat2 uni_matrix;\n"
5038 "\n"
5039 "STRUCTURE_DEFINITION"
5040 "\n"
5041 "void main()\n"
5042 "{\n"
5043 " vec4 result = vec4(0, 1, 0, 1);\n"
5044 "\n"
5045 "VERIFICATION"
5046 "\n"
5047 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5048 "}\n"
5049 "\n";
5050
5051 static const GLchar *fragment_shader_template = "VERSION\n"
5052 "\n"
5053 "in vec4 gs_fs_result;\n"
5054 "out vec4 fs_out_result;\n"
5055 "uniform float uni_scalar;\n"
5056 "uniform vec4 uni_vector;\n"
5057 "uniform mat2 uni_matrix;\n"
5058 "\n"
5059 "STRUCTURE_DEFINITION"
5060 "\n"
5061 "void main()\n"
5062 "{\n"
5063 " vec4 result = vec4(0, 1, 0, 1);\n"
5064 "\n"
5065 "VERIFICATION"
5066 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5067 " {\n"
5068 " result = vec4(1, 0, 0, 1);\n"
5069 " }\n"
5070 "\n"
5071 " fs_out_result = result;\n"
5072 "}\n"
5073 "\n";
5074
5075 static const GLchar *geometry_shader_template = "VERSION\n"
5076 "\n"
5077 "layout(points) in;\n"
5078 "layout(triangle_strip, max_vertices = 4) out;\n"
5079 "\n"
5080 "in vec4 tes_gs_result[];\n"
5081 "out vec4 gs_fs_result;\n"
5082 "uniform float uni_scalar;\n"
5083 "uniform vec4 uni_vector;\n"
5084 "uniform mat2 uni_matrix;\n"
5085 "\n"
5086 "STRUCTURE_DEFINITION"
5087 "\n"
5088 "void main()\n"
5089 "{\n"
5090 " vec4 result = vec4(0, 1, 0, 1);\n"
5091 "\n"
5092 "VERIFICATION"
5093 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5094 " {\n"
5095 " result = vec4(1, 0, 0, 1);\n"
5096 " }\n"
5097 "\n"
5098 " gs_fs_result = result;\n"
5099 " gl_Position = vec4(-1, -1, 0, 1);\n"
5100 " EmitVertex();\n"
5101 " gs_fs_result = result;\n"
5102 " gl_Position = vec4(-1, 1, 0, 1);\n"
5103 " EmitVertex();\n"
5104 " gs_fs_result = result;\n"
5105 " gl_Position = vec4(1, -1, 0, 1);\n"
5106 " EmitVertex();\n"
5107 " gs_fs_result = result;\n"
5108 " gl_Position = vec4(1, 1, 0, 1);\n"
5109 " EmitVertex();\n"
5110 "}\n"
5111 "\n";
5112
5113 static const GLchar *tess_ctrl_shader_template =
5114 "VERSION\n"
5115 "\n"
5116 "layout(vertices = 1) out;\n"
5117 "\n"
5118 "in vec4 vs_tcs_result[];\n"
5119 "out vec4 tcs_tes_result[];\n"
5120 "uniform float uni_scalar;\n"
5121 "uniform vec4 uni_vector;\n"
5122 "uniform mat2 uni_matrix;\n"
5123 "\n"
5124 "STRUCTURE_DEFINITION"
5125 "\n"
5126 "void main()\n"
5127 "{\n"
5128 " vec4 result = vec4(0, 1, 0, 1);\n"
5129 "\n"
5130 "VERIFICATION"
5131 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5132 " {\n"
5133 " result = vec4(1, 0, 0, 1);\n"
5134 " }\n"
5135 "\n"
5136 " tcs_tes_result[gl_InvocationID] = result;\n"
5137 "\n"
5138 " gl_TessLevelOuter[0] = 1.0;\n"
5139 " gl_TessLevelOuter[1] = 1.0;\n"
5140 " gl_TessLevelOuter[2] = 1.0;\n"
5141 " gl_TessLevelOuter[3] = 1.0;\n"
5142 " gl_TessLevelInner[0] = 1.0;\n"
5143 " gl_TessLevelInner[1] = 1.0;\n"
5144 "}\n"
5145 "\n";
5146
5147 static const GLchar *tess_eval_shader_template = "VERSION\n"
5148 "\n"
5149 "layout(isolines, point_mode) in;\n"
5150 "\n"
5151 "in vec4 tcs_tes_result[];\n"
5152 "out vec4 tes_gs_result;\n"
5153 "uniform float uni_scalar;\n"
5154 "uniform vec4 uni_vector;\n"
5155 "uniform mat2 uni_matrix;\n"
5156 "\n"
5157 "STRUCTURE_DEFINITION"
5158 "\n"
5159 "void main()\n"
5160 "{\n"
5161 " vec4 result = vec4(0, 1, 0, 1);\n"
5162 "\n"
5163 "VERIFICATION"
5164 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5165 " {\n"
5166 " result = vec4(1, 0, 0, 1);\n"
5167 " }\n"
5168 "\n"
5169 " tes_gs_result = result;\n"
5170 "}\n"
5171 "\n";
5172
5173 static const GLchar *vertex_shader_template = "VERSION\n"
5174 "\n"
5175 "out vec4 vs_tcs_result;\n"
5176 "uniform float uni_scalar;\n"
5177 "uniform vec4 uni_vector;\n"
5178 "uniform mat2 uni_matrix;\n"
5179 "\n"
5180 "STRUCTURE_DEFINITION"
5181 "\n"
5182 "void main()\n"
5183 "{\n"
5184 " vec4 result = vec4(0, 1, 0, 1);\n"
5185 "\n"
5186 "VERIFICATION"
5187 "\n"
5188 " vs_tcs_result = result;\n"
5189 "}\n"
5190 "\n";
5191
5192 static const GLchar *scalar = "0.5";
5193 static const GLchar *vector = "vec4(0.5, 0.125, 0.375, 0)";
5194 static const GLchar *matrix = "mat2(0.5, 0.125, 0.375, 0)";
5195
5196 const GLchar *shader_template = 0;
5197
5198 switch (in_stage)
5199 {
5200 case Utils::COMPUTE_SHADER:
5201 shader_template = compute_shader_template;
5202 break;
5203 case Utils::FRAGMENT_SHADER:
5204 shader_template = fragment_shader_template;
5205 break;
5206 case Utils::GEOMETRY_SHADER:
5207 shader_template = geometry_shader_template;
5208 break;
5209 case Utils::TESS_CTRL_SHADER:
5210 shader_template = tess_ctrl_shader_template;
5211 break;
5212 case Utils::TESS_EVAL_SHADER:
5213 shader_template = tess_eval_shader_template;
5214 break;
5215 case Utils::VERTEX_SHADER:
5216 shader_template = vertex_shader_template;
5217 break;
5218 default:
5219 TCU_FAIL("Invalid enum");
5220 }
5221
5222 out_source.m_parts[0].m_code = shader_template;
5223
5224 size_t position = 0;
5225 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5226 out_source.m_parts[0].m_code);
5227
5228 Utils::replaceToken("STRUCTURE_DEFINITION", position, struct_definition, out_source.m_parts[0].m_code);
5229
5230 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5231
5232 Utils::replaceAllTokens("SCALAR", scalar, out_source.m_parts[0].m_code);
5233
5234 Utils::replaceAllTokens("VECTOR", vector, out_source.m_parts[0].m_code);
5235
5236 Utils::replaceAllTokens("MATRIX", matrix, out_source.m_parts[0].m_code);
5237 }
5238
5239 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
5240 *
5241 * @param program Current program
5242 **/
prepareUniforms(Utils::program & program)5243 void ConstDynamicValueTest::prepareUniforms(Utils::program &program)
5244 {
5245 static const GLfloat float_data[4] = {0.5f, 0.125f, 0.375f, 0.0f};
5246 static const GLfloat scalar = 0.5f;
5247
5248 program.uniform("uni_scalar", Utils::FLOAT, 1, 1, &scalar);
5249 program.uniform("uni_vector", Utils::FLOAT, 1, 4, float_data);
5250 program.uniform("uni_matrix", Utils::FLOAT, 2, 2, float_data);
5251 }
5252
5253 /** Constructor
5254 *
5255 * @param context Test context
5256 **/
ConstAssignmentTest(deqp::Context & context)5257 ConstAssignmentTest::ConstAssignmentTest(deqp::Context &context)
5258 : NegativeTestBase(context, "const_assignment", "Verifies that constants cannot be overwritten")
5259 , m_current_test_case_index(0)
5260 {
5261 /* Nothing to be done here */
5262 }
5263
5264 /** Set up next test case
5265 *
5266 * @param test_case_index Index of next test case
5267 *
5268 * @return false if there is no more test cases, true otherwise
5269 **/
prepareNextTestCase(glw::GLuint test_case_index)5270 bool ConstAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
5271 {
5272 m_current_test_case_index = test_case_index;
5273
5274 if ((glw::GLuint)-1 == test_case_index)
5275 {
5276 return true;
5277 }
5278 else if (2 <= test_case_index)
5279 {
5280 return false;
5281 }
5282
5283 return true;
5284 }
5285
5286 /** Prepare source for given shader stage
5287 *
5288 * @param in_stage Shader stage, compute shader will use 430
5289 * @param in_use_version_400 Select if 400 or 420 should be used
5290 * @param out_source Prepared shader source instance
5291 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5292 void ConstAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5293 Utils::shaderSource &out_source)
5294 {
5295 static const GLchar *verification_snippet = " const float c1 = INIT;\n"
5296 "\n"
5297 " float temp = c1;\n"
5298 "\n"
5299 " for (uint i = 0; i < 4; ++i)"
5300 " {\n"
5301 " temp += c1 + uni_value;\n"
5302 " c1 -= 0.125;\n"
5303 " }\n"
5304 "\n"
5305 " if (0.0 == temp)\n"
5306 " {\n"
5307 " result = vec4(1, 0, 0, 1);\n"
5308 " }\n";
5309
5310 static const GLchar *compute_shader_template =
5311 "VERSION\n"
5312 "\n"
5313 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5314 "\n"
5315 "writeonly uniform image2D uni_image;\n"
5316 " uniform float uni_value;\n"
5317 "\n"
5318 "void main()\n"
5319 "{\n"
5320 " vec4 result = vec4(0, 1, 0, 1);\n"
5321 "\n"
5322 "VERIFICATION"
5323 "\n"
5324 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5325 "}\n"
5326 "\n";
5327
5328 static const GLchar *fragment_shader_template = "VERSION\n"
5329 "\n"
5330 "in vec4 gs_fs_result;\n"
5331 "out vec4 fs_out_result;\n"
5332 "uniform float uni_value;\n"
5333 "\n"
5334 "void main()\n"
5335 "{\n"
5336 " vec4 result = vec4(0, 1, 0, 1);\n"
5337 "\n"
5338 "VERIFICATION"
5339 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5340 " {\n"
5341 " result = vec4(1, 0, 0, 1);\n"
5342 " }\n"
5343 "\n"
5344 " fs_out_result = result;\n"
5345 "}\n"
5346 "\n";
5347
5348 static const GLchar *geometry_shader_template = "VERSION\n"
5349 "\n"
5350 "layout(points) in;\n"
5351 "layout(triangle_strip, max_vertices = 4) out;\n"
5352 "\n"
5353 "in vec4 tes_gs_result[];\n"
5354 "out vec4 gs_fs_result;\n"
5355 "uniform float uni_value;\n"
5356 "\n"
5357 "void main()\n"
5358 "{\n"
5359 " vec4 result = vec4(0, 1, 0, 1);\n"
5360 "\n"
5361 "VERIFICATION"
5362 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5363 " {\n"
5364 " result = vec4(1, 0, 0, 1);\n"
5365 " }\n"
5366 "\n"
5367 " gs_fs_result = result;\n"
5368 " gl_Position = vec4(-1, -1, 0, 1);\n"
5369 " EmitVertex();\n"
5370 " gs_fs_result = result;\n"
5371 " gl_Position = vec4(-1, 1, 0, 1);\n"
5372 " EmitVertex();\n"
5373 " gs_fs_result = result;\n"
5374 " gl_Position = vec4(1, -1, 0, 1);\n"
5375 " EmitVertex();\n"
5376 " gs_fs_result = result;\n"
5377 " gl_Position = vec4(1, 1, 0, 1);\n"
5378 " EmitVertex();\n"
5379 "}\n"
5380 "\n";
5381
5382 static const GLchar *tess_ctrl_shader_template =
5383 "VERSION\n"
5384 "\n"
5385 "layout(vertices = 1) out;\n"
5386 "\n"
5387 "in vec4 vs_tcs_result[];\n"
5388 "out vec4 tcs_tes_result[];\n"
5389 "uniform float uni_value;\n"
5390 "\n"
5391 "void main()\n"
5392 "{\n"
5393 " vec4 result = vec4(0, 1, 0, 1);\n"
5394 "\n"
5395 "VERIFICATION"
5396 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5397 " {\n"
5398 " result = vec4(1, 0, 0, 1);\n"
5399 " }\n"
5400 "\n"
5401 " tcs_tes_result[gl_InvocationID] = result;\n"
5402 "\n"
5403 " gl_TessLevelOuter[0] = 1.0;\n"
5404 " gl_TessLevelOuter[1] = 1.0;\n"
5405 " gl_TessLevelOuter[2] = 1.0;\n"
5406 " gl_TessLevelOuter[3] = 1.0;\n"
5407 " gl_TessLevelInner[0] = 1.0;\n"
5408 " gl_TessLevelInner[1] = 1.0;\n"
5409 "}\n"
5410 "\n";
5411
5412 static const GLchar *tess_eval_shader_template = "VERSION\n"
5413 "\n"
5414 "layout(isolines, point_mode) in;\n"
5415 "\n"
5416 "in vec4 tcs_tes_result[];\n"
5417 "out vec4 tes_gs_result;\n"
5418 "uniform float uni_value;\n"
5419 "\n"
5420 "void main()\n"
5421 "{\n"
5422 " vec4 result = vec4(0, 1, 0, 1);\n"
5423 "\n"
5424 "VERIFICATION"
5425 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5426 " {\n"
5427 " result = vec4(1, 0, 0, 1);\n"
5428 " }\n"
5429 "\n"
5430 " tes_gs_result = result;\n"
5431 "}\n"
5432 "\n";
5433
5434 static const GLchar *vertex_shader_template = "VERSION\n"
5435 "\n"
5436 "out vec4 vs_tcs_result;\n"
5437 "uniform float uni_value;\n"
5438 "\n"
5439 "void main()\n"
5440 "{\n"
5441 " vec4 result = vec4(0, 1, 0, 1);\n"
5442 "\n"
5443 "VERIFICATION"
5444 "\n"
5445 " vs_tcs_result = result;\n"
5446 "}\n"
5447 "\n";
5448
5449 static const GLchar *dynamic_init = "uni_value";
5450 static const GLchar *const_init = "0.75";
5451
5452 const GLchar *shader_template = 0;
5453 const GLchar *l_init = 0;
5454
5455 switch (in_stage)
5456 {
5457 case Utils::COMPUTE_SHADER:
5458 shader_template = compute_shader_template;
5459 break;
5460 case Utils::FRAGMENT_SHADER:
5461 shader_template = fragment_shader_template;
5462 break;
5463 case Utils::GEOMETRY_SHADER:
5464 shader_template = geometry_shader_template;
5465 break;
5466 case Utils::TESS_CTRL_SHADER:
5467 shader_template = tess_ctrl_shader_template;
5468 break;
5469 case Utils::TESS_EVAL_SHADER:
5470 shader_template = tess_eval_shader_template;
5471 break;
5472 case Utils::VERTEX_SHADER:
5473 shader_template = vertex_shader_template;
5474 break;
5475 default:
5476 TCU_FAIL("Invalid enum");
5477 }
5478
5479 if (0 == m_current_test_case_index)
5480 {
5481 l_init = dynamic_init;
5482 }
5483 else
5484 {
5485 l_init = const_init;
5486 }
5487
5488 out_source.m_parts[0].m_code = shader_template;
5489
5490 size_t position = 0;
5491 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5492 out_source.m_parts[0].m_code);
5493
5494 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5495
5496 Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5497 }
5498
5499 /** Constructor
5500 *
5501 * @param context Test context
5502 **/
ConstDynamicValueAsConstExprTest(deqp::Context & context)5503 ConstDynamicValueAsConstExprTest::ConstDynamicValueAsConstExprTest(deqp::Context &context)
5504 : NegativeTestBase(context, "const_dynamic_value_as_const_expr",
5505 "Verifies that dynamic constants cannot be used as constant foldable expressions")
5506 {
5507 /* Nothing to be done here */
5508 }
5509
5510 /** Prepare source for given shader stage
5511 *
5512 * @param in_stage Shader stage, compute shader will use 430
5513 * @param in_use_version_400 Select if 400 or 420 should be used
5514 * @param out_source Prepared shader source instance
5515 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5516 void ConstDynamicValueAsConstExprTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5517 Utils::shaderSource &out_source)
5518 {
5519 static const GLchar *verification_snippet = " const uint c1 = INIT;\n"
5520 "\n"
5521 " float temp[c1];\n"
5522 "\n"
5523 " for (uint i = 0; i < c1; ++i)"
5524 " {\n"
5525 " temp[i] += uni_value;\n"
5526 " }\n"
5527 "\n"
5528 " if (0.0 == temp[c1 - 1])\n"
5529 " {\n"
5530 " result = vec4(1, 0, 0, 1);\n"
5531 " }\n";
5532
5533 static const GLchar *compute_shader_template =
5534 "VERSION\n"
5535 "\n"
5536 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5537 "\n"
5538 "writeonly uniform image2D uni_image;\n"
5539 " uniform uint uni_value;\n"
5540 "\n"
5541 "void main()\n"
5542 "{\n"
5543 " vec4 result = vec4(0, 1, 0, 1);\n"
5544 "\n"
5545 "VERIFICATION"
5546 "\n"
5547 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5548 "}\n"
5549 "\n";
5550
5551 static const GLchar *fragment_shader_template = "VERSION\n"
5552 "\n"
5553 "in vec4 gs_fs_result;\n"
5554 "out vec4 fs_out_result;\n"
5555 "uniform uint uni_value;\n"
5556 "\n"
5557 "void main()\n"
5558 "{\n"
5559 " vec4 result = vec4(0, 1, 0, 1);\n"
5560 "\n"
5561 "VERIFICATION"
5562 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5563 " {\n"
5564 " result = vec4(1, 0, 0, 1);\n"
5565 " }\n"
5566 "\n"
5567 " fs_out_result = result;\n"
5568 "}\n"
5569 "\n";
5570
5571 static const GLchar *geometry_shader_template = "VERSION\n"
5572 "\n"
5573 "layout(points) in;\n"
5574 "layout(triangle_strip, max_vertices = 4) out;\n"
5575 "\n"
5576 "in vec4 tes_gs_result[];\n"
5577 "out vec4 gs_fs_result;\n"
5578 "uniform uint uni_value;\n"
5579 "\n"
5580 "void main()\n"
5581 "{\n"
5582 " vec4 result = vec4(0, 1, 0, 1);\n"
5583 "\n"
5584 "VERIFICATION"
5585 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5586 " {\n"
5587 " result = vec4(1, 0, 0, 1);\n"
5588 " }\n"
5589 "\n"
5590 " gs_fs_result = result;\n"
5591 " gl_Position = vec4(-1, -1, 0, 1);\n"
5592 " EmitVertex();\n"
5593 " gs_fs_result = result;\n"
5594 " gl_Position = vec4(-1, 1, 0, 1);\n"
5595 " EmitVertex();\n"
5596 " gs_fs_result = result;\n"
5597 " gl_Position = vec4(1, -1, 0, 1);\n"
5598 " EmitVertex();\n"
5599 " gs_fs_result = result;\n"
5600 " gl_Position = vec4(1, 1, 0, 1);\n"
5601 " EmitVertex();\n"
5602 "}\n"
5603 "\n";
5604
5605 static const GLchar *tess_ctrl_shader_template =
5606 "VERSION\n"
5607 "\n"
5608 "layout(vertices = 1) out;\n"
5609 "\n"
5610 "in vec4 vs_tcs_result[];\n"
5611 "out vec4 tcs_tes_result[];\n"
5612 "uniform uint uni_value;\n"
5613 "\n"
5614 "void main()\n"
5615 "{\n"
5616 " vec4 result = vec4(0, 1, 0, 1);\n"
5617 "\n"
5618 "VERIFICATION"
5619 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5620 " {\n"
5621 " result = vec4(1, 0, 0, 1);\n"
5622 " }\n"
5623 "\n"
5624 " tcs_tes_result[gl_InvocationID] = result;\n"
5625 "\n"
5626 " gl_TessLevelOuter[0] = 1.0;\n"
5627 " gl_TessLevelOuter[1] = 1.0;\n"
5628 " gl_TessLevelOuter[2] = 1.0;\n"
5629 " gl_TessLevelOuter[3] = 1.0;\n"
5630 " gl_TessLevelInner[0] = 1.0;\n"
5631 " gl_TessLevelInner[1] = 1.0;\n"
5632 "}\n"
5633 "\n";
5634
5635 static const GLchar *tess_eval_shader_template = "VERSION\n"
5636 "\n"
5637 "layout(isolines, point_mode) in;\n"
5638 "\n"
5639 "in vec4 tcs_tes_result[];\n"
5640 "out vec4 tes_gs_result;\n"
5641 "uniform uint uni_value;\n"
5642 "\n"
5643 "void main()\n"
5644 "{\n"
5645 " vec4 result = vec4(0, 1, 0, 1);\n"
5646 "\n"
5647 "VERIFICATION"
5648 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5649 " {\n"
5650 " result = vec4(1, 0, 0, 1);\n"
5651 " }\n"
5652 "\n"
5653 " tes_gs_result = result;\n"
5654 "}\n"
5655 "\n";
5656
5657 static const GLchar *vertex_shader_template = "VERSION\n"
5658 "\n"
5659 "out vec4 vs_tcs_result;\n"
5660 "uniform uint uni_value;\n"
5661 "\n"
5662 "void main()\n"
5663 "{\n"
5664 " vec4 result = vec4(0, 1, 0, 1);\n"
5665 "\n"
5666 "VERIFICATION"
5667 "\n"
5668 " vs_tcs_result = result;\n"
5669 "}\n"
5670 "\n";
5671
5672 static const GLchar *l_init = "uni_value";
5673
5674 const GLchar *shader_template = 0;
5675
5676 switch (in_stage)
5677 {
5678 case Utils::COMPUTE_SHADER:
5679 shader_template = compute_shader_template;
5680 break;
5681 case Utils::FRAGMENT_SHADER:
5682 shader_template = fragment_shader_template;
5683 break;
5684 case Utils::GEOMETRY_SHADER:
5685 shader_template = geometry_shader_template;
5686 break;
5687 case Utils::TESS_CTRL_SHADER:
5688 shader_template = tess_ctrl_shader_template;
5689 break;
5690 case Utils::TESS_EVAL_SHADER:
5691 shader_template = tess_eval_shader_template;
5692 break;
5693 case Utils::VERTEX_SHADER:
5694 shader_template = vertex_shader_template;
5695 break;
5696 default:
5697 TCU_FAIL("Invalid enum");
5698 }
5699
5700 out_source.m_parts[0].m_code = shader_template;
5701
5702 size_t position = 0;
5703 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5704 out_source.m_parts[0].m_code);
5705
5706 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5707
5708 Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5709 }
5710
5711 /** Constructor
5712 *
5713 * @param context Test context
5714 **/
QualifierOrderTest(deqp::Context & context)5715 QualifierOrderTest::QualifierOrderTest(deqp::Context &context)
5716 : GLSLTestBase(context, "qualifier_order",
5717 "Test verifies that valid permutation of input and output qalifiers are accepted")
5718 , m_current_test_case_index(0)
5719 {
5720 /* Nothing to be done */
5721 }
5722
5723 /** Set up next test case
5724 *
5725 * @param test_case_index Index of next test case
5726 *
5727 * @return false if there is no more test cases, true otherwise
5728 **/
prepareNextTestCase(glw::GLuint test_case_index)5729 bool QualifierOrderTest::prepareNextTestCase(glw::GLuint test_case_index)
5730 {
5731 m_current_test_case_index = test_case_index;
5732
5733 if ((glw::GLuint)-1 == test_case_index)
5734 {
5735 /* Nothing to be done here */
5736 }
5737 else if (m_test_cases.size() <= test_case_index)
5738 {
5739 return false;
5740 }
5741
5742 const Utils::qualifierSet &set = getCurrentTestCase();
5743
5744 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
5745
5746 for (GLuint i = 0; i < set.size(); ++i)
5747 {
5748 message << Utils::getQualifierString(set[i]) << " ";
5749 }
5750
5751 message << tcu::TestLog::EndMessage;
5752
5753 return true;
5754 }
5755
5756 /** Prepare source for given shader stage
5757 *
5758 * @param in_stage Shader stage, compute shader will use 430
5759 * @param in_use_version_400 Select if 400 or 420 should be used
5760 * @param out_source Prepared shader source instance
5761 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5762 void QualifierOrderTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5763 Utils::shaderSource &out_source)
5764 {
5765 static const GLchar *verification_snippet =
5766 " vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
5767 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
5768 " {\n"
5769 " result = INPUT_VARIABLE_NAME;\n"
5770 " }\n";
5771
5772 static const GLchar *fragment_shader_template = "VERSION\n"
5773 "\n"
5774 "in vec4 gs_fs_result;\n"
5775 "layout (location = 0) out vec4 fs_out_result;\n"
5776 "\n"
5777 "VARIABLE_DECLARATION;\n"
5778 "VARIABLE_DECLARATION;\n"
5779 "\n"
5780 "void main()\n"
5781 "{\n"
5782 " vec4 result = vec4(0, 1, 0, 1);\n"
5783 "\n"
5784 "VERIFICATION"
5785 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5786 " {\n"
5787 " result = vec4(1, 0, 0, 1);\n"
5788 " }\n"
5789 "\n"
5790 " fs_out_result = result;\n"
5791 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5792 "}\n"
5793 "\n";
5794
5795 static const GLchar *geometry_shader_template = "VERSION\n"
5796 "\n"
5797 "layout(points) in;\n"
5798 "layout(triangle_strip, max_vertices = 4) out;\n"
5799 "\n"
5800 "in vec4 tes_gs_result[];\n"
5801 "out vec4 gs_fs_result;\n"
5802 "\n"
5803 "VARIABLE_DECLARATION;\n"
5804 "VARIABLE_DECLARATION;\n"
5805 "\n"
5806 "void main()\n"
5807 "{\n"
5808 " vec4 result = vec4(0, 1, 0, 1);\n"
5809 "\n"
5810 "VERIFICATION"
5811 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5812 " {\n"
5813 " result = vec4(1, 0, 0, 1);\n"
5814 " }\n"
5815 "\n"
5816 " gs_fs_result = result;\n"
5817 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5818 " gl_Position = vec4(-1, -1, 0, 1);\n"
5819 " EmitVertex();\n"
5820 " gs_fs_result = result;\n"
5821 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5822 " gl_Position = vec4(-1, 1, 0, 1);\n"
5823 " EmitVertex();\n"
5824 " gs_fs_result = result;\n"
5825 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5826 " gl_Position = vec4(1, -1, 0, 1);\n"
5827 " EmitVertex();\n"
5828 " gs_fs_result = result;\n"
5829 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5830 " gl_Position = vec4(1, 1, 0, 1);\n"
5831 " EmitVertex();\n"
5832 "}\n"
5833 "\n";
5834
5835 static const GLchar *tess_ctrl_shader_template =
5836 "VERSION\n"
5837 "\n"
5838 "layout(vertices = 1) out;\n"
5839 "\n"
5840 "in vec4 vs_tcs_result[];\n"
5841 "out vec4 tcs_tes_result[];\n"
5842 "\n"
5843 "VARIABLE_DECLARATION;\n"
5844 "VARIABLE_DECLARATION;\n"
5845 "\n"
5846 "void main()\n"
5847 "{\n"
5848 " vec4 result = vec4(0, 1, 0, 1);\n"
5849 "\n"
5850 "VERIFICATION"
5851 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5852 " {\n"
5853 " result = vec4(1, 0, 0, 1);\n"
5854 " }\n"
5855 "\n"
5856 " tcs_tes_result[gl_InvocationID] = result;\n"
5857 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5858 "\n"
5859 " gl_TessLevelOuter[0] = 1.0;\n"
5860 " gl_TessLevelOuter[1] = 1.0;\n"
5861 " gl_TessLevelOuter[2] = 1.0;\n"
5862 " gl_TessLevelOuter[3] = 1.0;\n"
5863 " gl_TessLevelInner[0] = 1.0;\n"
5864 " gl_TessLevelInner[1] = 1.0;\n"
5865 "}\n"
5866 "\n";
5867
5868 static const GLchar *tess_eval_shader_template = "VERSION\n"
5869 "\n"
5870 "layout(isolines, point_mode) in;\n"
5871 "\n"
5872 "in vec4 tcs_tes_result[];\n"
5873 "out vec4 tes_gs_result;\n"
5874 "\n"
5875 "VARIABLE_DECLARATION;\n"
5876 "VARIABLE_DECLARATION;\n"
5877 "\n"
5878 "void main()\n"
5879 "{\n"
5880 " vec4 result = vec4(0, 1, 0, 1);\n"
5881 "\n"
5882 "VERIFICATION"
5883 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5884 " {\n"
5885 " result = vec4(1, 0, 0, 1);\n"
5886 " }\n"
5887 "\n"
5888 " tes_gs_result = result;\n"
5889 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5890 "}\n"
5891 "\n";
5892
5893 static const GLchar *vertex_shader_template = "VERSION\n"
5894 "\n"
5895 "out vec4 vs_tcs_result;\n"
5896 "\n"
5897 "VARIABLE_DECLARATION;\n"
5898 "VARIABLE_DECLARATION;\n"
5899 "\n"
5900 "void main()\n"
5901 "{\n"
5902 " vec4 result = vec4(0, 1, 0, 1);\n"
5903 "\n"
5904 "VERIFICATION"
5905 "\n"
5906 " vs_tcs_result = result;\n"
5907 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5908 "}\n"
5909 "\n";
5910
5911 const GLchar *shader_template = 0;
5912
5913 switch (in_stage)
5914 {
5915 case Utils::COMPUTE_SHADER:
5916 return;
5917 case Utils::FRAGMENT_SHADER:
5918 shader_template = fragment_shader_template;
5919 break;
5920 case Utils::GEOMETRY_SHADER:
5921 shader_template = geometry_shader_template;
5922 break;
5923 case Utils::TESS_CTRL_SHADER:
5924 shader_template = tess_ctrl_shader_template;
5925 break;
5926 case Utils::TESS_EVAL_SHADER:
5927 shader_template = tess_eval_shader_template;
5928 break;
5929 case Utils::VERTEX_SHADER:
5930 shader_template = vertex_shader_template;
5931 break;
5932 default:
5933 TCU_FAIL("Invalid enum");
5934 }
5935
5936 const Utils::qualifierSet &test_case = getCurrentTestCase();
5937
5938 std::string in_test_decl;
5939 std::string in_test_ref;
5940 std::string out_test_decl;
5941 std::string out_test_ref;
5942
5943 Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
5944 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
5945
5946 // sample storage qualifier is not a valid qualifier for fragment output
5947 if (in_stage == Utils::FRAGMENT_SHADER)
5948 {
5949 if (out_test_decl.find("sample") != std::string::npos)
5950 out_test_decl.erase(out_test_decl.find("sample"), 7);
5951 }
5952
5953 out_source.m_parts[0].m_code = shader_template;
5954
5955 size_t position = 0;
5956
5957 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5958 out_source.m_parts[0].m_code);
5959
5960 Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
5961
5962 Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
5963
5964 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5965
5966 position -= strlen(verification_snippet);
5967
5968 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
5969
5970 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
5971
5972 Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
5973 }
5974
5975 /**Prepare vertex buffer and vertex array object.
5976 *
5977 * @param program Program instance
5978 * @param buffer Buffer instance
5979 * @param vao VertexArray instance
5980 *
5981 * @return 0
5982 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)5983 void QualifierOrderTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
5984 Utils::vertexArray &vao)
5985 {
5986 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
5987 GLint test_loc = program.getAttribLocation(test_name.c_str());
5988
5989 if (-1 == test_loc)
5990 {
5991 TCU_FAIL("Vertex attribute location is invalid");
5992 }
5993
5994 vao.generate();
5995 vao.bind();
5996
5997 buffer.generate(GL_ARRAY_BUFFER);
5998
5999 GLfloat data[] = {0.0f, 0.0f, 1.0f, 1.0f};
6000 GLsizeiptr data_size = sizeof(data);
6001
6002 buffer.update(data_size, data, GL_STATIC_DRAW);
6003
6004 /* GL entry points */
6005 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
6006
6007 /* Set up vao */
6008 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6009 0 /* offset */);
6010 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6011
6012 /* Enable attribute */
6013 gl.enableVertexAttribArray(test_loc);
6014 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6015 }
6016
6017 /** Prepare test cases
6018 *
6019 * @return true
6020 **/
testInit()6021 bool QualifierOrderTest::testInit()
6022 {
6023 m_test_cases.resize(5);
6024
6025 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6026 m_test_cases[0].push_back(Utils::QUAL_IN);
6027 m_test_cases[0].push_back(Utils::QUAL_LOCATION);
6028 m_test_cases[0].push_back(Utils::QUAL_SMOOTH);
6029 m_test_cases[0].push_back(Utils::QUAL_INVARIANT);
6030
6031 m_test_cases[1].push_back(Utils::QUAL_LOWP);
6032 m_test_cases[1].push_back(Utils::QUAL_IN);
6033 m_test_cases[1].push_back(Utils::QUAL_SAMPLE);
6034 m_test_cases[1].push_back(Utils::QUAL_LOCATION);
6035 m_test_cases[1].push_back(Utils::QUAL_NOPERSPECTIVE);
6036 m_test_cases[1].push_back(Utils::QUAL_INVARIANT);
6037
6038 m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6039 m_test_cases[2].push_back(Utils::QUAL_IN);
6040 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6041 m_test_cases[2].push_back(Utils::QUAL_SMOOTH);
6042 m_test_cases[2].push_back(Utils::QUAL_INVARIANT);
6043 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6044
6045 m_test_cases[3].push_back(Utils::QUAL_LOWP);
6046 m_test_cases[3].push_back(Utils::QUAL_IN);
6047 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6048 m_test_cases[3].push_back(Utils::QUAL_SAMPLE);
6049 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6050 m_test_cases[3].push_back(Utils::QUAL_NOPERSPECTIVE);
6051 m_test_cases[3].push_back(Utils::QUAL_INVARIANT);
6052
6053 m_test_cases[4].push_back(Utils::QUAL_HIGHP);
6054 m_test_cases[4].push_back(Utils::QUAL_IN);
6055 m_test_cases[4].push_back(Utils::QUAL_PATCH);
6056 m_test_cases[4].push_back(Utils::QUAL_LOCATION);
6057 m_test_cases[4].push_back(Utils::QUAL_INVARIANT);
6058
6059 return true;
6060 }
6061
6062 /** Returns reference to current test case
6063 *
6064 * @return Reference to testCase
6065 **/
getCurrentTestCase()6066 const Utils::qualifierSet &QualifierOrderTest::getCurrentTestCase()
6067 {
6068 if ((glw::GLuint)-1 == m_current_test_case_index)
6069 {
6070 return m_test_cases[0];
6071 }
6072 else
6073 {
6074 return m_test_cases[m_current_test_case_index];
6075 }
6076 }
6077
6078 /** Constructor
6079 *
6080 * @param context Test context
6081 **/
QualifierOrderBlockTest(deqp::Context & context)6082 QualifierOrderBlockTest::QualifierOrderBlockTest(deqp::Context &context)
6083 : GLSLTestBase(context, "qualifier_order_block",
6084 "Verifies that qualifiers of members of input block can be arranged in any order")
6085 , m_current_test_case_index(0)
6086 {
6087 /* Nothing to be done here */
6088 }
6089
6090 /** Set up next test case
6091 *
6092 * @param test_case_index Index of next test case
6093 *
6094 * @return false if there is no more test cases, true otherwise
6095 **/
prepareNextTestCase(glw::GLuint test_case_index)6096 bool QualifierOrderBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
6097 {
6098 m_current_test_case_index = test_case_index;
6099
6100 if ((glw::GLuint)-1 == test_case_index)
6101 {
6102 /* Nothing to be done here */
6103 }
6104 else if (m_test_cases.size() <= test_case_index)
6105 {
6106 return false;
6107 }
6108
6109 const Utils::qualifierSet &set = getCurrentTestCase();
6110
6111 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6112
6113 for (GLuint i = 0; i < set.size(); ++i)
6114 {
6115 message << Utils::getQualifierString(set[i]) << " ";
6116 }
6117
6118 message << tcu::TestLog::EndMessage;
6119
6120 return true;
6121 }
6122
6123 /** Prepare source for given shader stage
6124 *
6125 * @param in_stage Shader stage, compute shader will use 430
6126 * @param in_use_version_400 Select if 400 or 420 should be used
6127 * @param out_source Prepared shader source instance
6128 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6129 void QualifierOrderBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6130 Utils::shaderSource &out_source)
6131 {
6132 static const GLchar *verification_snippet =
6133 " vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6134 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6135 " {\n"
6136 " result = INPUT_VARIABLE_NAME;\n"
6137 " }\n";
6138
6139 static const GLchar *fragment_shader_template = "VERSION\n"
6140 "\n"
6141 "in vec4 gs_fs_result;\n"
6142 "layout (location = 0) out vec4 fs_out_result;\n"
6143 "\n"
6144 "in GSOutputBlock {\n"
6145 " VARIABLE_DECLARATION;\n"
6146 "} input_block;\n"
6147 "out VARIABLE_DECLARATION;\n"
6148 "\n"
6149 "void main()\n"
6150 "{\n"
6151 " vec4 result = vec4(0, 1, 0, 1);\n"
6152 "\n"
6153 "VERIFICATION"
6154 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6155 " {\n"
6156 " result = vec4(1, 0, 0, 1);\n"
6157 " }\n"
6158 "\n"
6159 " fs_out_result = result;\n"
6160 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6161 "}\n"
6162 "\n";
6163
6164 static const GLchar *geometry_shader_template = "VERSION\n"
6165 "\n"
6166 "layout(points) in;\n"
6167 "layout(triangle_strip, max_vertices = 4) out;\n"
6168 "\n"
6169 "in vec4 tes_gs_result[];\n"
6170 "out vec4 gs_fs_result;\n"
6171 "\n"
6172 "in TCSOutputBlock {\n"
6173 " VARIABLE_DECLARATION;\n"
6174 "} input_block [];\n"
6175 "out GSOutputBlock {\n"
6176 " VARIABLE_DECLARATION;\n"
6177 "} output_block;\n"
6178 "\n"
6179 "void main()\n"
6180 "{\n"
6181 " vec4 result = vec4(0, 1, 0, 1);\n"
6182 "\n"
6183 "VERIFICATION"
6184 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6185 " {\n"
6186 " result = vec4(1, 0, 0, 1);\n"
6187 " }\n"
6188 "\n"
6189 " gs_fs_result = result;\n"
6190 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6191 " gl_Position = vec4(-1, -1, 0, 1);\n"
6192 " EmitVertex();\n"
6193 " gs_fs_result = result;\n"
6194 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6195 " gl_Position = vec4(-1, 1, 0, 1);\n"
6196 " EmitVertex();\n"
6197 " gs_fs_result = result;\n"
6198 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6199 " gl_Position = vec4(1, -1, 0, 1);\n"
6200 " EmitVertex();\n"
6201 " gs_fs_result = result;\n"
6202 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6203 " gl_Position = vec4(1, 1, 0, 1);\n"
6204 " EmitVertex();\n"
6205 "}\n"
6206 "\n";
6207
6208 static const GLchar *tess_ctrl_shader_template =
6209 "VERSION\n"
6210 "\n"
6211 "layout(vertices = 1) out;\n"
6212 "\n"
6213 "in vec4 vs_tcs_result[];\n"
6214 "out vec4 tcs_tes_result[];\n"
6215 "\n"
6216 "in VSOutputBlock {\n"
6217 " VARIABLE_DECLARATION;\n"
6218 "} input_block [];\n"
6219 "out TCSOutputBlock {\n"
6220 " VARIABLE_DECLARATION;\n"
6221 "} output_block [];\n"
6222 "\n"
6223 "void main()\n"
6224 "{\n"
6225 " vec4 result = vec4(0, 1, 0, 1);\n"
6226 "\n"
6227 "VERIFICATION"
6228 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6229 " {\n"
6230 " result = vec4(1, 0, 0, 1);\n"
6231 " }\n"
6232 "\n"
6233 " tcs_tes_result[gl_InvocationID] = result;\n"
6234 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6235 "\n"
6236 " gl_TessLevelOuter[0] = 1.0;\n"
6237 " gl_TessLevelOuter[1] = 1.0;\n"
6238 " gl_TessLevelOuter[2] = 1.0;\n"
6239 " gl_TessLevelOuter[3] = 1.0;\n"
6240 " gl_TessLevelInner[0] = 1.0;\n"
6241 " gl_TessLevelInner[1] = 1.0;\n"
6242 "}\n"
6243 "\n";
6244
6245 static const GLchar *tess_eval_shader_template = "VERSION\n"
6246 "\n"
6247 "layout(isolines, point_mode) in;\n"
6248 "\n"
6249 "in vec4 tcs_tes_result[];\n"
6250 "out vec4 tes_gs_result;\n"
6251 "\n"
6252 "in TCSOutputBlock {\n"
6253 " VARIABLE_DECLARATION;\n"
6254 "} input_block [];\n"
6255 "out TCSOutputBlock {\n"
6256 " VARIABLE_DECLARATION;\n"
6257 "} output_block;\n"
6258 "\n"
6259 "void main()\n"
6260 "{\n"
6261 " vec4 result = vec4(0, 1, 0, 1);\n"
6262 "\n"
6263 "VERIFICATION"
6264 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6265 " {\n"
6266 " result = vec4(1, 0, 0, 1);\n"
6267 " }\n"
6268 "\n"
6269 " tes_gs_result = result;\n"
6270 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6271 "}\n"
6272 "\n";
6273
6274 static const GLchar *vertex_shader_template = "VERSION\n"
6275 "\n"
6276 "out vec4 vs_tcs_result;\n"
6277 "\n"
6278 "in VARIABLE_DECLARATION;\n"
6279 "out VSOutputBlock {\n"
6280 " VARIABLE_DECLARATION;\n"
6281 "} output_block;\n"
6282 "\n"
6283 "void main()\n"
6284 "{\n"
6285 " vec4 result = vec4(0, 1, 0, 1);\n"
6286 "\n"
6287 "VERIFICATION"
6288 "\n"
6289 " vs_tcs_result = result;\n"
6290 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6291 "}\n"
6292 "\n";
6293
6294 const GLchar *shader_template = 0;
6295
6296 switch (in_stage)
6297 {
6298 case Utils::COMPUTE_SHADER:
6299 return;
6300 case Utils::FRAGMENT_SHADER:
6301 shader_template = fragment_shader_template;
6302 break;
6303 case Utils::GEOMETRY_SHADER:
6304 shader_template = geometry_shader_template;
6305 break;
6306 case Utils::TESS_CTRL_SHADER:
6307 shader_template = tess_ctrl_shader_template;
6308 break;
6309 case Utils::TESS_EVAL_SHADER:
6310 shader_template = tess_eval_shader_template;
6311 break;
6312 case Utils::VERTEX_SHADER:
6313 shader_template = vertex_shader_template;
6314 break;
6315 default:
6316 TCU_FAIL("Invalid enum");
6317 }
6318
6319 const Utils::qualifierSet &test_case = getCurrentTestCase();
6320
6321 std::string in_test_decl;
6322 std::string in_test_ref;
6323 std::string out_test_decl;
6324 std::string out_test_ref;
6325
6326 switch (in_stage)
6327 {
6328 case Utils::VERTEX_SHADER:
6329 Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
6330 break;
6331 default:
6332 Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", "input_block",
6333 in_test_decl, in_test_ref);
6334 break;
6335 }
6336
6337 switch (in_stage)
6338 {
6339 case Utils::FRAGMENT_SHADER:
6340 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
6341 break;
6342 default:
6343 Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", "output_block",
6344 out_test_decl, out_test_ref);
6345 break;
6346 }
6347
6348 // sample storage qualifier is not a valid qualifier for fragment output
6349 if (in_stage == Utils::FRAGMENT_SHADER)
6350 {
6351 if (out_test_decl.find("sample") != std::string::npos)
6352 out_test_decl.erase(out_test_decl.find("sample"), 7);
6353 }
6354 out_source.m_parts[0].m_code = shader_template;
6355
6356 size_t position = 0;
6357
6358 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6359 out_source.m_parts[0].m_code);
6360
6361 Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
6362
6363 Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
6364
6365 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6366
6367 position -= strlen(verification_snippet);
6368
6369 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
6370
6371 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
6372
6373 Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
6374 }
6375
6376 /**Prepare vertex buffer and vertex array object.
6377 *
6378 * @param program Program instance
6379 * @param buffer Buffer instance
6380 * @param vao VertexArray instance
6381 *
6382 * @return 0
6383 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)6384 void QualifierOrderBlockTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
6385 Utils::vertexArray &vao)
6386 {
6387 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
6388 GLint test_loc = program.getAttribLocation(test_name.c_str());
6389
6390 if (-1 == test_loc)
6391 {
6392 TCU_FAIL("Vertex attribute location is invalid");
6393 }
6394
6395 vao.generate();
6396 vao.bind();
6397
6398 buffer.generate(GL_ARRAY_BUFFER);
6399
6400 GLfloat data[] = {0.0f, 0.0f, 1.0f, 1.0f};
6401 GLsizeiptr data_size = sizeof(data);
6402
6403 buffer.update(data_size, data, GL_STATIC_DRAW);
6404
6405 /* GL entry points */
6406 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
6407
6408 /* Set up vao */
6409 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6410 0 /* offset */);
6411 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6412
6413 /* Enable attribute */
6414 gl.enableVertexAttribArray(test_loc);
6415 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6416 }
6417
6418 /** Prepare test cases
6419 *
6420 * @return true
6421 **/
testInit()6422 bool QualifierOrderBlockTest::testInit()
6423 {
6424 m_test_cases.resize(4);
6425
6426 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6427 m_test_cases[0].push_back(Utils::QUAL_FLAT);
6428 m_test_cases[0].push_back(Utils::QUAL_INVARIANT);
6429
6430 m_test_cases[1].push_back(Utils::QUAL_LOWP);
6431 m_test_cases[1].push_back(Utils::QUAL_SAMPLE);
6432 m_test_cases[1].push_back(Utils::QUAL_NOPERSPECTIVE);
6433 m_test_cases[1].push_back(Utils::QUAL_INVARIANT);
6434
6435 m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6436 m_test_cases[2].push_back(Utils::QUAL_SMOOTH);
6437 m_test_cases[2].push_back(Utils::QUAL_INVARIANT);
6438
6439 m_test_cases[3].push_back(Utils::QUAL_LOWP);
6440 m_test_cases[3].push_back(Utils::QUAL_SAMPLE);
6441 m_test_cases[3].push_back(Utils::QUAL_NOPERSPECTIVE);
6442 m_test_cases[3].push_back(Utils::QUAL_INVARIANT);
6443
6444 return true;
6445 }
6446
6447 /** Returns reference to current test case
6448 *
6449 * @return Reference to testCase
6450 **/
getCurrentTestCase()6451 const Utils::qualifierSet &QualifierOrderBlockTest::getCurrentTestCase()
6452 {
6453 if ((glw::GLuint)-1 == m_current_test_case_index)
6454 {
6455 return m_test_cases[0];
6456 }
6457 else
6458 {
6459 return m_test_cases[m_current_test_case_index];
6460 }
6461 }
6462
6463 /** Constructor
6464 *
6465 * @param context Test context
6466 **/
QualifierOrderUniformTest(deqp::Context & context)6467 QualifierOrderUniformTest::QualifierOrderUniformTest(deqp::Context &context)
6468 : GLSLTestBase(context, "qualifier_order_uniform",
6469 "Test verifies that all valid permutation of input qalifiers are accepted")
6470 , m_current_test_case_index(0)
6471 {
6472 /* Nothing to be done here */
6473 }
6474
6475 /** Set up next test case
6476 *
6477 * @param test_case_index Index of next test case
6478 *
6479 * @return false if there is no more test cases, true otherwise
6480 **/
prepareNextTestCase(glw::GLuint test_case_index)6481 bool QualifierOrderUniformTest::prepareNextTestCase(glw::GLuint test_case_index)
6482 {
6483 m_current_test_case_index = test_case_index;
6484
6485 if ((glw::GLuint)-1 == test_case_index)
6486 {
6487 /* Nothing to be done here */
6488 }
6489 else if (m_test_cases.size() <= test_case_index)
6490 {
6491 return false;
6492 }
6493
6494 const Utils::qualifierSet &set = getCurrentTestCase();
6495
6496 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6497
6498 for (GLuint i = 0; i < set.size(); ++i)
6499 {
6500 message << Utils::getQualifierString(set[i]) << " ";
6501 }
6502
6503 message << tcu::TestLog::EndMessage;
6504
6505 return true;
6506 }
6507
6508 /** Prepare source for given shader stage
6509 *
6510 * @param in_stage Shader stage, compute shader will use 430
6511 * @param in_use_version_400 Select if 400 or 420 should be used
6512 * @param out_source Prepared shader source instance
6513 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6514 void QualifierOrderUniformTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6515 Utils::shaderSource &out_source)
6516 {
6517 static const GLchar *verification_snippet =
6518 " vec4 diff = VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6519 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6520 " {\n"
6521 " result = VARIABLE_NAME;\n"
6522 " }\n";
6523
6524 static const GLchar *variable_declaration = " QUALIFIERS VARIABLE_NAME";
6525
6526 static const GLchar *fragment_shader_template = "VERSION\n"
6527 "#extension GL_ARB_explicit_uniform_location : enable\n"
6528 "\n"
6529 "in vec4 gs_fs_result;\n"
6530 "out vec4 fs_out_result;\n"
6531 "\n"
6532 "VARIABLE_DECLARATION;\n"
6533 "\n"
6534 "void main()\n"
6535 "{\n"
6536 " vec4 result = vec4(0, 1, 0, 1);\n"
6537 "\n"
6538 "VERIFICATION"
6539 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6540 " {\n"
6541 " result = vec4(1, 0, 0, 1);\n"
6542 " }\n"
6543 "\n"
6544 " fs_out_result = result;\n"
6545 "}\n"
6546 "\n";
6547
6548 static const GLchar *geometry_shader_template = "VERSION\n"
6549 "#extension GL_ARB_explicit_uniform_location : enable\n"
6550 "\n"
6551 "layout(points) in;\n"
6552 "layout(triangle_strip, max_vertices = 4) out;\n"
6553 "\n"
6554 "in vec4 tes_gs_result[];\n"
6555 "out vec4 gs_fs_result;\n"
6556 "\n"
6557 "VARIABLE_DECLARATION;\n"
6558 "\n"
6559 "void main()\n"
6560 "{\n"
6561 " vec4 result = vec4(0, 1, 0, 1);\n"
6562 "\n"
6563 "VERIFICATION"
6564 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6565 " {\n"
6566 " result = vec4(1, 0, 0, 1);\n"
6567 " }\n"
6568 "\n"
6569 " gs_fs_result = result;\n"
6570 " gl_Position = vec4(-1, -1, 0, 1);\n"
6571 " EmitVertex();\n"
6572 " gs_fs_result = result;\n"
6573 " gl_Position = vec4(-1, 1, 0, 1);\n"
6574 " EmitVertex();\n"
6575 " gs_fs_result = result;\n"
6576 " gl_Position = vec4(1, -1, 0, 1);\n"
6577 " EmitVertex();\n"
6578 " gs_fs_result = result;\n"
6579 " gl_Position = vec4(1, 1, 0, 1);\n"
6580 " EmitVertex();\n"
6581 "}\n"
6582 "\n";
6583
6584 static const GLchar *tess_ctrl_shader_template =
6585 "VERSION\n"
6586 "#extension GL_ARB_explicit_uniform_location : enable\n"
6587 "\n"
6588 "layout(vertices = 1) out;\n"
6589 "\n"
6590 "in vec4 vs_tcs_result[];\n"
6591 "out vec4 tcs_tes_result[];\n"
6592 "\n"
6593 "VARIABLE_DECLARATION;\n"
6594 "\n"
6595 "void main()\n"
6596 "{\n"
6597 " vec4 result = vec4(0, 1, 0, 1);\n"
6598 "\n"
6599 "VERIFICATION"
6600 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6601 " {\n"
6602 " result = vec4(1, 0, 0, 1);\n"
6603 " }\n"
6604 "\n"
6605 " tcs_tes_result[gl_InvocationID] = result;\n"
6606 "\n"
6607 " gl_TessLevelOuter[0] = 1.0;\n"
6608 " gl_TessLevelOuter[1] = 1.0;\n"
6609 " gl_TessLevelOuter[2] = 1.0;\n"
6610 " gl_TessLevelOuter[3] = 1.0;\n"
6611 " gl_TessLevelInner[0] = 1.0;\n"
6612 " gl_TessLevelInner[1] = 1.0;\n"
6613 "}\n"
6614 "\n";
6615
6616 static const GLchar *tess_eval_shader_template = "VERSION\n"
6617 "#extension GL_ARB_explicit_uniform_location : enable\n"
6618 "\n"
6619 "layout(isolines, point_mode) in;\n"
6620 "\n"
6621 "in vec4 tcs_tes_result[];\n"
6622 "out vec4 tes_gs_result;\n"
6623 "\n"
6624 "VARIABLE_DECLARATION;\n"
6625 "\n"
6626 "void main()\n"
6627 "{\n"
6628 " vec4 result = vec4(0, 1, 0, 1);\n"
6629 "\n"
6630 "VERIFICATION"
6631 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6632 " {\n"
6633 " result = vec4(1, 0, 0, 1);\n"
6634 " }\n"
6635 "\n"
6636 " tes_gs_result = result;\n"
6637 "}\n"
6638 "\n";
6639
6640 static const GLchar *vertex_shader_template = "VERSION\n"
6641 "#extension GL_ARB_explicit_uniform_location : enable\n"
6642 "\n"
6643 "out vec4 vs_tcs_result;\n"
6644 "\n"
6645 "VARIABLE_DECLARATION;\n"
6646 "\n"
6647 "void main()\n"
6648 "{\n"
6649 " vec4 result = vec4(0, 1, 0, 1);\n"
6650 "\n"
6651 "VERIFICATION"
6652 "\n"
6653 " vs_tcs_result = result;\n"
6654 "}\n"
6655 "\n";
6656
6657 const GLchar *shader_template = 0;
6658 const GLchar *location_string = 0;
6659
6660 switch (in_stage)
6661 {
6662 case Utils::COMPUTE_SHADER:
6663 return;
6664 case Utils::FRAGMENT_SHADER:
6665 shader_template = fragment_shader_template;
6666 location_string = "0";
6667 break;
6668 case Utils::GEOMETRY_SHADER:
6669 shader_template = geometry_shader_template;
6670 location_string = "1";
6671 break;
6672 case Utils::TESS_CTRL_SHADER:
6673 shader_template = tess_ctrl_shader_template;
6674 location_string = "4";
6675 break;
6676 case Utils::TESS_EVAL_SHADER:
6677 shader_template = tess_eval_shader_template;
6678 location_string = "3";
6679 break;
6680 case Utils::VERTEX_SHADER:
6681 shader_template = vertex_shader_template;
6682 location_string = "2";
6683 break;
6684 default:
6685 TCU_FAIL("Invalid enum");
6686 }
6687
6688 const Utils::qualifierSet &test_case = getCurrentTestCase();
6689
6690 std::string uni_declaration;
6691 std::string uni_reference;
6692 Utils::prepareVariableStrings(in_stage, Utils::UNIFORM, test_case, "vec4", "test", uni_declaration, uni_reference);
6693
6694 out_source.m_parts[0].m_code = shader_template;
6695
6696 size_t position = 0;
6697
6698 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6699 out_source.m_parts[0].m_code);
6700
6701 Utils::replaceToken("VARIABLE_DECLARATION", position, uni_declaration.c_str(), out_source.m_parts[0].m_code);
6702
6703 position -= strlen(variable_declaration);
6704
6705 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6706
6707 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
6708
6709 Utils::replaceAllTokens("LOC_VALUE", location_string, out_source.m_parts[0].m_code);
6710 }
6711
6712 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
6713 *
6714 * @param program Current program
6715 **/
prepareUniforms(Utils::program & program)6716 void QualifierOrderUniformTest::prepareUniforms(Utils::program &program)
6717 {
6718 static const GLfloat float_data[4] = {0.0f, 0.0f, 1.0f, 1.0f};
6719
6720 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6721 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6722 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6723 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6724 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6725 }
6726
6727 /** Prepare test cases
6728 *
6729 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
6730 **/
testInit()6731 bool QualifierOrderUniformTest::testInit()
6732 {
6733 if (false == m_is_explicit_uniform_location)
6734 {
6735 return false;
6736 }
6737
6738 m_test_cases.resize(4);
6739
6740 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6741 m_test_cases[0].push_back(Utils::QUAL_UNIFORM);
6742 m_test_cases[0].push_back(Utils::QUAL_LOCATION);
6743
6744 m_test_cases[1].push_back(Utils::QUAL_LOWP);
6745 m_test_cases[1].push_back(Utils::QUAL_UNIFORM);
6746 m_test_cases[1].push_back(Utils::QUAL_LOCATION);
6747
6748 m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6749 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6750 m_test_cases[2].push_back(Utils::QUAL_UNIFORM);
6751 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6752
6753 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6754 m_test_cases[3].push_back(Utils::QUAL_LOWP);
6755 m_test_cases[3].push_back(Utils::QUAL_UNIFORM);
6756 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6757
6758 return true;
6759 }
6760
6761 /** Returns reference to current test case
6762 *
6763 * @return Reference to testCase
6764 **/
getCurrentTestCase()6765 const Utils::qualifierSet &QualifierOrderUniformTest::getCurrentTestCase()
6766 {
6767 if ((glw::GLuint)-1 == m_current_test_case_index)
6768 {
6769 return m_test_cases[0];
6770 }
6771 else
6772 {
6773 return m_test_cases[m_current_test_case_index];
6774 }
6775 }
6776
6777 /** Constructor
6778 *
6779 * @param context Test context
6780 **/
QualifierOrderFunctionInoutTest(deqp::Context & context)6781 QualifierOrderFunctionInoutTest::QualifierOrderFunctionInoutTest(deqp::Context &context)
6782 : GLSLTestBase(context, "qualifier_order_function_inout", "Verify order of qualifiers of inout function parameters")
6783 , m_current_test_case_index(0)
6784 {
6785 /* Nothing to be done here */
6786 }
6787
6788 /** Set up next test case
6789 *
6790 * @param test_case_index Index of next test case
6791 *
6792 * @return false if there is no more test cases, true otherwise
6793 **/
prepareNextTestCase(glw::GLuint test_case_index)6794 bool QualifierOrderFunctionInoutTest::prepareNextTestCase(glw::GLuint test_case_index)
6795 {
6796 m_current_test_case_index = test_case_index;
6797
6798 if ((glw::GLuint)-1 == test_case_index)
6799 {
6800 /* Nothing to be done here */
6801 }
6802 else if (m_test_cases.size() <= test_case_index)
6803 {
6804 return false;
6805 }
6806
6807 const Utils::qualifierSet &set = getCurrentTestCase();
6808
6809 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6810
6811 for (GLuint i = 0; i < set.size(); ++i)
6812 {
6813 message << Utils::getQualifierString(set[i]) << " ";
6814 }
6815
6816 message << tcu::TestLog::EndMessage;
6817
6818 return true;
6819 }
6820
6821 /** Prepare source for given shader stage
6822 *
6823 * @param in_stage Shader stage, compute shader will use 430
6824 * @param in_use_version_400 Select if 400 or 420 should be used
6825 * @param out_source Prepared shader source instance
6826 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6827 void QualifierOrderFunctionInoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6828 Utils::shaderSource &out_source)
6829 {
6830 static const GLchar *verification_snippet =
6831 " vec4 temp = VARIABLE_NAME;\n"
6832 "\n"
6833 " function(temp);\n"
6834 "\n"
6835 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
6836 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6837 " {\n"
6838 " result = VARIABLE_NAME;\n"
6839 " }\n";
6840
6841 static const GLchar *function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
6842 "{\n"
6843 " param = param.wzyx;\n"
6844 "}\n";
6845
6846 static const GLchar *fragment_shader_template = "VERSION\n"
6847 "\n"
6848 "in vec4 gs_fs_result;\n"
6849 "out vec4 fs_out_result;\n"
6850 "\n"
6851 "uniform vec4 VARIABLE_NAME;\n"
6852 "\n"
6853 "FUNCTION_DECLARATION\n"
6854 "\n"
6855 "void main()\n"
6856 "{\n"
6857 " vec4 result = vec4(0, 1, 0, 1);\n"
6858 "\n"
6859 "VERIFICATION"
6860 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6861 " {\n"
6862 " result = vec4(1, 0, 0, 1);\n"
6863 " }\n"
6864 "\n"
6865 " fs_out_result = result;\n"
6866 "}\n"
6867 "\n";
6868
6869 static const GLchar *geometry_shader_template = "VERSION\n"
6870 "\n"
6871 "layout(points) in;\n"
6872 "layout(triangle_strip, max_vertices = 4) out;\n"
6873 "\n"
6874 "in vec4 tes_gs_result[];\n"
6875 "out vec4 gs_fs_result;\n"
6876 "\n"
6877 "uniform vec4 VARIABLE_NAME;\n"
6878 "\n"
6879 "FUNCTION_DECLARATION\n"
6880 "\n"
6881 "void main()\n"
6882 "{\n"
6883 " vec4 result = vec4(0, 1, 0, 1);\n"
6884 "\n"
6885 "VERIFICATION"
6886 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6887 " {\n"
6888 " result = vec4(1, 0, 0, 1);\n"
6889 " }\n"
6890 "\n"
6891 " gs_fs_result = result;\n"
6892 " gl_Position = vec4(-1, -1, 0, 1);\n"
6893 " EmitVertex();\n"
6894 " gs_fs_result = result;\n"
6895 " gl_Position = vec4(-1, 1, 0, 1);\n"
6896 " EmitVertex();\n"
6897 " gs_fs_result = result;\n"
6898 " gl_Position = vec4(1, -1, 0, 1);\n"
6899 " EmitVertex();\n"
6900 " gs_fs_result = result;\n"
6901 " gl_Position = vec4(1, 1, 0, 1);\n"
6902 " EmitVertex();\n"
6903 "}\n"
6904 "\n";
6905
6906 static const GLchar *tess_ctrl_shader_template =
6907 "VERSION\n"
6908 "\n"
6909 "layout(vertices = 1) out;\n"
6910 "\n"
6911 "in vec4 vs_tcs_result[];\n"
6912 "out vec4 tcs_tes_result[];\n"
6913 "\n"
6914 "uniform vec4 VARIABLE_NAME;\n"
6915 "\n"
6916 "FUNCTION_DECLARATION\n"
6917 "\n"
6918 "void main()\n"
6919 "{\n"
6920 " vec4 result = vec4(0, 1, 0, 1);\n"
6921 "\n"
6922 "VERIFICATION"
6923 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6924 " {\n"
6925 " result = vec4(1, 0, 0, 1);\n"
6926 " }\n"
6927 "\n"
6928 " tcs_tes_result[gl_InvocationID] = result;\n"
6929 "\n"
6930 " gl_TessLevelOuter[0] = 1.0;\n"
6931 " gl_TessLevelOuter[1] = 1.0;\n"
6932 " gl_TessLevelOuter[2] = 1.0;\n"
6933 " gl_TessLevelOuter[3] = 1.0;\n"
6934 " gl_TessLevelInner[0] = 1.0;\n"
6935 " gl_TessLevelInner[1] = 1.0;\n"
6936 "}\n"
6937 "\n";
6938
6939 static const GLchar *tess_eval_shader_template = "VERSION\n"
6940 "\n"
6941 "layout(isolines, point_mode) in;\n"
6942 "\n"
6943 "in vec4 tcs_tes_result[];\n"
6944 "out vec4 tes_gs_result;\n"
6945 "\n"
6946 "uniform vec4 VARIABLE_NAME;\n"
6947 "\n"
6948 "FUNCTION_DECLARATION\n"
6949 "\n"
6950 "void main()\n"
6951 "{\n"
6952 " vec4 result = vec4(0, 1, 0, 1);\n"
6953 "\n"
6954 "VERIFICATION"
6955 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6956 " {\n"
6957 " result = vec4(1, 0, 0, 1);\n"
6958 " }\n"
6959 "\n"
6960 " tes_gs_result = result;\n"
6961 "}\n"
6962 "\n";
6963
6964 static const GLchar *vertex_shader_template = "VERSION\n"
6965 "\n"
6966 "out vec4 vs_tcs_result;\n"
6967 "\n"
6968 "uniform vec4 VARIABLE_NAME;\n"
6969 "\n"
6970 "FUNCTION_DECLARATION\n"
6971 "\n"
6972 "void main()\n"
6973 "{\n"
6974 " vec4 result = vec4(0, 1, 0, 1);\n"
6975 "\n"
6976 "VERIFICATION"
6977 "\n"
6978 " vs_tcs_result = result;\n"
6979 "}\n"
6980 "\n";
6981
6982 const GLchar *shader_template = 0;
6983
6984 switch (in_stage)
6985 {
6986 case Utils::COMPUTE_SHADER:
6987 return;
6988 case Utils::FRAGMENT_SHADER:
6989 shader_template = fragment_shader_template;
6990 break;
6991 case Utils::GEOMETRY_SHADER:
6992 shader_template = geometry_shader_template;
6993 break;
6994 case Utils::TESS_CTRL_SHADER:
6995 shader_template = tess_ctrl_shader_template;
6996 break;
6997 case Utils::TESS_EVAL_SHADER:
6998 shader_template = tess_eval_shader_template;
6999 break;
7000 case Utils::VERTEX_SHADER:
7001 shader_template = vertex_shader_template;
7002 break;
7003 default:
7004 TCU_FAIL("Invalid enum");
7005 }
7006
7007 const std::string &uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7008 const std::string &qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7009
7010 out_source.m_parts[0].m_code = shader_template;
7011
7012 size_t position = 0;
7013
7014 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7015 out_source.m_parts[0].m_code);
7016
7017 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7018
7019 position -= strlen(function_declaration);
7020
7021 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7022
7023 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7024
7025 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7026 }
7027
7028 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7029 *
7030 * @param program Current program
7031 **/
prepareUniforms(Utils::program & program)7032 void QualifierOrderFunctionInoutTest::prepareUniforms(Utils::program &program)
7033 {
7034 static const GLfloat float_data[4] = {1.0f, 1.0f, 0.0f, 0.0f};
7035
7036 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7037 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7038 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7039 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7040 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7041 }
7042
7043 /** Prepare test cases
7044 *
7045 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7046 **/
testInit()7047 bool QualifierOrderFunctionInoutTest::testInit()
7048 {
7049 m_test_cases.resize(6);
7050
7051 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7052 m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7053 m_test_cases[0].push_back(Utils::QUAL_INOUT);
7054
7055 m_test_cases[1].push_back(Utils::QUAL_INOUT);
7056 m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7057 m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7058
7059 m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7060 m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7061 m_test_cases[2].push_back(Utils::QUAL_INOUT);
7062
7063 m_test_cases[3].push_back(Utils::QUAL_INOUT);
7064 m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7065 m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7066
7067 m_test_cases[4].push_back(Utils::QUAL_LOWP);
7068 m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7069 m_test_cases[4].push_back(Utils::QUAL_INOUT);
7070
7071 m_test_cases[5].push_back(Utils::QUAL_INOUT);
7072 m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7073 m_test_cases[5].push_back(Utils::QUAL_LOWP);
7074
7075 return true;
7076 }
7077
7078 /** Returns reference to current test case
7079 *
7080 * @return Reference to testCase
7081 **/
getCurrentTestCase()7082 const Utils::qualifierSet &QualifierOrderFunctionInoutTest::getCurrentTestCase()
7083 {
7084 if ((glw::GLuint)-1 == m_current_test_case_index)
7085 {
7086 return m_test_cases[0];
7087 }
7088 else
7089 {
7090 return m_test_cases[m_current_test_case_index];
7091 }
7092 }
7093
7094 /** Constructor
7095 *
7096 * @param context Test context
7097 **/
QualifierOrderFunctionInputTest(deqp::Context & context)7098 QualifierOrderFunctionInputTest::QualifierOrderFunctionInputTest(deqp::Context &context)
7099 : GLSLTestBase(context, "qualifier_order_function_input", "Verify order of qualifiers of function input parameters")
7100 , m_current_test_case_index(0)
7101 {
7102 /* Nothing to be done here */
7103 }
7104
7105 /** Set up next test case
7106 *
7107 * @param test_case_index Index of next test case
7108 *
7109 * @return false if there is no more test cases, true otherwise
7110 **/
prepareNextTestCase(glw::GLuint test_case_index)7111 bool QualifierOrderFunctionInputTest::prepareNextTestCase(glw::GLuint test_case_index)
7112 {
7113 m_current_test_case_index = test_case_index;
7114
7115 if ((glw::GLuint)-1 == test_case_index)
7116 {
7117 /* Nothing to be done here */
7118 }
7119 else if (m_test_cases.size() <= test_case_index)
7120 {
7121 return false;
7122 }
7123
7124 const Utils::qualifierSet &set = getCurrentTestCase();
7125
7126 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7127
7128 for (GLuint i = 0; i < set.size(); ++i)
7129 {
7130 message << Utils::getQualifierString(set[i]) << " ";
7131 }
7132
7133 message << tcu::TestLog::EndMessage;
7134
7135 return true;
7136 }
7137
7138 /** Prepare source for given shader stage
7139 *
7140 * @param in_stage Shader stage, compute shader will use 430
7141 * @param in_use_version_400 Select if 400 or 420 should be used
7142 * @param out_source Prepared shader source instance
7143 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7144 void QualifierOrderFunctionInputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7145 Utils::shaderSource &out_source)
7146 {
7147 static const GLchar *verification_snippet =
7148 " vec4 temp = function(VARIABLE_NAME);\n"
7149 "\n"
7150 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7151 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7152 " {\n"
7153 " result = VARIABLE_NAME;\n"
7154 " }\n";
7155
7156 static const GLchar *function_declaration = "vec4 function(QUALIFIERS_LIST vec4 param)\n"
7157 "{\n"
7158 " return param.wzyx;\n"
7159 "}\n";
7160
7161 static const GLchar *fragment_shader_template = "VERSION\n"
7162 "\n"
7163 "in vec4 gs_fs_result;\n"
7164 "out vec4 fs_out_result;\n"
7165 "\n"
7166 "uniform vec4 VARIABLE_NAME;\n"
7167 "\n"
7168 "FUNCTION_DECLARATION\n"
7169 "\n"
7170 "void main()\n"
7171 "{\n"
7172 " vec4 result = vec4(0, 1, 0, 1);\n"
7173 "\n"
7174 "VERIFICATION"
7175 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7176 " {\n"
7177 " result = vec4(1, 0, 0, 1);\n"
7178 " }\n"
7179 "\n"
7180 " fs_out_result = result;\n"
7181 "}\n"
7182 "\n";
7183
7184 static const GLchar *geometry_shader_template = "VERSION\n"
7185 "\n"
7186 "layout(points) in;\n"
7187 "layout(triangle_strip, max_vertices = 4) out;\n"
7188 "\n"
7189 "in vec4 tes_gs_result[];\n"
7190 "out vec4 gs_fs_result;\n"
7191 "\n"
7192 "uniform vec4 VARIABLE_NAME;\n"
7193 "\n"
7194 "FUNCTION_DECLARATION\n"
7195 "\n"
7196 "void main()\n"
7197 "{\n"
7198 " vec4 result = vec4(0, 1, 0, 1);\n"
7199 "\n"
7200 "VERIFICATION"
7201 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7202 " {\n"
7203 " result = vec4(1, 0, 0, 1);\n"
7204 " }\n"
7205 "\n"
7206 " gs_fs_result = result;\n"
7207 " gl_Position = vec4(-1, -1, 0, 1);\n"
7208 " EmitVertex();\n"
7209 " gs_fs_result = result;\n"
7210 " gl_Position = vec4(-1, 1, 0, 1);\n"
7211 " EmitVertex();\n"
7212 " gs_fs_result = result;\n"
7213 " gl_Position = vec4(1, -1, 0, 1);\n"
7214 " EmitVertex();\n"
7215 " gs_fs_result = result;\n"
7216 " gl_Position = vec4(1, 1, 0, 1);\n"
7217 " EmitVertex();\n"
7218 "}\n"
7219 "\n";
7220
7221 static const GLchar *tess_ctrl_shader_template =
7222 "VERSION\n"
7223 "\n"
7224 "layout(vertices = 1) out;\n"
7225 "\n"
7226 "in vec4 vs_tcs_result[];\n"
7227 "out vec4 tcs_tes_result[];\n"
7228 "\n"
7229 "uniform vec4 VARIABLE_NAME;\n"
7230 "\n"
7231 "FUNCTION_DECLARATION\n"
7232 "\n"
7233 "void main()\n"
7234 "{\n"
7235 " vec4 result = vec4(0, 1, 0, 1);\n"
7236 "\n"
7237 "VERIFICATION"
7238 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7239 " {\n"
7240 " result = vec4(1, 0, 0, 1);\n"
7241 " }\n"
7242 "\n"
7243 " tcs_tes_result[gl_InvocationID] = result;\n"
7244 "\n"
7245 " gl_TessLevelOuter[0] = 1.0;\n"
7246 " gl_TessLevelOuter[1] = 1.0;\n"
7247 " gl_TessLevelOuter[2] = 1.0;\n"
7248 " gl_TessLevelOuter[3] = 1.0;\n"
7249 " gl_TessLevelInner[0] = 1.0;\n"
7250 " gl_TessLevelInner[1] = 1.0;\n"
7251 "}\n"
7252 "\n";
7253
7254 static const GLchar *tess_eval_shader_template = "VERSION\n"
7255 "\n"
7256 "layout(isolines, point_mode) in;\n"
7257 "\n"
7258 "in vec4 tcs_tes_result[];\n"
7259 "out vec4 tes_gs_result;\n"
7260 "\n"
7261 "uniform vec4 VARIABLE_NAME;\n"
7262 "\n"
7263 "FUNCTION_DECLARATION\n"
7264 "\n"
7265 "void main()\n"
7266 "{\n"
7267 " vec4 result = vec4(0, 1, 0, 1);\n"
7268 "\n"
7269 "VERIFICATION"
7270 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7271 " {\n"
7272 " result = vec4(1, 0, 0, 1);\n"
7273 " }\n"
7274 "\n"
7275 " tes_gs_result = result;\n"
7276 "}\n"
7277 "\n";
7278
7279 static const GLchar *vertex_shader_template = "VERSION\n"
7280 "\n"
7281 "out vec4 vs_tcs_result;\n"
7282 "\n"
7283 "uniform vec4 VARIABLE_NAME;\n"
7284 "\n"
7285 "FUNCTION_DECLARATION\n"
7286 "\n"
7287 "void main()\n"
7288 "{\n"
7289 " vec4 result = vec4(0, 1, 0, 1);\n"
7290 "\n"
7291 "VERIFICATION"
7292 "\n"
7293 " vs_tcs_result = result;\n"
7294 "}\n"
7295 "\n";
7296
7297 const GLchar *shader_template = 0;
7298
7299 switch (in_stage)
7300 {
7301 case Utils::COMPUTE_SHADER:
7302 return;
7303 case Utils::FRAGMENT_SHADER:
7304 shader_template = fragment_shader_template;
7305 break;
7306 case Utils::GEOMETRY_SHADER:
7307 shader_template = geometry_shader_template;
7308 break;
7309 case Utils::TESS_CTRL_SHADER:
7310 shader_template = tess_ctrl_shader_template;
7311 break;
7312 case Utils::TESS_EVAL_SHADER:
7313 shader_template = tess_eval_shader_template;
7314 break;
7315 case Utils::VERTEX_SHADER:
7316 shader_template = vertex_shader_template;
7317 break;
7318 default:
7319 TCU_FAIL("Invalid enum");
7320 }
7321
7322 const std::string &uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7323 const std::string &qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7324
7325 out_source.m_parts[0].m_code = shader_template;
7326
7327 size_t position = 0;
7328
7329 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7330 out_source.m_parts[0].m_code);
7331
7332 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7333
7334 position -= strlen(function_declaration);
7335
7336 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7337
7338 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7339
7340 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7341 }
7342
7343 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7344 *
7345 * @param program Current program
7346 **/
prepareUniforms(Utils::program & program)7347 void QualifierOrderFunctionInputTest::prepareUniforms(Utils::program &program)
7348 {
7349 static const GLfloat float_data[4] = {1.0f, 1.0f, 0.0f, 0.0f};
7350
7351 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7352 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7353 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7354 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7355 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7356 }
7357
7358 /** Prepare test cases
7359 *
7360 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7361 **/
testInit()7362 bool QualifierOrderFunctionInputTest::testInit()
7363 {
7364 m_test_cases.resize(6);
7365
7366 m_test_cases[0].push_back(Utils::QUAL_CONST);
7367 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7368 m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7369 m_test_cases[0].push_back(Utils::QUAL_IN);
7370
7371 m_test_cases[1].push_back(Utils::QUAL_IN);
7372 m_test_cases[1].push_back(Utils::QUAL_CONST);
7373 m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7374 m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7375
7376 m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7377 m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7378 m_test_cases[2].push_back(Utils::QUAL_CONST);
7379 m_test_cases[2].push_back(Utils::QUAL_IN);
7380
7381 m_test_cases[3].push_back(Utils::QUAL_IN);
7382 m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7383 m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7384 m_test_cases[3].push_back(Utils::QUAL_CONST);
7385
7386 m_test_cases[4].push_back(Utils::QUAL_LOWP);
7387 m_test_cases[4].push_back(Utils::QUAL_CONST);
7388 m_test_cases[4].push_back(Utils::QUAL_IN);
7389 m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7390
7391 m_test_cases[5].push_back(Utils::QUAL_IN);
7392 m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7393 m_test_cases[5].push_back(Utils::QUAL_CONST);
7394 m_test_cases[5].push_back(Utils::QUAL_LOWP);
7395
7396 return true;
7397 }
7398
7399 /** Returns reference to current test case
7400 *
7401 * @return Reference to testCase
7402 **/
getCurrentTestCase()7403 const Utils::qualifierSet &QualifierOrderFunctionInputTest::getCurrentTestCase()
7404 {
7405 if ((glw::GLuint)-1 == m_current_test_case_index)
7406 {
7407 return m_test_cases[0];
7408 }
7409 else
7410 {
7411 return m_test_cases[m_current_test_case_index];
7412 }
7413 }
7414
7415 /** Constructor
7416 *
7417 * @param context Test context
7418 **/
QualifierOrderFunctionOutputTest(deqp::Context & context)7419 QualifierOrderFunctionOutputTest::QualifierOrderFunctionOutputTest(deqp::Context &context)
7420 : GLSLTestBase(context, "qualifier_order_function_output",
7421 "Verify order of qualifiers of output function parameters")
7422 , m_current_test_case_index(0)
7423 {
7424 /* Nothing to be done here */
7425 }
7426
7427 /** Set up next test case
7428 *
7429 * @param test_case_index Index of next test case
7430 *
7431 * @return false if there is no more test cases, true otherwise
7432 **/
prepareNextTestCase(glw::GLuint test_case_index)7433 bool QualifierOrderFunctionOutputTest::prepareNextTestCase(glw::GLuint test_case_index)
7434 {
7435 m_current_test_case_index = test_case_index;
7436
7437 if ((glw::GLuint)-1 == test_case_index)
7438 {
7439 /* Nothing to be done here */
7440 }
7441 else if (m_test_cases.size() <= test_case_index)
7442 {
7443 return false;
7444 }
7445
7446 const Utils::qualifierSet &set = getCurrentTestCase();
7447
7448 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7449
7450 for (GLuint i = 0; i < set.size(); ++i)
7451 {
7452 message << Utils::getQualifierString(set[i]) << " ";
7453 }
7454
7455 message << tcu::TestLog::EndMessage;
7456
7457 return true;
7458 }
7459
7460 /** Prepare source for given shader stage
7461 *
7462 * @param in_stage Shader stage, compute shader will use 430
7463 * @param in_use_version_400 Select if 400 or 420 should be used
7464 * @param out_source Prepared shader source instance
7465 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7466 void QualifierOrderFunctionOutputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7467 Utils::shaderSource &out_source)
7468 {
7469 static const GLchar *verification_snippet =
7470 " vec4 temp;\n"
7471 "\n"
7472 " function(temp);\n"
7473 "\n"
7474 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7475 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7476 " {\n"
7477 " result = VARIABLE_NAME;\n"
7478 " }\n";
7479
7480 static const GLchar *function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
7481 "{\n"
7482 " param = VARIABLE_NAME.wzyx;\n"
7483 "}\n";
7484
7485 static const GLchar *fragment_shader_template = "VERSION\n"
7486 "\n"
7487 "in vec4 gs_fs_result;\n"
7488 "out vec4 fs_out_result;\n"
7489 "\n"
7490 "uniform vec4 VARIABLE_NAME;\n"
7491 "\n"
7492 "FUNCTION_DECLARATION\n"
7493 "\n"
7494 "void main()\n"
7495 "{\n"
7496 " vec4 result = vec4(0, 1, 0, 1);\n"
7497 "\n"
7498 "VERIFICATION"
7499 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7500 " {\n"
7501 " result = vec4(1, 0, 0, 1);\n"
7502 " }\n"
7503 "\n"
7504 " fs_out_result = result;\n"
7505 "}\n"
7506 "\n";
7507
7508 static const GLchar *geometry_shader_template = "VERSION\n"
7509 "\n"
7510 "layout(points) in;\n"
7511 "layout(triangle_strip, max_vertices = 4) out;\n"
7512 "\n"
7513 "in vec4 tes_gs_result[];\n"
7514 "out vec4 gs_fs_result;\n"
7515 "\n"
7516 "uniform vec4 VARIABLE_NAME;\n"
7517 "\n"
7518 "FUNCTION_DECLARATION\n"
7519 "\n"
7520 "void main()\n"
7521 "{\n"
7522 " vec4 result = vec4(0, 1, 0, 1);\n"
7523 "\n"
7524 "VERIFICATION"
7525 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7526 " {\n"
7527 " result = vec4(1, 0, 0, 1);\n"
7528 " }\n"
7529 "\n"
7530 " gs_fs_result = result;\n"
7531 " gl_Position = vec4(-1, -1, 0, 1);\n"
7532 " EmitVertex();\n"
7533 " gs_fs_result = result;\n"
7534 " gl_Position = vec4(-1, 1, 0, 1);\n"
7535 " EmitVertex();\n"
7536 " gs_fs_result = result;\n"
7537 " gl_Position = vec4(1, -1, 0, 1);\n"
7538 " EmitVertex();\n"
7539 " gs_fs_result = result;\n"
7540 " gl_Position = vec4(1, 1, 0, 1);\n"
7541 " EmitVertex();\n"
7542 "}\n"
7543 "\n";
7544
7545 static const GLchar *tess_ctrl_shader_template =
7546 "VERSION\n"
7547 "\n"
7548 "layout(vertices = 1) out;\n"
7549 "\n"
7550 "in vec4 vs_tcs_result[];\n"
7551 "out vec4 tcs_tes_result[];\n"
7552 "\n"
7553 "uniform vec4 VARIABLE_NAME;\n"
7554 "\n"
7555 "FUNCTION_DECLARATION\n"
7556 "\n"
7557 "void main()\n"
7558 "{\n"
7559 " vec4 result = vec4(0, 1, 0, 1);\n"
7560 "\n"
7561 "VERIFICATION"
7562 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7563 " {\n"
7564 " result = vec4(1, 0, 0, 1);\n"
7565 " }\n"
7566 "\n"
7567 " tcs_tes_result[gl_InvocationID] = result;\n"
7568 "\n"
7569 " gl_TessLevelOuter[0] = 1.0;\n"
7570 " gl_TessLevelOuter[1] = 1.0;\n"
7571 " gl_TessLevelOuter[2] = 1.0;\n"
7572 " gl_TessLevelOuter[3] = 1.0;\n"
7573 " gl_TessLevelInner[0] = 1.0;\n"
7574 " gl_TessLevelInner[1] = 1.0;\n"
7575 "}\n"
7576 "\n";
7577
7578 static const GLchar *tess_eval_shader_template = "VERSION\n"
7579 "\n"
7580 "layout(isolines, point_mode) in;\n"
7581 "\n"
7582 "in vec4 tcs_tes_result[];\n"
7583 "out vec4 tes_gs_result;\n"
7584 "\n"
7585 "uniform vec4 VARIABLE_NAME;\n"
7586 "\n"
7587 "FUNCTION_DECLARATION\n"
7588 "\n"
7589 "void main()\n"
7590 "{\n"
7591 " vec4 result = vec4(0, 1, 0, 1);\n"
7592 "\n"
7593 "VERIFICATION"
7594 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7595 " {\n"
7596 " result = vec4(1, 0, 0, 1);\n"
7597 " }\n"
7598 "\n"
7599 " tes_gs_result = result;\n"
7600 "}\n"
7601 "\n";
7602
7603 static const GLchar *vertex_shader_template = "VERSION\n"
7604 "\n"
7605 "out vec4 vs_tcs_result;\n"
7606 "\n"
7607 "uniform vec4 VARIABLE_NAME;\n"
7608 "\n"
7609 "FUNCTION_DECLARATION\n"
7610 "\n"
7611 "void main()\n"
7612 "{\n"
7613 " vec4 result = vec4(0, 1, 0, 1);\n"
7614 "\n"
7615 "VERIFICATION"
7616 "\n"
7617 " vs_tcs_result = result;\n"
7618 "}\n"
7619 "\n";
7620
7621 const GLchar *shader_template = 0;
7622
7623 switch (in_stage)
7624 {
7625 case Utils::COMPUTE_SHADER:
7626 return;
7627 case Utils::FRAGMENT_SHADER:
7628 shader_template = fragment_shader_template;
7629 break;
7630 case Utils::GEOMETRY_SHADER:
7631 shader_template = geometry_shader_template;
7632 break;
7633 case Utils::TESS_CTRL_SHADER:
7634 shader_template = tess_ctrl_shader_template;
7635 break;
7636 case Utils::TESS_EVAL_SHADER:
7637 shader_template = tess_eval_shader_template;
7638 break;
7639 case Utils::VERTEX_SHADER:
7640 shader_template = vertex_shader_template;
7641 break;
7642 default:
7643 TCU_FAIL("Invalid enum");
7644 }
7645
7646 const std::string &uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7647 const std::string &qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7648
7649 out_source.m_parts[0].m_code = shader_template;
7650
7651 size_t position = 0;
7652
7653 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7654 out_source.m_parts[0].m_code);
7655
7656 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7657
7658 position -= strlen(function_declaration);
7659
7660 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7661
7662 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7663
7664 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7665 }
7666
7667 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7668 *
7669 * @param program Current program
7670 **/
prepareUniforms(Utils::program & program)7671 void QualifierOrderFunctionOutputTest::prepareUniforms(Utils::program &program)
7672 {
7673 static const GLfloat float_data[4] = {1.0f, 1.0f, 0.0f, 0.0f};
7674
7675 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7676 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7677 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7678 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7679 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7680 }
7681
7682 /** Prepare test cases
7683 *
7684 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7685 **/
testInit()7686 bool QualifierOrderFunctionOutputTest::testInit()
7687 {
7688 m_test_cases.resize(6);
7689
7690 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7691 m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7692 m_test_cases[0].push_back(Utils::QUAL_OUT);
7693
7694 m_test_cases[1].push_back(Utils::QUAL_OUT);
7695 m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7696 m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7697
7698 m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7699 m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7700 m_test_cases[2].push_back(Utils::QUAL_OUT);
7701
7702 m_test_cases[3].push_back(Utils::QUAL_OUT);
7703 m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7704 m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7705
7706 m_test_cases[4].push_back(Utils::QUAL_LOWP);
7707 m_test_cases[4].push_back(Utils::QUAL_OUT);
7708 m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7709
7710 m_test_cases[5].push_back(Utils::QUAL_OUT);
7711 m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7712 m_test_cases[5].push_back(Utils::QUAL_LOWP);
7713
7714 return true;
7715 }
7716
7717 /** Returns reference to current test case
7718 *
7719 * @return Reference to testCase
7720 **/
getCurrentTestCase()7721 const Utils::qualifierSet &QualifierOrderFunctionOutputTest::getCurrentTestCase()
7722 {
7723 if ((glw::GLuint)-1 == m_current_test_case_index)
7724 {
7725 return m_test_cases[0];
7726 }
7727 else
7728 {
7729 return m_test_cases[m_current_test_case_index];
7730 }
7731 }
7732
7733 /** Constructor
7734 *
7735 * @param context Test context
7736 **/
QualifierOverrideLayoutTest(deqp::Context & context)7737 QualifierOverrideLayoutTest::QualifierOverrideLayoutTest(deqp::Context &context)
7738 : GLSLTestBase(context, "qualifier_override_layout", "Verifies overriding layout qualifiers")
7739 {
7740 /* Nothing to be done here */
7741 }
7742
7743 /** Prepare source for given shader stage
7744 *
7745 * @param in_stage Shader stage, compute shader will use 430
7746 * @param in_use_version_400 Select if 400 or 420 should be used
7747 * @param out_source Prepared shader source instance
7748 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7749 void QualifierOverrideLayoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7750 Utils::shaderSource &out_source)
7751 {
7752 static const GLchar *fragment_shader_template = "VERSION\n"
7753 "\n"
7754 "in layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7755 "out vec4 fs_out_result;\n"
7756 "\n"
7757 "void main()\n"
7758 "{\n"
7759 " vec4 result = vec4(0, 1, 0, 1);\n"
7760 "\n"
7761 " if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7762 " {\n"
7763 " result = vec4(1, 0, 0, 1);\n"
7764 " }\n"
7765 "\n"
7766 " fs_out_result = result;\n"
7767 "}\n"
7768 "\n";
7769
7770 static const GLchar *geometry_shader_template =
7771 "VERSION\n"
7772 "\n"
7773 "layout(points) in;\n"
7774 "layout(triangle_strip, max_vertices = 2) layout(max_vertices = 4) out;\n"
7775 "\n"
7776 "in layout(location = 3) layout(location = 2) vec4 tes_gs_result[];\n"
7777 "out layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7778 "\n"
7779 "void main()\n"
7780 "{\n"
7781 " vec4 result = vec4(0, 1, 0, 1);\n"
7782 "\n"
7783 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7784 " {\n"
7785 " result = vec4(1, 0, 0, 1);\n"
7786 " }\n"
7787 "\n"
7788 " gs_fs_result = result;\n"
7789 " gl_Position = vec4(-1, -1, 0, 1);\n"
7790 " EmitVertex();\n"
7791 " gs_fs_result = result;\n"
7792 " gl_Position = vec4(-1, 1, 0, 1);\n"
7793 " EmitVertex();\n"
7794 " gs_fs_result = result;\n"
7795 " gl_Position = vec4(1, -1, 0, 1);\n"
7796 " EmitVertex();\n"
7797 " gs_fs_result = result;\n"
7798 " gl_Position = vec4(1, 1, 0, 1);\n"
7799 " EmitVertex();\n"
7800 "}\n"
7801 "\n";
7802
7803 static const GLchar *tess_ctrl_shader_template =
7804 "VERSION\n"
7805 "\n"
7806 "layout(vertices = 4) layout(vertices = 1) out;\n"
7807 "\n"
7808 "in layout(location = 3) layout(location = 2) vec4 vs_tcs_result[];\n"
7809 "out layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7810 "\n"
7811 "void main()\n"
7812 "{\n"
7813 " vec4 result = vec4(0, 1, 0, 1);\n"
7814 "\n"
7815 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7816 " {\n"
7817 " result = vec4(1, 0, 0, 1);\n"
7818 " }\n"
7819 "\n"
7820 " tcs_tes_result[gl_InvocationID] = result;\n"
7821 "\n"
7822 " gl_TessLevelOuter[0] = 1.0;\n"
7823 " gl_TessLevelOuter[1] = 1.0;\n"
7824 " gl_TessLevelOuter[2] = 1.0;\n"
7825 " gl_TessLevelOuter[3] = 1.0;\n"
7826 " gl_TessLevelInner[0] = 1.0;\n"
7827 " gl_TessLevelInner[1] = 1.0;\n"
7828 "}\n"
7829 "\n";
7830
7831 static const GLchar *tess_eval_shader_template =
7832 "VERSION\n"
7833 "\n"
7834 "layout(isolines, point_mode) in;\n"
7835 "\n"
7836 "in layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7837 "out layout(location = 3) layout(location = 2) vec4 tes_gs_result;\n"
7838 "\n"
7839 "void main()\n"
7840 "{\n"
7841 " vec4 result = vec4(0, 1, 0, 1);\n"
7842 "\n"
7843 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7844 " {\n"
7845 " result = vec4(1, 0, 0, 1);\n"
7846 " }\n"
7847 "\n"
7848 " tes_gs_result = result;\n"
7849 "}\n"
7850 "\n";
7851
7852 static const GLchar *vertex_shader_template = "VERSION\n"
7853 "\n"
7854 "in layout(location = 3) layout(location = 2) vec4 in_vs_test;\n"
7855 "out layout(location = 3) layout(location = 2) vec4 vs_tcs_result;\n"
7856 "\n"
7857 "void main()\n"
7858 "{\n"
7859 " vec4 result = in_vs_test;\n"
7860 "\n"
7861 " vs_tcs_result = result;\n"
7862 "}\n"
7863 "\n";
7864
7865 const GLchar *shader_template = 0;
7866
7867 switch (in_stage)
7868 {
7869 case Utils::COMPUTE_SHADER:
7870 return;
7871 case Utils::FRAGMENT_SHADER:
7872 shader_template = fragment_shader_template;
7873 break;
7874 case Utils::GEOMETRY_SHADER:
7875 shader_template = geometry_shader_template;
7876 break;
7877 case Utils::TESS_CTRL_SHADER:
7878 shader_template = tess_ctrl_shader_template;
7879 break;
7880 case Utils::TESS_EVAL_SHADER:
7881 shader_template = tess_eval_shader_template;
7882 break;
7883 case Utils::VERTEX_SHADER:
7884 shader_template = vertex_shader_template;
7885 break;
7886 default:
7887 TCU_FAIL("Invalid enum");
7888 }
7889
7890 out_source.m_parts[0].m_code = shader_template;
7891
7892 size_t position = 0;
7893
7894 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7895 out_source.m_parts[0].m_code);
7896 }
7897
7898 /**Prepare vertex buffer and vertex array object.
7899 *
7900 * @param program Program instance
7901 * @param buffer Buffer instance
7902 * @param vao VertexArray instance
7903 *
7904 * @return 0
7905 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)7906 void QualifierOverrideLayoutTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
7907 Utils::vertexArray &vao)
7908 {
7909 static const GLint expected_location = 2;
7910
7911 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
7912 GLint test_loc = program.getAttribLocation(test_name.c_str());
7913
7914 if (expected_location != test_loc)
7915 {
7916 TCU_FAIL("Vertex attribute location is invalid");
7917 }
7918
7919 vao.generate();
7920 vao.bind();
7921
7922 buffer.generate(GL_ARRAY_BUFFER);
7923
7924 GLfloat data[] = {0.0f, 1.0f, 0.0f, 1.0f};
7925 GLsizeiptr data_size = sizeof(data);
7926
7927 buffer.update(data_size, data, GL_STATIC_DRAW);
7928
7929 /* GL entry points */
7930 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
7931
7932 /* Set up vao */
7933 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
7934 0 /* offset */);
7935 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
7936
7937 /* Enable attribute */
7938 gl.enableVertexAttribArray(test_loc);
7939 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
7940 }
7941
7942 /** Constructor
7943 *
7944 * @param context Test context
7945 **/
BindingUniformBlocksTest(deqp::Context & context)7946 BindingUniformBlocksTest::BindingUniformBlocksTest(deqp::Context &context)
7947 : GLSLTestBase(context, "binding_uniform_blocks", "Test verifies uniform block binding")
7948 , m_goku_buffer(context)
7949 , m_vegeta_buffer(context)
7950 , m_children_buffer(context)
7951 {
7952 /* Nothing to be done here */
7953 }
7954
7955 /** Prepare source for given shader stage
7956 *
7957 * @param in_stage Shader stage, compute shader will use 430
7958 * @param in_use_version_400 Select if 400 or 420 should be used
7959 * @param out_source Prepared shader source instance
7960 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7961 void BindingUniformBlocksTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7962 Utils::shaderSource &out_source)
7963 {
7964 static const GLchar *uni_goku = "layout(std140, binding = 0) uniform GOKU {\n"
7965 " vec4 chichi;\n"
7966 "} goku;\n";
7967
7968 static const GLchar *uni_vegeta = "layout(std140, binding = 1) uniform VEGETA {\n"
7969 " vec3 bulma;\n"
7970 "} vegeta;\n";
7971
7972 static const GLchar *uni_children = "layout(std140, binding = 3) uniform CHILDREN {\n"
7973 " vec4 gohan;\n"
7974 " vec4 trunks;\n"
7975 "} children;\n\n";
7976
7977 static const GLchar *verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.chichi) ||\n"
7978 " (vec3(0, 1, 0) != vegeta.bulma) ||\n"
7979 " (vec4(0, 0, 1, 0) != children.gohan) ||\n"
7980 " (vec4(0, 0, 0, 1) != children.trunks) )\n"
7981 " {\n"
7982 " result = vec4(1, 0, 0, 1);\n"
7983 " }\n";
7984
7985 static const GLchar *compute_shader_template =
7986 "VERSION\n"
7987 "\n"
7988 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7989 "\n"
7990 "writeonly uniform image2D uni_image;\n"
7991 "\n"
7992 "UNI_GOKU\n"
7993 "UNI_VEGETA\n"
7994 "UNI_CHILDREN\n"
7995 "\n"
7996 "void main()\n"
7997 "{\n"
7998 " vec4 result = vec4(0, 1, 0, 1);\n"
7999 "\n"
8000 "VERIFICATION"
8001 "\n"
8002 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8003 "}\n"
8004 "\n";
8005
8006 static const GLchar *fragment_shader_template = "VERSION\n"
8007 "\n"
8008 "in vec4 gs_fs_result;\n"
8009 "out vec4 fs_out_result;\n"
8010 "\n"
8011 "UNI_GOKU\n"
8012 "UNI_VEGETA\n"
8013 "UNI_CHILDREN\n"
8014 "\n"
8015 "void main()\n"
8016 "{\n"
8017 " vec4 result = vec4(0, 1, 0, 1);\n"
8018 "\n"
8019 "VERIFICATION"
8020 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8021 " {\n"
8022 " result = vec4(1, 0, 0, 1);\n"
8023 " }\n"
8024 "\n"
8025 " fs_out_result = result;\n"
8026 "}\n"
8027 "\n";
8028
8029 static const GLchar *geometry_shader_template = "VERSION\n"
8030 "\n"
8031 "layout(points) in;\n"
8032 "layout(triangle_strip, max_vertices = 4) out;\n"
8033 "\n"
8034 "in vec4 tes_gs_result[];\n"
8035 "out vec4 gs_fs_result;\n"
8036 "\n"
8037 "UNI_CHILDREN\n"
8038 "UNI_GOKU\n"
8039 "UNI_VEGETA\n"
8040 "\n"
8041 "void main()\n"
8042 "{\n"
8043 " vec4 result = vec4(0, 1, 0, 1);\n"
8044 "\n"
8045 "VERIFICATION"
8046 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8047 " {\n"
8048 " result = vec4(1, 0, 0, 1);\n"
8049 " }\n"
8050 "\n"
8051 " gs_fs_result = result;\n"
8052 " gl_Position = vec4(-1, -1, 0, 1);\n"
8053 " EmitVertex();\n"
8054 " gs_fs_result = result;\n"
8055 " gl_Position = vec4(-1, 1, 0, 1);\n"
8056 " EmitVertex();\n"
8057 " gs_fs_result = result;\n"
8058 " gl_Position = vec4(1, -1, 0, 1);\n"
8059 " EmitVertex();\n"
8060 " gs_fs_result = result;\n"
8061 " gl_Position = vec4(1, 1, 0, 1);\n"
8062 " EmitVertex();\n"
8063 "}\n"
8064 "\n";
8065
8066 static const GLchar *tess_ctrl_shader_template =
8067 "VERSION\n"
8068 "\n"
8069 "layout(vertices = 1) out;\n"
8070 "\n"
8071 "in vec4 vs_tcs_result[];\n"
8072 "out vec4 tcs_tes_result[];\n"
8073 "\n"
8074 "UNI_VEGETA\n"
8075 "UNI_CHILDREN\n"
8076 "UNI_GOKU\n"
8077 "\n"
8078 "void main()\n"
8079 "{\n"
8080 " vec4 result = vec4(0, 1, 0, 1);\n"
8081 "\n"
8082 "VERIFICATION"
8083 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8084 " {\n"
8085 " result = vec4(1, 0, 0, 1);\n"
8086 " }\n"
8087 "\n"
8088 " tcs_tes_result[gl_InvocationID] = result;\n"
8089 "\n"
8090 " gl_TessLevelOuter[0] = 1.0;\n"
8091 " gl_TessLevelOuter[1] = 1.0;\n"
8092 " gl_TessLevelOuter[2] = 1.0;\n"
8093 " gl_TessLevelOuter[3] = 1.0;\n"
8094 " gl_TessLevelInner[0] = 1.0;\n"
8095 " gl_TessLevelInner[1] = 1.0;\n"
8096 "}\n"
8097 "\n";
8098
8099 static const GLchar *tess_eval_shader_template = "VERSION\n"
8100 "\n"
8101 "layout(isolines, point_mode) in;\n"
8102 "\n"
8103 "in vec4 tcs_tes_result[];\n"
8104 "out vec4 tes_gs_result;\n"
8105 "\n"
8106 "UNI_GOKU\n"
8107 "UNI_CHILDREN\n"
8108 "UNI_VEGETA\n"
8109 "\n"
8110 "void main()\n"
8111 "{\n"
8112 " vec4 result = vec4(0, 1, 0, 1);\n"
8113 "\n"
8114 "VERIFICATION"
8115 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8116 " {\n"
8117 " result = vec4(1, 0, 0, 1);\n"
8118 " }\n"
8119 "\n"
8120 " tes_gs_result = result;\n"
8121 "}\n"
8122 "\n";
8123
8124 static const GLchar *vertex_shader_template = "VERSION\n"
8125 "\n"
8126 "out vec4 vs_tcs_result;\n"
8127 "\n"
8128 "UNI_CHILDREN\n"
8129 "UNI_VEGETA\n"
8130 "UNI_GOKU\n"
8131 "\n"
8132 "void main()\n"
8133 "{\n"
8134 " vec4 result = vec4(0, 1, 0, 1);\n"
8135 "\n"
8136 "VERIFICATION"
8137 "\n"
8138 " vs_tcs_result = result;\n"
8139 "}\n"
8140 "\n";
8141
8142 const GLchar *shader_template = 0;
8143
8144 switch (in_stage)
8145 {
8146 case Utils::COMPUTE_SHADER:
8147 shader_template = compute_shader_template;
8148 break;
8149 case Utils::FRAGMENT_SHADER:
8150 shader_template = fragment_shader_template;
8151 break;
8152 case Utils::GEOMETRY_SHADER:
8153 shader_template = geometry_shader_template;
8154 break;
8155 case Utils::TESS_CTRL_SHADER:
8156 shader_template = tess_ctrl_shader_template;
8157 break;
8158 case Utils::TESS_EVAL_SHADER:
8159 shader_template = tess_eval_shader_template;
8160 break;
8161 case Utils::VERTEX_SHADER:
8162 shader_template = vertex_shader_template;
8163 break;
8164 default:
8165 TCU_FAIL("Invalid enum");
8166 }
8167
8168 out_source.m_parts[0].m_code = shader_template;
8169
8170 size_t position = 0;
8171
8172 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8173 out_source.m_parts[0].m_code);
8174
8175 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8176
8177 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8178
8179 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
8180
8181 Utils::replaceAllTokens("UNI_CHILDREN", uni_children, out_source.m_parts[0].m_code);
8182 }
8183
8184 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8185 *
8186 * @param program Current program
8187 **/
prepareUniforms(Utils::program & program)8188 void BindingUniformBlocksTest::prepareUniforms(Utils::program &program)
8189 {
8190 (void)program;
8191 static const GLfloat goku_data[4] = {1.0f, 0.0f, 0.0f, 0.0f};
8192 static const GLfloat vegeta_data[3] = {0.0f, 1.0f, 0.0f};
8193 static const GLfloat children_data[8] = {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
8194
8195 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8196 m_vegeta_buffer.generate(GL_UNIFORM_BUFFER);
8197 m_children_buffer.generate(GL_UNIFORM_BUFFER);
8198
8199 m_goku_buffer.update(sizeof(goku_data), (GLvoid *)goku_data, GL_STATIC_DRAW);
8200 m_vegeta_buffer.update(sizeof(vegeta_data), (GLvoid *)vegeta_data, GL_STATIC_DRAW);
8201 m_children_buffer.update(sizeof(children_data), (GLvoid *)children_data, GL_STATIC_DRAW);
8202
8203 m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8204 m_vegeta_buffer.bindRange(1 /* index */, 0 /* offset */, sizeof(vegeta_data));
8205 m_children_buffer.bindRange(3 /* index */, 0 /* offset */, sizeof(children_data));
8206 }
8207
8208 /** Overwrite of releaseResource method, release extra uniform buffer
8209 *
8210 * @param ignored
8211 **/
releaseResource()8212 void BindingUniformBlocksTest::releaseResource()
8213 {
8214 m_goku_buffer.release();
8215 m_vegeta_buffer.release();
8216 m_children_buffer.release();
8217 }
8218
8219 /** Constructor
8220 *
8221 * @param context Test context
8222 **/
BindingUniformSingleBlockTest(deqp::Context & context)8223 BindingUniformSingleBlockTest::BindingUniformSingleBlockTest(deqp::Context &context)
8224 : GLSLTestBase(context, "binding_uniform_single_block", "Test verifies uniform block binding")
8225 , m_goku_buffer(context)
8226 , m_test_stage(Utils::SHADER_STAGES_MAX)
8227 {
8228 /* Nothing to be done here */
8229 }
8230
8231 /** Set up next test case
8232 *
8233 * @param test_case_index Index of next test case
8234 *
8235 * @return false if there is no more test cases, true otherwise
8236 **/
prepareNextTestCase(glw::GLuint test_case_index)8237 bool BindingUniformSingleBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
8238 {
8239 switch (test_case_index)
8240 {
8241 case (glw::GLuint)-1:
8242 case 0:
8243 m_test_stage = Utils::VERTEX_SHADER;
8244 break;
8245 case 1:
8246 m_test_stage = Utils::TESS_CTRL_SHADER;
8247 break;
8248 case 2:
8249 m_test_stage = Utils::TESS_EVAL_SHADER;
8250 break;
8251 case 3:
8252 m_test_stage = Utils::GEOMETRY_SHADER;
8253 break;
8254 case 4:
8255 m_test_stage = Utils::FRAGMENT_SHADER;
8256 break;
8257 default:
8258 return false;
8259 }
8260
8261 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
8262 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
8263 << tcu::TestLog::EndMessage;
8264
8265 return true;
8266 }
8267
8268 /** Prepare source for given shader stage
8269 *
8270 * @param in_stage Shader stage, compute shader will use 430
8271 * @param in_use_version_400 Select if 400 or 420 should be used
8272 * @param out_source Prepared shader source instance
8273 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8274 void BindingUniformSingleBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8275 Utils::shaderSource &out_source)
8276 {
8277 static const GLchar *uni_goku_with_binding = "layout(std140, binding = 0) uniform GOKU {\n"
8278 " vec4 gohan;\n"
8279 " vec4 goten;\n"
8280 "} goku;\n";
8281
8282 static const GLchar *uni_goku_no_binding = "layout(std140) uniform GOKU {\n"
8283 " vec4 gohan;\n"
8284 " vec4 goten;\n"
8285 "} goku;\n";
8286
8287 static const GLchar *verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
8288 " (vec4(0, 1, 0, 0) != goku.goten) )\n"
8289 " {\n"
8290 " result = vec4(1, 0, 0, 1);\n"
8291 " }\n";
8292
8293 static const GLchar *compute_shader_template =
8294 "VERSION\n"
8295 "\n"
8296 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8297 "\n"
8298 "writeonly uniform image2D uni_image;\n"
8299 "\n"
8300 "UNI_GOKU\n"
8301 "\n"
8302 "void main()\n"
8303 "{\n"
8304 " vec4 result = vec4(0, 1, 0, 1);\n"
8305 "\n"
8306 "VERIFICATION"
8307 "\n"
8308 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8309 "}\n"
8310 "\n";
8311
8312 static const GLchar *fragment_shader_template = "VERSION\n"
8313 "\n"
8314 "in vec4 gs_fs_result;\n"
8315 "out vec4 fs_out_result;\n"
8316 "\n"
8317 "UNI_GOKU\n"
8318 "\n"
8319 "void main()\n"
8320 "{\n"
8321 " vec4 result = vec4(0, 1, 0, 1);\n"
8322 "\n"
8323 "VERIFICATION"
8324 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8325 " {\n"
8326 " result = vec4(1, 0, 0, 1);\n"
8327 " }\n"
8328 "\n"
8329 " fs_out_result = result;\n"
8330 "}\n"
8331 "\n";
8332
8333 static const GLchar *geometry_shader_template = "VERSION\n"
8334 "\n"
8335 "layout(points) in;\n"
8336 "layout(triangle_strip, max_vertices = 4) out;\n"
8337 "\n"
8338 "in vec4 tes_gs_result[];\n"
8339 "out vec4 gs_fs_result;\n"
8340 "\n"
8341 "UNI_GOKU\n"
8342 "\n"
8343 "void main()\n"
8344 "{\n"
8345 " vec4 result = vec4(0, 1, 0, 1);\n"
8346 "\n"
8347 "VERIFICATION"
8348 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8349 " {\n"
8350 " result = vec4(1, 0, 0, 1);\n"
8351 " }\n"
8352 "\n"
8353 " gs_fs_result = result;\n"
8354 " gl_Position = vec4(-1, -1, 0, 1);\n"
8355 " EmitVertex();\n"
8356 " gs_fs_result = result;\n"
8357 " gl_Position = vec4(-1, 1, 0, 1);\n"
8358 " EmitVertex();\n"
8359 " gs_fs_result = result;\n"
8360 " gl_Position = vec4(1, -1, 0, 1);\n"
8361 " EmitVertex();\n"
8362 " gs_fs_result = result;\n"
8363 " gl_Position = vec4(1, 1, 0, 1);\n"
8364 " EmitVertex();\n"
8365 "}\n"
8366 "\n";
8367
8368 static const GLchar *tess_ctrl_shader_template =
8369 "VERSION\n"
8370 "\n"
8371 "layout(vertices = 1) out;\n"
8372 "\n"
8373 "in vec4 vs_tcs_result[];\n"
8374 "out vec4 tcs_tes_result[];\n"
8375 "\n"
8376 "UNI_GOKU\n"
8377 "\n"
8378 "void main()\n"
8379 "{\n"
8380 " vec4 result = vec4(0, 1, 0, 1);\n"
8381 "\n"
8382 "VERIFICATION"
8383 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8384 " {\n"
8385 " result = vec4(1, 0, 0, 1);\n"
8386 " }\n"
8387 "\n"
8388 " tcs_tes_result[gl_InvocationID] = result;\n"
8389 "\n"
8390 " gl_TessLevelOuter[0] = 1.0;\n"
8391 " gl_TessLevelOuter[1] = 1.0;\n"
8392 " gl_TessLevelOuter[2] = 1.0;\n"
8393 " gl_TessLevelOuter[3] = 1.0;\n"
8394 " gl_TessLevelInner[0] = 1.0;\n"
8395 " gl_TessLevelInner[1] = 1.0;\n"
8396 "}\n"
8397 "\n";
8398
8399 static const GLchar *tess_eval_shader_template = "VERSION\n"
8400 "\n"
8401 "layout(isolines, point_mode) in;\n"
8402 "\n"
8403 "in vec4 tcs_tes_result[];\n"
8404 "out vec4 tes_gs_result;\n"
8405 "\n"
8406 "UNI_GOKU\n"
8407 "\n"
8408 "void main()\n"
8409 "{\n"
8410 " vec4 result = vec4(0, 1, 0, 1);\n"
8411 "\n"
8412 "VERIFICATION"
8413 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8414 " {\n"
8415 " result = vec4(1, 0, 0, 1);\n"
8416 " }\n"
8417 "\n"
8418 " tes_gs_result = result;\n"
8419 "}\n"
8420 "\n";
8421
8422 static const GLchar *vertex_shader_template = "VERSION\n"
8423 "\n"
8424 "out vec4 vs_tcs_result;\n"
8425 "\n"
8426 "UNI_GOKU\n"
8427 "\n"
8428 "void main()\n"
8429 "{\n"
8430 " vec4 result = vec4(0, 1, 0, 1);\n"
8431 "\n"
8432 "VERIFICATION"
8433 "\n"
8434 " vs_tcs_result = result;\n"
8435 "}\n"
8436 "\n";
8437
8438 const GLchar *shader_template = 0;
8439 const GLchar *uniform_definition = uni_goku_no_binding;
8440
8441 switch (in_stage)
8442 {
8443 case Utils::COMPUTE_SHADER:
8444 shader_template = compute_shader_template;
8445 uniform_definition = uni_goku_with_binding;
8446 break;
8447 case Utils::FRAGMENT_SHADER:
8448 shader_template = fragment_shader_template;
8449 break;
8450 case Utils::GEOMETRY_SHADER:
8451 shader_template = geometry_shader_template;
8452 break;
8453 case Utils::TESS_CTRL_SHADER:
8454 shader_template = tess_ctrl_shader_template;
8455 break;
8456 case Utils::TESS_EVAL_SHADER:
8457 shader_template = tess_eval_shader_template;
8458 break;
8459 case Utils::VERTEX_SHADER:
8460 shader_template = vertex_shader_template;
8461 break;
8462 default:
8463 TCU_FAIL("Invalid enum");
8464 }
8465
8466 if (in_stage == m_test_stage)
8467 {
8468 uniform_definition = uni_goku_with_binding;
8469 }
8470
8471 out_source.m_parts[0].m_code = shader_template;
8472
8473 size_t position = 0;
8474
8475 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8476 out_source.m_parts[0].m_code);
8477
8478 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8479
8480 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
8481 }
8482
8483 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8484 *
8485 * @param program Current program
8486 **/
prepareUniforms(Utils::program & program)8487 void BindingUniformSingleBlockTest::prepareUniforms(Utils::program &program)
8488 {
8489 (void)program;
8490 static const GLfloat goku_data[8] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
8491
8492 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8493
8494 m_goku_buffer.update(sizeof(goku_data), (GLvoid *)goku_data, GL_STATIC_DRAW);
8495
8496 m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8497 }
8498
8499 /** Overwrite of releaseResource method, release extra uniform buffer
8500 *
8501 * @param ignored
8502 **/
releaseResource()8503 void BindingUniformSingleBlockTest::releaseResource()
8504 {
8505 m_goku_buffer.release();
8506 }
8507
8508 /** Constructor
8509 *
8510 * @param context Test context
8511 **/
BindingUniformBlockArrayTest(deqp::Context & context)8512 BindingUniformBlockArrayTest::BindingUniformBlockArrayTest(deqp::Context &context)
8513 : GLSLTestBase(context, "binding_uniform_block_array", "Test verifies binding of uniform block arrays")
8514 , m_goku_00_buffer(context)
8515 , m_goku_01_buffer(context)
8516 , m_goku_02_buffer(context)
8517 , m_goku_03_buffer(context)
8518 , m_goku_04_buffer(context)
8519 , m_goku_05_buffer(context)
8520 , m_goku_06_buffer(context)
8521 , m_goku_07_buffer(context)
8522 , m_goku_08_buffer(context)
8523 , m_goku_09_buffer(context)
8524 , m_goku_10_buffer(context)
8525 , m_goku_11_buffer(context)
8526 , m_goku_12_buffer(context)
8527 , m_goku_13_buffer(context)
8528 {
8529 /* Nothing to be done here */
8530 }
8531
8532 /** Prepare source for given shader stage
8533 *
8534 * @param in_stage Shader stage, compute shader will use 430
8535 * @param in_use_version_400 Select if 400 or 420 should be used
8536 * @param out_source Prepared shader source instance
8537 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8538 void BindingUniformBlockArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8539 Utils::shaderSource &out_source)
8540 {
8541 static const GLchar *uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
8542 " vec4 gohan;\n"
8543 " vec4 goten;\n"
8544 "} goku[14];\n";
8545
8546 static const GLchar *verification_snippet = " if ((vec4(0, 0, 0, 0) != goku[0].gohan) ||\n"
8547 " (vec4(0, 0, 0, 1) != goku[0].goten) ||\n"
8548 " (vec4(0, 0, 1, 0) != goku[1].gohan) ||\n"
8549 " (vec4(0, 0, 1, 1) != goku[1].goten) ||\n"
8550 " (vec4(0, 1, 0, 0) != goku[2].gohan) ||\n"
8551 " (vec4(0, 1, 0, 1) != goku[2].goten) ||\n"
8552 " (vec4(0, 1, 1, 0) != goku[3].gohan) ||\n"
8553 " (vec4(0, 1, 1, 1) != goku[3].goten) ||\n"
8554 " (vec4(1, 0, 0, 0) != goku[4].gohan) ||\n"
8555 " (vec4(1, 0, 0, 1) != goku[4].goten) ||\n"
8556 " (vec4(1, 0, 1, 0) != goku[5].gohan) ||\n"
8557 " (vec4(1, 0, 1, 1) != goku[5].goten) ||\n"
8558 " (vec4(1, 1, 0, 0) != goku[6].gohan) ||\n"
8559 " (vec4(1, 1, 0, 1) != goku[6].goten) ||\n"
8560 " (vec4(1, 1, 1, 0) != goku[7].gohan) ||\n"
8561 " (vec4(1, 1, 1, 1) != goku[7].goten) ||\n"
8562 " (vec4(0, 0, 0, 0) != goku[8].gohan) ||\n"
8563 " (vec4(0, 0, 0, 1) != goku[8].goten) ||\n"
8564 " (vec4(0, 0, 1, 0) != goku[9].gohan) ||\n"
8565 " (vec4(0, 0, 1, 1) != goku[9].goten) ||\n"
8566 " (vec4(0, 1, 0, 0) != goku[10].gohan) ||\n"
8567 " (vec4(0, 1, 0, 1) != goku[10].goten) ||\n"
8568 " (vec4(0, 1, 1, 0) != goku[11].gohan) ||\n"
8569 " (vec4(0, 1, 1, 1) != goku[11].goten) ||\n"
8570 " (vec4(1, 0, 0, 0) != goku[12].gohan) ||\n"
8571 " (vec4(1, 0, 0, 1) != goku[12].goten) ||\n"
8572 " (vec4(1, 0, 1, 0) != goku[13].gohan) ||\n"
8573 " (vec4(1, 0, 1, 1) != goku[13].goten) )\n"
8574 " {\n"
8575 " result = vec4(1, 0, 0, 1);\n"
8576 " }\n";
8577
8578 static const GLchar *compute_shader_template =
8579 "VERSION\n"
8580 "\n"
8581 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8582 "\n"
8583 "writeonly uniform image2D uni_image;\n"
8584 "\n"
8585 "UNI_GOKU\n"
8586 "\n"
8587 "void main()\n"
8588 "{\n"
8589 " vec4 result = vec4(0, 1, 0, 1);\n"
8590 "\n"
8591 "VERIFICATION"
8592 "\n"
8593 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8594 "}\n"
8595 "\n";
8596
8597 static const GLchar *fragment_shader_template = "VERSION\n"
8598 "\n"
8599 "in vec4 gs_fs_result;\n"
8600 "out vec4 fs_out_result;\n"
8601 "\n"
8602 "UNI_GOKU\n"
8603 "\n"
8604 "void main()\n"
8605 "{\n"
8606 " vec4 result = vec4(0, 1, 0, 1);\n"
8607 "\n"
8608 "VERIFICATION"
8609 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8610 " {\n"
8611 " result = vec4(1, 0, 0, 1);\n"
8612 " }\n"
8613 "\n"
8614 " fs_out_result = result;\n"
8615 "}\n"
8616 "\n";
8617
8618 static const GLchar *geometry_shader_template = "VERSION\n"
8619 "\n"
8620 "layout(points) in;\n"
8621 "layout(triangle_strip, max_vertices = 4) out;\n"
8622 "\n"
8623 "in vec4 tes_gs_result[];\n"
8624 "out vec4 gs_fs_result;\n"
8625 "\n"
8626 "UNI_GOKU\n"
8627 "\n"
8628 "void main()\n"
8629 "{\n"
8630 " vec4 result = vec4(0, 1, 0, 1);\n"
8631 "\n"
8632 "VERIFICATION"
8633 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8634 " {\n"
8635 " result = vec4(1, 0, 0, 1);\n"
8636 " }\n"
8637 "\n"
8638 " gs_fs_result = result;\n"
8639 " gl_Position = vec4(-1, -1, 0, 1);\n"
8640 " EmitVertex();\n"
8641 " gs_fs_result = result;\n"
8642 " gl_Position = vec4(-1, 1, 0, 1);\n"
8643 " EmitVertex();\n"
8644 " gs_fs_result = result;\n"
8645 " gl_Position = vec4(1, -1, 0, 1);\n"
8646 " EmitVertex();\n"
8647 " gs_fs_result = result;\n"
8648 " gl_Position = vec4(1, 1, 0, 1);\n"
8649 " EmitVertex();\n"
8650 "}\n"
8651 "\n";
8652
8653 static const GLchar *tess_ctrl_shader_template =
8654 "VERSION\n"
8655 "\n"
8656 "layout(vertices = 1) out;\n"
8657 "\n"
8658 "in vec4 vs_tcs_result[];\n"
8659 "out vec4 tcs_tes_result[];\n"
8660 "\n"
8661 "UNI_GOKU\n"
8662 "\n"
8663 "void main()\n"
8664 "{\n"
8665 " vec4 result = vec4(0, 1, 0, 1);\n"
8666 "\n"
8667 "VERIFICATION"
8668 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8669 " {\n"
8670 " result = vec4(1, 0, 0, 1);\n"
8671 " }\n"
8672 "\n"
8673 " tcs_tes_result[gl_InvocationID] = result;\n"
8674 "\n"
8675 " gl_TessLevelOuter[0] = 1.0;\n"
8676 " gl_TessLevelOuter[1] = 1.0;\n"
8677 " gl_TessLevelOuter[2] = 1.0;\n"
8678 " gl_TessLevelOuter[3] = 1.0;\n"
8679 " gl_TessLevelInner[0] = 1.0;\n"
8680 " gl_TessLevelInner[1] = 1.0;\n"
8681 "}\n"
8682 "\n";
8683
8684 static const GLchar *tess_eval_shader_template = "VERSION\n"
8685 "\n"
8686 "layout(isolines, point_mode) in;\n"
8687 "\n"
8688 "in vec4 tcs_tes_result[];\n"
8689 "out vec4 tes_gs_result;\n"
8690 "\n"
8691 "UNI_GOKU\n"
8692 "\n"
8693 "void main()\n"
8694 "{\n"
8695 " vec4 result = vec4(0, 1, 0, 1);\n"
8696 "\n"
8697 "VERIFICATION"
8698 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8699 " {\n"
8700 " result = vec4(1, 0, 0, 1);\n"
8701 " }\n"
8702 "\n"
8703 " tes_gs_result = result;\n"
8704 "}\n"
8705 "\n";
8706
8707 static const GLchar *vertex_shader_template = "VERSION\n"
8708 "\n"
8709 "out vec4 vs_tcs_result;\n"
8710 "\n"
8711 "UNI_GOKU\n"
8712 "\n"
8713 "void main()\n"
8714 "{\n"
8715 " vec4 result = vec4(0, 1, 0, 1);\n"
8716 "\n"
8717 "VERIFICATION"
8718 "\n"
8719 " vs_tcs_result = result;\n"
8720 "}\n"
8721 "\n";
8722
8723 const GLchar *shader_template = 0;
8724
8725 switch (in_stage)
8726 {
8727 case Utils::COMPUTE_SHADER:
8728 shader_template = compute_shader_template;
8729 break;
8730 case Utils::FRAGMENT_SHADER:
8731 shader_template = fragment_shader_template;
8732 break;
8733 case Utils::GEOMETRY_SHADER:
8734 shader_template = geometry_shader_template;
8735 break;
8736 case Utils::TESS_CTRL_SHADER:
8737 shader_template = tess_ctrl_shader_template;
8738 break;
8739 case Utils::TESS_EVAL_SHADER:
8740 shader_template = tess_eval_shader_template;
8741 break;
8742 case Utils::VERTEX_SHADER:
8743 shader_template = vertex_shader_template;
8744 break;
8745 default:
8746 TCU_FAIL("Invalid enum");
8747 }
8748
8749 out_source.m_parts[0].m_code = shader_template;
8750
8751 size_t position = 0;
8752
8753 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8754 out_source.m_parts[0].m_code);
8755
8756 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8757
8758 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8759 }
8760
8761 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8762 *
8763 * @param program Current program
8764 **/
prepareUniforms(Utils::program & program)8765 void BindingUniformBlockArrayTest::prepareUniforms(Utils::program &program)
8766 {
8767 static const GLfloat goku_data[][8] = {
8768 {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},
8769 {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},
8770 {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},
8771 {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},
8772 {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},
8773 {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},
8774 {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}};
8775
8776 Utils::buffer *buffers[14] = {&m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8777 &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8778 &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8779 &m_goku_12_buffer, &m_goku_13_buffer};
8780
8781 for (GLuint i = 0; i < 14; ++i)
8782 {
8783 checkBinding(program, i, i + 2);
8784
8785 buffers[i]->generate(GL_UNIFORM_BUFFER);
8786 buffers[i]->update(sizeof(GLfloat) * 8, (GLvoid *)goku_data[i], GL_STATIC_DRAW);
8787 buffers[i]->bindRange(i + 2 /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
8788 }
8789 }
8790
8791 /** Overwrite of releaseResource method, release extra uniform buffer
8792 *
8793 * @param ignored
8794 **/
releaseResource()8795 void BindingUniformBlockArrayTest::releaseResource()
8796 {
8797 Utils::buffer *buffers[14] = {&m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8798 &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8799 &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8800 &m_goku_12_buffer, &m_goku_13_buffer};
8801
8802 for (GLuint i = 0; i < 14; ++i)
8803 {
8804 buffers[i]->release();
8805 }
8806 }
8807
8808 /** Verifies that API reports correct uniform binding
8809 *
8810 * @param program Program
8811 * @param index Index of array element
8812 * @param expected_binding Expected binding
8813 **/
checkBinding(Utils::program & program,glw::GLuint index,glw::GLint expected_binding)8814 void BindingUniformBlockArrayTest::checkBinding(Utils::program &program, glw::GLuint index, glw::GLint expected_binding)
8815 {
8816 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8817
8818 GLchar buffer[64];
8819 sprintf(buffer, "GOKU[%d]", index);
8820
8821 const GLuint uniform_index = gl.getUniformBlockIndex(program.m_program_object_id, buffer);
8822 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8823 if (GL_INVALID_INDEX == uniform_index)
8824 {
8825 TCU_FAIL("Uniform block is inactive");
8826 }
8827
8828 GLint binding = -1;
8829
8830 gl.getActiveUniformBlockiv(program.m_program_object_id, uniform_index, GL_UNIFORM_BLOCK_BINDING, &binding);
8831 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8832
8833 if (expected_binding != binding)
8834 {
8835 TCU_FAIL("Wrong binding reported by API");
8836 }
8837 }
8838
8839 /** Constructor
8840 *
8841 * @param context Test context
8842 **/
BindingUniformDefaultTest(deqp::Context & context)8843 BindingUniformDefaultTest::BindingUniformDefaultTest(deqp::Context &context)
8844 : APITestBase(context, "binding_uniform_default", "Test verifies default binding of uniform block")
8845 {
8846 /* Nothing to be done here */
8847 }
8848
8849 /** Execute API call and verifies results
8850 *
8851 * @return true when results are positive, false otherwise
8852 **/
checkResults(Utils::program & program)8853 bool BindingUniformDefaultTest::checkResults(Utils::program &program)
8854 {
8855 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
8856
8857 const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
8858 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8859 if (GL_INVALID_INDEX == index)
8860 {
8861 TCU_FAIL("Uniform block is inactive");
8862 return false;
8863 }
8864
8865 GLint binding = -1;
8866
8867 gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
8868 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8869
8870 if (0 != binding)
8871 {
8872 return false;
8873 }
8874
8875 return true;
8876 }
8877
8878 /** Prepare source for given shader stage
8879 *
8880 * @param in_stage Shader stage, compute shader will use 430
8881 * @param in_use_version_400 Select if 400 or 420 should be used
8882 * @param out_source Prepared shader source instance
8883 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8884 void BindingUniformDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8885 Utils::shaderSource &out_source)
8886 {
8887 static const GLchar *uni_goku = "layout(std140) uniform GOKU {\n"
8888 " vec4 gohan;\n"
8889 " vec4 goten;\n"
8890 "} goku;\n";
8891
8892 static const GLchar *verification_snippet = " if ((vec4(0, 0, 0, 0) != goku.gohan) ||\n"
8893 " (vec4(0, 0, 0, 1) != goku.goten) )\n"
8894 " {\n"
8895 " result = vec4(1, 0, 0, 1);\n"
8896 " }\n";
8897
8898 static const GLchar *compute_shader_template =
8899 "VERSION\n"
8900 "\n"
8901 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8902 "\n"
8903 "writeonly uniform image2D uni_image;\n"
8904 "\n"
8905 "UNI_GOKU\n"
8906 "\n"
8907 "void main()\n"
8908 "{\n"
8909 " vec4 result = vec4(0, 1, 0, 1);\n"
8910 "\n"
8911 "VERIFICATION"
8912 "\n"
8913 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8914 "}\n"
8915 "\n";
8916
8917 static const GLchar *fragment_shader_template = "VERSION\n"
8918 "\n"
8919 "in vec4 gs_fs_result;\n"
8920 "out vec4 fs_out_result;\n"
8921 "\n"
8922 "UNI_GOKU\n"
8923 "\n"
8924 "void main()\n"
8925 "{\n"
8926 " vec4 result = vec4(0, 1, 0, 1);\n"
8927 "\n"
8928 "VERIFICATION"
8929 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8930 " {\n"
8931 " result = vec4(1, 0, 0, 1);\n"
8932 " }\n"
8933 "\n"
8934 " fs_out_result = result;\n"
8935 "}\n"
8936 "\n";
8937
8938 static const GLchar *geometry_shader_template = "VERSION\n"
8939 "\n"
8940 "layout(points) in;\n"
8941 "layout(triangle_strip, max_vertices = 4) out;\n"
8942 "\n"
8943 "in vec4 tes_gs_result[];\n"
8944 "out vec4 gs_fs_result;\n"
8945 "\n"
8946 "UNI_GOKU\n"
8947 "\n"
8948 "void main()\n"
8949 "{\n"
8950 " vec4 result = vec4(0, 1, 0, 1);\n"
8951 "\n"
8952 "VERIFICATION"
8953 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8954 " {\n"
8955 " result = vec4(1, 0, 0, 1);\n"
8956 " }\n"
8957 "\n"
8958 " gs_fs_result = result;\n"
8959 " gl_Position = vec4(-1, -1, 0, 1);\n"
8960 " EmitVertex();\n"
8961 " gs_fs_result = result;\n"
8962 " gl_Position = vec4(-1, 1, 0, 1);\n"
8963 " EmitVertex();\n"
8964 " gs_fs_result = result;\n"
8965 " gl_Position = vec4(1, -1, 0, 1);\n"
8966 " EmitVertex();\n"
8967 " gs_fs_result = result;\n"
8968 " gl_Position = vec4(1, 1, 0, 1);\n"
8969 " EmitVertex();\n"
8970 "}\n"
8971 "\n";
8972
8973 static const GLchar *tess_ctrl_shader_template =
8974 "VERSION\n"
8975 "\n"
8976 "layout(vertices = 1) out;\n"
8977 "\n"
8978 "in vec4 vs_tcs_result[];\n"
8979 "out vec4 tcs_tes_result[];\n"
8980 "\n"
8981 "UNI_GOKU\n"
8982 "\n"
8983 "void main()\n"
8984 "{\n"
8985 " vec4 result = vec4(0, 1, 0, 1);\n"
8986 "\n"
8987 "VERIFICATION"
8988 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8989 " {\n"
8990 " result = vec4(1, 0, 0, 1);\n"
8991 " }\n"
8992 "\n"
8993 " tcs_tes_result[gl_InvocationID] = result;\n"
8994 "\n"
8995 " gl_TessLevelOuter[0] = 1.0;\n"
8996 " gl_TessLevelOuter[1] = 1.0;\n"
8997 " gl_TessLevelOuter[2] = 1.0;\n"
8998 " gl_TessLevelOuter[3] = 1.0;\n"
8999 " gl_TessLevelInner[0] = 1.0;\n"
9000 " gl_TessLevelInner[1] = 1.0;\n"
9001 "}\n"
9002 "\n";
9003
9004 static const GLchar *tess_eval_shader_template = "VERSION\n"
9005 "\n"
9006 "layout(isolines, point_mode) in;\n"
9007 "\n"
9008 "in vec4 tcs_tes_result[];\n"
9009 "out vec4 tes_gs_result;\n"
9010 "\n"
9011 "UNI_GOKU\n"
9012 "\n"
9013 "void main()\n"
9014 "{\n"
9015 " vec4 result = vec4(0, 1, 0, 1);\n"
9016 "\n"
9017 "VERIFICATION"
9018 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9019 " {\n"
9020 " result = vec4(1, 0, 0, 1);\n"
9021 " }\n"
9022 "\n"
9023 " tes_gs_result = result;\n"
9024 "}\n"
9025 "\n";
9026
9027 static const GLchar *vertex_shader_template = "VERSION\n"
9028 "\n"
9029 "out vec4 vs_tcs_result;\n"
9030 "\n"
9031 "UNI_GOKU\n"
9032 "\n"
9033 "void main()\n"
9034 "{\n"
9035 " vec4 result = vec4(0, 1, 0, 1);\n"
9036 "\n"
9037 "VERIFICATION"
9038 "\n"
9039 " vs_tcs_result = result;\n"
9040 "}\n"
9041 "\n";
9042
9043 const GLchar *shader_template = 0;
9044
9045 switch (in_stage)
9046 {
9047 case Utils::COMPUTE_SHADER:
9048 shader_template = compute_shader_template;
9049 break;
9050 case Utils::FRAGMENT_SHADER:
9051 shader_template = fragment_shader_template;
9052 break;
9053 case Utils::GEOMETRY_SHADER:
9054 shader_template = geometry_shader_template;
9055 break;
9056 case Utils::TESS_CTRL_SHADER:
9057 shader_template = tess_ctrl_shader_template;
9058 break;
9059 case Utils::TESS_EVAL_SHADER:
9060 shader_template = tess_eval_shader_template;
9061 break;
9062 case Utils::VERTEX_SHADER:
9063 shader_template = vertex_shader_template;
9064 break;
9065 default:
9066 TCU_FAIL("Invalid enum");
9067 }
9068
9069 out_source.m_parts[0].m_code = shader_template;
9070
9071 size_t position = 0;
9072
9073 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9074 out_source.m_parts[0].m_code);
9075
9076 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9077
9078 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9079 }
9080
9081 /** Constructor
9082 *
9083 * @param context Test context
9084 **/
BindingUniformAPIOverirdeTest(deqp::Context & context)9085 BindingUniformAPIOverirdeTest::BindingUniformAPIOverirdeTest(deqp::Context &context)
9086 : GLSLTestBase(context, "binding_uniform_api_overirde", "Test verifies if binding can be overriden with API")
9087 , m_goku_buffer(context)
9088 {
9089 /* Nothing to be done here */
9090 }
9091
9092 /** Prepare source for given shader stage
9093 *
9094 * @param in_stage Shader stage, compute shader will use 430
9095 * @param in_use_version_400 Select if 400 or 420 should be used
9096 * @param out_source Prepared shader source instance
9097 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9098 void BindingUniformAPIOverirdeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9099 Utils::shaderSource &out_source)
9100 {
9101 static const GLchar *uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
9102 " vec4 gohan;\n"
9103 " vec4 goten;\n"
9104 "} goku;\n";
9105
9106 static const GLchar *verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
9107 " (vec4(0, 1, 0, 0) != goku.goten) )\n"
9108 " {\n"
9109 " result = vec4(1, 0, 0, 1);\n"
9110 " }\n";
9111
9112 static const GLchar *compute_shader_template =
9113 "VERSION\n"
9114 "\n"
9115 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9116 "\n"
9117 "writeonly uniform image2D uni_image;\n"
9118 "\n"
9119 "UNI_GOKU\n"
9120 "\n"
9121 "void main()\n"
9122 "{\n"
9123 " vec4 result = vec4(0, 1, 0, 1);\n"
9124 "\n"
9125 "VERIFICATION"
9126 "\n"
9127 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9128 "}\n"
9129 "\n";
9130
9131 static const GLchar *fragment_shader_template = "VERSION\n"
9132 "\n"
9133 "in vec4 gs_fs_result;\n"
9134 "out vec4 fs_out_result;\n"
9135 "\n"
9136 "UNI_GOKU\n"
9137 "\n"
9138 "void main()\n"
9139 "{\n"
9140 " vec4 result = vec4(0, 1, 0, 1);\n"
9141 "\n"
9142 "VERIFICATION"
9143 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9144 " {\n"
9145 " result = vec4(1, 0, 0, 1);\n"
9146 " }\n"
9147 "\n"
9148 " fs_out_result = result;\n"
9149 "}\n"
9150 "\n";
9151
9152 static const GLchar *geometry_shader_template = "VERSION\n"
9153 "\n"
9154 "layout(points) in;\n"
9155 "layout(triangle_strip, max_vertices = 4) out;\n"
9156 "\n"
9157 "in vec4 tes_gs_result[];\n"
9158 "out vec4 gs_fs_result;\n"
9159 "\n"
9160 "UNI_GOKU\n"
9161 "\n"
9162 "void main()\n"
9163 "{\n"
9164 " vec4 result = vec4(0, 1, 0, 1);\n"
9165 "\n"
9166 "VERIFICATION"
9167 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9168 " {\n"
9169 " result = vec4(1, 0, 0, 1);\n"
9170 " }\n"
9171 "\n"
9172 " gs_fs_result = result;\n"
9173 " gl_Position = vec4(-1, -1, 0, 1);\n"
9174 " EmitVertex();\n"
9175 " gs_fs_result = result;\n"
9176 " gl_Position = vec4(-1, 1, 0, 1);\n"
9177 " EmitVertex();\n"
9178 " gs_fs_result = result;\n"
9179 " gl_Position = vec4(1, -1, 0, 1);\n"
9180 " EmitVertex();\n"
9181 " gs_fs_result = result;\n"
9182 " gl_Position = vec4(1, 1, 0, 1);\n"
9183 " EmitVertex();\n"
9184 "}\n"
9185 "\n";
9186
9187 static const GLchar *tess_ctrl_shader_template =
9188 "VERSION\n"
9189 "\n"
9190 "layout(vertices = 1) out;\n"
9191 "\n"
9192 "in vec4 vs_tcs_result[];\n"
9193 "out vec4 tcs_tes_result[];\n"
9194 "\n"
9195 "UNI_GOKU\n"
9196 "\n"
9197 "void main()\n"
9198 "{\n"
9199 " vec4 result = vec4(0, 1, 0, 1);\n"
9200 "\n"
9201 "VERIFICATION"
9202 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9203 " {\n"
9204 " result = vec4(1, 0, 0, 1);\n"
9205 " }\n"
9206 "\n"
9207 " tcs_tes_result[gl_InvocationID] = result;\n"
9208 "\n"
9209 " gl_TessLevelOuter[0] = 1.0;\n"
9210 " gl_TessLevelOuter[1] = 1.0;\n"
9211 " gl_TessLevelOuter[2] = 1.0;\n"
9212 " gl_TessLevelOuter[3] = 1.0;\n"
9213 " gl_TessLevelInner[0] = 1.0;\n"
9214 " gl_TessLevelInner[1] = 1.0;\n"
9215 "}\n"
9216 "\n";
9217
9218 static const GLchar *tess_eval_shader_template = "VERSION\n"
9219 "\n"
9220 "layout(isolines, point_mode) in;\n"
9221 "\n"
9222 "in vec4 tcs_tes_result[];\n"
9223 "out vec4 tes_gs_result;\n"
9224 "\n"
9225 "UNI_GOKU\n"
9226 "\n"
9227 "void main()\n"
9228 "{\n"
9229 " vec4 result = vec4(0, 1, 0, 1);\n"
9230 "\n"
9231 "VERIFICATION"
9232 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9233 " {\n"
9234 " result = vec4(1, 0, 0, 1);\n"
9235 " }\n"
9236 "\n"
9237 " tes_gs_result = result;\n"
9238 "}\n"
9239 "\n";
9240
9241 static const GLchar *vertex_shader_template = "VERSION\n"
9242 "\n"
9243 "out vec4 vs_tcs_result;\n"
9244 "\n"
9245 "UNI_GOKU\n"
9246 "\n"
9247 "void main()\n"
9248 "{\n"
9249 " vec4 result = vec4(0, 1, 0, 1);\n"
9250 "\n"
9251 "VERIFICATION"
9252 "\n"
9253 " vs_tcs_result = result;\n"
9254 "}\n"
9255 "\n";
9256
9257 const GLchar *shader_template = 0;
9258
9259 switch (in_stage)
9260 {
9261 case Utils::COMPUTE_SHADER:
9262 shader_template = compute_shader_template;
9263 break;
9264 case Utils::FRAGMENT_SHADER:
9265 shader_template = fragment_shader_template;
9266 break;
9267 case Utils::GEOMETRY_SHADER:
9268 shader_template = geometry_shader_template;
9269 break;
9270 case Utils::TESS_CTRL_SHADER:
9271 shader_template = tess_ctrl_shader_template;
9272 break;
9273 case Utils::TESS_EVAL_SHADER:
9274 shader_template = tess_eval_shader_template;
9275 break;
9276 case Utils::VERTEX_SHADER:
9277 shader_template = vertex_shader_template;
9278 break;
9279 default:
9280 TCU_FAIL("Invalid enum");
9281 }
9282
9283 out_source.m_parts[0].m_code = shader_template;
9284
9285 size_t position = 0;
9286
9287 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9288 out_source.m_parts[0].m_code);
9289
9290 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9291
9292 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9293 }
9294
9295 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
9296 *
9297 * @param program Current program
9298 **/
prepareUniforms(Utils::program & program)9299 void BindingUniformAPIOverirdeTest::prepareUniforms(Utils::program &program)
9300 {
9301 static const GLfloat goku_data[8] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
9302
9303 static const GLuint new_binding = 11;
9304
9305 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
9306
9307 const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
9308 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
9309 if (GL_INVALID_INDEX == index)
9310 {
9311 TCU_FAIL("Uniform block is inactive");
9312 return;
9313 }
9314
9315 gl.uniformBlockBinding(program.m_program_object_id, index, new_binding);
9316 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformBlockBinding");
9317
9318 GLint binding = -1;
9319
9320 gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
9321 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
9322
9323 if (new_binding != binding)
9324 {
9325 TCU_FAIL("GetActiveUniformBlockiv returned wrong binding");
9326 return;
9327 }
9328
9329 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
9330 m_goku_buffer.update(sizeof(GLfloat) * 8, (GLvoid *)goku_data, GL_STATIC_DRAW);
9331 m_goku_buffer.bindRange(new_binding /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
9332 }
9333
9334 /** Overwrite of releaseResource method, release extra uniform buffer
9335 *
9336 * @param ignored
9337 **/
releaseResource()9338 void BindingUniformAPIOverirdeTest::releaseResource()
9339 {
9340 m_goku_buffer.release();
9341 }
9342
9343 /** Constructor
9344 *
9345 * @param context Test context
9346 **/
BindingUniformGlobalBlockTest(deqp::Context & context)9347 BindingUniformGlobalBlockTest::BindingUniformGlobalBlockTest(deqp::Context &context)
9348 : NegativeTestBase(context, "binding_uniform_global_block",
9349 "Test verifies that global uniform cannot be qualified with binding")
9350 {
9351 /* Nothing to be done here */
9352 }
9353
9354 /** Prepare source for given shader stage
9355 *
9356 * @param in_stage Shader stage, compute shader will use 430
9357 * @param in_use_version_400 Select if 400 or 420 should be used
9358 * @param out_source Prepared shader source instance
9359 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9360 void BindingUniformGlobalBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9361 Utils::shaderSource &out_source)
9362 {
9363 static const GLchar *verification_snippet = " if (vec4(0, 0, 1, 1) != uni_test)\n"
9364 " {\n"
9365 " result = vec4(1, 0, 0, 1);\n"
9366 " }\n";
9367
9368 static const GLchar *uniform_definition = "layout(binding = 0) uniform vec4 uni_test;\n";
9369
9370 static const GLchar *compute_shader_template =
9371 "VERSION\n"
9372 "\n"
9373 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9374 "\n"
9375 "writeonly uniform image2D uni_image;\n"
9376 "\n"
9377 "UNIFORM_DEFINITION\n"
9378 "\n"
9379 "void main()\n"
9380 "{\n"
9381 " vec4 result = vec4(0, 1, 0, 1);\n"
9382 "\n"
9383 "VERIFICATION"
9384 "\n"
9385 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9386 "}\n"
9387 "\n";
9388
9389 static const GLchar *fragment_shader_template = "VERSION\n"
9390 "\n"
9391 "in vec4 gs_fs_result;\n"
9392 "out vec4 fs_out_result;\n"
9393 "\n"
9394 "UNIFORM_DEFINITION\n"
9395 "\n"
9396 "void main()\n"
9397 "{\n"
9398 " vec4 result = vec4(0, 1, 0, 1);\n"
9399 "\n"
9400 "VERIFICATION"
9401 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9402 " {\n"
9403 " result = vec4(1, 0, 0, 1);\n"
9404 " }\n"
9405 "\n"
9406 " fs_out_result = result;\n"
9407 "}\n"
9408 "\n";
9409
9410 static const GLchar *geometry_shader_template = "VERSION\n"
9411 "\n"
9412 "layout(points) in;\n"
9413 "layout(triangle_strip, max_vertices = 4) out;\n"
9414 "\n"
9415 "in vec4 tes_gs_result[];\n"
9416 "out vec4 gs_fs_result;\n"
9417 "\n"
9418 "UNIFORM_DEFINITION\n"
9419 "\n"
9420 "void main()\n"
9421 "{\n"
9422 " vec4 result = vec4(0, 1, 0, 1);\n"
9423 "\n"
9424 "VERIFICATION"
9425 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9426 " {\n"
9427 " result = vec4(1, 0, 0, 1);\n"
9428 " }\n"
9429 "\n"
9430 " gs_fs_result = result;\n"
9431 " gl_Position = vec4(-1, -1, 0, 1);\n"
9432 " EmitVertex();\n"
9433 " gs_fs_result = result;\n"
9434 " gl_Position = vec4(-1, 1, 0, 1);\n"
9435 " EmitVertex();\n"
9436 " gs_fs_result = result;\n"
9437 " gl_Position = vec4(1, -1, 0, 1);\n"
9438 " EmitVertex();\n"
9439 " gs_fs_result = result;\n"
9440 " gl_Position = vec4(1, 1, 0, 1);\n"
9441 " EmitVertex();\n"
9442 "}\n"
9443 "\n";
9444
9445 static const GLchar *tess_ctrl_shader_template =
9446 "VERSION\n"
9447 "\n"
9448 "layout(vertices = 1) out;\n"
9449 "\n"
9450 "in vec4 vs_tcs_result[];\n"
9451 "out vec4 tcs_tes_result[];\n"
9452 "\n"
9453 "UNIFORM_DEFINITION\n"
9454 "\n"
9455 "void main()\n"
9456 "{\n"
9457 " vec4 result = vec4(0, 1, 0, 1);\n"
9458 "\n"
9459 "VERIFICATION"
9460 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9461 " {\n"
9462 " result = vec4(1, 0, 0, 1);\n"
9463 " }\n"
9464 "\n"
9465 " tcs_tes_result[gl_InvocationID] = result;\n"
9466 "\n"
9467 " gl_TessLevelOuter[0] = 1.0;\n"
9468 " gl_TessLevelOuter[1] = 1.0;\n"
9469 " gl_TessLevelOuter[2] = 1.0;\n"
9470 " gl_TessLevelOuter[3] = 1.0;\n"
9471 " gl_TessLevelInner[0] = 1.0;\n"
9472 " gl_TessLevelInner[1] = 1.0;\n"
9473 "}\n"
9474 "\n";
9475
9476 static const GLchar *tess_eval_shader_template = "VERSION\n"
9477 "\n"
9478 "layout(isolines, point_mode) in;\n"
9479 "\n"
9480 "in vec4 tcs_tes_result[];\n"
9481 "out vec4 tes_gs_result;\n"
9482 "\n"
9483 "UNIFORM_DEFINITION\n"
9484 "\n"
9485 "void main()\n"
9486 "{\n"
9487 " vec4 result = vec4(0, 1, 0, 1);\n"
9488 "\n"
9489 "VERIFICATION"
9490 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9491 " {\n"
9492 " result = vec4(1, 0, 0, 1);\n"
9493 " }\n"
9494 "\n"
9495 " tes_gs_result = result;\n"
9496 "}\n"
9497 "\n";
9498
9499 static const GLchar *vertex_shader_template = "VERSION\n"
9500 "\n"
9501 "out vec4 vs_tcs_result;\n"
9502 "\n"
9503 "UNIFORM_DEFINITION\n"
9504 "\n"
9505 "void main()\n"
9506 "{\n"
9507 " vec4 result = vec4(0, 1, 0, 1);\n"
9508 "\n"
9509 "VERIFICATION"
9510 "\n"
9511 " vs_tcs_result = result;\n"
9512 "}\n"
9513 "\n";
9514
9515 const GLchar *shader_template = 0;
9516
9517 switch (in_stage)
9518 {
9519 case Utils::COMPUTE_SHADER:
9520 shader_template = compute_shader_template;
9521 break;
9522 case Utils::FRAGMENT_SHADER:
9523 shader_template = fragment_shader_template;
9524 break;
9525 case Utils::GEOMETRY_SHADER:
9526 shader_template = geometry_shader_template;
9527 break;
9528 case Utils::TESS_CTRL_SHADER:
9529 shader_template = tess_ctrl_shader_template;
9530 break;
9531 case Utils::TESS_EVAL_SHADER:
9532 shader_template = tess_eval_shader_template;
9533 break;
9534 case Utils::VERTEX_SHADER:
9535 shader_template = vertex_shader_template;
9536 break;
9537 default:
9538 TCU_FAIL("Invalid enum");
9539 }
9540
9541 out_source.m_parts[0].m_code = shader_template;
9542
9543 size_t position = 0;
9544 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9545 out_source.m_parts[0].m_code);
9546
9547 Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9548
9549 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9550 }
9551
9552 /** Constructor
9553 *
9554 * @param context Test context
9555 **/
BindingUniformInvalidTest(deqp::Context & context)9556 BindingUniformInvalidTest::BindingUniformInvalidTest(deqp::Context &context)
9557 : NegativeTestBase(context, "binding_uniform_invalid", "Test verifies invalid binding values")
9558 , m_case(TEST_CASES_MAX)
9559 {
9560 /* Nothing to be done here */
9561 }
9562
9563 /** Set up next test case
9564 *
9565 * @param test_case_index Index of next test case
9566 *
9567 * @return false if there is no more test cases, true otherwise
9568 **/
prepareNextTestCase(glw::GLuint test_case_index)9569 bool BindingUniformInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
9570 {
9571 switch (test_case_index)
9572 {
9573 case (glw::GLuint)-1:
9574 m_case = TEST_CASES_MAX;
9575 break;
9576 case NEGATIVE_VALUE:
9577 case VARIABLE_NAME:
9578 case STD140:
9579 case MISSING:
9580 m_case = (TESTCASES)test_case_index;
9581 break;
9582 default:
9583 return false;
9584 }
9585
9586 return true;
9587 }
9588
9589 /** Prepare source for given shader stage
9590 *
9591 * @param in_stage Shader stage, compute shader will use 430
9592 * @param in_use_version_400 Select if 400 or 420 should be used
9593 * @param out_source Prepared shader source instance
9594 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9595 void BindingUniformInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9596 Utils::shaderSource &out_source)
9597 {
9598 static const GLchar *verification_snippet = " if (vec4(0, 0, 1, 1) != goku.gohan)\n"
9599 " {\n"
9600 " result = vec4(1, 0, 0, 1);\n"
9601 " }\n";
9602
9603 static const GLchar *uniform_definition = "layout(std140, binding BINDING) uniform GOKU {\n"
9604 " vec4 gohan;\n"
9605 " vec4 goten;\n"
9606 "} goku;\n";
9607
9608 static const GLchar *compute_shader_template =
9609 "VERSION\n"
9610 "\n"
9611 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9612 "\n"
9613 "writeonly uniform image2D uni_image;\n"
9614 "\n"
9615 "UNIFORM_DEFINITION\n"
9616 "\n"
9617 "void main()\n"
9618 "{\n"
9619 " vec4 result = vec4(0, 1, 0, 1);\n"
9620 "\n"
9621 "VERIFICATION"
9622 "\n"
9623 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9624 "}\n"
9625 "\n";
9626
9627 static const GLchar *fragment_shader_template = "VERSION\n"
9628 "\n"
9629 "in vec4 gs_fs_result;\n"
9630 "out vec4 fs_out_result;\n"
9631 "\n"
9632 "UNIFORM_DEFINITION\n"
9633 "\n"
9634 "void main()\n"
9635 "{\n"
9636 " vec4 result = vec4(0, 1, 0, 1);\n"
9637 "\n"
9638 "VERIFICATION"
9639 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9640 " {\n"
9641 " result = vec4(1, 0, 0, 1);\n"
9642 " }\n"
9643 "\n"
9644 " fs_out_result = result;\n"
9645 "}\n"
9646 "\n";
9647
9648 static const GLchar *geometry_shader_template = "VERSION\n"
9649 "\n"
9650 "layout(points) in;\n"
9651 "layout(triangle_strip, max_vertices = 4) out;\n"
9652 "\n"
9653 "in vec4 tes_gs_result[];\n"
9654 "out vec4 gs_fs_result;\n"
9655 "\n"
9656 "UNIFORM_DEFINITION\n"
9657 "\n"
9658 "void main()\n"
9659 "{\n"
9660 " vec4 result = vec4(0, 1, 0, 1);\n"
9661 "\n"
9662 "VERIFICATION"
9663 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9664 " {\n"
9665 " result = vec4(1, 0, 0, 1);\n"
9666 " }\n"
9667 "\n"
9668 " gs_fs_result = result;\n"
9669 " gl_Position = vec4(-1, -1, 0, 1);\n"
9670 " EmitVertex();\n"
9671 " gs_fs_result = result;\n"
9672 " gl_Position = vec4(-1, 1, 0, 1);\n"
9673 " EmitVertex();\n"
9674 " gs_fs_result = result;\n"
9675 " gl_Position = vec4(1, -1, 0, 1);\n"
9676 " EmitVertex();\n"
9677 " gs_fs_result = result;\n"
9678 " gl_Position = vec4(1, 1, 0, 1);\n"
9679 " EmitVertex();\n"
9680 "}\n"
9681 "\n";
9682
9683 static const GLchar *tess_ctrl_shader_template =
9684 "VERSION\n"
9685 "\n"
9686 "layout(vertices = 1) out;\n"
9687 "\n"
9688 "in vec4 vs_tcs_result[];\n"
9689 "out vec4 tcs_tes_result[];\n"
9690 "\n"
9691 "UNIFORM_DEFINITION\n"
9692 "\n"
9693 "void main()\n"
9694 "{\n"
9695 " vec4 result = vec4(0, 1, 0, 1);\n"
9696 "\n"
9697 "VERIFICATION"
9698 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9699 " {\n"
9700 " result = vec4(1, 0, 0, 1);\n"
9701 " }\n"
9702 "\n"
9703 " tcs_tes_result[gl_InvocationID] = result;\n"
9704 "\n"
9705 " gl_TessLevelOuter[0] = 1.0;\n"
9706 " gl_TessLevelOuter[1] = 1.0;\n"
9707 " gl_TessLevelOuter[2] = 1.0;\n"
9708 " gl_TessLevelOuter[3] = 1.0;\n"
9709 " gl_TessLevelInner[0] = 1.0;\n"
9710 " gl_TessLevelInner[1] = 1.0;\n"
9711 "}\n"
9712 "\n";
9713
9714 static const GLchar *tess_eval_shader_template = "VERSION\n"
9715 "\n"
9716 "layout(isolines, point_mode) in;\n"
9717 "\n"
9718 "in vec4 tcs_tes_result[];\n"
9719 "out vec4 tes_gs_result;\n"
9720 "\n"
9721 "UNIFORM_DEFINITION\n"
9722 "\n"
9723 "void main()\n"
9724 "{\n"
9725 " vec4 result = vec4(0, 1, 0, 1);\n"
9726 "\n"
9727 "VERIFICATION"
9728 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9729 " {\n"
9730 " result = vec4(1, 0, 0, 1);\n"
9731 " }\n"
9732 "\n"
9733 " tes_gs_result = result;\n"
9734 "}\n"
9735 "\n";
9736
9737 static const GLchar *vertex_shader_template = "VERSION\n"
9738 "\n"
9739 "out vec4 vs_tcs_result;\n"
9740 "\n"
9741 "UNIFORM_DEFINITION\n"
9742 "\n"
9743 "void main()\n"
9744 "{\n"
9745 " vec4 result = vec4(0, 1, 0, 1);\n"
9746 "\n"
9747 "VERIFICATION"
9748 "\n"
9749 " vs_tcs_result = result;\n"
9750 "}\n"
9751 "\n";
9752
9753 const GLchar *shader_template = 0;
9754
9755 switch (in_stage)
9756 {
9757 case Utils::COMPUTE_SHADER:
9758 shader_template = compute_shader_template;
9759 break;
9760 case Utils::FRAGMENT_SHADER:
9761 shader_template = fragment_shader_template;
9762 break;
9763 case Utils::GEOMETRY_SHADER:
9764 shader_template = geometry_shader_template;
9765 break;
9766 case Utils::TESS_CTRL_SHADER:
9767 shader_template = tess_ctrl_shader_template;
9768 break;
9769 case Utils::TESS_EVAL_SHADER:
9770 shader_template = tess_eval_shader_template;
9771 break;
9772 case Utils::VERTEX_SHADER:
9773 shader_template = vertex_shader_template;
9774 break;
9775 default:
9776 TCU_FAIL("Invalid enum");
9777 }
9778
9779 out_source.m_parts[0].m_code = shader_template;
9780
9781 size_t position = 0;
9782 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9783 out_source.m_parts[0].m_code);
9784
9785 Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9786
9787 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9788
9789 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
9790 }
9791
getCaseString(TESTCASES test_case)9792 const GLchar *BindingUniformInvalidTest::getCaseString(TESTCASES test_case)
9793 {
9794 (void)test_case;
9795 const GLchar *binding = 0;
9796
9797 switch (m_case)
9798 {
9799 case NEGATIVE_VALUE:
9800 binding = "= -1";
9801 break;
9802 case VARIABLE_NAME:
9803 binding = "= goku";
9804 break;
9805 case STD140:
9806 binding = "= std140";
9807 break;
9808 case MISSING:
9809 binding = "";
9810 break;
9811 case TEST_CASES_MAX:
9812 binding = "= 0";
9813 break;
9814 default:
9815 TCU_FAIL("Invalid enum");
9816 }
9817
9818 return binding;
9819 }
9820
9821 /** Constructor
9822 *
9823 * @param context Test context
9824 **/
BindingSamplersTest(deqp::Context & context)9825 BindingSamplersTest::BindingSamplersTest(deqp::Context &context)
9826 : GLSLTestBase(context, "binding_samplers", "Test verifies smaplers binding")
9827 , m_goku_texture(context)
9828 , m_vegeta_texture(context)
9829 , m_trunks_texture(context)
9830 , m_buffer(context)
9831 , m_test_case(Utils::TEXTURE_TYPES_MAX)
9832 {
9833 /* Nothing to be done here */
9834 }
9835
9836 /** Set up next test case
9837 *
9838 * @param test_case_index Index of next test case
9839 *
9840 * @return false if there is no more test cases, true otherwise
9841 **/
prepareNextTestCase(glw::GLuint test_case_index)9842 bool BindingSamplersTest::prepareNextTestCase(glw::GLuint test_case_index)
9843 {
9844 switch (test_case_index)
9845 {
9846 case (glw::GLuint)-1:
9847 case 0:
9848 m_test_case = Utils::TEX_2D;
9849 break;
9850 case 1:
9851 m_test_case = Utils::TEX_BUFFER;
9852 break;
9853 case 2:
9854 m_test_case = Utils::TEX_2D_RECT;
9855 break;
9856 case 3:
9857 m_test_case = Utils::TEX_2D_ARRAY;
9858 break;
9859 case 4:
9860 m_test_case = Utils::TEX_3D;
9861 break;
9862 case 5:
9863 m_test_case = Utils::TEX_CUBE;
9864 break;
9865 case 6:
9866 m_test_case = Utils::TEX_1D;
9867 break;
9868 case 7:
9869 m_test_case = Utils::TEX_1D_ARRAY;
9870 break;
9871 default:
9872 return false;
9873 }
9874
9875 m_context.getTestContext().getLog() << tcu::TestLog::Message
9876 << "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
9877 << tcu::TestLog::EndMessage;
9878
9879 return true;
9880 }
9881
9882 /** Prepare source for given shader stage
9883 *
9884 * @param in_stage Shader stage, compute shader will use 430
9885 * @param in_use_version_400 Select if 400 or 420 should be used
9886 * @param out_source Prepared shader source instance
9887 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9888 void BindingSamplersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9889 Utils::shaderSource &out_source)
9890 {
9891 static const GLchar *uni_goku = "layout(binding = 0) uniform TYPE goku;\n";
9892
9893 static const GLchar *uni_vegeta = "layout(binding = 1) uniform TYPE vegeta;\n";
9894
9895 static const GLchar *uni_trunks = "layout(binding = 3) uniform TYPE trunks;\n\n";
9896
9897 static const GLchar *verification_snippet = " TEX_COORD_TYPE tex_coord = TEX_COORD_TYPE(COORDINATES);\n"
9898 " vec4 goku_color = SAMPLING_FUNCTION(goku, tex_coord);\n"
9899 " vec4 vegeta_color = SAMPLING_FUNCTION(vegeta, tex_coord);\n"
9900 " vec4 trunks_color = SAMPLING_FUNCTION(trunks, tex_coord);\n"
9901 "\n"
9902 " if ((vec4(1, 0, 0, 0) != goku_color) ||\n"
9903 " (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
9904 " (vec4(0, 0, 1, 0) != trunks_color) )\n"
9905 " {\n"
9906 " result = vec4(1, 0, 0, 1);\n"
9907 " }\n";
9908
9909 static const GLchar *compute_shader_template =
9910 "VERSION\n"
9911 "\n"
9912 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9913 "\n"
9914 "writeonly uniform image2D uni_image;\n"
9915 "\n"
9916 "UNI_GOKU\n"
9917 "UNI_VEGETA\n"
9918 "UNI_TRUNKS\n"
9919 "\n"
9920 "void main()\n"
9921 "{\n"
9922 " vec4 result = vec4(0, 1, 0, 1);\n"
9923 "\n"
9924 "VERIFICATION"
9925 "\n"
9926 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9927 "}\n"
9928 "\n";
9929
9930 static const GLchar *fragment_shader_template = "VERSION\n"
9931 "\n"
9932 "in vec4 gs_fs_result;\n"
9933 "out vec4 fs_out_result;\n"
9934 "\n"
9935 "UNI_GOKU\n"
9936 "UNI_VEGETA\n"
9937 "UNI_TRUNKS\n"
9938 "\n"
9939 "void main()\n"
9940 "{\n"
9941 " vec4 result = vec4(0, 1, 0, 1);\n"
9942 "\n"
9943 "VERIFICATION"
9944 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9945 " {\n"
9946 " result = vec4(1, 0, 0, 1);\n"
9947 " }\n"
9948 "\n"
9949 " fs_out_result = result;\n"
9950 "}\n"
9951 "\n";
9952
9953 static const GLchar *geometry_shader_template = "VERSION\n"
9954 "\n"
9955 "layout(points) in;\n"
9956 "layout(triangle_strip, max_vertices = 4) out;\n"
9957 "\n"
9958 "in vec4 tes_gs_result[];\n"
9959 "out vec4 gs_fs_result;\n"
9960 "\n"
9961 "UNI_TRUNKS\n"
9962 "UNI_GOKU\n"
9963 "UNI_VEGETA\n"
9964 "\n"
9965 "void main()\n"
9966 "{\n"
9967 " vec4 result = vec4(0, 1, 0, 1);\n"
9968 "\n"
9969 "VERIFICATION"
9970 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9971 " {\n"
9972 " result = vec4(1, 0, 0, 1);\n"
9973 " }\n"
9974 "\n"
9975 " gs_fs_result = result;\n"
9976 " gl_Position = vec4(-1, -1, 0, 1);\n"
9977 " EmitVertex();\n"
9978 " gs_fs_result = result;\n"
9979 " gl_Position = vec4(-1, 1, 0, 1);\n"
9980 " EmitVertex();\n"
9981 " gs_fs_result = result;\n"
9982 " gl_Position = vec4(1, -1, 0, 1);\n"
9983 " EmitVertex();\n"
9984 " gs_fs_result = result;\n"
9985 " gl_Position = vec4(1, 1, 0, 1);\n"
9986 " EmitVertex();\n"
9987 "}\n"
9988 "\n";
9989
9990 static const GLchar *tess_ctrl_shader_template =
9991 "VERSION\n"
9992 "\n"
9993 "layout(vertices = 1) out;\n"
9994 "\n"
9995 "in vec4 vs_tcs_result[];\n"
9996 "out vec4 tcs_tes_result[];\n"
9997 "\n"
9998 "UNI_VEGETA\n"
9999 "UNI_TRUNKS\n"
10000 "UNI_GOKU\n"
10001 "\n"
10002 "void main()\n"
10003 "{\n"
10004 " vec4 result = vec4(0, 1, 0, 1);\n"
10005 "\n"
10006 "VERIFICATION"
10007 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10008 " {\n"
10009 " result = vec4(1, 0, 0, 1);\n"
10010 " }\n"
10011 "\n"
10012 " tcs_tes_result[gl_InvocationID] = result;\n"
10013 "\n"
10014 " gl_TessLevelOuter[0] = 1.0;\n"
10015 " gl_TessLevelOuter[1] = 1.0;\n"
10016 " gl_TessLevelOuter[2] = 1.0;\n"
10017 " gl_TessLevelOuter[3] = 1.0;\n"
10018 " gl_TessLevelInner[0] = 1.0;\n"
10019 " gl_TessLevelInner[1] = 1.0;\n"
10020 "}\n"
10021 "\n";
10022
10023 static const GLchar *tess_eval_shader_template = "VERSION\n"
10024 "\n"
10025 "layout(isolines, point_mode) in;\n"
10026 "\n"
10027 "in vec4 tcs_tes_result[];\n"
10028 "out vec4 tes_gs_result;\n"
10029 "\n"
10030 "UNI_GOKU\n"
10031 "UNI_TRUNKS\n"
10032 "UNI_VEGETA\n"
10033 "\n"
10034 "void main()\n"
10035 "{\n"
10036 " vec4 result = vec4(0, 1, 0, 1);\n"
10037 "\n"
10038 "VERIFICATION"
10039 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10040 " {\n"
10041 " result = vec4(1, 0, 0, 1);\n"
10042 " }\n"
10043 "\n"
10044 " tes_gs_result = result;\n"
10045 "}\n"
10046 "\n";
10047
10048 static const GLchar *vertex_shader_template = "VERSION\n"
10049 "\n"
10050 "out vec4 vs_tcs_result;\n"
10051 "\n"
10052 "UNI_TRUNKS\n"
10053 "UNI_VEGETA\n"
10054 "UNI_GOKU\n"
10055 "\n"
10056 "void main()\n"
10057 "{\n"
10058 " vec4 result = vec4(0, 1, 0, 1);\n"
10059 "\n"
10060 "VERIFICATION"
10061 "\n"
10062 " vs_tcs_result = result;\n"
10063 "}\n"
10064 "\n";
10065
10066 const Utils::TYPES base_tex_coord_type = (Utils::TEX_BUFFER == m_test_case) ? Utils::INT : Utils::FLOAT;
10067 const GLchar *coordinates = 0;
10068 GLuint n_coordinates = Utils::getNumberOfCoordinates(m_test_case);
10069 const GLchar *shader_template = 0;
10070 const GLchar *sampler_type = Utils::getSamplerType(m_test_case);
10071 const GLchar *sampling_function = (Utils::TEX_BUFFER == m_test_case) ? "texelFetch" : "texture";
10072 const GLchar *tex_coord_type = Utils::getTypeName(base_tex_coord_type, 1 /* n_columns */, n_coordinates);
10073
10074 switch (in_stage)
10075 {
10076 case Utils::COMPUTE_SHADER:
10077 shader_template = compute_shader_template;
10078 break;
10079 case Utils::FRAGMENT_SHADER:
10080 shader_template = fragment_shader_template;
10081 break;
10082 case Utils::GEOMETRY_SHADER:
10083 shader_template = geometry_shader_template;
10084 break;
10085 case Utils::TESS_CTRL_SHADER:
10086 shader_template = tess_ctrl_shader_template;
10087 break;
10088 case Utils::TESS_EVAL_SHADER:
10089 shader_template = tess_eval_shader_template;
10090 break;
10091 case Utils::VERTEX_SHADER:
10092 shader_template = vertex_shader_template;
10093 break;
10094 default:
10095 TCU_FAIL("Invalid enum");
10096 }
10097
10098 switch (n_coordinates)
10099 {
10100 case 1:
10101 coordinates = "0";
10102 break;
10103 case 2:
10104 coordinates = "0, 0";
10105 break;
10106 case 3:
10107 coordinates = "0, 0, 0";
10108 break;
10109 case 4:
10110 coordinates = "0, 0, 0, 0";
10111 break;
10112 }
10113
10114 out_source.m_parts[0].m_code = shader_template;
10115
10116 size_t position = 0;
10117
10118 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10119 out_source.m_parts[0].m_code);
10120
10121 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10122
10123 position -= strlen(verification_snippet);
10124
10125 Utils::replaceToken("COORDINATES", position, coordinates, out_source.m_parts[0].m_code);
10126
10127 Utils::replaceAllTokens("SAMPLING_FUNCTION", sampling_function, out_source.m_parts[0].m_code);
10128
10129 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10130
10131 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
10132
10133 Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
10134
10135 Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
10136
10137 Utils::replaceAllTokens("TYPE", sampler_type, out_source.m_parts[0].m_code);
10138 }
10139
10140 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10141 *
10142 * @param program Current program
10143 **/
prepareUniforms(Utils::program & program)10144 void BindingSamplersTest::prepareUniforms(Utils::program &program)
10145 {
10146 (void)program;
10147 static const GLuint goku_data = 0x000000ff;
10148 static const GLuint vegeta_data = 0x0000ff00;
10149 static const GLuint trunks_data = 0x00ff0000;
10150
10151 prepareTexture(m_goku_texture, m_test_case, goku_data);
10152 prepareTexture(m_vegeta_texture, m_test_case, vegeta_data);
10153 prepareTexture(m_trunks_texture, m_test_case, trunks_data);
10154
10155 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10156
10157 gl.activeTexture(GL_TEXTURE0);
10158 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10159
10160 m_goku_texture.bind();
10161
10162 gl.activeTexture(GL_TEXTURE1);
10163 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10164
10165 m_vegeta_texture.bind();
10166
10167 gl.activeTexture(GL_TEXTURE3);
10168 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10169
10170 m_trunks_texture.bind();
10171 }
10172
10173 /** Overwrite of releaseResource method, release extra buffer and texture
10174 *
10175 * @param ignored
10176 **/
releaseResource()10177 void BindingSamplersTest::releaseResource()
10178 {
10179 m_goku_texture.release();
10180 m_vegeta_texture.release();
10181 m_trunks_texture.release();
10182 m_buffer.release();
10183 }
10184
10185 /** Prepare texture of given type filled with given color
10186 *
10187 * @param texture Texture
10188 * @param texture_type Type of texture
10189 * @param color Color
10190 **/
prepareTexture(Utils::texture & texture,Utils::TEXTURE_TYPES texture_type,glw::GLuint color)10191 void BindingSamplersTest::prepareTexture(Utils::texture &texture, Utils::TEXTURE_TYPES texture_type, glw::GLuint color)
10192 {
10193 (void)texture_type;
10194 static const GLuint width = 16;
10195 static const GLuint height = 16;
10196 static const GLuint depth = 1;
10197
10198 std::vector<GLuint> texture_data;
10199 texture_data.resize(width * height);
10200
10201 for (GLuint i = 0; i < texture_data.size(); ++i)
10202 {
10203 texture_data[i] = color;
10204 }
10205
10206 if (Utils::TEX_BUFFER != m_test_case)
10207 {
10208 texture.create(width, height, depth, GL_RGBA8, m_test_case);
10209
10210 texture.update(width, height, depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10211 }
10212 else
10213 {
10214 m_buffer.generate(GL_TEXTURE_BUFFER);
10215 m_buffer.update(texture_data.size(), &texture_data[0], GL_STATIC_DRAW);
10216
10217 texture.createBuffer(GL_RGBA8, m_buffer.m_id);
10218 }
10219 }
10220
10221 /** Constructor
10222 *
10223 * @param context Test context
10224 **/
BindingSamplerSingleTest(deqp::Context & context)10225 BindingSamplerSingleTest::BindingSamplerSingleTest(deqp::Context &context)
10226 : GLSLTestBase(context, "binding_sampler_single", "Test verifies sampler binding")
10227 , m_goku_texture(context)
10228 {
10229 /* Nothing to be done here */
10230 }
10231
10232 /** Set up next test case
10233 *
10234 * @param test_case_index Index of next test case
10235 *
10236 * @return false if there is no more test cases, true otherwise
10237 **/
prepareNextTestCase(glw::GLuint test_case_index)10238 bool BindingSamplerSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
10239 {
10240 switch (test_case_index)
10241 {
10242 case (glw::GLuint)-1:
10243 case 0:
10244 m_test_stage = Utils::VERTEX_SHADER;
10245 break;
10246 case 1:
10247 m_test_stage = Utils::TESS_CTRL_SHADER;
10248 break;
10249 case 2:
10250 m_test_stage = Utils::TESS_EVAL_SHADER;
10251 break;
10252 case 3:
10253 m_test_stage = Utils::GEOMETRY_SHADER;
10254 break;
10255 case 4:
10256 m_test_stage = Utils::FRAGMENT_SHADER;
10257 break;
10258 default:
10259 return false;
10260 }
10261
10262 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
10263 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
10264 << tcu::TestLog::EndMessage;
10265
10266 return true;
10267 }
10268
10269 /** Prepare source for given shader stage
10270 *
10271 * @param in_stage Shader stage, compute shader will use 430
10272 * @param in_use_version_400 Select if 400 or 420 should be used
10273 * @param out_source Prepared shader source instance
10274 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10275 void BindingSamplerSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10276 Utils::shaderSource &out_source)
10277 {
10278 static const GLchar *uni_goku_with_binding = "layout(binding = 2) uniform sampler2D goku;\n";
10279
10280 static const GLchar *uni_goku_no_binding = "uniform sampler2D goku;\n";
10281
10282 static const GLchar *verification_snippet = " vec4 goku_color = texture(goku, vec2(0,0));\n"
10283 "\n"
10284 " if (vec4(1, 0, 0, 0) != goku_color)\n"
10285 " {\n"
10286 " result = vec4(1, 0, 0, 1);\n"
10287 " }\n";
10288
10289 static const GLchar *compute_shader_template =
10290 "VERSION\n"
10291 "\n"
10292 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10293 "\n"
10294 "writeonly uniform image2D uni_image;\n"
10295 "\n"
10296 "UNI_GOKU\n"
10297 "\n"
10298 "void main()\n"
10299 "{\n"
10300 " vec4 result = vec4(0, 1, 0, 1);\n"
10301 "\n"
10302 "VERIFICATION"
10303 "\n"
10304 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10305 "}\n"
10306 "\n";
10307
10308 static const GLchar *fragment_shader_template = "VERSION\n"
10309 "\n"
10310 "in vec4 gs_fs_result;\n"
10311 "out vec4 fs_out_result;\n"
10312 "\n"
10313 "UNI_GOKU\n"
10314 "\n"
10315 "void main()\n"
10316 "{\n"
10317 " vec4 result = vec4(0, 1, 0, 1);\n"
10318 "\n"
10319 "VERIFICATION"
10320 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10321 " {\n"
10322 " result = vec4(1, 0, 0, 1);\n"
10323 " }\n"
10324 "\n"
10325 " fs_out_result = result;\n"
10326 "}\n"
10327 "\n";
10328
10329 static const GLchar *geometry_shader_template = "VERSION\n"
10330 "\n"
10331 "layout(points) in;\n"
10332 "layout(triangle_strip, max_vertices = 4) out;\n"
10333 "\n"
10334 "in vec4 tes_gs_result[];\n"
10335 "out vec4 gs_fs_result;\n"
10336 "\n"
10337 "UNI_GOKU\n"
10338 "\n"
10339 "void main()\n"
10340 "{\n"
10341 " vec4 result = vec4(0, 1, 0, 1);\n"
10342 "\n"
10343 "VERIFICATION"
10344 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10345 " {\n"
10346 " result = vec4(1, 0, 0, 1);\n"
10347 " }\n"
10348 "\n"
10349 " gs_fs_result = result;\n"
10350 " gl_Position = vec4(-1, -1, 0, 1);\n"
10351 " EmitVertex();\n"
10352 " gs_fs_result = result;\n"
10353 " gl_Position = vec4(-1, 1, 0, 1);\n"
10354 " EmitVertex();\n"
10355 " gs_fs_result = result;\n"
10356 " gl_Position = vec4(1, -1, 0, 1);\n"
10357 " EmitVertex();\n"
10358 " gs_fs_result = result;\n"
10359 " gl_Position = vec4(1, 1, 0, 1);\n"
10360 " EmitVertex();\n"
10361 "}\n"
10362 "\n";
10363
10364 static const GLchar *tess_ctrl_shader_template =
10365 "VERSION\n"
10366 "\n"
10367 "layout(vertices = 1) out;\n"
10368 "\n"
10369 "in vec4 vs_tcs_result[];\n"
10370 "out vec4 tcs_tes_result[];\n"
10371 "\n"
10372 "UNI_GOKU\n"
10373 "\n"
10374 "void main()\n"
10375 "{\n"
10376 " vec4 result = vec4(0, 1, 0, 1);\n"
10377 "\n"
10378 "VERIFICATION"
10379 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10380 " {\n"
10381 " result = vec4(1, 0, 0, 1);\n"
10382 " }\n"
10383 "\n"
10384 " tcs_tes_result[gl_InvocationID] = result;\n"
10385 "\n"
10386 " gl_TessLevelOuter[0] = 1.0;\n"
10387 " gl_TessLevelOuter[1] = 1.0;\n"
10388 " gl_TessLevelOuter[2] = 1.0;\n"
10389 " gl_TessLevelOuter[3] = 1.0;\n"
10390 " gl_TessLevelInner[0] = 1.0;\n"
10391 " gl_TessLevelInner[1] = 1.0;\n"
10392 "}\n"
10393 "\n";
10394
10395 static const GLchar *tess_eval_shader_template = "VERSION\n"
10396 "\n"
10397 "layout(isolines, point_mode) in;\n"
10398 "\n"
10399 "in vec4 tcs_tes_result[];\n"
10400 "out vec4 tes_gs_result;\n"
10401 "\n"
10402 "UNI_GOKU\n"
10403 "\n"
10404 "void main()\n"
10405 "{\n"
10406 " vec4 result = vec4(0, 1, 0, 1);\n"
10407 "\n"
10408 "VERIFICATION"
10409 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10410 " {\n"
10411 " result = vec4(1, 0, 0, 1);\n"
10412 " }\n"
10413 "\n"
10414 " tes_gs_result = result;\n"
10415 "}\n"
10416 "\n";
10417
10418 static const GLchar *vertex_shader_template = "VERSION\n"
10419 "\n"
10420 "out vec4 vs_tcs_result;\n"
10421 "\n"
10422 "UNI_GOKU\n"
10423 "\n"
10424 "void main()\n"
10425 "{\n"
10426 " vec4 result = vec4(0, 1, 0, 1);\n"
10427 "\n"
10428 "VERIFICATION"
10429 "\n"
10430 " vs_tcs_result = result;\n"
10431 "}\n"
10432 "\n";
10433
10434 const GLchar *shader_template = 0;
10435 const GLchar *uniform_definition = uni_goku_no_binding;
10436
10437 switch (in_stage)
10438 {
10439 case Utils::COMPUTE_SHADER:
10440 shader_template = compute_shader_template;
10441 uniform_definition = uni_goku_with_binding;
10442 break;
10443 case Utils::FRAGMENT_SHADER:
10444 shader_template = fragment_shader_template;
10445 break;
10446 case Utils::GEOMETRY_SHADER:
10447 shader_template = geometry_shader_template;
10448 break;
10449 case Utils::TESS_CTRL_SHADER:
10450 shader_template = tess_ctrl_shader_template;
10451 break;
10452 case Utils::TESS_EVAL_SHADER:
10453 shader_template = tess_eval_shader_template;
10454 break;
10455 case Utils::VERTEX_SHADER:
10456 shader_template = vertex_shader_template;
10457 break;
10458 default:
10459 TCU_FAIL("Invalid enum");
10460 }
10461
10462 if (in_stage == m_test_stage)
10463 {
10464 uniform_definition = uni_goku_with_binding;
10465 }
10466
10467 out_source.m_parts[0].m_code = shader_template;
10468
10469 size_t position = 0;
10470
10471 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10472 out_source.m_parts[0].m_code);
10473
10474 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10475
10476 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
10477 }
10478
10479 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10480 *
10481 * @param program Current program
10482 **/
prepareUniforms(Utils::program & program)10483 void BindingSamplerSingleTest::prepareUniforms(Utils::program &program)
10484 {
10485 (void)program;
10486 static const GLuint goku_data = 0x000000ff;
10487
10488 m_goku_texture.create(16, 16, GL_RGBA8);
10489
10490 std::vector<GLuint> texture_data;
10491 texture_data.resize(16 * 16);
10492
10493 for (GLuint i = 0; i < texture_data.size(); ++i)
10494 {
10495 texture_data[i] = goku_data;
10496 }
10497
10498 m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10499
10500 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10501
10502 gl.activeTexture(GL_TEXTURE2);
10503 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10504
10505 m_goku_texture.bind();
10506 }
10507
10508 /** Overwrite of releaseResource method, release extra texture
10509 *
10510 * @param ignored
10511 **/
releaseResource()10512 void BindingSamplerSingleTest::releaseResource()
10513 {
10514 m_goku_texture.release();
10515 }
10516
10517 /** Constructor
10518 *
10519 * @param context Test context
10520 **/
BindingSamplerArrayTest(deqp::Context & context)10521 BindingSamplerArrayTest::BindingSamplerArrayTest(deqp::Context &context)
10522 : GLSLTestBase(context, "binding_sampler_array", "Test verifies binding of sampler arrays")
10523 , m_goku_00_texture(context)
10524 , m_goku_01_texture(context)
10525 , m_goku_02_texture(context)
10526 , m_goku_03_texture(context)
10527 , m_goku_04_texture(context)
10528 , m_goku_05_texture(context)
10529 , m_goku_06_texture(context)
10530 {
10531 /* Nothing to be done here */
10532 }
10533
10534 /** Prepare source for given shader stage
10535 *
10536 * @param in_stage Shader stage, compute shader will use 430
10537 * @param in_use_version_400 Select if 400 or 420 should be used
10538 * @param out_source Prepared shader source instance
10539 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10540 void BindingSamplerArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10541 Utils::shaderSource &out_source)
10542 {
10543 static const GLchar *uni_goku = "layout(binding = 1) uniform sampler2D goku[7];\n";
10544
10545 static const GLchar *verification_snippet = " vec4 color[7];\n"
10546 "\n"
10547 " for (uint i = 0u; i < 7; ++i)\n"
10548 " {\n"
10549 " color[i] = texture(goku[i], vec2(0, 0));\n"
10550 " }\n"
10551 "\n"
10552 " if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
10553 " (vec4(0, 0, 0, 1) != color[1]) ||\n"
10554 " (vec4(0, 0, 1, 0) != color[2]) ||\n"
10555 " (vec4(0, 0, 1, 1) != color[3]) ||\n"
10556 " (vec4(0, 1, 0, 0) != color[4]) ||\n"
10557 " (vec4(0, 1, 0, 1) != color[5]) ||\n"
10558 " (vec4(0, 1, 1, 0) != color[6]) )\n"
10559 " {\n"
10560 " result = vec4(1, 0, 0, 1);\n"
10561 " }\n";
10562
10563 static const GLchar *compute_shader_template =
10564 "VERSION\n"
10565 "\n"
10566 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10567 "\n"
10568 "writeonly uniform image2D uni_image;\n"
10569 "\n"
10570 "UNI_GOKU\n"
10571 "\n"
10572 "void main()\n"
10573 "{\n"
10574 " vec4 result = vec4(0, 1, 0, 1);\n"
10575 "\n"
10576 "VERIFICATION"
10577 "\n"
10578 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10579 "}\n"
10580 "\n";
10581
10582 static const GLchar *fragment_shader_template = "VERSION\n"
10583 "\n"
10584 "in vec4 gs_fs_result;\n"
10585 "out vec4 fs_out_result;\n"
10586 "\n"
10587 "UNI_GOKU\n"
10588 "\n"
10589 "void main()\n"
10590 "{\n"
10591 " vec4 result = vec4(0, 1, 0, 1);\n"
10592 "\n"
10593 "VERIFICATION"
10594 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10595 " {\n"
10596 " result = vec4(1, 0, 0, 1);\n"
10597 " }\n"
10598 "\n"
10599 " fs_out_result = result;\n"
10600 "}\n"
10601 "\n";
10602
10603 static const GLchar *geometry_shader_template = "VERSION\n"
10604 "\n"
10605 "layout(points) in;\n"
10606 "layout(triangle_strip, max_vertices = 4) out;\n"
10607 "\n"
10608 "in vec4 tes_gs_result[];\n"
10609 "out vec4 gs_fs_result;\n"
10610 "\n"
10611 "UNI_GOKU\n"
10612 "\n"
10613 "void main()\n"
10614 "{\n"
10615 " vec4 result = vec4(0, 1, 0, 1);\n"
10616 "\n"
10617 "VERIFICATION"
10618 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10619 " {\n"
10620 " result = vec4(1, 0, 0, 1);\n"
10621 " }\n"
10622 "\n"
10623 " gs_fs_result = result;\n"
10624 " gl_Position = vec4(-1, -1, 0, 1);\n"
10625 " EmitVertex();\n"
10626 " gs_fs_result = result;\n"
10627 " gl_Position = vec4(-1, 1, 0, 1);\n"
10628 " EmitVertex();\n"
10629 " gs_fs_result = result;\n"
10630 " gl_Position = vec4(1, -1, 0, 1);\n"
10631 " EmitVertex();\n"
10632 " gs_fs_result = result;\n"
10633 " gl_Position = vec4(1, 1, 0, 1);\n"
10634 " EmitVertex();\n"
10635 "}\n"
10636 "\n";
10637
10638 static const GLchar *tess_ctrl_shader_template =
10639 "VERSION\n"
10640 "\n"
10641 "layout(vertices = 1) out;\n"
10642 "\n"
10643 "in vec4 vs_tcs_result[];\n"
10644 "out vec4 tcs_tes_result[];\n"
10645 "\n"
10646 "UNI_GOKU\n"
10647 "\n"
10648 "void main()\n"
10649 "{\n"
10650 " vec4 result = vec4(0, 1, 0, 1);\n"
10651 "\n"
10652 "VERIFICATION"
10653 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10654 " {\n"
10655 " result = vec4(1, 0, 0, 1);\n"
10656 " }\n"
10657 "\n"
10658 " tcs_tes_result[gl_InvocationID] = result;\n"
10659 "\n"
10660 " gl_TessLevelOuter[0] = 1.0;\n"
10661 " gl_TessLevelOuter[1] = 1.0;\n"
10662 " gl_TessLevelOuter[2] = 1.0;\n"
10663 " gl_TessLevelOuter[3] = 1.0;\n"
10664 " gl_TessLevelInner[0] = 1.0;\n"
10665 " gl_TessLevelInner[1] = 1.0;\n"
10666 "}\n"
10667 "\n";
10668
10669 static const GLchar *tess_eval_shader_template = "VERSION\n"
10670 "\n"
10671 "layout(isolines, point_mode) in;\n"
10672 "\n"
10673 "in vec4 tcs_tes_result[];\n"
10674 "out vec4 tes_gs_result;\n"
10675 "\n"
10676 "UNI_GOKU\n"
10677 "\n"
10678 "void main()\n"
10679 "{\n"
10680 " vec4 result = vec4(0, 1, 0, 1);\n"
10681 "\n"
10682 "VERIFICATION"
10683 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10684 " {\n"
10685 " result = vec4(1, 0, 0, 1);\n"
10686 " }\n"
10687 "\n"
10688 " tes_gs_result = result;\n"
10689 "}\n"
10690 "\n";
10691
10692 static const GLchar *vertex_shader_template = "VERSION\n"
10693 "\n"
10694 "out vec4 vs_tcs_result;\n"
10695 "\n"
10696 "UNI_GOKU\n"
10697 "\n"
10698 "void main()\n"
10699 "{\n"
10700 " vec4 result = vec4(0, 1, 0, 1);\n"
10701 "\n"
10702 "VERIFICATION"
10703 "\n"
10704 " vs_tcs_result = result;\n"
10705 "}\n"
10706 "\n";
10707
10708 const GLchar *shader_template = 0;
10709
10710 switch (in_stage)
10711 {
10712 case Utils::COMPUTE_SHADER:
10713 shader_template = compute_shader_template;
10714 break;
10715 case Utils::FRAGMENT_SHADER:
10716 shader_template = fragment_shader_template;
10717 break;
10718 case Utils::GEOMETRY_SHADER:
10719 shader_template = geometry_shader_template;
10720 break;
10721 case Utils::TESS_CTRL_SHADER:
10722 shader_template = tess_ctrl_shader_template;
10723 break;
10724 case Utils::TESS_EVAL_SHADER:
10725 shader_template = tess_eval_shader_template;
10726 break;
10727 case Utils::VERTEX_SHADER:
10728 shader_template = vertex_shader_template;
10729 break;
10730 default:
10731 TCU_FAIL("Invalid enum");
10732 }
10733
10734 out_source.m_parts[0].m_code = shader_template;
10735
10736 size_t position = 0;
10737
10738 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10739 out_source.m_parts[0].m_code);
10740
10741 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10742
10743 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10744 }
10745
10746 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10747 *
10748 * @param program Current program
10749 **/
prepareUniforms(Utils::program & program)10750 void BindingSamplerArrayTest::prepareUniforms(Utils::program &program)
10751 {
10752 static const GLuint goku_data[7] = {
10753 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
10754 };
10755
10756 static const GLuint binding_offset = 1;
10757
10758 Utils::texture *textures[7] = {
10759 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10760 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10761 };
10762
10763 std::vector<GLuint> texture_data;
10764 texture_data.resize(16 * 16);
10765
10766 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
10767
10768 for (GLuint i = 0; i < 7; ++i)
10769 {
10770 GLint expected_binding = i + binding_offset;
10771
10772 checkBinding(program, i, expected_binding);
10773
10774 gl.activeTexture(GL_TEXTURE0 + expected_binding);
10775 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10776
10777 textures[i]->create(16, 16, GL_RGBA8);
10778
10779 for (GLuint j = 0; j < texture_data.size(); ++j)
10780 {
10781 texture_data[j] = goku_data[i];
10782 }
10783
10784 textures[i]->update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10785 }
10786 }
10787
10788 /** Overwrite of releaseResource method, release extra textures
10789 *
10790 * @param ignored
10791 **/
releaseResource()10792 void BindingSamplerArrayTest::releaseResource()
10793 {
10794 Utils::texture *textures[7] = {
10795 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10796 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10797 };
10798
10799 for (GLuint i = 0; i < 7; ++i)
10800 {
10801 textures[i]->release();
10802 }
10803 }
10804
10805 /** Verifies that API reports correct uniform binding
10806 *
10807 * @param program Program
10808 * @param index Index of array element
10809 * @param expected_binding Expected binding
10810 **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)10811 void BindingSamplerArrayTest::checkBinding(Utils::program &program, GLuint index, GLint expected_binding)
10812 {
10813 if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
10814 {
10815 TCU_FAIL("Wrong binding reported by API");
10816 }
10817 }
10818
10819 /** Constructor
10820 *
10821 * @param context Test context
10822 **/
BindingSamplerDefaultTest(deqp::Context & context)10823 BindingSamplerDefaultTest::BindingSamplerDefaultTest(deqp::Context &context)
10824 : APITestBase(context, "binding_sampler_default", "Test verifies default sampler binding")
10825 {
10826 /* Nothing to be done here */
10827 }
10828
10829 /** Execute API call and verifies results
10830 *
10831 * @return true when results are positive, false otherwise
10832 **/
checkResults(Utils::program & program)10833 bool BindingSamplerDefaultTest::checkResults(Utils::program &program)
10834 {
10835 return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
10836 }
10837
10838 /** Prepare source for given shader stage
10839 *
10840 * @param in_stage Shader stage, compute shader will use 430
10841 * @param in_use_version_400 Select if 400 or 420 should be used
10842 * @param out_source Prepared shader source instance
10843 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10844 void BindingSamplerDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10845 Utils::shaderSource &out_source)
10846 {
10847 static const GLchar *uni_goku = "uniform sampler2D goku;\n";
10848
10849 static const GLchar *verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
10850 " if (vec4(1, 0, 0, 0) != color)\n"
10851 " {\n"
10852 " result = vec4(1, 0, 0, 1);\n"
10853 " }\n";
10854
10855 static const GLchar *compute_shader_template =
10856 "VERSION\n"
10857 "\n"
10858 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10859 "\n"
10860 "writeonly uniform image2D uni_image;\n"
10861 "\n"
10862 "UNI_GOKU\n"
10863 "\n"
10864 "void main()\n"
10865 "{\n"
10866 " vec4 result = vec4(0, 1, 0, 1);\n"
10867 "\n"
10868 "VERIFICATION"
10869 "\n"
10870 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10871 "}\n"
10872 "\n";
10873
10874 static const GLchar *fragment_shader_template = "VERSION\n"
10875 "\n"
10876 "in vec4 gs_fs_result;\n"
10877 "out vec4 fs_out_result;\n"
10878 "\n"
10879 "UNI_GOKU\n"
10880 "\n"
10881 "void main()\n"
10882 "{\n"
10883 " vec4 result = vec4(0, 1, 0, 1);\n"
10884 "\n"
10885 "VERIFICATION"
10886 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10887 " {\n"
10888 " result = vec4(1, 0, 0, 1);\n"
10889 " }\n"
10890 "\n"
10891 " fs_out_result = result;\n"
10892 "}\n"
10893 "\n";
10894
10895 static const GLchar *geometry_shader_template = "VERSION\n"
10896 "\n"
10897 "layout(points) in;\n"
10898 "layout(triangle_strip, max_vertices = 4) out;\n"
10899 "\n"
10900 "in vec4 tes_gs_result[];\n"
10901 "out vec4 gs_fs_result;\n"
10902 "\n"
10903 "UNI_GOKU\n"
10904 "\n"
10905 "void main()\n"
10906 "{\n"
10907 " vec4 result = vec4(0, 1, 0, 1);\n"
10908 "\n"
10909 "VERIFICATION"
10910 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10911 " {\n"
10912 " result = vec4(1, 0, 0, 1);\n"
10913 " }\n"
10914 "\n"
10915 " gs_fs_result = result;\n"
10916 " gl_Position = vec4(-1, -1, 0, 1);\n"
10917 " EmitVertex();\n"
10918 " gs_fs_result = result;\n"
10919 " gl_Position = vec4(-1, 1, 0, 1);\n"
10920 " EmitVertex();\n"
10921 " gs_fs_result = result;\n"
10922 " gl_Position = vec4(1, -1, 0, 1);\n"
10923 " EmitVertex();\n"
10924 " gs_fs_result = result;\n"
10925 " gl_Position = vec4(1, 1, 0, 1);\n"
10926 " EmitVertex();\n"
10927 "}\n"
10928 "\n";
10929
10930 static const GLchar *tess_ctrl_shader_template =
10931 "VERSION\n"
10932 "\n"
10933 "layout(vertices = 1) out;\n"
10934 "\n"
10935 "in vec4 vs_tcs_result[];\n"
10936 "out vec4 tcs_tes_result[];\n"
10937 "\n"
10938 "UNI_GOKU\n"
10939 "\n"
10940 "void main()\n"
10941 "{\n"
10942 " vec4 result = vec4(0, 1, 0, 1);\n"
10943 "\n"
10944 "VERIFICATION"
10945 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10946 " {\n"
10947 " result = vec4(1, 0, 0, 1);\n"
10948 " }\n"
10949 "\n"
10950 " tcs_tes_result[gl_InvocationID] = result;\n"
10951 "\n"
10952 " gl_TessLevelOuter[0] = 1.0;\n"
10953 " gl_TessLevelOuter[1] = 1.0;\n"
10954 " gl_TessLevelOuter[2] = 1.0;\n"
10955 " gl_TessLevelOuter[3] = 1.0;\n"
10956 " gl_TessLevelInner[0] = 1.0;\n"
10957 " gl_TessLevelInner[1] = 1.0;\n"
10958 "}\n"
10959 "\n";
10960
10961 static const GLchar *tess_eval_shader_template = "VERSION\n"
10962 "\n"
10963 "layout(isolines, point_mode) in;\n"
10964 "\n"
10965 "in vec4 tcs_tes_result[];\n"
10966 "out vec4 tes_gs_result;\n"
10967 "\n"
10968 "UNI_GOKU\n"
10969 "\n"
10970 "void main()\n"
10971 "{\n"
10972 " vec4 result = vec4(0, 1, 0, 1);\n"
10973 "\n"
10974 "VERIFICATION"
10975 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10976 " {\n"
10977 " result = vec4(1, 0, 0, 1);\n"
10978 " }\n"
10979 "\n"
10980 " tes_gs_result = result;\n"
10981 "}\n"
10982 "\n";
10983
10984 static const GLchar *vertex_shader_template = "VERSION\n"
10985 "\n"
10986 "out vec4 vs_tcs_result;\n"
10987 "\n"
10988 "UNI_GOKU\n"
10989 "\n"
10990 "void main()\n"
10991 "{\n"
10992 " vec4 result = vec4(0, 1, 0, 1);\n"
10993 "\n"
10994 "VERIFICATION"
10995 "\n"
10996 " vs_tcs_result = result;\n"
10997 "}\n"
10998 "\n";
10999
11000 const GLchar *shader_template = 0;
11001
11002 switch (in_stage)
11003 {
11004 case Utils::COMPUTE_SHADER:
11005 shader_template = compute_shader_template;
11006 break;
11007 case Utils::FRAGMENT_SHADER:
11008 shader_template = fragment_shader_template;
11009 break;
11010 case Utils::GEOMETRY_SHADER:
11011 shader_template = geometry_shader_template;
11012 break;
11013 case Utils::TESS_CTRL_SHADER:
11014 shader_template = tess_ctrl_shader_template;
11015 break;
11016 case Utils::TESS_EVAL_SHADER:
11017 shader_template = tess_eval_shader_template;
11018 break;
11019 case Utils::VERTEX_SHADER:
11020 shader_template = vertex_shader_template;
11021 break;
11022 default:
11023 TCU_FAIL("Invalid enum");
11024 }
11025
11026 out_source.m_parts[0].m_code = shader_template;
11027
11028 size_t position = 0;
11029
11030 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11031 out_source.m_parts[0].m_code);
11032
11033 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11034
11035 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11036 }
11037
11038 /** Constructor
11039 *
11040 * @param context Test context
11041 **/
BindingSamplerAPIOverrideTest(deqp::Context & context)11042 BindingSamplerAPIOverrideTest::BindingSamplerAPIOverrideTest(deqp::Context &context)
11043 : GLSLTestBase(context, "binding_sampler_api_override", "Verifies that API can override sampler binding")
11044 , m_goku_texture(context)
11045 {
11046 /* Nothing to be done here */
11047 }
11048
11049 /** Prepare source for given shader stage
11050 *
11051 * @param in_stage Shader stage, compute shader will use 430
11052 * @param in_use_version_400 Select if 400 or 420 should be used
11053 * @param out_source Prepared shader source instance
11054 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11055 void BindingSamplerAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11056 Utils::shaderSource &out_source)
11057 {
11058 static const GLchar *uni_goku = "layout(binding = 2) uniform sampler2D goku;\n";
11059
11060 static const GLchar *verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
11061 " if (vec4(1, 0, 0, 0) != color)\n"
11062 " {\n"
11063 " result = vec4(1, 0, 0, 1);\n"
11064 " }\n";
11065
11066 static const GLchar *compute_shader_template =
11067 "VERSION\n"
11068 "\n"
11069 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11070 "\n"
11071 "writeonly uniform image2D uni_image;\n"
11072 "\n"
11073 "UNI_GOKU\n"
11074 "\n"
11075 "void main()\n"
11076 "{\n"
11077 " vec4 result = vec4(0, 1, 0, 1);\n"
11078 "\n"
11079 "VERIFICATION"
11080 "\n"
11081 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11082 "}\n"
11083 "\n";
11084
11085 static const GLchar *fragment_shader_template = "VERSION\n"
11086 "\n"
11087 "in vec4 gs_fs_result;\n"
11088 "out vec4 fs_out_result;\n"
11089 "\n"
11090 "UNI_GOKU\n"
11091 "\n"
11092 "void main()\n"
11093 "{\n"
11094 " vec4 result = vec4(0, 1, 0, 1);\n"
11095 "\n"
11096 "VERIFICATION"
11097 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11098 " {\n"
11099 " result = vec4(1, 0, 0, 1);\n"
11100 " }\n"
11101 "\n"
11102 " fs_out_result = result;\n"
11103 "}\n"
11104 "\n";
11105
11106 static const GLchar *geometry_shader_template = "VERSION\n"
11107 "\n"
11108 "layout(points) in;\n"
11109 "layout(triangle_strip, max_vertices = 4) out;\n"
11110 "\n"
11111 "in vec4 tes_gs_result[];\n"
11112 "out vec4 gs_fs_result;\n"
11113 "\n"
11114 "UNI_GOKU\n"
11115 "\n"
11116 "void main()\n"
11117 "{\n"
11118 " vec4 result = vec4(0, 1, 0, 1);\n"
11119 "\n"
11120 "VERIFICATION"
11121 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11122 " {\n"
11123 " result = vec4(1, 0, 0, 1);\n"
11124 " }\n"
11125 "\n"
11126 " gs_fs_result = result;\n"
11127 " gl_Position = vec4(-1, -1, 0, 1);\n"
11128 " EmitVertex();\n"
11129 " gs_fs_result = result;\n"
11130 " gl_Position = vec4(-1, 1, 0, 1);\n"
11131 " EmitVertex();\n"
11132 " gs_fs_result = result;\n"
11133 " gl_Position = vec4(1, -1, 0, 1);\n"
11134 " EmitVertex();\n"
11135 " gs_fs_result = result;\n"
11136 " gl_Position = vec4(1, 1, 0, 1);\n"
11137 " EmitVertex();\n"
11138 "}\n"
11139 "\n";
11140
11141 static const GLchar *tess_ctrl_shader_template =
11142 "VERSION\n"
11143 "\n"
11144 "layout(vertices = 1) out;\n"
11145 "\n"
11146 "in vec4 vs_tcs_result[];\n"
11147 "out vec4 tcs_tes_result[];\n"
11148 "\n"
11149 "UNI_GOKU\n"
11150 "\n"
11151 "void main()\n"
11152 "{\n"
11153 " vec4 result = vec4(0, 1, 0, 1);\n"
11154 "\n"
11155 "VERIFICATION"
11156 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11157 " {\n"
11158 " result = vec4(1, 0, 0, 1);\n"
11159 " }\n"
11160 "\n"
11161 " tcs_tes_result[gl_InvocationID] = result;\n"
11162 "\n"
11163 " gl_TessLevelOuter[0] = 1.0;\n"
11164 " gl_TessLevelOuter[1] = 1.0;\n"
11165 " gl_TessLevelOuter[2] = 1.0;\n"
11166 " gl_TessLevelOuter[3] = 1.0;\n"
11167 " gl_TessLevelInner[0] = 1.0;\n"
11168 " gl_TessLevelInner[1] = 1.0;\n"
11169 "}\n"
11170 "\n";
11171
11172 static const GLchar *tess_eval_shader_template = "VERSION\n"
11173 "\n"
11174 "layout(isolines, point_mode) in;\n"
11175 "\n"
11176 "in vec4 tcs_tes_result[];\n"
11177 "out vec4 tes_gs_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) != tcs_tes_result[0])\n"
11187 " {\n"
11188 " result = vec4(1, 0, 0, 1);\n"
11189 " }\n"
11190 "\n"
11191 " tes_gs_result = result;\n"
11192 "}\n"
11193 "\n";
11194
11195 static const GLchar *vertex_shader_template = "VERSION\n"
11196 "\n"
11197 "out vec4 vs_tcs_result;\n"
11198 "\n"
11199 "UNI_GOKU\n"
11200 "\n"
11201 "void main()\n"
11202 "{\n"
11203 " vec4 result = vec4(0, 1, 0, 1);\n"
11204 "\n"
11205 "VERIFICATION"
11206 "\n"
11207 " vs_tcs_result = result;\n"
11208 "}\n"
11209 "\n";
11210
11211 const GLchar *shader_template = 0;
11212
11213 switch (in_stage)
11214 {
11215 case Utils::COMPUTE_SHADER:
11216 shader_template = compute_shader_template;
11217 break;
11218 case Utils::FRAGMENT_SHADER:
11219 shader_template = fragment_shader_template;
11220 break;
11221 case Utils::GEOMETRY_SHADER:
11222 shader_template = geometry_shader_template;
11223 break;
11224 case Utils::TESS_CTRL_SHADER:
11225 shader_template = tess_ctrl_shader_template;
11226 break;
11227 case Utils::TESS_EVAL_SHADER:
11228 shader_template = tess_eval_shader_template;
11229 break;
11230 case Utils::VERTEX_SHADER:
11231 shader_template = vertex_shader_template;
11232 break;
11233 default:
11234 TCU_FAIL("Invalid enum");
11235 }
11236
11237 out_source.m_parts[0].m_code = shader_template;
11238
11239 size_t position = 0;
11240
11241 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11242 out_source.m_parts[0].m_code);
11243
11244 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11245
11246 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11247 }
11248
11249 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11250 *
11251 * @param program Current program
11252 **/
prepareUniforms(Utils::program & program)11253 void BindingSamplerAPIOverrideTest::prepareUniforms(Utils::program &program)
11254 {
11255 static const GLuint goku_data = 0x000000ff;
11256 static const GLint new_binding = 11;
11257
11258 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
11259
11260 const GLint uniform_location = program.getUniformLocation("goku");
11261 if (-1 == uniform_location)
11262 {
11263 TCU_FAIL("Uniform is inactive");
11264 }
11265
11266 gl.uniform1i(uniform_location, new_binding);
11267
11268 GLint binding = -1;
11269
11270 gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
11271 GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
11272
11273 if (new_binding != binding)
11274 {
11275 TCU_FAIL("Wrong binding value");
11276 return;
11277 }
11278
11279 m_goku_texture.create(16, 16, GL_RGBA8);
11280
11281 std::vector<GLuint> texture_data;
11282 texture_data.resize(16 * 16);
11283
11284 for (GLuint i = 0; i < texture_data.size(); ++i)
11285 {
11286 texture_data[i] = goku_data;
11287 }
11288
11289 m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
11290
11291 gl.activeTexture(GL_TEXTURE11);
11292 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
11293
11294 m_goku_texture.bind();
11295 }
11296
11297 /** Overwrite of releaseResource method, release extra texture
11298 *
11299 * @param ignored
11300 **/
releaseResource()11301 void BindingSamplerAPIOverrideTest::releaseResource()
11302 {
11303 m_goku_texture.release();
11304 }
11305
11306 /** Constructor
11307 *
11308 * @param context Test context
11309 **/
BindingSamplerInvalidTest(deqp::Context & context)11310 BindingSamplerInvalidTest::BindingSamplerInvalidTest(deqp::Context &context)
11311 : NegativeTestBase(context, "binding_sampler_invalid", "Test verifies invalid binding values")
11312 {
11313 /* Nothing to be done here */
11314 }
11315
11316 /** Set up next test case
11317 *
11318 * @param test_case_index Index of next test case
11319 *
11320 * @return false if there is no more test cases, true otherwise
11321 **/
prepareNextTestCase(glw::GLuint test_case_index)11322 bool BindingSamplerInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
11323 {
11324 switch (test_case_index)
11325 {
11326 case (glw::GLuint)-1:
11327 m_case = TEST_CASES_MAX;
11328 break;
11329 case NEGATIVE_VALUE:
11330 case VARIABLE_NAME:
11331 case STD140:
11332 case MISSING:
11333 m_case = (TESTCASES)test_case_index;
11334 break;
11335 default:
11336 return false;
11337 }
11338
11339 return true;
11340 }
11341
11342 /** Prepare source for given shader stage
11343 *
11344 * @param in_stage Shader stage, compute shader will use 430
11345 * @param in_use_version_400 Select if 400 or 420 should be used
11346 * @param out_source Prepared shader source instance
11347 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11348 void BindingSamplerInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11349 Utils::shaderSource &out_source)
11350 {
11351 static const GLchar *uni_goku = "layout(binding BINDING) uniform sampler2D goku;\n";
11352
11353 static const GLchar *verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
11354 " if (vec4(1, 0, 0, 0) != color)\n"
11355 " {\n"
11356 " result = vec4(1, 0, 0, 1);\n"
11357 " }\n";
11358
11359 static const GLchar *compute_shader_template =
11360 "VERSION\n"
11361 "\n"
11362 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11363 "\n"
11364 "writeonly uniform image2D uni_image;\n"
11365 "\n"
11366 "UNI_GOKU\n"
11367 "\n"
11368 "void main()\n"
11369 "{\n"
11370 " vec4 result = vec4(0, 1, 0, 1);\n"
11371 "\n"
11372 "VERIFICATION"
11373 "\n"
11374 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11375 "}\n"
11376 "\n";
11377
11378 static const GLchar *fragment_shader_template = "VERSION\n"
11379 "\n"
11380 "in vec4 gs_fs_result;\n"
11381 "out vec4 fs_out_result;\n"
11382 "\n"
11383 "UNI_GOKU\n"
11384 "\n"
11385 "void main()\n"
11386 "{\n"
11387 " vec4 result = vec4(0, 1, 0, 1);\n"
11388 "\n"
11389 "VERIFICATION"
11390 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11391 " {\n"
11392 " result = vec4(1, 0, 0, 1);\n"
11393 " }\n"
11394 "\n"
11395 " fs_out_result = result;\n"
11396 "}\n"
11397 "\n";
11398
11399 static const GLchar *geometry_shader_template = "VERSION\n"
11400 "\n"
11401 "layout(points) in;\n"
11402 "layout(triangle_strip, max_vertices = 4) out;\n"
11403 "\n"
11404 "in vec4 tes_gs_result[];\n"
11405 "out vec4 gs_fs_result;\n"
11406 "\n"
11407 "UNI_GOKU\n"
11408 "\n"
11409 "void main()\n"
11410 "{\n"
11411 " vec4 result = vec4(0, 1, 0, 1);\n"
11412 "\n"
11413 "VERIFICATION"
11414 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11415 " {\n"
11416 " result = vec4(1, 0, 0, 1);\n"
11417 " }\n"
11418 "\n"
11419 " gs_fs_result = result;\n"
11420 " gl_Position = vec4(-1, -1, 0, 1);\n"
11421 " EmitVertex();\n"
11422 " gs_fs_result = result;\n"
11423 " gl_Position = vec4(-1, 1, 0, 1);\n"
11424 " EmitVertex();\n"
11425 " gs_fs_result = result;\n"
11426 " gl_Position = vec4(1, -1, 0, 1);\n"
11427 " EmitVertex();\n"
11428 " gs_fs_result = result;\n"
11429 " gl_Position = vec4(1, 1, 0, 1);\n"
11430 " EmitVertex();\n"
11431 "}\n"
11432 "\n";
11433
11434 static const GLchar *tess_ctrl_shader_template =
11435 "VERSION\n"
11436 "\n"
11437 "layout(vertices = 1) out;\n"
11438 "\n"
11439 "in vec4 vs_tcs_result[];\n"
11440 "out vec4 tcs_tes_result[];\n"
11441 "\n"
11442 "UNI_GOKU\n"
11443 "\n"
11444 "void main()\n"
11445 "{\n"
11446 " vec4 result = vec4(0, 1, 0, 1);\n"
11447 "\n"
11448 "VERIFICATION"
11449 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11450 " {\n"
11451 " result = vec4(1, 0, 0, 1);\n"
11452 " }\n"
11453 "\n"
11454 " tcs_tes_result[gl_InvocationID] = result;\n"
11455 "\n"
11456 " gl_TessLevelOuter[0] = 1.0;\n"
11457 " gl_TessLevelOuter[1] = 1.0;\n"
11458 " gl_TessLevelOuter[2] = 1.0;\n"
11459 " gl_TessLevelOuter[3] = 1.0;\n"
11460 " gl_TessLevelInner[0] = 1.0;\n"
11461 " gl_TessLevelInner[1] = 1.0;\n"
11462 "}\n"
11463 "\n";
11464
11465 static const GLchar *tess_eval_shader_template = "VERSION\n"
11466 "\n"
11467 "layout(isolines, point_mode) in;\n"
11468 "\n"
11469 "in vec4 tcs_tes_result[];\n"
11470 "out vec4 tes_gs_result;\n"
11471 "\n"
11472 "UNI_GOKU\n"
11473 "\n"
11474 "void main()\n"
11475 "{\n"
11476 " vec4 result = vec4(0, 1, 0, 1);\n"
11477 "\n"
11478 "VERIFICATION"
11479 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11480 " {\n"
11481 " result = vec4(1, 0, 0, 1);\n"
11482 " }\n"
11483 "\n"
11484 " tes_gs_result = result;\n"
11485 "}\n"
11486 "\n";
11487
11488 static const GLchar *vertex_shader_template = "VERSION\n"
11489 "\n"
11490 "out vec4 vs_tcs_result;\n"
11491 "\n"
11492 "UNI_GOKU\n"
11493 "\n"
11494 "void main()\n"
11495 "{\n"
11496 " vec4 result = vec4(0, 1, 0, 1);\n"
11497 "\n"
11498 "VERIFICATION"
11499 "\n"
11500 " vs_tcs_result = result;\n"
11501 "}\n"
11502 "\n";
11503
11504 const GLchar *shader_template = 0;
11505
11506 switch (in_stage)
11507 {
11508 case Utils::COMPUTE_SHADER:
11509 shader_template = compute_shader_template;
11510 break;
11511 case Utils::FRAGMENT_SHADER:
11512 shader_template = fragment_shader_template;
11513 break;
11514 case Utils::GEOMETRY_SHADER:
11515 shader_template = geometry_shader_template;
11516 break;
11517 case Utils::TESS_CTRL_SHADER:
11518 shader_template = tess_ctrl_shader_template;
11519 break;
11520 case Utils::TESS_EVAL_SHADER:
11521 shader_template = tess_eval_shader_template;
11522 break;
11523 case Utils::VERTEX_SHADER:
11524 shader_template = vertex_shader_template;
11525 break;
11526 default:
11527 TCU_FAIL("Invalid enum");
11528 }
11529
11530 out_source.m_parts[0].m_code = shader_template;
11531
11532 size_t position = 0;
11533
11534 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11535 out_source.m_parts[0].m_code);
11536
11537 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11538
11539 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11540
11541 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
11542 }
11543
getCaseString(TESTCASES test_case)11544 const GLchar *BindingSamplerInvalidTest::getCaseString(TESTCASES test_case)
11545 {
11546 (void)test_case;
11547 const GLchar *binding = 0;
11548
11549 switch (m_case)
11550 {
11551 case NEGATIVE_VALUE:
11552 binding = "= -1";
11553 break;
11554 case VARIABLE_NAME:
11555 binding = "= goku";
11556 break;
11557 case STD140:
11558 binding = "= std140";
11559 break;
11560 case MISSING:
11561 binding = "";
11562 break;
11563 case TEST_CASES_MAX:
11564 binding = "= 0";
11565 break;
11566 default:
11567 TCU_FAIL("Invalid enum");
11568 }
11569
11570 return binding;
11571 }
11572
11573 /* Constants used by BindingImagesTest */
11574 const GLuint BindingImagesTest::m_goku_data = 0x000000ff;
11575 const GLuint BindingImagesTest::m_vegeta_data = 0x0000ff00;
11576 const GLuint BindingImagesTest::m_trunks_data = 0x00ff0000;
11577
11578 /** Constructor
11579 *
11580 * @param context Test context
11581 **/
BindingImagesTest(deqp::Context & context)11582 BindingImagesTest::BindingImagesTest(deqp::Context &context)
11583 : BindingImageTest(context, "binding_images", "Test verifies binding of images")
11584 , m_goku_texture(context)
11585 , m_vegeta_texture(context)
11586 , m_trunks_texture(context)
11587 , m_goku_buffer(context)
11588 , m_vegeta_buffer(context)
11589 , m_trunks_buffer(context)
11590 {
11591 /* Nothing to be done here */
11592 }
11593
11594 /** Set up next test case
11595 *
11596 * @param test_case_index Index of next test case
11597 *
11598 * @return false if there is no more test cases, true otherwise
11599 **/
prepareNextTestCase(glw::GLuint test_case_index)11600 bool BindingImagesTest::prepareNextTestCase(glw::GLuint test_case_index)
11601 {
11602 switch (test_case_index)
11603 {
11604 case (glw::GLuint)-1:
11605 case 0:
11606 m_test_case = Utils::TEX_2D;
11607 break;
11608 case 1:
11609 m_test_case = Utils::TEX_BUFFER;
11610 break;
11611 case 2:
11612 m_test_case = Utils::TEX_2D_RECT;
11613 break;
11614 case 3:
11615 m_test_case = Utils::TEX_2D_ARRAY;
11616 break;
11617 case 4:
11618 m_test_case = Utils::TEX_3D;
11619 break;
11620 case 5:
11621 m_test_case = Utils::TEX_CUBE;
11622 break;
11623 case 6:
11624 m_test_case = Utils::TEX_1D;
11625 break;
11626 case 7:
11627 m_test_case = Utils::TEX_1D_ARRAY;
11628 break;
11629 default:
11630 return false;
11631 }
11632
11633 m_context.getTestContext().getLog() << tcu::TestLog::Message
11634 << "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
11635 << tcu::TestLog::EndMessage;
11636
11637 return true;
11638 }
11639
11640 /** Prepare source for given shader stage
11641 *
11642 * @param in_stage Shader stage, compute shader will use 430
11643 * @param in_use_version_400 Select if 400 or 420 should be used
11644 * @param out_source Prepared shader source instance
11645 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11646 void BindingImagesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11647 Utils::shaderSource &out_source)
11648 {
11649 static const GLchar *uni_goku = "layout(binding = 1, rgba8) uniform TYPE goku;\n";
11650
11651 static const GLchar *uni_vegeta = "layout(binding = 2, rgba8) uniform TYPE vegeta;\n";
11652
11653 static const GLchar *uni_trunks = "layout(binding = 4, rgba8) uniform TYPE trunks;\n\n";
11654
11655 static const GLchar *verification_snippet = " TEX_COORD_TYPE tex_coord_read = TEX_COORD_TYPE(COORDINATES);\n"
11656 " TEX_COORD_TYPE tex_coord_write = TEX_COORD_TYPE(COORDINATES);\n"
11657 " vec4 goku_color = imageLoad(goku, tex_coord_read);\n"
11658 " vec4 vegeta_color = imageLoad(vegeta, tex_coord_read);\n"
11659 " vec4 trunks_color = imageLoad(trunks, tex_coord_read);\n"
11660 "\n"
11661 " imageStore(goku, tex_coord_write, vec4(0, 1, 0, 1));\n"
11662 " imageStore(vegeta, tex_coord_write, vec4(0, 1, 0, 1));\n"
11663 " imageStore(trunks, tex_coord_write, vec4(0, 1, 0, 1));\n"
11664 "\n"
11665 " if ((vec4(1, 0, 0, 0) != goku_color) ||\n"
11666 " (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
11667 " (vec4(0, 0, 1, 0) != trunks_color) )\n"
11668 " {\n"
11669 " result = goku_color;\n"
11670 " //result = vec4(1, 0, 0, 1);\n"
11671 " }\n";
11672
11673 static const GLchar *compute_shader_template =
11674 "VERSION\n"
11675 "#extension GL_ARB_shader_image_load_store : enable\n"
11676 "\n"
11677 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11678 "\n"
11679 "writeonly uniform image2D uni_image;\n"
11680 "\n"
11681 "UNI_GOKU\n"
11682 "UNI_VEGETA\n"
11683 "UNI_TRUNKS\n"
11684 "\n"
11685 "void main()\n"
11686 "{\n"
11687 " vec4 result = vec4(0, 1, 0, 1);\n"
11688 "\n"
11689 " if(gl_GlobalInvocationID.xy == vec2(0, 0)) {\n"
11690 "VERIFICATION"
11691 " }\n"
11692 "\n"
11693 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11694 "}\n"
11695 "\n";
11696
11697 static const GLchar *fragment_shader_template = "VERSION\n"
11698 "#extension GL_ARB_shader_image_load_store : enable\n"
11699 "\n"
11700 "in vec4 gs_fs_result;\n"
11701 "out vec4 fs_out_result;\n"
11702 "\n"
11703 "UNI_GOKU\n"
11704 "UNI_VEGETA\n"
11705 "UNI_TRUNKS\n"
11706 "\n"
11707 "void main()\n"
11708 "{\n"
11709 " vec4 result = vec4(0, 1, 0, 1);\n"
11710 "\n"
11711 "VERIFICATION"
11712 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11713 " {\n"
11714 " result = vec4(1, 0, 0, 1);\n"
11715 " }\n"
11716 "\n"
11717 " fs_out_result = result;\n"
11718 "}\n"
11719 "\n";
11720
11721 static const GLchar *geometry_shader_template = "VERSION\n"
11722 "#extension GL_ARB_shader_image_load_store : enable\n"
11723 "\n"
11724 "layout(points) in;\n"
11725 "layout(triangle_strip, max_vertices = 4) out;\n"
11726 "\n"
11727 "in vec4 tes_gs_result[];\n"
11728 "out vec4 gs_fs_result;\n"
11729 "\n"
11730 "#if IMAGES\n"
11731 "UNI_TRUNKS\n"
11732 "UNI_GOKU\n"
11733 "UNI_VEGETA\n"
11734 "#endif\n"
11735 "\n"
11736 "void main()\n"
11737 "{\n"
11738 " vec4 result = vec4(0, 1, 0, 1);\n"
11739 "\n"
11740 "#if IMAGES\n"
11741 "VERIFICATION else\n"
11742 "#endif\n"
11743 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11744 " {\n"
11745 " result = vec4(1, 0, 0, 1);\n"
11746 " }\n"
11747 "\n"
11748 " gs_fs_result = result;\n"
11749 " gl_Position = vec4(-1, -1, 0, 1);\n"
11750 " EmitVertex();\n"
11751 " gs_fs_result = result;\n"
11752 " gl_Position = vec4(-1, 1, 0, 1);\n"
11753 " EmitVertex();\n"
11754 " gs_fs_result = result;\n"
11755 " gl_Position = vec4(1, -1, 0, 1);\n"
11756 " EmitVertex();\n"
11757 " gs_fs_result = result;\n"
11758 " gl_Position = vec4(1, 1, 0, 1);\n"
11759 " EmitVertex();\n"
11760 "}\n"
11761 "\n";
11762
11763 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
11764 "#extension GL_ARB_shader_image_load_store : enable\n"
11765 "\n"
11766 "layout(vertices = 1) out;\n"
11767 "\n"
11768 "in vec4 vs_tcs_result[];\n"
11769 "out vec4 tcs_tes_result[];\n"
11770 "\n"
11771 "#if IMAGES\n"
11772 "UNI_VEGETA\n"
11773 "UNI_TRUNKS\n"
11774 "UNI_GOKU\n"
11775 "#endif\n"
11776 "\n"
11777 "void main()\n"
11778 "{\n"
11779 " vec4 result = vec4(0, 1, 0, 1);\n"
11780 "\n"
11781 "#if IMAGES\n"
11782 "VERIFICATION else\n"
11783 "#endif\n"
11784 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11785 " {\n"
11786 " result = vec4(1, 0, 0, 1);\n"
11787 " }\n"
11788 "\n"
11789 " tcs_tes_result[gl_InvocationID] = result;\n"
11790 "\n"
11791 " gl_TessLevelOuter[0] = 1.0;\n"
11792 " gl_TessLevelOuter[1] = 1.0;\n"
11793 " gl_TessLevelOuter[2] = 1.0;\n"
11794 " gl_TessLevelOuter[3] = 1.0;\n"
11795 " gl_TessLevelInner[0] = 1.0;\n"
11796 " gl_TessLevelInner[1] = 1.0;\n"
11797 "}\n"
11798 "\n";
11799
11800 static const GLchar *tess_eval_shader_template = "VERSION\n"
11801 "#extension GL_ARB_shader_image_load_store : enable\n"
11802 "\n"
11803 "layout(isolines, point_mode) in;\n"
11804 "\n"
11805 "in vec4 tcs_tes_result[];\n"
11806 "out vec4 tes_gs_result;\n"
11807 "\n"
11808 "#if IMAGES\n"
11809 "UNI_GOKU\n"
11810 "UNI_TRUNKS\n"
11811 "UNI_VEGETA\n"
11812 "#endif\n"
11813 "\n"
11814 "void main()\n"
11815 "{\n"
11816 " vec4 result = vec4(0, 1, 0, 1);\n"
11817 "\n"
11818 "#if IMAGES\n"
11819 "VERIFICATION else\n"
11820 "#endif\n"
11821 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11822 " {\n"
11823 " result = vec4(1, 0, 0, 1);\n"
11824 " }\n"
11825 "\n"
11826 " tes_gs_result = result;\n"
11827 "}\n"
11828 "\n";
11829
11830 static const GLchar *vertex_shader_template = "VERSION\n"
11831 "#extension GL_ARB_shader_image_load_store : enable\n"
11832 "\n"
11833 "out vec4 vs_tcs_result;\n"
11834 "\n"
11835 "#if IMAGES\n"
11836 "UNI_TRUNKS\n"
11837 "UNI_VEGETA\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"
11847 "#endif\n"
11848 "\n"
11849 " vs_tcs_result = result;\n"
11850 "}\n"
11851 "\n";
11852
11853 const GLchar *coordinates_read = 0;
11854 const GLchar *coordinates_write = 0;
11855 const GLchar *image_type = Utils::getImageType(m_test_case);
11856 GLuint n_coordinates = Utils::getNumberOfCoordinates(m_test_case);
11857 const GLchar *shader_template = 0;
11858 const GLchar *tex_coord_type = Utils::getTypeName(Utils::INT, 1 /* n_columns */, n_coordinates);
11859
11860 switch (in_stage)
11861 {
11862 case Utils::COMPUTE_SHADER:
11863 shader_template = compute_shader_template;
11864 break;
11865 case Utils::FRAGMENT_SHADER:
11866 shader_template = fragment_shader_template;
11867 break;
11868 case Utils::GEOMETRY_SHADER:
11869 shader_template = geometry_shader_template;
11870 break;
11871 case Utils::TESS_CTRL_SHADER:
11872 shader_template = tess_ctrl_shader_template;
11873 break;
11874 case Utils::TESS_EVAL_SHADER:
11875 shader_template = tess_eval_shader_template;
11876 break;
11877 case Utils::VERTEX_SHADER:
11878 shader_template = vertex_shader_template;
11879 break;
11880 default:
11881 TCU_FAIL("Invalid enum");
11882 }
11883
11884 switch (n_coordinates)
11885 {
11886 case 1:
11887 coordinates_read = "1";
11888 coordinates_write = "0";
11889 break;
11890 case 2:
11891 coordinates_read = "1, 0";
11892 coordinates_write = "0, 0";
11893 break;
11894 case 3:
11895 coordinates_read = "1, 0, 0";
11896 coordinates_write = "0, 0, 0";
11897 break;
11898 case 4:
11899 coordinates_read = "1, 0, 0, 0";
11900 coordinates_write = "0, 0, 0, 0";
11901 break;
11902 }
11903
11904 out_source.m_parts[0].m_code = shader_template;
11905
11906 size_t position = 0;
11907
11908 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11909 out_source.m_parts[0].m_code);
11910
11911 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11912
11913 position -= strlen(verification_snippet);
11914
11915 Utils::replaceToken("COORDINATES", position, coordinates_read, out_source.m_parts[0].m_code);
11916
11917 Utils::replaceToken("COORDINATES", position, coordinates_write, out_source.m_parts[0].m_code);
11918
11919 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
11920
11921 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11922
11923 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
11924
11925 Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
11926
11927 Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
11928
11929 Utils::replaceAllTokens("TYPE", image_type, out_source.m_parts[0].m_code);
11930 }
11931
11932 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11933 *
11934 * @param program Current program
11935 **/
prepareUniforms(Utils::program & program)11936 void BindingImagesTest::prepareUniforms(Utils::program &program)
11937 {
11938 (void)program;
11939 prepareBuffer(m_goku_buffer, m_goku_data);
11940 prepareBuffer(m_vegeta_buffer, m_vegeta_data);
11941 prepareBuffer(m_trunks_buffer, m_trunks_data);
11942
11943 prepareTexture(m_goku_texture, m_goku_buffer, m_test_case, m_goku_data, 1);
11944 prepareTexture(m_vegeta_texture, m_vegeta_buffer, m_test_case, m_vegeta_data, 2);
11945 prepareTexture(m_trunks_texture, m_trunks_buffer, m_test_case, m_trunks_data, 4);
11946 }
11947
11948 /** Overwrite of releaseResource method, release extra buffers and textures
11949 *
11950 * @param ignored
11951 **/
releaseResource()11952 void BindingImagesTest::releaseResource()
11953 {
11954 m_goku_texture.release();
11955 m_vegeta_texture.release();
11956 m_trunks_texture.release();
11957 if (m_test_case != Utils::TEX_BUFFER)
11958 {
11959 m_goku_buffer.release();
11960 m_vegeta_buffer.release();
11961 m_trunks_buffer.release();
11962 }
11963 }
11964
11965 /** Verify that all images have green texel at [0,0,0,0]
11966 *
11967 * @return true texel is green, false otherwise
11968 **/
verifyAdditionalResults() const11969 bool BindingImagesTest::verifyAdditionalResults() const
11970 {
11971 if (Utils::TEX_BUFFER != m_test_case)
11972 {
11973 return (verifyTexture(m_goku_texture) && verifyTexture(m_vegeta_texture) && verifyTexture(m_trunks_texture));
11974 }
11975 else
11976 {
11977 return (verifyBuffer(m_goku_buffer) && verifyBuffer(m_vegeta_buffer) && verifyBuffer(m_trunks_buffer));
11978 }
11979 }
11980
11981 /** Constructor
11982 *
11983 * @param context Test context
11984 **/
BindingImageSingleTest(deqp::Context & context)11985 BindingImageSingleTest::BindingImageSingleTest(deqp::Context &context)
11986 : BindingImageTest(context, "binding_image_single", "Test verifies single binding of image used in multiple stages")
11987 , m_goku_texture(context)
11988 {
11989 /* Nothing to be done here */
11990 }
11991
11992 /** Set up next test case
11993 *
11994 * @param test_case_index Index of next test case
11995 *
11996 * @return false if there is no more test cases, true otherwise
11997 **/
prepareNextTestCase(glw::GLuint test_case_index)11998 bool BindingImageSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
11999 {
12000 switch (test_case_index)
12001 {
12002 case (glw::GLuint)-1:
12003 case 0:
12004 m_test_stage = Utils::VERTEX_SHADER;
12005 break;
12006 case 1:
12007 m_test_stage = Utils::TESS_CTRL_SHADER;
12008 break;
12009 case 2:
12010 m_test_stage = Utils::TESS_EVAL_SHADER;
12011 break;
12012 case 3:
12013 m_test_stage = Utils::GEOMETRY_SHADER;
12014 break;
12015 case 4:
12016 m_test_stage = Utils::FRAGMENT_SHADER;
12017 break;
12018 default:
12019 return false;
12020 }
12021
12022 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
12023 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
12024 << tcu::TestLog::EndMessage;
12025
12026 return true;
12027 }
12028
12029 /** Prepare source for given shader stage
12030 *
12031 * @param in_stage Shader stage, compute shader will use 430
12032 * @param in_use_version_400 Select if 400 or 420 should be used
12033 * @param out_source Prepared shader source instance
12034 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12035 void BindingImageSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12036 Utils::shaderSource &out_source)
12037 {
12038 static const GLchar *uni_goku_with_binding = "layout(binding = 2, rgba8) uniform image2D goku;\n";
12039
12040 static const GLchar *uni_goku_no_binding = "layout(rgba8) uniform image2D goku;\n";
12041
12042 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,1));\n"
12043 "\n"
12044 " imageStore(goku, ivec2(0,0), vec4(0, 1, 0, 1));\n"
12045 "\n"
12046 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12047 " {\n"
12048 " result = vec4(1, 0, 0, 1);\n"
12049 " }\n";
12050
12051 static const GLchar *compute_shader_template =
12052 "VERSION\n"
12053 "#extension GL_ARB_shader_image_load_store : enable\n"
12054 "\n"
12055 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12056 "\n"
12057 "writeonly uniform image2D uni_image;\n"
12058 "\n"
12059 "UNI_GOKU\n"
12060 "\n"
12061 "void main()\n"
12062 "{\n"
12063 " vec4 result = vec4(0, 1, 0, 1);\n"
12064 "\n"
12065 "VERIFICATION"
12066 "\n"
12067 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12068 "}\n"
12069 "\n";
12070
12071 static const GLchar *fragment_shader_template = "VERSION\n"
12072 "#extension GL_ARB_shader_image_load_store : enable\n"
12073 "\n"
12074 "in vec4 gs_fs_result;\n"
12075 "out vec4 fs_out_result;\n"
12076 "\n"
12077 "UNI_GOKU\n"
12078 "\n"
12079 "void main()\n"
12080 "{\n"
12081 " vec4 result = vec4(0, 1, 0, 1);\n"
12082 "\n"
12083 "VERIFICATION"
12084 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12085 " {\n"
12086 " result = vec4(1, 0, 0, 1);\n"
12087 " }\n"
12088 "\n"
12089 " fs_out_result = result;\n"
12090 "}\n"
12091 "\n";
12092
12093 static const GLchar *geometry_shader_template = "VERSION\n"
12094 "#extension GL_ARB_shader_image_load_store : enable\n"
12095 "\n"
12096 "layout(points) in;\n"
12097 "layout(triangle_strip, max_vertices = 4) out;\n"
12098 "\n"
12099 "in vec4 tes_gs_result[];\n"
12100 "out vec4 gs_fs_result;\n"
12101 "\n"
12102 "#if IMAGES\n"
12103 "UNI_GOKU\n"
12104 "#endif\n"
12105 "\n"
12106 "void main()\n"
12107 "{\n"
12108 " vec4 result = vec4(0, 1, 0, 1);\n"
12109 "\n"
12110 "#if IMAGES\n"
12111 "VERIFICATION else\n"
12112 "#endif\n"
12113 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12114 " {\n"
12115 " result = vec4(1, 0, 0, 1);\n"
12116 " }\n"
12117 "\n"
12118 " gs_fs_result = result;\n"
12119 " gl_Position = vec4(-1, -1, 0, 1);\n"
12120 " EmitVertex();\n"
12121 " gs_fs_result = result;\n"
12122 " gl_Position = vec4(-1, 1, 0, 1);\n"
12123 " EmitVertex();\n"
12124 " gs_fs_result = result;\n"
12125 " gl_Position = vec4(1, -1, 0, 1);\n"
12126 " EmitVertex();\n"
12127 " gs_fs_result = result;\n"
12128 " gl_Position = vec4(1, 1, 0, 1);\n"
12129 " EmitVertex();\n"
12130 "}\n"
12131 "\n";
12132
12133 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12134 "#extension GL_ARB_shader_image_load_store : enable\n"
12135 "\n"
12136 "layout(vertices = 1) out;\n"
12137 "\n"
12138 "in vec4 vs_tcs_result[];\n"
12139 "out vec4 tcs_tes_result[];\n"
12140 "\n"
12141 "#if IMAGES\n"
12142 "UNI_GOKU\n"
12143 "#endif\n"
12144 "\n"
12145 "void main()\n"
12146 "{\n"
12147 " vec4 result = vec4(0, 1, 0, 1);\n"
12148 "\n"
12149 "#if IMAGES\n"
12150 "VERIFICATION else\n"
12151 "#endif\n"
12152 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12153 " {\n"
12154 " result = vec4(1, 0, 0, 1);\n"
12155 " }\n"
12156 "\n"
12157 " tcs_tes_result[gl_InvocationID] = result;\n"
12158 "\n"
12159 " gl_TessLevelOuter[0] = 1.0;\n"
12160 " gl_TessLevelOuter[1] = 1.0;\n"
12161 " gl_TessLevelOuter[2] = 1.0;\n"
12162 " gl_TessLevelOuter[3] = 1.0;\n"
12163 " gl_TessLevelInner[0] = 1.0;\n"
12164 " gl_TessLevelInner[1] = 1.0;\n"
12165 "}\n"
12166 "\n";
12167
12168 static const GLchar *tess_eval_shader_template = "VERSION\n"
12169 "#extension GL_ARB_shader_image_load_store : enable\n"
12170 "\n"
12171 "layout(isolines, point_mode) in;\n"
12172 "\n"
12173 "in vec4 tcs_tes_result[];\n"
12174 "out vec4 tes_gs_result;\n"
12175 "\n"
12176 "#if IMAGES\n"
12177 "UNI_GOKU\n"
12178 "#endif\n"
12179 "\n"
12180 "void main()\n"
12181 "{\n"
12182 " vec4 result = vec4(0, 1, 0, 1);\n"
12183 "\n"
12184 "#if IMAGES\n"
12185 "VERIFICATION else\n"
12186 "#endif\n"
12187 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12188 " {\n"
12189 " result = vec4(1, 0, 0, 1);\n"
12190 " }\n"
12191 "\n"
12192 " tes_gs_result = result;\n"
12193 "}\n"
12194 "\n";
12195
12196 static const GLchar *vertex_shader_template = "VERSION\n"
12197 "#extension GL_ARB_shader_image_load_store : enable\n"
12198 "\n"
12199 "out vec4 vs_tcs_result;\n"
12200 "\n"
12201 "#if IMAGES\n"
12202 "UNI_GOKU\n"
12203 "#endif\n"
12204 "\n"
12205 "void main()\n"
12206 "{\n"
12207 " vec4 result = vec4(0, 1, 0, 1);\n"
12208 "\n"
12209 "#if IMAGES\n"
12210 "VERIFICATION"
12211 "#endif\n"
12212 "\n"
12213 " vs_tcs_result = result;\n"
12214 "}\n"
12215 "\n";
12216
12217 const GLchar *shader_template = 0;
12218 const GLchar *uniform_definition = uni_goku_no_binding;
12219
12220 switch (in_stage)
12221 {
12222 case Utils::COMPUTE_SHADER:
12223 shader_template = compute_shader_template;
12224 uniform_definition = uni_goku_with_binding;
12225 break;
12226 case Utils::FRAGMENT_SHADER:
12227 shader_template = fragment_shader_template;
12228 /* We can't rely on the binding qualifier being present in m_test_stage
12229 * if images are unsupported in that stage.
12230 */
12231 if (maxImageUniforms(m_test_stage) == 0)
12232 uniform_definition = uni_goku_with_binding;
12233 break;
12234 case Utils::GEOMETRY_SHADER:
12235 shader_template = geometry_shader_template;
12236 break;
12237 case Utils::TESS_CTRL_SHADER:
12238 shader_template = tess_ctrl_shader_template;
12239 break;
12240 case Utils::TESS_EVAL_SHADER:
12241 shader_template = tess_eval_shader_template;
12242 break;
12243 case Utils::VERTEX_SHADER:
12244 shader_template = vertex_shader_template;
12245 break;
12246 default:
12247 TCU_FAIL("Invalid enum");
12248 }
12249
12250 if (in_stage == m_test_stage)
12251 {
12252 uniform_definition = uni_goku_with_binding;
12253 }
12254
12255 out_source.m_parts[0].m_code = shader_template;
12256
12257 size_t position = 0;
12258
12259 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12260 out_source.m_parts[0].m_code);
12261
12262 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12263
12264 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12265
12266 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
12267 }
12268
12269 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12270 *
12271 * @param program Current program
12272 **/
prepareUniforms(Utils::program & program)12273 void BindingImageSingleTest::prepareUniforms(Utils::program &program)
12274 {
12275 (void)program;
12276 static const GLuint goku_data = 0x000000ff;
12277
12278 prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, 2 /* unit */);
12279 }
12280
12281 /** Overwrite of releaseResource method, release extra texture
12282 *
12283 * @param ignored
12284 **/
releaseResource()12285 void BindingImageSingleTest::releaseResource()
12286 {
12287 m_goku_texture.release();
12288 }
12289
12290 /** Verify that all images have green texel at [0,0,0,0]
12291 *
12292 * @return true texel is green, false otherwise
12293 **/
verifyAdditionalResults() const12294 bool BindingImageSingleTest::verifyAdditionalResults() const
12295 {
12296 return verifyTexture(m_goku_texture);
12297 }
12298
12299 /** Constructor
12300 *
12301 * @param context Test context
12302 **/
BindingImageArrayTest(deqp::Context & context)12303 BindingImageArrayTest::BindingImageArrayTest(deqp::Context &context)
12304 : BindingImageTest(context, "binding_image_array", "Test verifies binding of image array")
12305 , m_goku_00_texture(context)
12306 , m_goku_01_texture(context)
12307 , m_goku_02_texture(context)
12308 , m_goku_03_texture(context)
12309 , m_goku_04_texture(context)
12310 , m_goku_05_texture(context)
12311 , m_goku_06_texture(context)
12312 {
12313 /* Nothing to be done here */
12314 }
12315
12316 /** Prepare source for given shader stage
12317 *
12318 * @param in_stage Shader stage, compute shader will use 430
12319 * @param in_use_version_400 Select if 400 or 420 should be used
12320 * @param out_source Prepared shader source instance
12321 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12322 void BindingImageArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12323 Utils::shaderSource &out_source)
12324 {
12325 static const GLchar *uni_goku = "layout(binding = 1, rgba8) uniform image2D goku[7];\n";
12326
12327 static const GLchar *verification_snippet = " vec4 color[7];\n"
12328 "\n"
12329 " for (uint i = 0u; i < 7; ++i)\n"
12330 " {\n"
12331 " color[i] = imageLoad(goku[i], ivec2(0,0));\n"
12332 " }\n"
12333 "\n"
12334 " if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
12335 " (vec4(0, 0, 0, 1) != color[1]) ||\n"
12336 " (vec4(0, 0, 1, 0) != color[2]) ||\n"
12337 " (vec4(0, 0, 1, 1) != color[3]) ||\n"
12338 " (vec4(0, 1, 0, 0) != color[4]) ||\n"
12339 " (vec4(0, 1, 0, 1) != color[5]) ||\n"
12340 " (vec4(0, 1, 1, 0) != color[6]) )\n"
12341 " {\n"
12342 " result = vec4(1, 0, 0, 1);\n"
12343 " }\n";
12344
12345 static const GLchar *compute_shader_template =
12346 "VERSION\n"
12347 "#extension GL_ARB_shader_image_load_store : enable\n"
12348 "\n"
12349 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12350 "\n"
12351 "writeonly uniform image2D uni_image;\n"
12352 "\n"
12353 "UNI_GOKU\n"
12354 "\n"
12355 "void main()\n"
12356 "{\n"
12357 " vec4 result = vec4(0, 1, 0, 1);\n"
12358 "\n"
12359 "VERIFICATION"
12360 "\n"
12361 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12362 "}\n"
12363 "\n";
12364
12365 static const GLchar *fragment_shader_template = "VERSION\n"
12366 "#extension GL_ARB_shader_image_load_store : enable\n"
12367 "\n"
12368 "in vec4 gs_fs_result;\n"
12369 "out vec4 fs_out_result;\n"
12370 "\n"
12371 "UNI_GOKU\n"
12372 "\n"
12373 "void main()\n"
12374 "{\n"
12375 " vec4 result = vec4(0, 1, 0, 1);\n"
12376 "\n"
12377 "VERIFICATION"
12378 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12379 " {\n"
12380 " result = vec4(1, 0, 0, 1);\n"
12381 " }\n"
12382 "\n"
12383 " fs_out_result = result;\n"
12384 "}\n"
12385 "\n";
12386
12387 static const GLchar *geometry_shader_template = "VERSION\n"
12388 "#extension GL_ARB_shader_image_load_store : enable\n"
12389 "\n"
12390 "layout(points) in;\n"
12391 "layout(triangle_strip, max_vertices = 4) out;\n"
12392 "\n"
12393 "in vec4 tes_gs_result[];\n"
12394 "out vec4 gs_fs_result;\n"
12395 "\n"
12396 "#if IMAGES\n"
12397 "UNI_GOKU\n"
12398 "#endif\n"
12399 "\n"
12400 "void main()\n"
12401 "{\n"
12402 " vec4 result = vec4(0, 1, 0, 1);\n"
12403 "\n"
12404 "#if IMAGES\n"
12405 "VERIFICATION else\n"
12406 "#endif\n"
12407 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12408 " {\n"
12409 " result = vec4(1, 0, 0, 1);\n"
12410 " }\n"
12411 "\n"
12412 " gs_fs_result = result;\n"
12413 " gl_Position = vec4(-1, -1, 0, 1);\n"
12414 " EmitVertex();\n"
12415 " gs_fs_result = result;\n"
12416 " gl_Position = vec4(-1, 1, 0, 1);\n"
12417 " EmitVertex();\n"
12418 " gs_fs_result = result;\n"
12419 " gl_Position = vec4(1, -1, 0, 1);\n"
12420 " EmitVertex();\n"
12421 " gs_fs_result = result;\n"
12422 " gl_Position = vec4(1, 1, 0, 1);\n"
12423 " EmitVertex();\n"
12424 "}\n"
12425 "\n";
12426
12427 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12428 "#extension GL_ARB_shader_image_load_store : enable\n"
12429 "\n"
12430 "layout(vertices = 1) out;\n"
12431 "\n"
12432 "in vec4 vs_tcs_result[];\n"
12433 "out vec4 tcs_tes_result[];\n"
12434 "\n"
12435 "#if IMAGES\n"
12436 "UNI_GOKU\n"
12437 "#endif\n"
12438 "\n"
12439 "void main()\n"
12440 "{\n"
12441 " vec4 result = vec4(0, 1, 0, 1);\n"
12442 "\n"
12443 "#if IMAGES\n"
12444 "VERIFICATION else\n"
12445 "#endif\n"
12446 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12447 " {\n"
12448 " result = vec4(1, 0, 0, 1);\n"
12449 " }\n"
12450 "\n"
12451 " tcs_tes_result[gl_InvocationID] = result;\n"
12452 "\n"
12453 " gl_TessLevelOuter[0] = 1.0;\n"
12454 " gl_TessLevelOuter[1] = 1.0;\n"
12455 " gl_TessLevelOuter[2] = 1.0;\n"
12456 " gl_TessLevelOuter[3] = 1.0;\n"
12457 " gl_TessLevelInner[0] = 1.0;\n"
12458 " gl_TessLevelInner[1] = 1.0;\n"
12459 "}\n"
12460 "\n";
12461
12462 static const GLchar *tess_eval_shader_template = "VERSION\n"
12463 "#extension GL_ARB_shader_image_load_store : enable\n"
12464 "\n"
12465 "layout(isolines, point_mode) in;\n"
12466 "\n"
12467 "in vec4 tcs_tes_result[];\n"
12468 "out vec4 tes_gs_result;\n"
12469 "\n"
12470 "#if IMAGES\n"
12471 "UNI_GOKU\n"
12472 "#endif\n"
12473 "\n"
12474 "void main()\n"
12475 "{\n"
12476 " vec4 result = vec4(0, 1, 0, 1);\n"
12477 "\n"
12478 "#if IMAGES\n"
12479 "VERIFICATION else\n"
12480 "#endif\n"
12481 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12482 " {\n"
12483 " result = vec4(1, 0, 0, 1);\n"
12484 " }\n"
12485 "\n"
12486 " tes_gs_result = result;\n"
12487 "}\n"
12488 "\n";
12489
12490 static const GLchar *vertex_shader_template = "VERSION\n"
12491 "#extension GL_ARB_shader_image_load_store : enable\n"
12492 "\n"
12493 "out vec4 vs_tcs_result;\n"
12494 "\n"
12495 "#if IMAGES\n"
12496 "UNI_GOKU\n"
12497 "#endif\n"
12498 "\n"
12499 "void main()\n"
12500 "{\n"
12501 " vec4 result = vec4(0, 1, 0, 1);\n"
12502 "\n"
12503 "#if IMAGES\n"
12504 "VERIFICATION"
12505 "#endif\n"
12506 "\n"
12507 " vs_tcs_result = result;\n"
12508 "}\n"
12509 "\n";
12510
12511 const GLchar *shader_template = 0;
12512
12513 switch (in_stage)
12514 {
12515 case Utils::COMPUTE_SHADER:
12516 shader_template = compute_shader_template;
12517 break;
12518 case Utils::FRAGMENT_SHADER:
12519 shader_template = fragment_shader_template;
12520 break;
12521 case Utils::GEOMETRY_SHADER:
12522 shader_template = geometry_shader_template;
12523 break;
12524 case Utils::TESS_CTRL_SHADER:
12525 shader_template = tess_ctrl_shader_template;
12526 break;
12527 case Utils::TESS_EVAL_SHADER:
12528 shader_template = tess_eval_shader_template;
12529 break;
12530 case Utils::VERTEX_SHADER:
12531 shader_template = vertex_shader_template;
12532 break;
12533 default:
12534 TCU_FAIL("Invalid enum");
12535 }
12536
12537 out_source.m_parts[0].m_code = shader_template;
12538
12539 size_t position = 0;
12540
12541 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12542 out_source.m_parts[0].m_code);
12543
12544 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12545
12546 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12547
12548 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12549 }
12550
12551 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12552 *
12553 * @param program Current program
12554 **/
prepareUniforms(Utils::program & program)12555 void BindingImageArrayTest::prepareUniforms(Utils::program &program)
12556 {
12557 static const GLuint goku_data[7] = {
12558 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
12559 };
12560
12561 Utils::texture *textures[7] = {
12562 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12563 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12564 };
12565
12566 for (GLuint i = 0; i < 7; ++i)
12567 {
12568 GLint expected_binding = i + 1;
12569
12570 checkBinding(program, i, expected_binding);
12571
12572 prepareTexture(*textures[i], Utils::buffer(m_context), Utils::TEX_2D, goku_data[i], expected_binding);
12573 }
12574 }
12575
12576 /** Overwrite of releaseResource method, release extra textures
12577 *
12578 * @param ignored
12579 **/
releaseResource()12580 void BindingImageArrayTest::releaseResource()
12581 {
12582 Utils::texture *textures[7] = {
12583 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12584 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12585 };
12586
12587 for (GLuint i = 0; i < 7; ++i)
12588 {
12589 textures[i]->release();
12590 }
12591 }
12592
12593 /** Verifies that API reports correct uniform binding
12594 *
12595 * @param program Program
12596 * @param index Index of array element
12597 * @param expected_binding Expected binding
12598 **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)12599 void BindingImageArrayTest::checkBinding(Utils::program &program, GLuint index, GLint expected_binding)
12600 {
12601 if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
12602 {
12603 TCU_FAIL("Wrong binding reported by API");
12604 }
12605 }
12606
12607 /** Constructor
12608 *
12609 * @param context Test context
12610 **/
BindingImageDefaultTest(deqp::Context & context)12611 BindingImageDefaultTest::BindingImageDefaultTest(deqp::Context &context)
12612 : APITestBase(context, "binding_image_default", "Test verifies default image binding")
12613 {
12614 /* Nothing to be done here */
12615 }
12616
12617 /** Execute API call and verifies results
12618 *
12619 * @return true when results are positive, false otherwise
12620 **/
checkResults(Utils::program & program)12621 bool BindingImageDefaultTest::checkResults(Utils::program &program)
12622 {
12623 return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
12624 }
12625
12626 /** Prepare source for given shader stage
12627 *
12628 * @param in_stage Shader stage, compute shader will use 430
12629 * @param in_use_version_400 Select if 400 or 420 should be used
12630 * @param out_source Prepared shader source instance
12631 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12632 void BindingImageDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12633 Utils::shaderSource &out_source)
12634 {
12635 static const GLchar *uni_goku = "layout(rgba8) uniform image2D goku;\n";
12636
12637 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12638 "\n"
12639 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12640 " {\n"
12641 " result = vec4(1, 0, 0, 1);\n"
12642 " }\n";
12643
12644 static const GLchar *compute_shader_template =
12645 "VERSION\n"
12646 "#extension GL_ARB_shader_image_load_store : enable\n"
12647 "\n"
12648 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12649 "\n"
12650 "writeonly uniform image2D uni_image;\n"
12651 "\n"
12652 "UNI_GOKU\n"
12653 "\n"
12654 "void main()\n"
12655 "{\n"
12656 " vec4 result = vec4(0, 1, 0, 1);\n"
12657 "\n"
12658 "VERIFICATION"
12659 "\n"
12660 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12661 "}\n"
12662 "\n";
12663
12664 static const GLchar *fragment_shader_template = "VERSION\n"
12665 "#extension GL_ARB_shader_image_load_store : enable\n"
12666 "\n"
12667 "in vec4 gs_fs_result;\n"
12668 "out vec4 fs_out_result;\n"
12669 "\n"
12670 "UNI_GOKU\n"
12671 "\n"
12672 "void main()\n"
12673 "{\n"
12674 " vec4 result = vec4(0, 1, 0, 1);\n"
12675 "\n"
12676 "VERIFICATION"
12677 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12678 " {\n"
12679 " result = vec4(1, 0, 0, 1);\n"
12680 " }\n"
12681 "\n"
12682 " fs_out_result = result;\n"
12683 "}\n"
12684 "\n";
12685
12686 static const GLchar *geometry_shader_template = "VERSION\n"
12687 "#extension GL_ARB_shader_image_load_store : enable\n"
12688 "\n"
12689 "layout(points) in;\n"
12690 "layout(triangle_strip, max_vertices = 4) out;\n"
12691 "\n"
12692 "in vec4 tes_gs_result[];\n"
12693 "out vec4 gs_fs_result;\n"
12694 "\n"
12695 "#if IMAGES\n"
12696 "UNI_GOKU\n"
12697 "#endif\n"
12698 "\n"
12699 "void main()\n"
12700 "{\n"
12701 " vec4 result = vec4(0, 1, 0, 1);\n"
12702 "\n"
12703 "#if IMAGES\n"
12704 "VERIFICATION else\n"
12705 "#endif\n"
12706 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12707 " {\n"
12708 " result = vec4(1, 0, 0, 1);\n"
12709 " }\n"
12710 "\n"
12711 " gs_fs_result = result;\n"
12712 " gl_Position = vec4(-1, -1, 0, 1);\n"
12713 " EmitVertex();\n"
12714 " gs_fs_result = result;\n"
12715 " gl_Position = vec4(-1, 1, 0, 1);\n"
12716 " EmitVertex();\n"
12717 " gs_fs_result = result;\n"
12718 " gl_Position = vec4(1, -1, 0, 1);\n"
12719 " EmitVertex();\n"
12720 " gs_fs_result = result;\n"
12721 " gl_Position = vec4(1, 1, 0, 1);\n"
12722 " EmitVertex();\n"
12723 "}\n"
12724 "\n";
12725
12726 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12727 "#extension GL_ARB_shader_image_load_store : enable\n"
12728 "\n"
12729 "layout(vertices = 1) out;\n"
12730 "\n"
12731 "in vec4 vs_tcs_result[];\n"
12732 "out vec4 tcs_tes_result[];\n"
12733 "\n"
12734 "#if IMAGES\n"
12735 "UNI_GOKU\n"
12736 "#endif\n"
12737 "\n"
12738 "void main()\n"
12739 "{\n"
12740 " vec4 result = vec4(0, 1, 0, 1);\n"
12741 "\n"
12742 "#if IMAGES\n"
12743 "VERIFICATION else\n"
12744 "#endif\n"
12745 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12746 " {\n"
12747 " result = vec4(1, 0, 0, 1);\n"
12748 " }\n"
12749 "\n"
12750 " tcs_tes_result[gl_InvocationID] = result;\n"
12751 "\n"
12752 " gl_TessLevelOuter[0] = 1.0;\n"
12753 " gl_TessLevelOuter[1] = 1.0;\n"
12754 " gl_TessLevelOuter[2] = 1.0;\n"
12755 " gl_TessLevelOuter[3] = 1.0;\n"
12756 " gl_TessLevelInner[0] = 1.0;\n"
12757 " gl_TessLevelInner[1] = 1.0;\n"
12758 "}\n"
12759 "\n";
12760
12761 static const GLchar *tess_eval_shader_template = "VERSION\n"
12762 "#extension GL_ARB_shader_image_load_store : enable\n"
12763 "\n"
12764 "layout(isolines, point_mode) in;\n"
12765 "\n"
12766 "in vec4 tcs_tes_result[];\n"
12767 "out vec4 tes_gs_result;\n"
12768 "\n"
12769 "#if IMAGES\n"
12770 "UNI_GOKU\n"
12771 "#endif\n"
12772 "\n"
12773 "void main()\n"
12774 "{\n"
12775 " vec4 result = vec4(0, 1, 0, 1);\n"
12776 "\n"
12777 "#if IMAGES\n"
12778 "VERIFICATION else\n"
12779 "#endif\n"
12780 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12781 " {\n"
12782 " result = vec4(1, 0, 0, 1);\n"
12783 " }\n"
12784 "\n"
12785 " tes_gs_result = result;\n"
12786 "}\n"
12787 "\n";
12788
12789 static const GLchar *vertex_shader_template = "VERSION\n"
12790 "#extension GL_ARB_shader_image_load_store : enable\n"
12791 "\n"
12792 "out vec4 vs_tcs_result;\n"
12793 "\n"
12794 "#if IMAGES\n"
12795 "UNI_GOKU\n"
12796 "#endif\n"
12797 "\n"
12798 "void main()\n"
12799 "{\n"
12800 " vec4 result = vec4(0, 1, 0, 1);\n"
12801 "\n"
12802 "#if IMAGES\n"
12803 "VERIFICATION"
12804 "#endif\n"
12805 "\n"
12806 " vs_tcs_result = result;\n"
12807 "}\n"
12808 "\n";
12809
12810 const GLchar *shader_template = 0;
12811
12812 switch (in_stage)
12813 {
12814 case Utils::COMPUTE_SHADER:
12815 shader_template = compute_shader_template;
12816 break;
12817 case Utils::FRAGMENT_SHADER:
12818 shader_template = fragment_shader_template;
12819 break;
12820 case Utils::GEOMETRY_SHADER:
12821 shader_template = geometry_shader_template;
12822 break;
12823 case Utils::TESS_CTRL_SHADER:
12824 shader_template = tess_ctrl_shader_template;
12825 break;
12826 case Utils::TESS_EVAL_SHADER:
12827 shader_template = tess_eval_shader_template;
12828 break;
12829 case Utils::VERTEX_SHADER:
12830 shader_template = vertex_shader_template;
12831 break;
12832 default:
12833 TCU_FAIL("Invalid enum");
12834 }
12835
12836 out_source.m_parts[0].m_code = shader_template;
12837
12838 size_t position = 0;
12839
12840 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12841 out_source.m_parts[0].m_code);
12842
12843 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12844
12845 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
12846
12847 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12848 }
12849
12850 /** Constructor
12851 *
12852 * @param context Test context
12853 **/
BindingImageAPIOverrideTest(deqp::Context & context)12854 BindingImageAPIOverrideTest::BindingImageAPIOverrideTest(deqp::Context &context)
12855 : BindingImageTest(context, "binding_image_api_override", "Verifies that API can override image binding")
12856 , m_goku_texture(context)
12857 {
12858 /* Nothing to be done here */
12859 }
12860
12861 /** Prepare source for given shader stage
12862 *
12863 * @param in_stage Shader stage, compute shader will use 430
12864 * @param in_use_version_400 Select if 400 or 420 should be used
12865 * @param out_source Prepared shader source instance
12866 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12867 void BindingImageAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12868 Utils::shaderSource &out_source)
12869 {
12870 static const GLchar *uni_goku = "layout(binding = 3, rgba8) uniform image2D goku;\n";
12871
12872 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12873 "\n"
12874 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12875 " {\n"
12876 " result = vec4(1, 0, 0, 1);\n"
12877 " }\n";
12878
12879 static const GLchar *compute_shader_template =
12880 "VERSION\n"
12881 "#extension GL_ARB_shader_image_load_store : enable\n"
12882 "\n"
12883 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12884 "\n"
12885 "writeonly uniform image2D uni_image;\n"
12886 "\n"
12887 "UNI_GOKU\n"
12888 "\n"
12889 "void main()\n"
12890 "{\n"
12891 " vec4 result = vec4(0, 1, 0, 1);\n"
12892 "\n"
12893 "VERIFICATION"
12894 "\n"
12895 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12896 "}\n"
12897 "\n";
12898
12899 static const GLchar *fragment_shader_template = "VERSION\n"
12900 "#extension GL_ARB_shader_image_load_store : enable\n"
12901 "\n"
12902 "in vec4 gs_fs_result;\n"
12903 "out vec4 fs_out_result;\n"
12904 "\n"
12905 "UNI_GOKU\n"
12906 "\n"
12907 "void main()\n"
12908 "{\n"
12909 " vec4 result = vec4(0, 1, 0, 1);\n"
12910 "\n"
12911 "VERIFICATION"
12912 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12913 " {\n"
12914 " result = vec4(1, 0, 0, 1);\n"
12915 " }\n"
12916 "\n"
12917 " fs_out_result = result;\n"
12918 "}\n"
12919 "\n";
12920
12921 static const GLchar *geometry_shader_template = "VERSION\n"
12922 "#extension GL_ARB_shader_image_load_store : enable\n"
12923 "\n"
12924 "layout(points) in;\n"
12925 "layout(triangle_strip, max_vertices = 4) out;\n"
12926 "\n"
12927 "in vec4 tes_gs_result[];\n"
12928 "out vec4 gs_fs_result;\n"
12929 "\n"
12930 "#if IMAGES\n"
12931 "UNI_GOKU\n"
12932 "#endif\n"
12933 "\n"
12934 "void main()\n"
12935 "{\n"
12936 " vec4 result = vec4(0, 1, 0, 1);\n"
12937 "\n"
12938 "#if IMAGES\n"
12939 "VERIFICATION else\n"
12940 "#endif\n"
12941 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12942 " {\n"
12943 " result = vec4(1, 0, 0, 1);\n"
12944 " }\n"
12945 "\n"
12946 " gs_fs_result = result;\n"
12947 " gl_Position = vec4(-1, -1, 0, 1);\n"
12948 " EmitVertex();\n"
12949 " gs_fs_result = result;\n"
12950 " gl_Position = vec4(-1, 1, 0, 1);\n"
12951 " EmitVertex();\n"
12952 " gs_fs_result = result;\n"
12953 " gl_Position = vec4(1, -1, 0, 1);\n"
12954 " EmitVertex();\n"
12955 " gs_fs_result = result;\n"
12956 " gl_Position = vec4(1, 1, 0, 1);\n"
12957 " EmitVertex();\n"
12958 "}\n"
12959 "\n";
12960
12961 static const GLchar *tess_ctrl_shader_template = "VERSION\n"
12962 "#extension GL_ARB_shader_image_load_store : enable\n"
12963 "\n"
12964 "layout(vertices = 1) out;\n"
12965 "\n"
12966 "in vec4 vs_tcs_result[];\n"
12967 "out vec4 tcs_tes_result[];\n"
12968 "\n"
12969 "#if IMAGES\n"
12970 "UNI_GOKU\n"
12971 "#endif\n"
12972 "\n"
12973 "void main()\n"
12974 "{\n"
12975 " vec4 result = vec4(0, 1, 0, 1);\n"
12976 "\n"
12977 "#if IMAGES\n"
12978 "VERIFICATION else\n"
12979 "#endif\n"
12980 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12981 " {\n"
12982 " result = vec4(1, 0, 0, 1);\n"
12983 " }\n"
12984 "\n"
12985 " tcs_tes_result[gl_InvocationID] = result;\n"
12986 "\n"
12987 " gl_TessLevelOuter[0] = 1.0;\n"
12988 " gl_TessLevelOuter[1] = 1.0;\n"
12989 " gl_TessLevelOuter[2] = 1.0;\n"
12990 " gl_TessLevelOuter[3] = 1.0;\n"
12991 " gl_TessLevelInner[0] = 1.0;\n"
12992 " gl_TessLevelInner[1] = 1.0;\n"
12993 "}\n"
12994 "\n";
12995
12996 static const GLchar *tess_eval_shader_template = "VERSION\n"
12997 "#extension GL_ARB_shader_image_load_store : enable\n"
12998 "\n"
12999 "layout(isolines, point_mode) in;\n"
13000 "\n"
13001 "in vec4 tcs_tes_result[];\n"
13002 "out vec4 tes_gs_result;\n"
13003 "\n"
13004 "#if IMAGES\n"
13005 "UNI_GOKU\n"
13006 "#endif\n"
13007 "\n"
13008 "void main()\n"
13009 "{\n"
13010 " vec4 result = vec4(0, 1, 0, 1);\n"
13011 "\n"
13012 "#if IMAGES\n"
13013 "VERIFICATION else\n"
13014 "#endif\n"
13015 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13016 " {\n"
13017 " result = vec4(1, 0, 0, 1);\n"
13018 " }\n"
13019 "\n"
13020 " tes_gs_result = result;\n"
13021 "}\n"
13022 "\n";
13023
13024 static const GLchar *vertex_shader_template = "VERSION\n"
13025 "#extension GL_ARB_shader_image_load_store : enable\n"
13026 "\n"
13027 "out vec4 vs_tcs_result;\n"
13028 "\n"
13029 "#if IMAGES\n"
13030 "UNI_GOKU\n"
13031 "#endif\n"
13032 "\n"
13033 "void main()\n"
13034 "{\n"
13035 " vec4 result = vec4(0, 1, 0, 1);\n"
13036 "\n"
13037 "#if IMAGES\n"
13038 "VERIFICATION"
13039 "#endif\n"
13040 "\n"
13041 " vs_tcs_result = result;\n"
13042 "}\n"
13043 "\n";
13044
13045 const GLchar *shader_template = 0;
13046
13047 switch (in_stage)
13048 {
13049 case Utils::COMPUTE_SHADER:
13050 shader_template = compute_shader_template;
13051 break;
13052 case Utils::FRAGMENT_SHADER:
13053 shader_template = fragment_shader_template;
13054 break;
13055 case Utils::GEOMETRY_SHADER:
13056 shader_template = geometry_shader_template;
13057 break;
13058 case Utils::TESS_CTRL_SHADER:
13059 shader_template = tess_ctrl_shader_template;
13060 break;
13061 case Utils::TESS_EVAL_SHADER:
13062 shader_template = tess_eval_shader_template;
13063 break;
13064 case Utils::VERTEX_SHADER:
13065 shader_template = vertex_shader_template;
13066 break;
13067 default:
13068 TCU_FAIL("Invalid enum");
13069 }
13070
13071 out_source.m_parts[0].m_code = shader_template;
13072
13073 size_t position = 0;
13074
13075 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13076 out_source.m_parts[0].m_code);
13077
13078 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13079
13080 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0", out_source.m_parts[0].m_code);
13081
13082 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13083 }
13084
13085 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
13086 *
13087 * @param program Current program
13088 **/
prepareUniforms(Utils::program & program)13089 void BindingImageAPIOverrideTest::prepareUniforms(Utils::program &program)
13090 {
13091 static const GLuint goku_data = 0x000000ff;
13092 static const GLint new_binding = 7;
13093
13094 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
13095
13096 const GLint uniform_location = program.getUniformLocation("goku");
13097 if (-1 == uniform_location)
13098 {
13099 TCU_FAIL("Uniform is inactive");
13100 }
13101
13102 gl.uniform1i(uniform_location, new_binding);
13103
13104 GLint binding = -1;
13105
13106 gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
13107 GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
13108
13109 if (new_binding != binding)
13110 {
13111 TCU_FAIL("Wrong binding value");
13112 return;
13113 }
13114
13115 prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, new_binding);
13116 }
13117
13118 /** Overwrite of releaseResource method, release extra texture
13119 *
13120 * @param ignored
13121 **/
releaseResource()13122 void BindingImageAPIOverrideTest::releaseResource()
13123 {
13124 m_goku_texture.release();
13125 }
13126
13127 /** Constructor
13128 *
13129 * @param context Test context
13130 **/
BindingImageInvalidTest(deqp::Context & context)13131 BindingImageInvalidTest::BindingImageInvalidTest(deqp::Context &context)
13132 : NegativeTestBase(context, "binding_image_invalid", "Test verifies invalid binding values")
13133 {
13134 /* Nothing to be done here */
13135 }
13136
13137 /** Set up next test case
13138 *
13139 * @param test_case_index Index of next test case
13140 *
13141 * @return false if there is no more test cases, true otherwise
13142 **/
prepareNextTestCase(glw::GLuint test_case_index)13143 bool BindingImageInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
13144 {
13145 switch (test_case_index)
13146 {
13147 case (glw::GLuint)-1:
13148 m_case = TEST_CASES_MAX;
13149 break;
13150 case NEGATIVE_VALUE:
13151 case VARIABLE_NAME:
13152 case STD140:
13153 case MISSING:
13154 m_case = (TESTCASES)test_case_index;
13155 break;
13156 default:
13157 return false;
13158 }
13159
13160 return true;
13161 }
13162
13163 /** Prepare source for given shader stage
13164 *
13165 * @param in_stage Shader stage, compute shader will use 430
13166 * @param in_use_version_400 Select if 400 or 420 should be used
13167 * @param out_source Prepared shader source instance
13168 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13169 void BindingImageInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13170 Utils::shaderSource &out_source)
13171 {
13172 static const GLchar *uni_goku = "layout(binding BINDING, rgba8) uniform image2D goku;\n";
13173
13174 static const GLchar *verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
13175 "\n"
13176 " if (vec4(1, 0, 0, 0) != goku_color)\n"
13177 " {\n"
13178 " result = vec4(1, 0, 0, 1);\n"
13179 " }\n";
13180
13181 static const GLchar *compute_shader_template =
13182 "VERSION\n"
13183 "#extension GL_ARB_shader_image_load_store : enable\n"
13184 "\n"
13185 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13186 "\n"
13187 "writeonly uniform image2D uni_image;\n"
13188 "\n"
13189 "UNI_GOKU\n"
13190 "\n"
13191 "void main()\n"
13192 "{\n"
13193 " vec4 result = vec4(0, 1, 0, 1);\n"
13194 "\n"
13195 "VERIFICATION"
13196 "\n"
13197 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13198 "}\n"
13199 "\n";
13200
13201 static const GLchar *fragment_shader_template = "VERSION\n"
13202 "#extension GL_ARB_shader_image_load_store : enable\n"
13203 "\n"
13204 "in vec4 gs_fs_result;\n"
13205 "out vec4 fs_out_result;\n"
13206 "\n"
13207 "UNI_GOKU\n"
13208 "\n"
13209 "void main()\n"
13210 "{\n"
13211 " vec4 result = vec4(0, 1, 0, 1);\n"
13212 "\n"
13213 "VERIFICATION"
13214 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13215 " {\n"
13216 " result = vec4(1, 0, 0, 1);\n"
13217 " }\n"
13218 "\n"
13219 " fs_out_result = result;\n"
13220 "}\n"
13221 "\n";
13222
13223 static const GLchar *geometry_shader_template = "VERSION\n"
13224 "#extension GL_ARB_shader_image_load_store : enable\n"
13225 "\n"
13226 "layout(points) in;\n"
13227 "layout(triangle_strip, max_vertices = 4) out;\n"
13228 "\n"
13229 "in vec4 tes_gs_result[];\n"
13230 "out vec4 gs_fs_result;\n"
13231 "\n"
13232 "UNI_GOKU\n"
13233 "\n"
13234 "void main()\n"
13235 "{\n"
13236 " vec4 result = vec4(0, 1, 0, 1);\n"
13237 "\n"
13238 "VERIFICATION"
13239 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13240 " {\n"
13241 " result = vec4(1, 0, 0, 1);\n"
13242 " }\n"
13243 "\n"
13244 " gs_fs_result = result;\n"
13245 " gl_Position = vec4(-1, -1, 0, 1);\n"
13246 " EmitVertex();\n"
13247 " gs_fs_result = result;\n"
13248 " gl_Position = vec4(-1, 1, 0, 1);\n"
13249 " EmitVertex();\n"
13250 " gs_fs_result = result;\n"
13251 " gl_Position = vec4(1, -1, 0, 1);\n"
13252 " EmitVertex();\n"
13253 " gs_fs_result = result;\n"
13254 " gl_Position = vec4(1, 1, 0, 1);\n"
13255 " EmitVertex();\n"
13256 "}\n"
13257 "\n";
13258
13259 static const GLchar *tess_ctrl_shader_template =
13260 "VERSION\n"
13261 "#extension GL_ARB_shader_image_load_store : enable\n"
13262 "\n"
13263 "layout(vertices = 1) out;\n"
13264 "\n"
13265 "in vec4 vs_tcs_result[];\n"
13266 "out vec4 tcs_tes_result[];\n"
13267 "\n"
13268 "UNI_GOKU\n"
13269 "\n"
13270 "void main()\n"
13271 "{\n"
13272 " vec4 result = vec4(0, 1, 0, 1);\n"
13273 "\n"
13274 "VERIFICATION"
13275 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13276 " {\n"
13277 " result = vec4(1, 0, 0, 1);\n"
13278 " }\n"
13279 "\n"
13280 " tcs_tes_result[gl_InvocationID] = result;\n"
13281 "\n"
13282 " gl_TessLevelOuter[0] = 1.0;\n"
13283 " gl_TessLevelOuter[1] = 1.0;\n"
13284 " gl_TessLevelOuter[2] = 1.0;\n"
13285 " gl_TessLevelOuter[3] = 1.0;\n"
13286 " gl_TessLevelInner[0] = 1.0;\n"
13287 " gl_TessLevelInner[1] = 1.0;\n"
13288 "}\n"
13289 "\n";
13290
13291 static const GLchar *tess_eval_shader_template = "VERSION\n"
13292 "#extension GL_ARB_shader_image_load_store : enable\n"
13293 "\n"
13294 "layout(isolines, point_mode) in;\n"
13295 "\n"
13296 "in vec4 tcs_tes_result[];\n"
13297 "out vec4 tes_gs_result;\n"
13298 "\n"
13299 "UNI_GOKU\n"
13300 "\n"
13301 "void main()\n"
13302 "{\n"
13303 " vec4 result = vec4(0, 1, 0, 1);\n"
13304 "\n"
13305 "VERIFICATION"
13306 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13307 " {\n"
13308 " result = vec4(1, 0, 0, 1);\n"
13309 " }\n"
13310 "\n"
13311 " tes_gs_result = result;\n"
13312 "}\n"
13313 "\n";
13314
13315 static const GLchar *vertex_shader_template = "VERSION\n"
13316 "#extension GL_ARB_shader_image_load_store : enable\n"
13317 "\n"
13318 "out vec4 vs_tcs_result;\n"
13319 "\n"
13320 "UNI_GOKU\n"
13321 "\n"
13322 "void main()\n"
13323 "{\n"
13324 " vec4 result = vec4(0, 1, 0, 1);\n"
13325 "\n"
13326 "VERIFICATION"
13327 "\n"
13328 " vs_tcs_result = result;\n"
13329 "}\n"
13330 "\n";
13331
13332 const GLchar *shader_template = 0;
13333
13334 switch (in_stage)
13335 {
13336 case Utils::COMPUTE_SHADER:
13337 shader_template = compute_shader_template;
13338 break;
13339 case Utils::FRAGMENT_SHADER:
13340 shader_template = fragment_shader_template;
13341 break;
13342 case Utils::GEOMETRY_SHADER:
13343 shader_template = geometry_shader_template;
13344 break;
13345 case Utils::TESS_CTRL_SHADER:
13346 shader_template = tess_ctrl_shader_template;
13347 break;
13348 case Utils::TESS_EVAL_SHADER:
13349 shader_template = tess_eval_shader_template;
13350 break;
13351 case Utils::VERTEX_SHADER:
13352 shader_template = vertex_shader_template;
13353 break;
13354 default:
13355 TCU_FAIL("Invalid enum");
13356 }
13357
13358 out_source.m_parts[0].m_code = shader_template;
13359
13360 size_t position = 0;
13361
13362 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13363 out_source.m_parts[0].m_code);
13364
13365 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13366
13367 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13368
13369 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
13370 }
13371
getCaseString(TESTCASES test_case)13372 const GLchar *BindingImageInvalidTest::getCaseString(TESTCASES test_case)
13373 {
13374 (void)test_case;
13375 const GLchar *binding = 0;
13376
13377 switch (m_case)
13378 {
13379 case NEGATIVE_VALUE:
13380 binding = "= -1";
13381 break;
13382 case VARIABLE_NAME:
13383 binding = "= goku";
13384 break;
13385 case STD140:
13386 binding = "= std140";
13387 break;
13388 case MISSING:
13389 binding = "";
13390 break;
13391 case TEST_CASES_MAX:
13392 binding = "= 0";
13393 break;
13394 default:
13395 TCU_FAIL("Invalid enum");
13396 }
13397
13398 return binding;
13399 }
13400
13401 /* Constants used by InitializerListTest */
13402 const GLfloat InitializerListTest::m_value = 0.0625f;
13403
13404 /** Constructor
13405 *
13406 * @param context Test context
13407 **/
InitializerListTest(deqp::Context & context)13408 InitializerListTest::InitializerListTest(deqp::Context &context)
13409 : GLSLTestBase(context, "initializer_list", "Test verifies initializer lists")
13410 , m_current_test_case_index(0)
13411 {
13412 /* Nothing to be done here */
13413 }
13414
13415 /** Set up next test case
13416 *
13417 * @param test_case_index Index of next test case
13418 *
13419 * @return false if there is no more test cases, true otherwise
13420 **/
prepareNextTestCase(glw::GLuint test_case_index)13421 bool InitializerListTest::prepareNextTestCase(glw::GLuint test_case_index)
13422 {
13423 m_current_test_case_index = test_case_index;
13424
13425 if ((glw::GLuint)-1 == test_case_index)
13426 {
13427 m_current_test_case_index = 0;
13428 return true;
13429 }
13430 else if (m_test_cases.size() <= test_case_index)
13431 {
13432 return false;
13433 }
13434
13435 logTestCaseName();
13436
13437 return true;
13438 }
13439
13440 /** Overwritte of prepareUniforms method
13441 *
13442 * @param program Current program
13443 **/
prepareUniforms(Utils::program & program)13444 void InitializerListTest::prepareUniforms(Utils::program &program)
13445 {
13446 static const GLfloat float_data[16] = {m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value,
13447 m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value};
13448
13449 program.uniform("uni_matrix", Utils::FLOAT, 4, 4, float_data);
13450 }
13451
13452 /** Prepare source for given shader stage
13453 *
13454 * @param in_stage Shader stage, compute shader will use 430
13455 * @param in_use_version_400 Select if 400 or 420 should be used
13456 * @param out_source Prepared shader source instance
13457 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13458 void InitializerListTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13459 Utils::shaderSource &out_source)
13460 {
13461 static const GLchar *verification_snippet = " TYPE_NAME variableARRAY_DEFINITION = INITIALIZATION;\n"
13462 "\n"
13463 " float sum = SUM;\n"
13464 "\n"
13465 " if (EXPECTED_VALUE != sum)\n"
13466 " {\n"
13467 " result = vec4(1, 0, 0, 1);\n"
13468 " }\n";
13469
13470 static const GLchar *compute_shader_template =
13471 "VERSION\n"
13472 "\n"
13473 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13474 "\n"
13475 "writeonly uniform image2D uni_image;\n"
13476 " uniform mat4 uni_matrix;\n"
13477 "\n"
13478 "TYPE_DEFINITION\n"
13479 "\n"
13480 "void main()\n"
13481 "{\n"
13482 " vec4 result = vec4(0, 1, 0, 1);\n"
13483 "\n"
13484 "VERIFICATION"
13485 "\n"
13486 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13487 "}\n"
13488 "\n";
13489
13490 static const GLchar *fragment_shader_template = "VERSION\n"
13491 "\n"
13492 "in vec4 gs_fs_result;\n"
13493 "out vec4 fs_out_result;\n"
13494 "\n"
13495 "uniform mat4 uni_matrix;\n"
13496 "\n"
13497 "TYPE_DEFINITION\n"
13498 "\n"
13499 "void main()\n"
13500 "{\n"
13501 " vec4 result = vec4(0, 1, 0, 1);\n"
13502 "\n"
13503 "VERIFICATION"
13504 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13505 " {\n"
13506 " result = vec4(1, 0, 0, 1);\n"
13507 " }\n"
13508 "\n"
13509 " fs_out_result = result;\n"
13510 "}\n"
13511 "\n";
13512
13513 static const GLchar *geometry_shader_template = "VERSION\n"
13514 "\n"
13515 "layout(points) in;\n"
13516 "layout(triangle_strip, max_vertices = 4) out;\n"
13517 "\n"
13518 "in vec4 tes_gs_result[];\n"
13519 "out vec4 gs_fs_result;\n"
13520 "\n"
13521 "uniform mat4 uni_matrix;\n"
13522 "\n"
13523 "TYPE_DEFINITION\n"
13524 "\n"
13525 "void main()\n"
13526 "{\n"
13527 " vec4 result = vec4(0, 1, 0, 1);\n"
13528 "\n"
13529 "VERIFICATION"
13530 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13531 " {\n"
13532 " result = vec4(1, 0, 0, 1);\n"
13533 " }\n"
13534 "\n"
13535 " gs_fs_result = result;\n"
13536 " gl_Position = vec4(-1, -1, 0, 1);\n"
13537 " EmitVertex();\n"
13538 " gs_fs_result = result;\n"
13539 " gl_Position = vec4(-1, 1, 0, 1);\n"
13540 " EmitVertex();\n"
13541 " gs_fs_result = result;\n"
13542 " gl_Position = vec4(1, -1, 0, 1);\n"
13543 " EmitVertex();\n"
13544 " gs_fs_result = result;\n"
13545 " gl_Position = vec4(1, 1, 0, 1);\n"
13546 " EmitVertex();\n"
13547 "}\n"
13548 "\n";
13549
13550 static const GLchar *tess_ctrl_shader_template =
13551 "VERSION\n"
13552 "\n"
13553 "layout(vertices = 1) out;\n"
13554 "\n"
13555 "in vec4 vs_tcs_result[];\n"
13556 "out vec4 tcs_tes_result[];\n"
13557 "\n"
13558 "uniform mat4 uni_matrix;\n"
13559 "\n"
13560 "TYPE_DEFINITION\n"
13561 "\n"
13562 "void main()\n"
13563 "{\n"
13564 " vec4 result = vec4(0, 1, 0, 1);\n"
13565 "\n"
13566 "VERIFICATION"
13567 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13568 " {\n"
13569 " result = vec4(1, 0, 0, 1);\n"
13570 " }\n"
13571 "\n"
13572 " tcs_tes_result[gl_InvocationID] = result;\n"
13573 "\n"
13574 " gl_TessLevelOuter[0] = 1.0;\n"
13575 " gl_TessLevelOuter[1] = 1.0;\n"
13576 " gl_TessLevelOuter[2] = 1.0;\n"
13577 " gl_TessLevelOuter[3] = 1.0;\n"
13578 " gl_TessLevelInner[0] = 1.0;\n"
13579 " gl_TessLevelInner[1] = 1.0;\n"
13580 "}\n"
13581 "\n";
13582
13583 static const GLchar *tess_eval_shader_template = "VERSION\n"
13584 "\n"
13585 "layout(isolines, point_mode) in;\n"
13586 "\n"
13587 "in vec4 tcs_tes_result[];\n"
13588 "out vec4 tes_gs_result;\n"
13589 "\n"
13590 "uniform mat4 uni_matrix;\n"
13591 "\n"
13592 "TYPE_DEFINITION\n"
13593 "\n"
13594 "void main()\n"
13595 "{\n"
13596 " vec4 result = vec4(0, 1, 0, 1);\n"
13597 "\n"
13598 "VERIFICATION"
13599 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13600 " {\n"
13601 " result = vec4(1, 0, 0, 1);\n"
13602 " }\n"
13603 "\n"
13604 " tes_gs_result = result;\n"
13605 "}\n"
13606 "\n";
13607
13608 static const GLchar *vertex_shader_template = "VERSION\n"
13609 "\n"
13610 "out vec4 vs_tcs_result;\n"
13611 "\n"
13612 "uniform mat4 uni_matrix;\n"
13613 "\n"
13614 "TYPE_DEFINITION\n"
13615 "\n"
13616 "void main()\n"
13617 "{\n"
13618 " vec4 result = vec4(0, 1, 0, 1);\n"
13619 "\n"
13620 "VERIFICATION"
13621 "\n"
13622 " vs_tcs_result = result;\n"
13623 "}\n"
13624 "\n";
13625
13626 const std::string &array_definition = getArrayDefinition();
13627 const std::string &expected_value = getExpectedValue();
13628 const std::string &initialization = getInitialization();
13629 const GLchar *shader_template = 0;
13630 const std::string &sum = getSum();
13631 const std::string &type_definition = getTypeDefinition();
13632 const std::string &type_name = getTypeName();
13633
13634 switch (in_stage)
13635 {
13636 case Utils::COMPUTE_SHADER:
13637 shader_template = compute_shader_template;
13638 break;
13639 case Utils::FRAGMENT_SHADER:
13640 shader_template = fragment_shader_template;
13641 break;
13642 case Utils::GEOMETRY_SHADER:
13643 shader_template = geometry_shader_template;
13644 break;
13645 case Utils::TESS_CTRL_SHADER:
13646 shader_template = tess_ctrl_shader_template;
13647 break;
13648 case Utils::TESS_EVAL_SHADER:
13649 shader_template = tess_eval_shader_template;
13650 break;
13651 case Utils::VERTEX_SHADER:
13652 shader_template = vertex_shader_template;
13653 break;
13654 default:
13655 TCU_FAIL("Invalid enum");
13656 }
13657
13658 out_source.m_parts[0].m_code = shader_template;
13659
13660 size_t position = 0;
13661 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13662 out_source.m_parts[0].m_code);
13663
13664 Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
13665
13666 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13667
13668 position -= strlen(verification_snippet);
13669
13670 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
13671
13672 Utils::replaceToken("ARRAY_DEFINITION", position, array_definition.c_str(), out_source.m_parts[0].m_code);
13673
13674 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
13675
13676 Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
13677
13678 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
13679 }
13680
13681 /** Prepare test cases
13682 *
13683 * @return true
13684 **/
testInit()13685 bool InitializerListTest::testInit()
13686 {
13687 for (GLuint i = 0; i < TESTED_INITIALIZERS_MAX; ++i)
13688 {
13689 const TESTED_INITIALIZERS l_init = (TESTED_INITIALIZERS)i;
13690
13691 testCase test_case = {l_init, 1, 1};
13692
13693 switch (l_init)
13694 {
13695 case VECTOR:
13696 case ARRAY_VECTOR_CTR:
13697 case ARRAY_VECTOR_LIST:
13698 case UNSIZED_ARRAY_VECTOR:
13699 for (GLuint row = 2; row <= 4; ++row)
13700 {
13701 test_case.m_n_rows = row;
13702
13703 m_test_cases.push_back(test_case);
13704 }
13705
13706 break;
13707
13708 case MATRIX:
13709 case MATRIX_ROWS:
13710 case ARRAY_MATRIX_CTR:
13711 case ARRAY_MATRIX_LIST:
13712 case UNSIZED_ARRAY_MATRIX:
13713 for (GLuint col = 2; col <= 4; ++col)
13714 {
13715 for (GLuint row = 2; row <= 4; ++row)
13716 {
13717 test_case.m_n_cols = col;
13718 test_case.m_n_rows = row;
13719
13720 m_test_cases.push_back(test_case);
13721 }
13722 }
13723
13724 break;
13725
13726 case ARRAY_SCALAR:
13727 case UNSIZED_ARRAY_SCALAR:
13728 m_test_cases.push_back(test_case);
13729
13730 break;
13731
13732 case STRUCT:
13733 case ARRAY_STRUCT:
13734 case NESTED_STRUCT_CTR:
13735 case NESTED_STRUCT_LIST:
13736 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13737 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13738 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13739 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13740 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13741 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13742 case UNSIZED_ARRAY_STRUCT:
13743 test_case.m_n_rows = 4;
13744 m_test_cases.push_back(test_case);
13745
13746 break;
13747 default:
13748 DE_ASSERT(0);
13749 break;
13750 }
13751 }
13752
13753 return true;
13754 }
13755
13756 /** Get string representing "[SIZE]" for current test case
13757 *
13758 * @return String
13759 **/
getArrayDefinition()13760 std::string InitializerListTest::getArrayDefinition()
13761 {
13762 const testCase &test_case = m_test_cases[m_current_test_case_index];
13763
13764 std::string array_definition;
13765
13766 switch (test_case.m_initializer)
13767 {
13768 case VECTOR:
13769 case MATRIX:
13770 case MATRIX_ROWS:
13771 case STRUCT:
13772 case NESTED_STRUCT_CTR:
13773 case NESTED_STRUCT_LIST:
13774 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13775 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13776 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13777 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13778 array_definition = "";
13779 break;
13780 case ARRAY_SCALAR:
13781 case ARRAY_VECTOR_CTR:
13782 case ARRAY_VECTOR_LIST:
13783 case ARRAY_MATRIX_CTR:
13784 case ARRAY_MATRIX_LIST:
13785 case ARRAY_STRUCT:
13786 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13787 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13788 array_definition = "[4]";
13789 break;
13790 case UNSIZED_ARRAY_SCALAR:
13791 case UNSIZED_ARRAY_VECTOR:
13792 case UNSIZED_ARRAY_MATRIX:
13793 case UNSIZED_ARRAY_STRUCT:
13794 array_definition = "[]";
13795 break;
13796 default:
13797 TCU_FAIL("Invalid enum");
13798 }
13799
13800 return array_definition;
13801 }
13802
13803 /** Get string representing expected value of sum for current test case
13804 *
13805 * @return String
13806 **/
getExpectedValue()13807 std::string InitializerListTest::getExpectedValue()
13808 {
13809 const testCase &test_case = m_test_cases[m_current_test_case_index];
13810
13811 GLfloat value = 0.0f;
13812
13813 switch (test_case.m_initializer)
13814 {
13815 case VECTOR:
13816 case MATRIX:
13817 case MATRIX_ROWS:
13818 value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows);
13819 break;
13820 case ARRAY_VECTOR_CTR:
13821 case ARRAY_VECTOR_LIST:
13822 case ARRAY_MATRIX_CTR:
13823 case ARRAY_MATRIX_LIST:
13824 case UNSIZED_ARRAY_VECTOR:
13825 case UNSIZED_ARRAY_MATRIX:
13826 value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows) * 4.0f;
13827 break;
13828 case ARRAY_SCALAR:
13829 case UNSIZED_ARRAY_SCALAR:
13830 value = 4.0f;
13831 break;
13832 case STRUCT:
13833 value = 8.0f;
13834 break;
13835 case NESTED_STRUCT_CTR:
13836 case NESTED_STRUCT_LIST:
13837 value = 12.0f;
13838 break;
13839 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13840 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13841 value = 16.0f;
13842 break;
13843 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13844 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13845 value = 28.0f;
13846 break;
13847 case ARRAY_STRUCT:
13848 case UNSIZED_ARRAY_STRUCT:
13849 value = 32.0f;
13850 break;
13851 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13852 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13853 value = 48.0f;
13854 break;
13855 default:
13856 TCU_FAIL("Invalid enum");
13857 }
13858
13859 value *= m_value;
13860
13861 std::string expected_value;
13862 expected_value.resize(64, 0);
13863
13864 sprintf(&expected_value[0], "%f", value);
13865
13866 return expected_value;
13867 }
13868
13869 /** Get string representing initialization list for current test case
13870 *
13871 * @return String
13872 **/
getInitialization()13873 std::string InitializerListTest::getInitialization()
13874 {
13875 const testCase &test_case = m_test_cases[m_current_test_case_index];
13876
13877 std::string initialization;
13878
13879 switch (test_case.m_initializer)
13880 {
13881 case VECTOR:
13882 initialization.append(getVectorInitializer(0 /*column*/, test_case.m_n_rows));
13883
13884 break;
13885
13886 case MATRIX:
13887 initialization = "{ ";
13888 initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13889 initialization.append(" }");
13890
13891 break;
13892
13893 case MATRIX_ROWS:
13894 {
13895 initialization = "{ ";
13896 initialization.append(getVectorArrayCtr(test_case.m_n_cols, test_case.m_n_rows));
13897 initialization.append(" }");
13898 }
13899 break;
13900
13901 case STRUCT:
13902 initialization = "{ ";
13903 initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
13904 initialization.append(", ");
13905 initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
13906 initialization.append(" }");
13907
13908 break;
13909
13910 case ARRAY_SCALAR:
13911 case UNSIZED_ARRAY_SCALAR:
13912 initialization = "{ ";
13913 initialization.append(getVectorValues(0 /* column */, 4 /* size */));
13914 initialization.append(" }");
13915
13916 break;
13917
13918 case ARRAY_VECTOR_LIST:
13919 case UNSIZED_ARRAY_VECTOR:
13920 initialization = "{ ";
13921 initialization.append(getVectorArrayList(4 /* columns */, test_case.m_n_rows));
13922 initialization.append(" }");
13923
13924 break;
13925
13926 case ARRAY_VECTOR_CTR:
13927 initialization = "{ ";
13928 initialization.append(getVectorArrayCtr(4 /* columns */, test_case.m_n_rows));
13929 initialization.append(" }");
13930
13931 break;
13932
13933 case ARRAY_MATRIX_LIST:
13934 case UNSIZED_ARRAY_MATRIX:
13935 initialization = "{ ";
13936
13937 for (GLuint i = 0; i < 4; ++i)
13938 {
13939 initialization.append("{ ");
13940 initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13941 initialization.append(" }");
13942
13943 if (i + 1 < 4)
13944 {
13945 initialization.append(", ");
13946 }
13947 }
13948
13949 initialization.append(" }");
13950
13951 break;
13952
13953 case ARRAY_MATRIX_CTR:
13954 {
13955 const std::string &type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
13956
13957 initialization = "{ ";
13958
13959 for (GLuint i = 0; i < 4; ++i)
13960 {
13961 initialization.append(type_name);
13962 initialization.append("(");
13963 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
13964 {
13965 initialization.append(getVectorValues(col, test_case.m_n_rows));
13966
13967 if (col + 1 < test_case.m_n_cols)
13968 {
13969 initialization.append(", ");
13970 }
13971 }
13972 initialization.append(")");
13973
13974 if (i + 1 < 4)
13975 {
13976 initialization.append(", ");
13977 }
13978 }
13979
13980 initialization.append(" }");
13981 }
13982 break;
13983
13984 case ARRAY_STRUCT:
13985 case UNSIZED_ARRAY_STRUCT:
13986 initialization = "{ ";
13987
13988 for (GLuint i = 0; i < 4; ++i)
13989 {
13990 initialization.append("{ ");
13991 initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
13992 initialization.append(", ");
13993 initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
13994 initialization.append(" }");
13995
13996 if (i + 1 < 4)
13997 {
13998 initialization.append(", ");
13999 }
14000 }
14001
14002 initialization.append(" }");
14003
14004 break;
14005
14006 case NESTED_STRUCT_CTR:
14007 initialization = "StructureWithStructure(BasicStructure(";
14008 initialization.append(getVectorConstructor(0 /* column */, 4));
14009 initialization.append(", ");
14010 initialization.append(getVectorConstructor(2 /* column */, 4));
14011 initialization.append("), ");
14012 initialization.append(getVectorConstructor(3 /* column */, 4));
14013 initialization.append(")");
14014
14015 break;
14016
14017 case NESTED_STRUCT_LIST:
14018 initialization = "{ { ";
14019 initialization.append(getVectorInitializer(0 /* column */, 4));
14020 initialization.append(", ");
14021 initialization.append(getVectorInitializer(2 /* column */, 4));
14022 initialization.append(" }, ");
14023 initialization.append(getVectorInitializer(3 /* column */, 4));
14024 initialization.append(" }");
14025
14026 break;
14027
14028 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14029 initialization = "{ ";
14030 initialization.append(getVectorInitializer(0 /* column */, 4));
14031 initialization.append(", { ");
14032
14033 for (GLuint i = 0; i < 3; ++i)
14034 {
14035 initialization.append("{ ");
14036 initialization.append(getVectorInitializer(2 /* column */, 4));
14037 initialization.append(", ");
14038 initialization.append(getVectorInitializer(3 /* column */, 4));
14039 initialization.append(" }");
14040
14041 if (i + 1 < 3)
14042 {
14043 initialization.append(", ");
14044 }
14045 }
14046
14047 initialization.append(" } }");
14048
14049 break;
14050
14051 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14052 initialization = "{ ";
14053 initialization.append(getVectorConstructor(0 /* column */, 4));
14054 initialization.append(", { ");
14055
14056 for (GLuint i = 0; i < 3; ++i)
14057 {
14058 initialization.append("{ ");
14059 initialization.append(getVectorInitializer(2 /* column */, 4));
14060 initialization.append(", ");
14061 initialization.append(getVectorConstructor(3 /* column */, 4));
14062 initialization.append(" }");
14063
14064 if (i + 1 < 3)
14065 {
14066 initialization.append(", ");
14067 }
14068 }
14069
14070 initialization.append(" } }");
14071
14072 break;
14073
14074 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14075 initialization = "{ ";
14076
14077 for (GLuint i = 0; i < 4; ++i)
14078 {
14079 initialization.append("{ { ");
14080
14081 initialization.append(getVectorInitializer(0 /* column */, 4));
14082 initialization.append(", ");
14083 initialization.append(getVectorInitializer(1 /* column */, 4));
14084
14085 initialization.append(" }, ");
14086
14087 initialization.append(getVectorInitializer(2 /* column */, 4));
14088
14089 initialization.append(" }");
14090
14091 if (i + 1 < 4)
14092 {
14093 initialization.append(", ");
14094 }
14095 }
14096
14097 initialization.append(" }");
14098
14099 break;
14100
14101 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14102 initialization = "{\n";
14103
14104 for (GLuint i = 0; i < 2; ++i)
14105 {
14106 initialization.append("StructureWithStructure(\n");
14107 initialization.append("BasicStructure(");
14108
14109 initialization.append(getVectorConstructor(0 /* column */, 4));
14110 initialization.append(" , ");
14111 initialization.append(getVectorConstructor(1 /* column */, 4));
14112
14113 initialization.append("), ");
14114
14115 initialization.append(getVectorConstructor(2 /* column */, 4));
14116
14117 initialization.append(")");
14118
14119 initialization.append(" , ");
14120
14121 initialization.append("{ { ");
14122
14123 initialization.append(getVectorInitializer(0 /* column */, 4));
14124 initialization.append(", ");
14125 initialization.append(getVectorInitializer(1 /* column */, 4));
14126
14127 initialization.append(" }, ");
14128
14129 initialization.append(getVectorInitializer(2 /* column */, 4));
14130
14131 initialization.append(" }");
14132
14133 if (i + 1 < 2)
14134 {
14135 initialization.append(" , ");
14136 }
14137 }
14138
14139 initialization.append(" }");
14140
14141 break;
14142
14143 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14144 initialization = "{ ";
14145 initialization.append("{ ");
14146 initialization.append(getVectorInitializer(0 /* column */, 4));
14147 initialization.append(", ");
14148 initialization.append("{ ");
14149 initialization.append(getVectorInitializer(1 /* column */, 4));
14150 initialization.append(", ");
14151 initialization.append(getVectorInitializer(2 /* column */, 4));
14152 initialization.append(" }");
14153 initialization.append(" }");
14154 initialization.append(", ");
14155 initialization.append(getVectorInitializer(3 /* column */, 4));
14156 initialization.append(" }");
14157
14158 break;
14159
14160 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14161 initialization = "StructureWithStructureWithArray(";
14162 initialization.append("StructureWithArray(");
14163 initialization.append(getVectorConstructor(0 /* column */, 4));
14164 initialization.append(" , vec4[2]( ");
14165 initialization.append(getVectorConstructor(1 /* column */, 4));
14166 initialization.append(" , ");
14167 initialization.append(getVectorConstructor(2 /* column */, 4));
14168 initialization.append(" )");
14169 initialization.append(")");
14170 initialization.append(" , ");
14171 initialization.append(getVectorConstructor(3 /* column */, 4));
14172 initialization.append(")");
14173
14174 break;
14175
14176 default:
14177 TCU_FAIL("Invalid enum");
14178 }
14179
14180 return initialization;
14181 }
14182
14183 /** Logs description of current test case
14184 *
14185 **/
logTestCaseName()14186 void InitializerListTest::logTestCaseName()
14187 {
14188 const testCase &test_case = m_test_cases[m_current_test_case_index];
14189
14190 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
14191
14192 switch (test_case.m_initializer)
14193 {
14194 case VECTOR:
14195 message << "List. Single vec" << test_case.m_n_rows;
14196 break;
14197 case MATRIX:
14198 message << "List. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14199 break;
14200 case MATRIX_ROWS:
14201 message << "Ctr. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14202 break;
14203 case STRUCT:
14204 message << "List. Structure";
14205 break;
14206 case NESTED_STRUCT_CTR:
14207 message << "Ctr. Nested structure";
14208 break;
14209 case NESTED_STRUCT_LIST:
14210 message << "List. Nested structure";
14211 break;
14212 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14213 message << "List. Structure with structure array";
14214 break;
14215 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14216 message << "Mix. Structure with structure array";
14217 break;
14218 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14219 message << "List. Structure with structure with array";
14220 break;
14221 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14222 message << "Mix. Structure with structure with array";
14223 break;
14224 case ARRAY_SCALAR:
14225 message << "List. Array of scalars";
14226 break;
14227 case ARRAY_VECTOR_CTR:
14228 message << "Ctr. Array of vec" << test_case.m_n_rows;
14229 break;
14230 case ARRAY_VECTOR_LIST:
14231 message << "List. Array of vec" << test_case.m_n_rows;
14232 break;
14233 case ARRAY_MATRIX_CTR:
14234 message << "Ctr. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14235 break;
14236 case ARRAY_MATRIX_LIST:
14237 message << "List. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14238 break;
14239 case ARRAY_STRUCT:
14240 message << "List. Array of structures";
14241 break;
14242 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14243 message << "List. Array of structures with structures";
14244 break;
14245 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14246 message << "Mix. Array of structures with structures";
14247 break;
14248 case UNSIZED_ARRAY_SCALAR:
14249 message << "List. Unsized array of scalars";
14250 break;
14251 case UNSIZED_ARRAY_VECTOR:
14252 message << "List. Unsized array of vec" << test_case.m_n_rows;
14253 break;
14254 case UNSIZED_ARRAY_MATRIX:
14255 message << "List. Unsized array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14256 break;
14257 case UNSIZED_ARRAY_STRUCT:
14258 message << "List. Unsized array of structures";
14259 break;
14260 default:
14261 TCU_FAIL("Invalid enum");
14262 }
14263
14264 message << tcu::TestLog::EndMessage;
14265 }
14266
14267 /** Get string representing sum for current test case
14268 *
14269 * @return String
14270 **/
getSum()14271 std::string InitializerListTest::getSum()
14272 {
14273 static const GLchar *var = "variable";
14274
14275 const testCase &test_case = m_test_cases[m_current_test_case_index];
14276
14277 std::string sum;
14278
14279 switch (test_case.m_initializer)
14280 {
14281 case VECTOR:
14282 sum = getVectorSum(var, test_case.m_n_rows);
14283
14284 break;
14285
14286 case MATRIX:
14287 case MATRIX_ROWS:
14288 sum = getVectorArraySum("variable[INDEX]", test_case.m_n_cols, test_case.m_n_rows);
14289
14290 break;
14291
14292 case STRUCT:
14293 sum = getVectorSum("variable.member_a", test_case.m_n_rows);
14294 sum.append(" + ");
14295 sum.append(getVectorSum("variable.member_b", test_case.m_n_rows));
14296
14297 break;
14298
14299 case ARRAY_SCALAR:
14300 case UNSIZED_ARRAY_SCALAR:
14301 sum = "variable[0] + variable[1] + variable[2] + variable[3]";
14302
14303 break;
14304
14305 case ARRAY_VECTOR_LIST:
14306 case ARRAY_VECTOR_CTR:
14307 case UNSIZED_ARRAY_VECTOR:
14308 sum = getVectorArraySum("variable[INDEX]", 4 /* columns */, test_case.m_n_rows);
14309
14310 break;
14311
14312 case ARRAY_MATRIX_LIST:
14313 case ARRAY_MATRIX_CTR:
14314 case UNSIZED_ARRAY_MATRIX:
14315 sum.append(getVectorArraySum("variable[0][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14316 sum.append(" + ");
14317 sum.append(getVectorArraySum("variable[1][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14318 sum.append(" + ");
14319 sum.append(getVectorArraySum("variable[2][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14320 sum.append(" + ");
14321 sum.append(getVectorArraySum("variable[3][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14322
14323 break;
14324
14325 case ARRAY_STRUCT:
14326 case UNSIZED_ARRAY_STRUCT:
14327 sum.append(getVectorArraySum("variable[INDEX].member_a", 4, test_case.m_n_rows));
14328 sum.append(" + ");
14329 sum.append(getVectorArraySum("variable[INDEX].member_b", 4, test_case.m_n_rows));
14330
14331 break;
14332
14333 case NESTED_STRUCT_CTR:
14334 case NESTED_STRUCT_LIST:
14335 sum.append(getVectorSum("variable.member_a.member_a", 4));
14336 sum.append(" + ");
14337 sum.append(getVectorSum("variable.member_a.member_b", 4));
14338 sum.append(" + ");
14339 sum.append(getVectorSum("variable.member_b", 4));
14340
14341 break;
14342
14343 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14344 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14345 sum.append(getVectorSum("variable.member_a", 4));
14346 sum.append(" + ");
14347 sum.append(getVectorArraySum("variable.member_b[INDEX].member_a", 3, 4));
14348 sum.append(" + ");
14349 sum.append(getVectorArraySum("variable.member_b[INDEX].member_b", 3, 4));
14350
14351 break;
14352
14353 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14354 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14355 sum.append(getVectorArraySum("variable[INDEX].member_a.member_a", 4, 4));
14356 sum.append(" + ");
14357 sum.append(getVectorArraySum("variable[INDEX].member_a.member_b", 4, 4));
14358 sum.append(" + ");
14359 sum.append(getVectorArraySum("variable[INDEX].member_b", 4, 4));
14360
14361 break;
14362
14363 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14364 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14365 sum.append(getVectorSum("variable.member_a.member_a", 4));
14366 sum.append(" + ");
14367 sum.append(getVectorArraySum("variable.member_a.member_b[INDEX]", 2, 4));
14368 sum.append(" + ");
14369 sum.append(getVectorSum("variable.member_b", 4));
14370
14371 break;
14372
14373 default:
14374 TCU_FAIL("Invalid enum");
14375 }
14376
14377 return sum;
14378 }
14379
14380 /** Get string representing types definition for current test case
14381 *
14382 * @return String
14383 **/
getTypeDefinition()14384 std::string InitializerListTest::getTypeDefinition()
14385 {
14386 const testCase &test_case = m_test_cases[m_current_test_case_index];
14387
14388 static const GLchar *basic_struct = "struct BasicStructure {\n"
14389 " vec4 member_a;\n"
14390 " vec4 member_b;\n"
14391 "};\n";
14392
14393 static const GLchar *struct_with_array = "struct StructureWithArray {\n"
14394 " vec4 member_a;\n"
14395 " vec4 member_b[2];\n"
14396 "};\n";
14397
14398 static const GLchar *struct_with_struct = "struct StructureWithStructure {\n"
14399 " BasicStructure member_a;\n"
14400 " vec4 member_b;\n"
14401 "};\n";
14402
14403 static const GLchar *struct_with_struct_array = "struct StructureWithStructArray {\n"
14404 " vec4 member_a;\n"
14405 " BasicStructure member_b[3];\n"
14406 "};\n";
14407
14408 static const GLchar *struct_with_struct_with_array = "struct StructureWithStructureWithArray {\n"
14409 " StructureWithArray member_a;\n"
14410 " vec4 member_b;\n"
14411 "};\n";
14412
14413 std::string type_definition;
14414
14415 switch (test_case.m_initializer)
14416 {
14417 case VECTOR:
14418 case MATRIX:
14419 case MATRIX_ROWS:
14420 case ARRAY_SCALAR:
14421 case ARRAY_VECTOR_CTR:
14422 case ARRAY_VECTOR_LIST:
14423 case ARRAY_MATRIX_CTR:
14424 case ARRAY_MATRIX_LIST:
14425 case UNSIZED_ARRAY_SCALAR:
14426 case UNSIZED_ARRAY_VECTOR:
14427 case UNSIZED_ARRAY_MATRIX:
14428 type_definition = "";
14429 break;
14430 case STRUCT:
14431 case ARRAY_STRUCT:
14432 case UNSIZED_ARRAY_STRUCT:
14433 type_definition = basic_struct;
14434 break;
14435 case NESTED_STRUCT_CTR:
14436 case NESTED_STRUCT_LIST:
14437 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14438 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14439 type_definition = basic_struct;
14440 type_definition.append(struct_with_struct);
14441 break;
14442 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14443 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14444 type_definition = basic_struct;
14445 type_definition.append(struct_with_struct_array);
14446 break;
14447 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14448 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14449 type_definition = struct_with_array;
14450 type_definition.append(struct_with_struct_with_array);
14451 break;
14452 default:
14453 TCU_FAIL("Invalid enum");
14454 }
14455
14456 return type_definition;
14457 }
14458
14459 /** Get string representing name of variable's type for current test case
14460 *
14461 * @return String
14462 **/
getTypeName()14463 std::string InitializerListTest::getTypeName()
14464 {
14465 const testCase &test_case = m_test_cases[m_current_test_case_index];
14466
14467 static const GLchar *basic_struct = "BasicStructure";
14468
14469 static const GLchar *struct_with_struct = "StructureWithStructure";
14470
14471 static const GLchar *struct_with_struct_array = "StructureWithStructArray";
14472
14473 static const GLchar *struct_with_struct_with_array = "StructureWithStructureWithArray";
14474
14475 std::string type_name;
14476
14477 switch (test_case.m_initializer)
14478 {
14479 case VECTOR:
14480 case MATRIX:
14481 case MATRIX_ROWS:
14482 case ARRAY_VECTOR_CTR:
14483 case ARRAY_VECTOR_LIST:
14484 case ARRAY_MATRIX_CTR:
14485 case ARRAY_MATRIX_LIST:
14486 case UNSIZED_ARRAY_VECTOR:
14487 case UNSIZED_ARRAY_MATRIX:
14488 type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
14489 break;
14490 case STRUCT:
14491 case ARRAY_STRUCT:
14492 case UNSIZED_ARRAY_STRUCT:
14493 type_name = basic_struct;
14494 break;
14495 case NESTED_STRUCT_CTR:
14496 case NESTED_STRUCT_LIST:
14497 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14498 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14499 type_name = struct_with_struct;
14500 break;
14501 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14502 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14503 type_name = struct_with_struct_array;
14504 break;
14505 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14506 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14507 type_name = struct_with_struct_with_array;
14508 break;
14509 case ARRAY_SCALAR:
14510 case UNSIZED_ARRAY_SCALAR:
14511 type_name = "float";
14512 break;
14513 default:
14514 TCU_FAIL("Invalid enum");
14515 }
14516
14517 return type_name;
14518 }
14519
14520 /** Get string representing array of vector constructors
14521 *
14522 * @param columns Number of columns
14523 * @param size Size of vector
14524 *
14525 * @return String
14526 **/
getVectorArrayCtr(GLuint columns,GLuint size)14527 std::string InitializerListTest::getVectorArrayCtr(GLuint columns, GLuint size)
14528 {
14529 std::string result;
14530
14531 for (GLuint col = 0; col < columns; ++col)
14532 {
14533 result.append(getVectorConstructor(col, size));
14534
14535 if (col + 1 < columns)
14536 {
14537 result.append(", ");
14538 }
14539 }
14540
14541 return result;
14542 }
14543
14544 /** Get string representing array of vector initializers
14545 *
14546 * @param columns Number of columns
14547 * @param size Size of vector
14548 *
14549 * @return String
14550 **/
getVectorArrayList(GLuint columns,GLuint size)14551 std::string InitializerListTest::getVectorArrayList(GLuint columns, GLuint size)
14552 {
14553 std::string result;
14554
14555 for (GLuint col = 0; col < columns; ++col)
14556 {
14557 result.append(getVectorInitializer(col, size));
14558
14559 if (col + 1 < columns)
14560 {
14561 result.append(", ");
14562 }
14563 }
14564
14565 return result;
14566 }
14567
14568 /** Get string representing vector constructor
14569 *
14570 * @param column Index of column of uni_matrix to use as data source
14571 * @param size Size of vector
14572 *
14573 * @return String
14574 **/
getVectorConstructor(GLuint column,GLuint size)14575 std::string InitializerListTest::getVectorConstructor(GLuint column, GLuint size)
14576 {
14577 const std::string &type_name = Utils::getTypeName(Utils::FLOAT, 1 /*n_cols*/, size);
14578
14579 std::string result;
14580
14581 result.append(type_name);
14582 result.append("(");
14583 result.append(getVectorValues(column, size));
14584 result.append(")");
14585
14586 return result;
14587 }
14588
14589 /** Get string representing vector initializer
14590 *
14591 * @param column Index of column of uni_matrix to use as data source
14592 * @param size Size of vector
14593 *
14594 * @return String
14595 **/
getVectorInitializer(GLuint column,GLuint size)14596 std::string InitializerListTest::getVectorInitializer(GLuint column, GLuint size)
14597 {
14598 std::string result;
14599
14600 result.append("{");
14601 result.append(getVectorValues(column, size));
14602 result.append("}");
14603
14604 return result;
14605 }
14606
14607 /** Get string representing sum of vector array. Token INDEX in name will be replaced with element index.
14608 *
14609 * @param array_name Name of array variable
14610 * @param columns Number of columns to sum
14611 * @param size Size of vector
14612 *
14613 * @return String
14614 **/
getVectorArraySum(const GLchar * array_name,GLuint columns,GLuint size)14615 std::string InitializerListTest::getVectorArraySum(const GLchar *array_name, GLuint columns, GLuint size)
14616 {
14617 static const GLchar *lut[] = {"0", "1", "2", "3"};
14618
14619 std::string sum;
14620
14621 for (GLuint i = 0; i < columns; ++i)
14622 {
14623 size_t position = 0;
14624 std::string name = array_name;
14625
14626 Utils::replaceToken("INDEX", position, lut[i], name);
14627
14628 sum.append(getVectorSum(name.c_str(), size));
14629
14630 if (i + 1 < columns)
14631 {
14632 sum.append(" + ");
14633 }
14634 }
14635
14636 return sum;
14637 }
14638
14639 /** Get string representing sum of vectors' elements
14640 *
14641 * @param vector_name Name of vector variable
14642 * @param size Size of vector
14643 *
14644 * @return String
14645 **/
getVectorSum(const GLchar * vector_name,GLuint size)14646 std::string InitializerListTest::getVectorSum(const GLchar *vector_name, GLuint size)
14647 {
14648 static const GLchar *lut[] = {
14649 ".x",
14650 ".y",
14651 ".z",
14652 ".w",
14653 };
14654
14655 std::string sum;
14656
14657 for (GLuint i = 0; i < size; ++i)
14658 {
14659 sum.append(vector_name);
14660 sum.append(lut[i]);
14661
14662 if (i + 1 < size)
14663 {
14664 sum.append(" + ");
14665 }
14666 }
14667
14668 return sum;
14669 }
14670
14671 /** Get string representing vector values
14672 *
14673 * @param column Index of column of uni_matrix to use as data source
14674 * @param size Size of vector
14675 *
14676 * @return String
14677 **/
getVectorValues(GLuint column,GLuint size)14678 std::string InitializerListTest::getVectorValues(GLuint column, GLuint size)
14679 {
14680 const GLchar *init_template = 0;
14681 const GLchar *column_index = 0;
14682
14683 switch (size)
14684 {
14685 case 2:
14686 init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y";
14687 break;
14688 case 3:
14689 init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z";
14690 break;
14691 case 4:
14692 init_template = "uni_matrix[COLUMN].z, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z, uni_matrix[COLUMN].w";
14693 break;
14694 }
14695
14696 switch (column)
14697 {
14698 case 0:
14699 column_index = "0";
14700 break;
14701 case 1:
14702 column_index = "1";
14703 break;
14704 case 2:
14705 column_index = "2";
14706 break;
14707 case 3:
14708 column_index = "3";
14709 break;
14710 }
14711
14712 std::string initializer = init_template;
14713
14714 Utils::replaceAllTokens("COLUMN", column_index, initializer);
14715
14716 return initializer;
14717 }
14718
14719 /** Constructor
14720 *
14721 * @param context Test context
14722 **/
InitializerListNegativeTest(deqp::Context & context)14723 InitializerListNegativeTest::InitializerListNegativeTest(deqp::Context &context)
14724 : NegativeTestBase(context, "initializer_list_negative", "Verifies invalid initializers")
14725 , m_current_test_case_index(0)
14726 {
14727 /* Nothing to be done here */
14728 }
14729
14730 /** Set up next test case
14731 *
14732 * @param test_case_index Index of next test case
14733 *
14734 * @return false if there is no more test cases, true otherwise
14735 **/
prepareNextTestCase(glw::GLuint test_case_index)14736 bool InitializerListNegativeTest::prepareNextTestCase(glw::GLuint test_case_index)
14737 {
14738 m_current_test_case_index = test_case_index;
14739
14740 if ((glw::GLuint)-1 == test_case_index)
14741 {
14742 m_current_test_case_index = 0;
14743 return true;
14744 }
14745 else if (m_test_cases.size() <= test_case_index)
14746 {
14747 return false;
14748 }
14749
14750 logTestCaseName();
14751
14752 return true;
14753 }
14754
14755 /** Prepare source for given shader stage
14756 *
14757 * @param in_stage Shader stage, compute shader will use 430
14758 * @param in_use_version_400 Select if 400 or 420 should be used
14759 * @param out_source Prepared shader source instance
14760 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)14761 void InitializerListNegativeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
14762 Utils::shaderSource &out_source)
14763 {
14764 static const GLchar *verification_snippet = " TYPE_NAME variable = INITIALIZATION;\n"
14765 "\n"
14766 " float sum = SUM;\n"
14767 "\n"
14768 " if (0 != sum)\n"
14769 " {\n"
14770 " result = vec4(1, 0, 0, 1);\n"
14771 " }\n";
14772
14773 static const GLchar *compute_shader_template =
14774 "VERSION\n"
14775 "\n"
14776 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
14777 "\n"
14778 "writeonly uniform image2D uni_image;\n"
14779 "\n"
14780 "TYPE_DEFINITION\n"
14781 "\n"
14782 "void main()\n"
14783 "{\n"
14784 " vec4 result = vec4(0, 1, 0, 1);\n"
14785 "\n"
14786 "VERIFICATION"
14787 "\n"
14788 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
14789 "}\n"
14790 "\n";
14791
14792 static const GLchar *fragment_shader_template = "VERSION\n"
14793 "\n"
14794 "in vec4 gs_fs_result;\n"
14795 "out vec4 fs_out_result;\n"
14796 "\n"
14797 "TYPE_DEFINITION\n"
14798 "\n"
14799 "void main()\n"
14800 "{\n"
14801 " vec4 result = vec4(0, 1, 0, 1);\n"
14802 "\n"
14803 "VERIFICATION"
14804 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
14805 " {\n"
14806 " result = vec4(1, 0, 0, 1);\n"
14807 " }\n"
14808 "\n"
14809 " fs_out_result = result;\n"
14810 "}\n"
14811 "\n";
14812
14813 static const GLchar *geometry_shader_template = "VERSION\n"
14814 "\n"
14815 "layout(points) in;\n"
14816 "layout(triangle_strip, max_vertices = 4) out;\n"
14817 "\n"
14818 "in vec4 tes_gs_result[];\n"
14819 "out vec4 gs_fs_result;\n"
14820 "\n"
14821 "TYPE_DEFINITION\n"
14822 "\n"
14823 "void main()\n"
14824 "{\n"
14825 " vec4 result = vec4(0, 1, 0, 1);\n"
14826 "\n"
14827 "VERIFICATION"
14828 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
14829 " {\n"
14830 " result = vec4(1, 0, 0, 1);\n"
14831 " }\n"
14832 "\n"
14833 " gs_fs_result = result;\n"
14834 " gl_Position = vec4(-1, -1, 0, 1);\n"
14835 " EmitVertex();\n"
14836 " gs_fs_result = result;\n"
14837 " gl_Position = vec4(-1, 1, 0, 1);\n"
14838 " EmitVertex();\n"
14839 " gs_fs_result = result;\n"
14840 " gl_Position = vec4(1, -1, 0, 1);\n"
14841 " EmitVertex();\n"
14842 " gs_fs_result = result;\n"
14843 " gl_Position = vec4(1, 1, 0, 1);\n"
14844 " EmitVertex();\n"
14845 "}\n"
14846 "\n";
14847
14848 static const GLchar *tess_ctrl_shader_template =
14849 "VERSION\n"
14850 "\n"
14851 "layout(vertices = 1) out;\n"
14852 "\n"
14853 "in vec4 vs_tcs_result[];\n"
14854 "out vec4 tcs_tes_result[];\n"
14855 "\n"
14856 "TYPE_DEFINITION\n"
14857 "\n"
14858 "void main()\n"
14859 "{\n"
14860 " vec4 result = vec4(0, 1, 0, 1);\n"
14861 "\n"
14862 "VERIFICATION"
14863 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
14864 " {\n"
14865 " result = vec4(1, 0, 0, 1);\n"
14866 " }\n"
14867 "\n"
14868 " tcs_tes_result[gl_InvocationID] = result;\n"
14869 "\n"
14870 " gl_TessLevelOuter[0] = 1.0;\n"
14871 " gl_TessLevelOuter[1] = 1.0;\n"
14872 " gl_TessLevelOuter[2] = 1.0;\n"
14873 " gl_TessLevelOuter[3] = 1.0;\n"
14874 " gl_TessLevelInner[0] = 1.0;\n"
14875 " gl_TessLevelInner[1] = 1.0;\n"
14876 "}\n"
14877 "\n";
14878
14879 static const GLchar *tess_eval_shader_template = "VERSION\n"
14880 "\n"
14881 "layout(isolines, point_mode) in;\n"
14882 "\n"
14883 "in vec4 tcs_tes_result[];\n"
14884 "out vec4 tes_gs_result;\n"
14885 "\n"
14886 "TYPE_DEFINITION\n"
14887 "\n"
14888 "void main()\n"
14889 "{\n"
14890 " vec4 result = vec4(0, 1, 0, 1);\n"
14891 "\n"
14892 "VERIFICATION"
14893 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
14894 " {\n"
14895 " result = vec4(1, 0, 0, 1);\n"
14896 " }\n"
14897 "\n"
14898 " tes_gs_result = result;\n"
14899 "}\n"
14900 "\n";
14901
14902 static const GLchar *vertex_shader_template = "VERSION\n"
14903 "\n"
14904 "out vec4 vs_tcs_result;\n"
14905 "\n"
14906 "TYPE_DEFINITION\n"
14907 "\n"
14908 "void main()\n"
14909 "{\n"
14910 " vec4 result = vec4(0, 1, 0, 1);\n"
14911 "\n"
14912 "VERIFICATION"
14913 "\n"
14914 " vs_tcs_result = result;\n"
14915 "}\n"
14916 "\n";
14917
14918 const std::string &initialization = getInitialization();
14919 const GLchar *shader_template = 0;
14920 const std::string &sum = getSum();
14921 const std::string &type_definition = getTypeDefinition();
14922 const std::string &type_name = getTypeName();
14923
14924 switch (in_stage)
14925 {
14926 case Utils::COMPUTE_SHADER:
14927 shader_template = compute_shader_template;
14928 break;
14929 case Utils::FRAGMENT_SHADER:
14930 shader_template = fragment_shader_template;
14931 break;
14932 case Utils::GEOMETRY_SHADER:
14933 shader_template = geometry_shader_template;
14934 break;
14935 case Utils::TESS_CTRL_SHADER:
14936 shader_template = tess_ctrl_shader_template;
14937 break;
14938 case Utils::TESS_EVAL_SHADER:
14939 shader_template = tess_eval_shader_template;
14940 break;
14941 case Utils::VERTEX_SHADER:
14942 shader_template = vertex_shader_template;
14943 break;
14944 default:
14945 TCU_FAIL("Invalid enum");
14946 }
14947
14948 out_source.m_parts[0].m_code = shader_template;
14949
14950 size_t position = 0;
14951 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
14952 out_source.m_parts[0].m_code);
14953
14954 Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
14955
14956 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
14957
14958 position -= strlen(verification_snippet);
14959
14960 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
14961
14962 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
14963
14964 Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
14965 }
14966
14967 /** Prepare test cases
14968 *
14969 * @return true
14970 **/
testInit()14971 bool InitializerListNegativeTest::testInit()
14972 {
14973 for (GLuint i = 0; i < TESTED_ERRORS_MAX; ++i)
14974 {
14975 const TESTED_ERRORS error = (TESTED_ERRORS)i;
14976
14977 m_test_cases.push_back(error);
14978 }
14979
14980 return true;
14981 }
14982
14983 /** Get string representing initialization list for current test case
14984 *
14985 * @return String
14986 **/
getInitialization()14987 std::string InitializerListNegativeTest::getInitialization()
14988 {
14989 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
14990
14991 std::string initialization;
14992
14993 switch (error)
14994 {
14995 case TYPE_UIVEC_BOOL:
14996 initialization = "{ true, 0, 1, 2 }";
14997
14998 break;
14999
15000 case TYPE_IVEC_BOOL:
15001 initialization = "{ true, 0, -1, 2 }";
15002
15003 break;
15004
15005 case TYPE_VEC_BOOL:
15006 initialization = "{ true, 0.125, 0.25, 0.375 }";
15007
15008 break;
15009
15010 case TYPE_MAT_BOOL:
15011 initialization = "{ {false, 0, 1, 1}, {0, 1, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15012
15013 break;
15014
15015 case COMPONENTS_VEC_LESS:
15016 case COMPONENTS_VEC_MORE:
15017 initialization = "{ 0, 0.25, 0.375 }";
15018
15019 break;
15020
15021 case COMPONENTS_MAT_LESS_ROWS:
15022 initialization = "{ {0, 0, 1, 1}, {0, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15023
15024 break;
15025
15026 case COMPONENTS_MAT_MORE_ROWS:
15027 initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1, 0}, {1, 0, 1} }";
15028
15029 break;
15030
15031 case COMPONENTS_MAT_LESS_COLUMNS:
15032 initialization = "{ {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15033
15034 break;
15035
15036 case COMPONENTS_MAT_MORE_COLUMNS:
15037 initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1}, {1, 0, 1} }";
15038
15039 break;
15040
15041 case LIST_IN_CONSTRUCTOR:
15042 initialization = "Struct( { vec4(0, 1, 0, 1), vec3(0, 1, 0) }, vec4(1, 0, 1, 0) )";
15043
15044 break;
15045
15046 case STRUCT_LAYOUT_MEMBER_TYPE:
15047 initialization = "{ { {0, 1, 0, 1}, vec4(0, 1, 0, 1) }, vec4(1, 0, 1, 0) }";
15048
15049 break;
15050
15051 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15052 initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } , vec4(1, 0, 1, 0), vec4(1, 0, 1, 0) }";
15053
15054 break;
15055
15056 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15057 initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } }";
15058
15059 break;
15060
15061 case STRUCT_LAYOUT_MEMBER_ORDER:
15062 initialization = "{ vec4(1, 0, 1, 0), { vec3(0, 1, 0) , {0, 1, 0, 1} } }";
15063
15064 break;
15065
15066 default:
15067 TCU_FAIL("Invalid enum");
15068 }
15069
15070 return initialization;
15071 }
15072
15073 /** Logs description of current test case
15074 *
15075 **/
logTestCaseName()15076 void InitializerListNegativeTest::logTestCaseName()
15077 {
15078 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
15079
15080 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
15081
15082 switch (error)
15083 {
15084 case TYPE_UIVEC_BOOL:
15085 message << "Wrong type in uvec initializer list";
15086 break;
15087 case TYPE_IVEC_BOOL:
15088 message << "Wrong type in ivec initializer list";
15089 break;
15090 case TYPE_VEC_BOOL:
15091 message << "Wrong type in vec initializer list";
15092 break;
15093 case TYPE_MAT_BOOL:
15094 message << "Wrong type in mat initializer list";
15095 break;
15096 case COMPONENTS_VEC_LESS:
15097 message << "Wrong number of componenets in vec initialize list - less";
15098 break;
15099 case COMPONENTS_VEC_MORE:
15100 message << "Wrong number of componenets in vec initialize list - more";
15101 break;
15102 case COMPONENTS_MAT_LESS_ROWS:
15103 message << "Wrong number of componenets in mat initialize list - less rows";
15104 break;
15105 case COMPONENTS_MAT_LESS_COLUMNS:
15106 message << "Wrong number of componenets in mat initialize list - less columns";
15107 break;
15108 case COMPONENTS_MAT_MORE_ROWS:
15109 message << "Wrong number of componenets in mat initialize list - more rows";
15110 break;
15111 case COMPONENTS_MAT_MORE_COLUMNS:
15112 message << "Wrong number of componenets in mat initialize list - more columns";
15113 break;
15114 case LIST_IN_CONSTRUCTOR:
15115 message << "Initializer list in constructor";
15116 break;
15117 case STRUCT_LAYOUT_MEMBER_TYPE:
15118 message << "Wrong type of structure member";
15119 break;
15120 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15121 message << "Wrong number of structure members - more";
15122 break;
15123 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15124 message << "Wrong number of structure members - less";
15125 break;
15126 case STRUCT_LAYOUT_MEMBER_ORDER:
15127 message << "Wrong order of structure members";
15128 break;
15129 default:
15130 TCU_FAIL("Invalid enum");
15131 }
15132
15133 message << tcu::TestLog::EndMessage;
15134 }
15135
15136 /** Get string representing sum for current test case
15137 *
15138 * @return String
15139 **/
getSum()15140 std::string InitializerListNegativeTest::getSum()
15141 {
15142 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
15143
15144 std::string sum;
15145
15146 switch (error)
15147 {
15148 case TYPE_UIVEC_BOOL:
15149 case TYPE_IVEC_BOOL:
15150 case TYPE_VEC_BOOL:
15151 case COMPONENTS_VEC_LESS:
15152 sum = "variable.x + variable.y + variable.z + variable.w";
15153 break;
15154 case TYPE_MAT_BOOL:
15155 case COMPONENTS_MAT_LESS_ROWS:
15156 case COMPONENTS_MAT_LESS_COLUMNS:
15157 sum = "variable[0].x + variable[0].y + variable[0].z + variable[0].w + "
15158 "variable[1].x + variable[1].y + variable[1].z + variable[1].w + "
15159 "variable[2].x + variable[2].y + variable[2].z + variable[2].w + "
15160 "variable[3].x + variable[3].y + variable[3].z + variable[3].w";
15161 break;
15162 case COMPONENTS_VEC_MORE:
15163 sum = "variable.x + variable.y + variable.z";
15164 break;
15165 case COMPONENTS_MAT_MORE_ROWS:
15166 case COMPONENTS_MAT_MORE_COLUMNS:
15167 sum = "variable[0].x + variable[0].y + variable[0].z"
15168 "variable[1].x + variable[1].y + variable[1].z"
15169 "variable[2].x + variable[2].y + variable[2].z";
15170 break;
15171 case LIST_IN_CONSTRUCTOR:
15172 case STRUCT_LAYOUT_MEMBER_TYPE:
15173 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15174 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15175 case STRUCT_LAYOUT_MEMBER_ORDER:
15176 sum = "variable.member_a.member_a.x + variable.member_a.member_a.y + variable.member_a.member_a.z + "
15177 "variable.member_a.member_a.w + "
15178 "variable.member_a.member_b.x + variable.member_a.member_b.y + variable.member_a.member_b.z + "
15179 "variable.member_b.x + variable.member_b.y + variable.member_b.z + variable.member_b.w";
15180 break;
15181 default:
15182 TCU_FAIL("Invalid enum");
15183 }
15184
15185 return sum;
15186 }
15187
15188 /** Get string representing types definition for current test case
15189 *
15190 * @return String
15191 **/
getTypeDefinition()15192 std::string InitializerListNegativeTest::getTypeDefinition()
15193 {
15194 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
15195
15196 static const GLchar *struct_def = "struct BasicStructure {\n"
15197 " vec4 member_a;\n"
15198 " vec3 member_b;\n"
15199 "};\n"
15200 "\n"
15201 "struct StructureWithStructure {\n"
15202 " BasicStructure member_a;\n"
15203 " vec4 member_b;\n"
15204 "};\n";
15205
15206 std::string type_definition;
15207
15208 switch (error)
15209 {
15210 case TYPE_UIVEC_BOOL:
15211 case TYPE_IVEC_BOOL:
15212 case TYPE_VEC_BOOL:
15213 case TYPE_MAT_BOOL:
15214 case COMPONENTS_VEC_LESS:
15215 case COMPONENTS_VEC_MORE:
15216 case COMPONENTS_MAT_LESS_ROWS:
15217 case COMPONENTS_MAT_LESS_COLUMNS:
15218 case COMPONENTS_MAT_MORE_ROWS:
15219 case COMPONENTS_MAT_MORE_COLUMNS:
15220 type_definition = "";
15221 break;
15222 case LIST_IN_CONSTRUCTOR:
15223 case STRUCT_LAYOUT_MEMBER_TYPE:
15224 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15225 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15226 case STRUCT_LAYOUT_MEMBER_ORDER:
15227 type_definition = struct_def;
15228 break;
15229 default:
15230 TCU_FAIL("Invalid enum");
15231 }
15232
15233 return type_definition;
15234 }
15235
15236 /** Get string representing name of variable's type for current test case
15237 *
15238 * @return String
15239 **/
getTypeName()15240 std::string InitializerListNegativeTest::getTypeName()
15241 {
15242 const TESTED_ERRORS &error = m_test_cases[m_current_test_case_index];
15243
15244 static const GLchar *struct_with_struct = "StructureWithStructure";
15245
15246 std::string type_name;
15247
15248 switch (error)
15249 {
15250 case TYPE_UIVEC_BOOL:
15251 type_name = "uvec4";
15252 break;
15253 case TYPE_IVEC_BOOL:
15254 type_name = "ivec4";
15255 break;
15256 case TYPE_VEC_BOOL:
15257 case COMPONENTS_VEC_LESS:
15258 type_name = "vec4";
15259 break;
15260 case COMPONENTS_VEC_MORE:
15261 type_name = "vec2";
15262 break;
15263 case TYPE_MAT_BOOL:
15264 case COMPONENTS_MAT_LESS_ROWS:
15265 case COMPONENTS_MAT_LESS_COLUMNS:
15266 type_name = "mat4";
15267 break;
15268 case COMPONENTS_MAT_MORE_ROWS:
15269 case COMPONENTS_MAT_MORE_COLUMNS:
15270 type_name = "mat3";
15271 break;
15272 case LIST_IN_CONSTRUCTOR:
15273 case STRUCT_LAYOUT_MEMBER_TYPE:
15274 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15275 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15276 case STRUCT_LAYOUT_MEMBER_ORDER:
15277 type_name = struct_with_struct;
15278 break;
15279 default:
15280 TCU_FAIL("Invalid enum");
15281 }
15282
15283 return type_name;
15284 }
15285
15286 /** Constructor
15287 *
15288 * @param context Test context
15289 **/
LengthOfVectorAndMatrixTest(deqp::Context & context)15290 LengthOfVectorAndMatrixTest::LengthOfVectorAndMatrixTest(deqp::Context &context)
15291 : GLSLTestBase(context, "length_of_vector_and_matrix", "Test verifies .length() for vectors and matrices")
15292 {
15293 /* Nothing to be done here */
15294 }
15295
15296 /** Set up next test case
15297 *
15298 * @param test_case_index Index of next test case
15299 *
15300 * @return false if there is no more test cases, true otherwise
15301 **/
prepareNextTestCase(glw::GLuint test_case_index)15302 bool LengthOfVectorAndMatrixTest::prepareNextTestCase(glw::GLuint test_case_index)
15303 {
15304 m_current_test_case_index = test_case_index;
15305
15306 if ((glw::GLuint)-1 == test_case_index)
15307 {
15308 m_current_test_case_index = 0;
15309 return true;
15310 }
15311 else if (m_test_cases.size() <= test_case_index)
15312 {
15313 return false;
15314 }
15315
15316 const testCase &test_case = m_test_cases[m_current_test_case_index];
15317
15318 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested type: "
15319 << Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows)
15320 << tcu::TestLog::EndMessage;
15321
15322 return true;
15323 }
15324
15325 /** Prepare source for given shader stage
15326 *
15327 * @param in_stage Shader stage, compute shader will use 430
15328 * @param in_use_version_400 Select if 400 or 420 should be used
15329 * @param out_source Prepared shader source instance
15330 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15331 void LengthOfVectorAndMatrixTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15332 Utils::shaderSource &out_source)
15333 {
15334 if (Utils::COMPUTE_SHADER == in_stage)
15335 {
15336 m_is_compute_program = true;
15337 prepareComputeShaderSource(out_source);
15338 }
15339 else
15340 {
15341 m_is_compute_program = false;
15342 prepareDrawShaderSource(in_stage, in_use_version_400, out_source);
15343 }
15344 }
15345
15346 /** Overwritte of prepareUniforms method
15347 *
15348 * @param program Current program
15349 **/
prepareUniforms(Utils::program & program)15350 void LengthOfVectorAndMatrixTest::prepareUniforms(Utils::program &program)
15351 {
15352 static const GLfloat float_value = 0.125;
15353 static const GLint int_value = -1;
15354 static const GLuint uint_value = 1;
15355
15356 static const GLfloat float_data[16] = {float_value, float_value, float_value, float_value, float_value, float_value,
15357 float_value, float_value, float_value, float_value, float_value, float_value,
15358 float_value, float_value, float_value, float_value};
15359
15360 static const GLint int_data[4] = {int_value, int_value, int_value, int_value};
15361
15362 static const GLuint uint_data[4] = {uint_value, uint_value, uint_value, uint_value};
15363
15364 if (false == m_is_compute_program)
15365 {
15366 return;
15367 }
15368
15369 const testCase &test_case = m_test_cases[m_current_test_case_index];
15370
15371 switch (test_case.m_type)
15372 {
15373 case Utils::FLOAT:
15374 program.uniform("uni_variable", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
15375 break;
15376 case Utils::INT:
15377 program.uniform("uni_variable", Utils::INT, 1 /* columns */, test_case.m_n_rows, int_data);
15378 break;
15379 case Utils::UINT:
15380 program.uniform("uni_variable", Utils::UINT, 1 /* columns */, test_case.m_n_rows, uint_data);
15381 break;
15382 default:
15383 TCU_FAIL("Invalid enum");
15384 }
15385 }
15386
15387 /** Prepare vertex buffer
15388 *
15389 * @param program Program object
15390 * @param buffer Vertex buffer
15391 * @param vao Vertex array object
15392 *
15393 * @return 0
15394 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)15395 void LengthOfVectorAndMatrixTest::prepareVertexBuffer(const Utils::program &program, Utils::buffer &buffer,
15396 Utils::vertexArray &vao)
15397 {
15398 static const GLfloat float_value = 0.125f;
15399 static const GLint int_value = -1;
15400 static const GLuint uint_value = 1;
15401
15402 static const GLfloat float_data[16] = {float_value, float_value, float_value, float_value, float_value, float_value,
15403 float_value, float_value, float_value, float_value, float_value, float_value,
15404 float_value, float_value, float_value, float_value};
15405
15406 static const GLint int_data[4] = {int_value, int_value, int_value, int_value};
15407
15408 static const GLuint uint_data[4] = {uint_value, uint_value, uint_value, uint_value};
15409
15410 const testCase &test_case = m_test_cases[m_current_test_case_index];
15411
15412 std::string variable_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "variable");
15413 GLint variable_loc = program.getAttribLocation(variable_name.c_str());
15414
15415 if (-1 == variable_loc)
15416 {
15417 TCU_FAIL("Vertex attribute location is invalid");
15418 }
15419
15420 vao.generate();
15421 vao.bind();
15422
15423 buffer.generate(GL_ARRAY_BUFFER);
15424
15425 GLvoid *data_ptr = 0;
15426 GLsizeiptr data_size = 0;
15427
15428 switch (test_case.m_type)
15429 {
15430 case Utils::FLOAT:
15431 data_ptr = (GLvoid *)float_data;
15432 data_size = sizeof(float_data);
15433 break;
15434 case Utils::INT:
15435 data_ptr = (GLvoid *)int_data;
15436 data_size = sizeof(int_data);
15437 break;
15438 case Utils::UINT:
15439 data_ptr = (GLvoid *)uint_data;
15440 data_size = sizeof(uint_data);
15441 break;
15442 default:
15443 TCU_FAIL("Invalid enum");
15444 }
15445
15446 buffer.update(data_size, data_ptr, GL_STATIC_DRAW);
15447
15448 /* GL entry points */
15449 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
15450
15451 /* Set up vao */
15452 switch (test_case.m_type)
15453 {
15454 case Utils::FLOAT:
15455 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15456 {
15457 const GLuint index = variable_loc + col;
15458 const GLint size = test_case.m_n_rows;
15459 const GLvoid *offset = (const GLvoid *)(test_case.m_n_rows * sizeof(GLfloat) * col);
15460
15461 gl.vertexAttribPointer(index, size, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0, offset);
15462 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
15463 }
15464 break;
15465 case Utils::INT:
15466 gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_INT /* type */, 0 /* stride */,
15467 0 /* offset */);
15468 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15469 break;
15470 case Utils::UINT:
15471 gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_UNSIGNED_INT /* type */, 0 /* stride */,
15472 0 /* offset */);
15473 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15474 break;
15475 default:
15476 DE_ASSERT(0);
15477 break;
15478 }
15479
15480 /* Enable attribute */
15481 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15482 {
15483 gl.enableVertexAttribArray(variable_loc + col);
15484 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
15485 }
15486 }
15487
15488 /** Prepare test cases
15489 *
15490 * @return true
15491 **/
testInit()15492 bool LengthOfVectorAndMatrixTest::testInit()
15493 {
15494 /* Vectors */
15495 for (GLuint row = 2; row <= 4; ++row)
15496 {
15497 testCase test_case = {Utils::UINT, 1 /* n_cols */, row};
15498
15499 m_test_cases.push_back(test_case);
15500 }
15501
15502 for (GLuint row = 2; row <= 4; ++row)
15503 {
15504 testCase test_case = {Utils::INT, 1 /* n_cols */, row};
15505
15506 m_test_cases.push_back(test_case);
15507 }
15508
15509 for (GLuint row = 2; row <= 4; ++row)
15510 {
15511 testCase test_case = {Utils::FLOAT, 1 /* n_cols */, row};
15512
15513 m_test_cases.push_back(test_case);
15514 }
15515
15516 /* Matrices */
15517 for (GLuint col = 2; col <= 4; ++col)
15518 {
15519 for (GLuint row = 2; row <= 4; ++row)
15520 {
15521 testCase test_case = {Utils::FLOAT, col, row};
15522
15523 m_test_cases.push_back(test_case);
15524 }
15525 }
15526
15527 return true;
15528 }
15529
15530 /** Get string representing value that should be placed at token EXPECTED_VALUE
15531 *
15532 * @param in_stage Shader stage
15533 *
15534 * @return String with value
15535 **/
getExpectedValue(Utils::SHADER_STAGES in_stage)15536 std::string LengthOfVectorAndMatrixTest::getExpectedValue(Utils::SHADER_STAGES in_stage)
15537 {
15538 const testCase &test_case = m_test_cases[m_current_test_case_index];
15539
15540 GLuint count = 0;
15541
15542 switch (in_stage)
15543 {
15544 case Utils::FRAGMENT_SHADER:
15545 count = 3;
15546 break;
15547 case Utils::COMPUTE_SHADER:
15548 count = 2;
15549 break;
15550 default:
15551 count = 4;
15552 }
15553
15554 if (1 == test_case.m_n_cols)
15555 {
15556 count *= test_case.m_n_rows;
15557 }
15558 else
15559 {
15560 count *= test_case.m_n_cols;
15561 }
15562
15563 std::string expected_value;
15564 expected_value.resize(64, 0);
15565
15566 switch (test_case.m_type)
15567 {
15568 case Utils::FLOAT:
15569 {
15570 GLfloat value = 0.125f * (GLfloat)count;
15571 sprintf(&expected_value[0], "%f", value);
15572 }
15573 break;
15574 case Utils::INT:
15575 {
15576 GLint value = -1 * (GLint)count;
15577 sprintf(&expected_value[0], "%d", value);
15578 }
15579 break;
15580 case Utils::UINT:
15581 {
15582 GLuint value = 1 * (GLuint)count;
15583 sprintf(&expected_value[0], "%d", value);
15584 }
15585 break;
15586 default:
15587 DE_ASSERT(0);
15588 break;
15589 }
15590
15591 return expected_value;
15592 }
15593
15594 /** Get string reresenting initialization of local variables for current test case
15595 *
15596 * @return String with initialization
15597 **/
getInitialization()15598 std::string LengthOfVectorAndMatrixTest::getInitialization()
15599 {
15600 const testCase &test_case = m_test_cases[m_current_test_case_index];
15601
15602 std::string initialization;
15603
15604 if (1 == test_case.m_n_cols)
15605 {
15606 initialization = getVectorInitializer(test_case.m_type, test_case.m_n_rows);
15607 }
15608 else
15609 {
15610 initialization = getMatrixInitializer(test_case.m_n_cols, test_case.m_n_rows);
15611 }
15612
15613 return initialization;
15614 }
15615
15616 /** Get string reresenting initialization of local matrix variables
15617 *
15618 * @param n_cols Number of columns
15619 * @param n_rows Number of rows
15620 *
15621 * @return String with initialization
15622 **/
getMatrixInitializer(GLuint n_cols,GLuint n_rows)15623 std::string LengthOfVectorAndMatrixTest::getMatrixInitializer(GLuint n_cols, GLuint n_rows)
15624 {
15625 std::string result;
15626
15627 result.append("{ ");
15628
15629 for (GLuint col = 0; col < n_cols; ++col)
15630 {
15631 result.append(getVectorInitializer(Utils::FLOAT, n_rows));
15632
15633 if (col + 1 < n_cols)
15634 {
15635 result.append(", ");
15636 }
15637 }
15638
15639 result.append(" }");
15640
15641 return result;
15642 }
15643
15644 /** Get string reresenting initialization of local vector variables
15645 *
15646 * @param type Basic type of vector
15647 * @param n_rows Number of rows
15648 *
15649 * @return String with initialization
15650 **/
getVectorInitializer(Utils::TYPES type,glw::GLuint n_rows)15651 std::string LengthOfVectorAndMatrixTest::getVectorInitializer(Utils::TYPES type, glw::GLuint n_rows)
15652 {
15653 std::string result;
15654 const GLchar *value = 0;
15655
15656 switch (type)
15657 {
15658 case Utils::FLOAT:
15659 value = "0.125";
15660 break;
15661 case Utils::UINT:
15662 value = "1";
15663 break;
15664 case Utils::INT:
15665 value = "-1";
15666 break;
15667 default:
15668 TCU_FAIL("Invalid enum");
15669 }
15670
15671 result.append("{");
15672
15673 for (GLuint row = 0; row < n_rows; ++row)
15674 {
15675 result.append(value);
15676
15677 if (row + 1 < n_rows)
15678 {
15679 result.append(", ");
15680 }
15681 }
15682
15683 result.append("}");
15684
15685 return result;
15686 }
15687
15688 /** Prepare source for given shader stage
15689 *
15690 * @param in_stage Shader stage, compute shader will use 430
15691 * @param in_use_version_400 Select if 400 or 420 should be used
15692 * @param out_source Prepared shader source instance
15693 **/
prepareDrawShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15694 void LengthOfVectorAndMatrixTest::prepareDrawShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15695 Utils::shaderSource &out_source)
15696 {
15697 static const GLchar *verification_snippet =
15698 " VARIABLE_TYPE variable = INITIALIZATION;\n"
15699 " Structure structure = { { 0, 1, 0, 1 } , INITIALIZATION };\n"
15700 "\n"
15701 " const uint variable_length = variable.length();\n"
15702 " const uint structure_member_b_length = structure.member_b.length();\n"
15703 " const uint input_member_length = INPUT_VARIABLE_NAME.length();\n"
15704 "#ifndef FRAGMENT\n"
15705 " const uint output_member_length = OUTPUT_VARIABLE_NAME.length();\n"
15706 "#endif // FRAGMENT\n"
15707 "\n"
15708 " BASE_TYPE array_var[variable.length()];\n"
15709 " BASE_TYPE array_str[structure.member_b.length()];\n"
15710 " BASE_TYPE array_in [INPUT_VARIABLE_NAME.length()];\n"
15711 "#ifndef FRAGMENT\n"
15712 " BASE_TYPE array_out[OUTPUT_VARIABLE_NAME.length()];\n"
15713 "#endif // FRAGMENT\n"
15714 "\n"
15715 " BASE_TYPE sum = 0;\n"
15716 "\n"
15717 " for (uint i = 0; i < variable_length; ++i)\n"
15718 " {\n"
15719 " array_var[i] = variableARRAY_INDEX.x;\n"
15720 " }\n"
15721 "\n"
15722 " for (uint i = 0; i < structure_member_b_length; ++i)\n"
15723 " {\n"
15724 " array_str[i] = structure.member_bARRAY_INDEX.y;\n"
15725 " }\n"
15726 "\n"
15727 " for (uint i = 0; i < input_member_length; ++i)\n"
15728 " {\n"
15729 " array_in[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.x;\n"
15730 " }\n"
15731 "\n"
15732 "#ifndef FRAGMENT\n"
15733 " for (uint i = 0; i < output_member_length; ++i)\n"
15734 " {\n"
15735 " array_out[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.y;\n"
15736 " }\n"
15737 "#endif // FRAGMENT\n"
15738 "\n"
15739 " for (uint i = 0; i < array_var.length(); ++i)\n"
15740 " {\n"
15741 " sum += array_var[i];\n"
15742 " }\n"
15743 "\n"
15744 " for (uint i = 0; i < array_str.length(); ++i)\n"
15745 " {\n"
15746 " sum += array_str[i];\n"
15747 " }\n"
15748 "\n"
15749 " for (uint i = 0; i < array_in.length(); ++i)\n"
15750 " {\n"
15751 " sum += array_in[i];\n"
15752 " }\n"
15753 "\n"
15754 "#ifndef FRAGMENT\n"
15755 " for (uint i = 0; i < array_out.length(); ++i)\n"
15756 " {\n"
15757 " sum += array_out[i];\n"
15758 " }\n"
15759 "#endif // FRAGMENT\n"
15760 "\n"
15761 " if (EXPECTED_VALUE != sum)\n"
15762 " {\n"
15763 " result = vec4(1, 0, 0, 1);\n"
15764 " }\n";
15765
15766 static const GLchar *fragment_shader_template = "VERSION\n"
15767 "\n"
15768 "#define FRAGMENT\n"
15769 "\n"
15770 "in vec4 gs_fs_result;\n"
15771 "out vec4 fs_out_result;\n"
15772 "\n"
15773 "in GSOutputBlock {\n"
15774 " VARIABLE_DECLARATION;\n"
15775 "} input_block;\n"
15776 "\n"
15777 "struct Structure {\n"
15778 " vec4 member_a;\n"
15779 " TYPE_NAME member_b;\n"
15780 "};\n"
15781 "\n"
15782 "void main()\n"
15783 "{\n"
15784 " vec4 result = vec4(0, 1, 0, 1);\n"
15785 "\n"
15786 "VERIFICATION"
15787 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
15788 " {\n"
15789 " result = vec4(1, 0, 0, 1);\n"
15790 " }\n"
15791 "\n"
15792 " fs_out_result = result;\n"
15793 "}\n"
15794 "\n";
15795
15796 static const GLchar *geometry_shader_template = "VERSION\n"
15797 "\n"
15798 "layout(points) in;\n"
15799 "layout(triangle_strip, max_vertices = 4) out;\n"
15800 "\n"
15801 "in vec4 tes_gs_result[];\n"
15802 "out vec4 gs_fs_result;\n"
15803 "\n"
15804 "in TCSOutputBlock {\n"
15805 " VARIABLE_DECLARATION;\n"
15806 "} input_block[];\n"
15807 "out GSOutputBlock {\n"
15808 " VARIABLE_DECLARATION;\n"
15809 "} output_block;\n"
15810 "\n"
15811 "struct Structure {\n"
15812 " vec4 member_a;\n"
15813 " TYPE_NAME member_b;\n"
15814 "};\n"
15815 "\n"
15816 "void main()\n"
15817 "{\n"
15818 " vec4 result = vec4(0, 1, 0, 1);\n"
15819 "\n"
15820 "VERIFICATION"
15821 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
15822 " {\n"
15823 " result = vec4(1, 0, 0, 1);\n"
15824 " }\n"
15825 "\n"
15826 " gs_fs_result = result;\n"
15827 " gl_Position = vec4(-1, -1, 0, 1);\n"
15828 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15829 " EmitVertex();\n"
15830 " gs_fs_result = result;\n"
15831 " gl_Position = vec4(-1, 1, 0, 1);\n"
15832 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15833 " EmitVertex();\n"
15834 " gs_fs_result = result;\n"
15835 " gl_Position = vec4(1, -1, 0, 1);\n"
15836 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15837 " EmitVertex();\n"
15838 " gs_fs_result = result;\n"
15839 " gl_Position = vec4(1, 1, 0, 1);\n"
15840 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15841 " EmitVertex();\n"
15842 "}\n"
15843 "\n";
15844
15845 static const GLchar *tess_ctrl_shader_template =
15846 "VERSION\n"
15847 "\n"
15848 "layout(vertices = 1) out;\n"
15849 "\n"
15850 "in vec4 vs_tcs_result[];\n"
15851 "out vec4 tcs_tes_result[];\n"
15852 "\n"
15853 "in VSOutputBlock {\n"
15854 " VARIABLE_DECLARATION;\n"
15855 "} input_block[];\n"
15856 "out TCSOutputBlock {\n"
15857 " VARIABLE_DECLARATION;\n"
15858 "} output_block[];\n"
15859 "\n"
15860 "struct Structure {\n"
15861 " vec4 member_a;\n"
15862 " TYPE_NAME member_b;\n"
15863 "};\n"
15864 "\n"
15865 "void main()\n"
15866 "{\n"
15867 " vec4 result = vec4(0, 1, 0, 1);\n"
15868 "\n"
15869 "VERIFICATION"
15870 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
15871 " {\n"
15872 " result = vec4(1, 0, 0, 1);\n"
15873 " }\n"
15874 "\n"
15875 " tcs_tes_result[gl_InvocationID] = result;\n"
15876 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15877 "\n"
15878 " gl_TessLevelOuter[0] = 1.0;\n"
15879 " gl_TessLevelOuter[1] = 1.0;\n"
15880 " gl_TessLevelOuter[2] = 1.0;\n"
15881 " gl_TessLevelOuter[3] = 1.0;\n"
15882 " gl_TessLevelInner[0] = 1.0;\n"
15883 " gl_TessLevelInner[1] = 1.0;\n"
15884 "}\n"
15885 "\n";
15886
15887 static const GLchar *tess_eval_shader_template = "VERSION\n"
15888 "\n"
15889 "layout(isolines, point_mode) in;\n"
15890 "\n"
15891 "in vec4 tcs_tes_result[];\n"
15892 "out vec4 tes_gs_result;\n"
15893 "\n"
15894 "in TCSOutputBlock {\n"
15895 " VARIABLE_DECLARATION;\n"
15896 "} input_block[];\n"
15897 "out TCSOutputBlock {\n"
15898 " VARIABLE_DECLARATION;\n"
15899 "} output_block;\n"
15900 "\n"
15901 "struct Structure {\n"
15902 " vec4 member_a;\n"
15903 " TYPE_NAME member_b;\n"
15904 "};\n"
15905 "\n"
15906 "void main()\n"
15907 "{\n"
15908 " vec4 result = vec4(0, 1, 0, 1);\n"
15909 "\n"
15910 "VERIFICATION"
15911 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
15912 " {\n"
15913 " result = vec4(1, 0, 0, 1);\n"
15914 " }\n"
15915 "\n"
15916 " tes_gs_result = result;\n"
15917 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15918 "}\n"
15919 "\n";
15920
15921 static const GLchar *vertex_shader_template = "VERSION\n"
15922 "\n"
15923 "out vec4 vs_tcs_result;\n"
15924 "\n"
15925 "in VARIABLE_DECLARATION;\n"
15926 "out VSOutputBlock {\n"
15927 " VARIABLE_DECLARATION;\n"
15928 "} output_block;\n"
15929 "\n"
15930 "struct Structure {\n"
15931 " vec4 member_a;\n"
15932 " TYPE_NAME member_b;\n"
15933 "};\n"
15934 "\n"
15935 "void main()\n"
15936 "{\n"
15937 " vec4 result = vec4(0, 1, 0, 1);\n"
15938 "\n"
15939 "VERIFICATION"
15940 "\n"
15941 " vs_tcs_result = result;\n"
15942 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15943 "}\n"
15944 "\n";
15945
15946 const GLchar *array_index = "";
15947 const testCase &test_case = m_test_cases[m_current_test_case_index];
15948 const GLchar *shader_template = 0;
15949 const GLchar *input_block_name = "input_block";
15950 const GLchar *output_block_name = "output_block";
15951
15952 const std::string &base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
15953 const std::string &expected_value = getExpectedValue(in_stage);
15954 const std::string &initialization = getInitialization();
15955 const std::string &type_name = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
15956
15957 std::string input_decl;
15958 std::string input_ref;
15959 std::string output_decl;
15960 std::string output_ref;
15961
15962 Utils::qualifierSet in_qualifiers;
15963 Utils::qualifierSet out_qualifiers;
15964
15965 if ((Utils::UINT == test_case.m_type) || (Utils::INT == test_case.m_type))
15966 {
15967 if (Utils::VERTEX_SHADER != in_stage)
15968 {
15969 in_qualifiers.push_back(Utils::QUAL_FLAT);
15970 }
15971
15972 out_qualifiers.push_back(Utils::QUAL_FLAT);
15973 }
15974
15975 switch (in_stage)
15976 {
15977 case Utils::COMPUTE_SHADER:
15978 shader_template = 0;
15979 break;
15980 case Utils::FRAGMENT_SHADER:
15981 shader_template = fragment_shader_template;
15982 break;
15983 case Utils::GEOMETRY_SHADER:
15984 shader_template = geometry_shader_template;
15985 break;
15986 case Utils::TESS_CTRL_SHADER:
15987 shader_template = tess_ctrl_shader_template;
15988 break;
15989 case Utils::TESS_EVAL_SHADER:
15990 shader_template = tess_eval_shader_template;
15991 break;
15992 case Utils::VERTEX_SHADER:
15993 shader_template = vertex_shader_template;
15994 break;
15995 default:
15996 TCU_FAIL("Invalid enum");
15997 }
15998
15999 if (Utils::VERTEX_SHADER != in_stage)
16000 {
16001 Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable",
16002 input_block_name, input_decl, input_ref);
16003 }
16004 else
16005 {
16006 Utils::prepareVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable", input_decl,
16007 input_ref);
16008 }
16009 if (Utils::FRAGMENT_SHADER != in_stage)
16010 {
16011 Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
16012 output_block_name, output_decl, output_ref);
16013 }
16014 else
16015 {
16016 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
16017 output_decl, output_ref);
16018 }
16019
16020 if (1 != test_case.m_n_cols)
16021 {
16022 array_index = "[i]";
16023 }
16024
16025 out_source.m_parts[0].m_code = shader_template;
16026
16027 size_t position = 0;
16028 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16029 out_source.m_parts[0].m_code);
16030
16031 Utils::replaceToken("VARIABLE_DECLARATION", position, input_decl.c_str(), out_source.m_parts[0].m_code);
16032
16033 if (Utils::FRAGMENT_SHADER != in_stage)
16034 {
16035 Utils::replaceToken("VARIABLE_DECLARATION", position, output_decl.c_str(), out_source.m_parts[0].m_code);
16036 }
16037
16038 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16039
16040 size_t temp = position;
16041
16042 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16043
16044 position = temp;
16045
16046 Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
16047
16048 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
16049
16050 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
16051
16052 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16053
16054 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16055
16056 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16057
16058 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16059
16060 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16061
16062 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
16063
16064 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", input_ref.c_str(), out_source.m_parts[0].m_code);
16065
16066 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", output_ref.c_str(), out_source.m_parts[0].m_code);
16067
16068 Utils::replaceAllTokens("ARRAY_INDEX", array_index, out_source.m_parts[0].m_code);
16069 }
16070
16071 /** Prepare source for compute shader stage
16072 *
16073 * @param out_source Prepared shader source instance
16074 **/
prepareComputeShaderSource(Utils::shaderSource & out_source)16075 void LengthOfVectorAndMatrixTest::prepareComputeShaderSource(Utils::shaderSource &out_source)
16076 {
16077 static const GLchar *verification_snippet =
16078 " VARIABLE_TYPE variable = uni_variable;\n"
16079 " Structure structure = { { 0, 1, 0, 1 } , uni_variable };\n"
16080 "\n"
16081 " const uint variable_length = variable.length();\n"
16082 " const uint structure_member_b_length = structure.member_b.length();\n"
16083 "\n"
16084 " BASE_TYPE array_var[variable.length()];\n"
16085 " BASE_TYPE array_str[structure.member_b.length()];\n"
16086 "\n"
16087 " BASE_TYPE sum = 0;\n"
16088 "\n"
16089 " for (uint i = 0; i < variable_length; ++i)\n"
16090 " {\n"
16091 " array_var[i] = variableARRAY_INDEX.x;\n"
16092 " }\n"
16093 "\n"
16094 " for (uint i = 0; i < structure_member_b_length; ++i)\n"
16095 " {\n"
16096 " array_str[i] = structure.member_bARRAY_INDEX.y;\n"
16097 " }\n"
16098 "\n"
16099 " for (uint i = 0; i < array_var.length(); ++i)\n"
16100 " {\n"
16101 " sum += array_var[i];\n"
16102 " }\n"
16103 "\n"
16104 " for (uint i = 0; i < array_str.length(); ++i)\n"
16105 " {\n"
16106 " sum += array_str[i];\n"
16107 " }\n"
16108 "\n"
16109 " if (EXPECTED_VALUE != sum)\n"
16110 " {\n"
16111 " result = vec4(1, 0, 0, 1);\n"
16112 " }\n";
16113
16114 static const GLchar *compute_shader_template =
16115 "VERSION\n"
16116 "\n"
16117 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16118 "\n"
16119 "writeonly uniform image2D uni_image;\n"
16120 " uniform TYPE_NAME uni_variable;\n"
16121 "\n"
16122 "struct Structure {\n"
16123 " vec4 member_a;\n"
16124 " TYPE_NAME member_b;\n"
16125 "};\n"
16126 "\n"
16127 "void main()\n"
16128 "{\n"
16129 " vec4 result = vec4(0, 1, 0, 1);\n"
16130 "\n"
16131 "VERIFICATION"
16132 "\n"
16133 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16134 "}\n"
16135 "\n";
16136
16137 const testCase &test_case = m_test_cases[m_current_test_case_index];
16138 const GLchar *array_index = "";
16139
16140 const std::string &base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
16141 const std::string &expected_value = getExpectedValue(Utils::COMPUTE_SHADER);
16142 const std::string &type_name = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
16143
16144 if (1 != test_case.m_n_cols)
16145 {
16146 array_index = "[i]";
16147 }
16148
16149 out_source.m_parts[0].m_code = compute_shader_template;
16150
16151 size_t position = 0;
16152 Utils::replaceToken("VERSION", position, getVersionString(Utils::COMPUTE_SHADER, false),
16153 out_source.m_parts[0].m_code);
16154
16155 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16156
16157 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16158
16159 size_t temp = position;
16160
16161 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16162
16163 position = temp;
16164
16165 Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
16166
16167 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16168
16169 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16170
16171 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16172
16173 Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
16174
16175 Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
16176
16177 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
16178 }
16179
16180 /** Constructor
16181 *
16182 * @param context Test context
16183 **/
LengthOfComputeResultTest(deqp::Context & context)16184 LengthOfComputeResultTest::LengthOfComputeResultTest(deqp::Context &context)
16185 : GLSLTestBase(context, "length_of_compute_result", "Test verifies .length() for results of computation")
16186 {
16187 /* Nothing to be done here */
16188 }
16189
16190 /** Prepare source for given shader stage
16191 *
16192 * @param in_stage Shader stage, compute shader will use 430
16193 * @param in_use_version_400 Select if 400 or 420 should be used
16194 * @param out_source Prepared shader source instance
16195 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16196 void LengthOfComputeResultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16197 Utils::shaderSource &out_source)
16198 {
16199 static const GLchar *uniforms = "uniform mat2x4 goten;\n"
16200 "uniform uvec4 indices;\n"
16201 "uniform uvec4 expected_lengths;\n"
16202 "uniform mat4x3 gohan;\n"
16203 "uniform vec3 vegeta;\n"
16204 "uniform vec3 trunks;\n"
16205 "uniform uint variable;\n"
16206 "uniform float expected_sum;\n";
16207
16208 static const GLchar *verification_snippet =
16209 " uint lengths[4];\n"
16210 " float x[(gohan * goten).length()];\n"
16211 " float y[(gohan * goten)[variable - 1].length()];\n"
16212 "\n"
16213 " lengths[indices.x] = gohan[variable].length();\n"
16214 " lengths[indices.y] = (gohan * goten).length();\n"
16215 " lengths[indices.z] = (gohan * goten)[variable].length();\n"
16216 " lengths[indices.w] = (vegeta * trunks).length();\n"
16217 "\n"
16218 " float dot_result = dot(vegeta, trunks);\n"
16219 " mat2x3 mul_result = gohan * goten;\n"
16220 "\n"
16221 "#ifdef TESS_CTRL\n"
16222 " const uint position_length = gl_out[gl_InvocationID].gl_Position.length();\n"
16223 "#endif\n"
16224 "#ifndef COMPUTE\n"
16225 "#ifndef FRAGMENT\n"
16226 "#ifndef TESS_CTRL\n"
16227 " const uint position_length = gl_Position.length();\n"
16228 "#endif /*TESS_CTRL */\n"
16229 "#endif /* FRAGMENT */\n"
16230 "#endif /* COMPUTE */\n"
16231 "#ifdef FRAGMENT\n"
16232 " const uint point_coord_length = gl_PointCoord.length();\n"
16233 " const uint sample_position_length = gl_SamplePosition.length();\n"
16234 "#endif /* FRAGMENT */\n"
16235 " const uint outer_length = outerProduct(vegeta, trunks).length();\n"
16236 "\n"
16237 " for (uint i = 0; i < x.length(); ++i)\n"
16238 " {\n"
16239 " x[i] = mul_result[i].x;\n"
16240 " }\n"
16241 "\n"
16242 " for (uint i = 0; i < y.length(); ++i)\n"
16243 " {\n"
16244 " y[i] = mul_result[0][i];\n"
16245 " }\n"
16246 "\n"
16247 " if ( (expected_lengths.x != lengths[0]) ||\n"
16248 " (expected_lengths.y != lengths[1]) ||\n"
16249 " (expected_lengths.z != lengths[2]) ||\n"
16250 " (expected_lengths.w != lengths[3]) ||\n"
16251 "#ifndef COMPUTE\n"
16252 "#ifndef FRAGMENT\n"
16253 " (4 /* vec4 */ != position_length) ||\n"
16254 "#endif /* FRAGMENT */\n"
16255 "#endif /* COMPUTE */\n"
16256 "#ifdef FRAGMENT\n"
16257 " (2 /* vec2 */ != point_coord_length) ||\n"
16258 " (2 /* vec2 */ != sample_position_length) ||\n"
16259 "#endif /* FRAGMENT */\n"
16260 " (0.5 != dot_result) ||\n"
16261 " (3 /* mat3 */ != outer_length) ||\n"
16262 " (expected_sum != x[variable] + y[variable]) )\n"
16263 " {\n"
16264 " result = vec4(1, 0, 0, 1);\n"
16265 " }\n";
16266
16267 static const GLchar *compute_shader_template =
16268 "VERSION\n"
16269 "\n"
16270 "#define COMPUTE\n"
16271 "\n"
16272 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16273 "\n"
16274 "writeonly uniform image2D uni_image;\n"
16275 "\n"
16276 "UNIFORMS"
16277 "\n"
16278 "void main()\n"
16279 "{\n"
16280 " vec4 result = vec4(0, 1, 0, 1);\n"
16281 "\n"
16282 "VERIFICATION"
16283 "\n"
16284 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16285 "}\n"
16286 "\n";
16287
16288 static const GLchar *fragment_shader_template = "VERSION\n"
16289 "\n"
16290 "#define FRAGMENT\n"
16291 "\n"
16292 "in vec4 gs_fs_result;\n"
16293 "out vec4 fs_out_result;\n"
16294 "\n"
16295 "UNIFORMS"
16296 "\n"
16297 "void main()\n"
16298 "{\n"
16299 " vec4 result = vec4(0, 1, 0, 1);\n"
16300 "\n"
16301 "VERIFICATION"
16302 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16303 " {\n"
16304 " result = vec4(1, 0, 0, 1);\n"
16305 " }\n"
16306 "\n"
16307 " fs_out_result = result;\n"
16308 "}\n"
16309 "\n";
16310
16311 static const GLchar *geometry_shader_template = "VERSION\n"
16312 "\n"
16313 "layout(points) in;\n"
16314 "layout(triangle_strip, max_vertices = 4) out;\n"
16315 "\n"
16316 "in vec4 tes_gs_result[];\n"
16317 "out vec4 gs_fs_result;\n"
16318 "\n"
16319 "UNIFORMS"
16320 "\n"
16321 "void main()\n"
16322 "{\n"
16323 " vec4 result = vec4(0, 1, 0, 1);\n"
16324 "\n"
16325 "VERIFICATION"
16326 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16327 " {\n"
16328 " result = vec4(1, 0, 0, 1);\n"
16329 " }\n"
16330 "\n"
16331 " gs_fs_result = result;\n"
16332 " gl_Position = vec4(-1, -1, 0, 1);\n"
16333 " EmitVertex();\n"
16334 " gs_fs_result = result;\n"
16335 " gl_Position = vec4(-1, 1, 0, 1);\n"
16336 " EmitVertex();\n"
16337 " gs_fs_result = result;\n"
16338 " gl_Position = vec4(1, -1, 0, 1);\n"
16339 " EmitVertex();\n"
16340 " gs_fs_result = result;\n"
16341 " gl_Position = vec4(1, 1, 0, 1);\n"
16342 " EmitVertex();\n"
16343 "}\n"
16344 "\n";
16345
16346 static const GLchar *tess_ctrl_shader_template =
16347 "VERSION\n"
16348 "#define TESS_CTRL\n"
16349 "\n"
16350 "layout(vertices = 1) out;\n"
16351 "\n"
16352 "in vec4 vs_tcs_result[];\n"
16353 "out vec4 tcs_tes_result[];\n"
16354 "\n"
16355 "UNIFORMS"
16356 "\n"
16357 "void main()\n"
16358 "{\n"
16359 " vec4 result = vec4(0, 1, 0, 1);\n"
16360 "\n"
16361 "VERIFICATION"
16362 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16363 " {\n"
16364 " result = vec4(1, 0, 0, 1);\n"
16365 " }\n"
16366 "\n"
16367 " tcs_tes_result[gl_InvocationID] = result;\n"
16368 "\n"
16369 " gl_TessLevelOuter[0] = 1.0;\n"
16370 " gl_TessLevelOuter[1] = 1.0;\n"
16371 " gl_TessLevelOuter[2] = 1.0;\n"
16372 " gl_TessLevelOuter[3] = 1.0;\n"
16373 " gl_TessLevelInner[0] = 1.0;\n"
16374 " gl_TessLevelInner[1] = 1.0;\n"
16375 "}\n"
16376 "\n";
16377
16378 static const GLchar *tess_eval_shader_template = "VERSION\n"
16379 "\n"
16380 "layout(isolines, point_mode) in;\n"
16381 "\n"
16382 "in vec4 tcs_tes_result[];\n"
16383 "out vec4 tes_gs_result;\n"
16384 "\n"
16385 "UNIFORMS"
16386 "\n"
16387 "void main()\n"
16388 "{\n"
16389 " vec4 result = vec4(0, 1, 0, 1);\n"
16390 "\n"
16391 "VERIFICATION"
16392 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16393 " {\n"
16394 " result = vec4(1, 0, 0, 1);\n"
16395 " }\n"
16396 "\n"
16397 " tes_gs_result = result;\n"
16398 "}\n"
16399 "\n";
16400
16401 static const GLchar *vertex_shader_template = "VERSION\n"
16402 "\n"
16403 "out vec4 vs_tcs_result;\n"
16404 "\n"
16405 "UNIFORMS"
16406 "\n"
16407 "void main()\n"
16408 "{\n"
16409 " vec4 result = vec4(0, 1, 0, 1);\n"
16410 "\n"
16411 "VERIFICATION"
16412 "\n"
16413 " vs_tcs_result = result;\n"
16414 "}\n"
16415 "\n";
16416
16417 const GLchar *shader_template = 0;
16418
16419 switch (in_stage)
16420 {
16421 case Utils::COMPUTE_SHADER:
16422 shader_template = compute_shader_template;
16423 break;
16424 case Utils::FRAGMENT_SHADER:
16425 shader_template = fragment_shader_template;
16426 break;
16427 case Utils::GEOMETRY_SHADER:
16428 shader_template = geometry_shader_template;
16429 break;
16430 case Utils::TESS_CTRL_SHADER:
16431 shader_template = tess_ctrl_shader_template;
16432 break;
16433 case Utils::TESS_EVAL_SHADER:
16434 shader_template = tess_eval_shader_template;
16435 break;
16436 case Utils::VERTEX_SHADER:
16437 shader_template = vertex_shader_template;
16438 break;
16439 default:
16440 TCU_FAIL("Invalid enum");
16441 }
16442
16443 out_source.m_parts[0].m_code = shader_template;
16444
16445 size_t position = 0;
16446 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16447 out_source.m_parts[0].m_code);
16448
16449 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16450
16451 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16452 }
16453
16454 /** Overwritte of prepareUniforms method
16455 *
16456 * @param program Current program
16457 **/
prepareUniforms(Utils::program & program)16458 void LengthOfComputeResultTest::prepareUniforms(Utils::program &program)
16459 {
16460 static const GLfloat gohan_data[12] = {0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f,
16461 0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f};
16462
16463 static const GLfloat goten_data[8] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
16464
16465 static const GLfloat vegeta_data[3] = {0.5f, 0.5f, 0.0f};
16466
16467 static const GLfloat trunks_data[3] = {0.5f, 0.5f, 0.0f};
16468
16469 static const GLuint indices_data[4] = {2, 1, 0, 3};
16470
16471 static const GLuint variable_data[1] = {1};
16472
16473 static const GLuint expected_lengths_data[4] = {3, 2, 3, 3};
16474
16475 static const GLfloat expected_sum_data[1] = {1.0f};
16476
16477 program.uniform("gohan", Utils::FLOAT, 4 /* n_cols */, 3 /* n_rows */, gohan_data);
16478 program.uniform("goten", Utils::FLOAT, 2 /* n_cols */, 4 /* n_rows */, goten_data);
16479 program.uniform("vegeta", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, vegeta_data);
16480 program.uniform("trunks", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, trunks_data);
16481 program.uniform("indices", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, indices_data);
16482 program.uniform("variable", Utils::UINT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16483 program.uniform("expected_lengths", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, expected_lengths_data);
16484 program.uniform("expected_sum", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, expected_sum_data);
16485 }
16486
16487 /** Constructor
16488 *
16489 * @param context Test context
16490 **/
ScalarSwizzlersTest(deqp::Context & context)16491 ScalarSwizzlersTest::ScalarSwizzlersTest(deqp::Context &context)
16492 : GLSLTestBase(context, "scalar_swizzlers", "Verifies that swizzlers can be used on scalars")
16493 {
16494 /* Nothing to be done here */
16495 }
16496
16497 /** Prepare source for given shader stage
16498 *
16499 * @param in_stage Shader stage, compute shader will use 430
16500 * @param in_use_version_400 Select if 400 or 420 should be used
16501 * @param out_source Prepared shader source instance
16502 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16503 void ScalarSwizzlersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16504 Utils::shaderSource &out_source)
16505 {
16506 static const GLchar *uniforms = "uniform float variable;\n"
16507 "uniform vec3 expected_values;\n";
16508
16509 static const GLchar *literal = "#define LITERAL 0.375\n";
16510
16511 static const GLchar *structure = "struct Structure {\n"
16512 " vec2 m_xx;\n"
16513 " vec3 m_xxx;\n"
16514 " vec4 m_xxxx;\n"
16515 " vec2 m_nested_xx;\n"
16516 " vec3 m_nested_xxx;\n"
16517 " vec4 m_nested_xxxx;\n"
16518 "};\n";
16519
16520 static const GLchar *function = "bool check_values(in Structure structure, in float value)\n"
16521 "{\n"
16522 " const vec2 xx = vec2(value, value);\n"
16523 " const vec3 xxx = vec3(value, value, value);\n"
16524 " const vec4 xxxx = vec4(value, value, value, value);\n"
16525 "\n"
16526 " bool result = true;\n"
16527 "\n"
16528 " if ((xx != structure.m_xx) ||\n"
16529 " (xxx != structure.m_xxx) ||\n"
16530 " (xxxx != structure.m_xxxx) ||\n"
16531 " (xx != structure.m_nested_xx) ||\n"
16532 " (xxx != structure.m_nested_xxx) ||\n"
16533 " (xxxx != structure.m_nested_xxxx) )\n"
16534 " {\n"
16535 " result = false;\n"
16536 " }\n"
16537 "\n"
16538 " return result;\n"
16539 "}\n";
16540
16541 static const GLchar *verification_snippet =
16542 " Structure literal_result;\n"
16543 " Structure constant_result;\n"
16544 " Structure variable_result;\n"
16545 "\n"
16546 " literal_result.m_xx = LITERAL.xx ;\n"
16547 " literal_result.m_xxx = LITERAL.xxx ;\n"
16548 " literal_result.m_xxxx = LITERAL.xxxx;\n"
16549 " literal_result.m_nested_xx = LITERAL.x.rr.sss.rr ;\n"
16550 " literal_result.m_nested_xxx = LITERAL.s.xx.rrr.xxx ;\n"
16551 " literal_result.m_nested_xxxx = LITERAL.r.ss.xxx.ssss;\n"
16552 "\n"
16553 " const float constant = 0.125;\n"
16554 "\n"
16555 " constant_result.m_xx = constant.xx ;\n"
16556 " constant_result.m_xxx = constant.xxx ;\n"
16557 " constant_result.m_xxxx = constant.xxxx;\n"
16558 " constant_result.m_nested_xx = constant.x.rr.sss.rr ;\n"
16559 " constant_result.m_nested_xxx = constant.s.xx.rrr.xxx ;\n"
16560 " constant_result.m_nested_xxxx = constant.r.ss.xxx.ssss;\n"
16561 "\n"
16562 " variable_result.m_xx = variable.xx ;\n"
16563 " variable_result.m_xxx = variable.xxx ;\n"
16564 " variable_result.m_xxxx = variable.xxxx;\n"
16565 " variable_result.m_nested_xx = variable.x.rr.sss.rr ;\n"
16566 " variable_result.m_nested_xxx = variable.s.xx.rrr.xxx ;\n"
16567 " variable_result.m_nested_xxxx = variable.r.ss.xxx.ssss;\n"
16568 "\n"
16569 " if ((false == check_values(literal_result, expected_values.x)) ||\n"
16570 " (false == check_values(constant_result, expected_values.y)) ||\n"
16571 " (false == check_values(variable_result, expected_values.z)) )\n"
16572 " {\n"
16573 " result = vec4(1, 0, 0, 1);\n"
16574 " }\n";
16575
16576 static const GLchar *compute_shader_template =
16577 "VERSION\n"
16578 "\n"
16579 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16580 "\n"
16581 "writeonly uniform image2D uni_image;\n"
16582 "\n"
16583 "STRUCTURE"
16584 "\n"
16585 "UNIFORMS"
16586 "\n"
16587 "FUNCTION"
16588 "\n"
16589 "LITERAL"
16590 "\n"
16591 "void main()\n"
16592 "{\n"
16593 " vec4 result = vec4(0, 1, 0, 1);\n"
16594 "\n"
16595 "VERIFICATION"
16596 "\n"
16597 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16598 "}\n"
16599 "\n";
16600
16601 static const GLchar *fragment_shader_template = "VERSION\n"
16602 "\n"
16603 "#define FRAGMENT\n"
16604 "\n"
16605 "in vec4 gs_fs_result;\n"
16606 "out vec4 fs_out_result;\n"
16607 "\n"
16608 "STRUCTURE"
16609 "\n"
16610 "UNIFORMS"
16611 "\n"
16612 "FUNCTION"
16613 "\n"
16614 "LITERAL"
16615 "\n"
16616 "void main()\n"
16617 "{\n"
16618 " vec4 result = vec4(0, 1, 0, 1);\n"
16619 "\n"
16620 "VERIFICATION"
16621 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16622 " {\n"
16623 " result = vec4(1, 0, 0, 1);\n"
16624 " }\n"
16625 "\n"
16626 " fs_out_result = result;\n"
16627 "}\n"
16628 "\n";
16629
16630 static const GLchar *geometry_shader_template = "VERSION\n"
16631 "\n"
16632 "layout(points) in;\n"
16633 "layout(triangle_strip, max_vertices = 4) out;\n"
16634 "\n"
16635 "in vec4 tes_gs_result[];\n"
16636 "out vec4 gs_fs_result;\n"
16637 "\n"
16638 "STRUCTURE"
16639 "\n"
16640 "UNIFORMS"
16641 "\n"
16642 "FUNCTION"
16643 "\n"
16644 "LITERAL"
16645 "\n"
16646 "void main()\n"
16647 "{\n"
16648 " vec4 result = vec4(0, 1, 0, 1);\n"
16649 "\n"
16650 "VERIFICATION"
16651 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16652 " {\n"
16653 " result = vec4(1, 0, 0, 1);\n"
16654 " }\n"
16655 "\n"
16656 " gs_fs_result = result;\n"
16657 " gl_Position = vec4(-1, -1, 0, 1);\n"
16658 " EmitVertex();\n"
16659 " gs_fs_result = result;\n"
16660 " gl_Position = vec4(-1, 1, 0, 1);\n"
16661 " EmitVertex();\n"
16662 " gs_fs_result = result;\n"
16663 " gl_Position = vec4(1, -1, 0, 1);\n"
16664 " EmitVertex();\n"
16665 " gs_fs_result = result;\n"
16666 " gl_Position = vec4(1, 1, 0, 1);\n"
16667 " EmitVertex();\n"
16668 "}\n"
16669 "\n";
16670
16671 static const GLchar *tess_ctrl_shader_template =
16672 "VERSION\n"
16673 "\n"
16674 "layout(vertices = 1) out;\n"
16675 "\n"
16676 "in vec4 vs_tcs_result[];\n"
16677 "out vec4 tcs_tes_result[];\n"
16678 "\n"
16679 "STRUCTURE"
16680 "\n"
16681 "UNIFORMS"
16682 "\n"
16683 "FUNCTION"
16684 "\n"
16685 "LITERAL"
16686 "\n"
16687 "void main()\n"
16688 "{\n"
16689 " vec4 result = vec4(0, 1, 0, 1);\n"
16690 "\n"
16691 "VERIFICATION"
16692 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16693 " {\n"
16694 " result = vec4(1, 0, 0, 1);\n"
16695 " }\n"
16696 "\n"
16697 " tcs_tes_result[gl_InvocationID] = result;\n"
16698 "\n"
16699 " gl_TessLevelOuter[0] = 1.0;\n"
16700 " gl_TessLevelOuter[1] = 1.0;\n"
16701 " gl_TessLevelOuter[2] = 1.0;\n"
16702 " gl_TessLevelOuter[3] = 1.0;\n"
16703 " gl_TessLevelInner[0] = 1.0;\n"
16704 " gl_TessLevelInner[1] = 1.0;\n"
16705 "}\n"
16706 "\n";
16707
16708 static const GLchar *tess_eval_shader_template = "VERSION\n"
16709 "\n"
16710 "layout(isolines, point_mode) in;\n"
16711 "\n"
16712 "in vec4 tcs_tes_result[];\n"
16713 "out vec4 tes_gs_result;\n"
16714 "\n"
16715 "STRUCTURE"
16716 "\n"
16717 "UNIFORMS"
16718 "\n"
16719 "FUNCTION"
16720 "\n"
16721 "LITERAL"
16722 "\n"
16723 "void main()\n"
16724 "{\n"
16725 " vec4 result = vec4(0, 1, 0, 1);\n"
16726 "\n"
16727 "VERIFICATION"
16728 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16729 " {\n"
16730 " result = vec4(1, 0, 0, 1);\n"
16731 " }\n"
16732 "\n"
16733 " tes_gs_result = result;\n"
16734 "}\n"
16735 "\n";
16736
16737 static const GLchar *vertex_shader_template = "VERSION\n"
16738 "\n"
16739 "out vec4 vs_tcs_result;\n"
16740 "\n"
16741 "STRUCTURE"
16742 "\n"
16743 "UNIFORMS"
16744 "\n"
16745 "FUNCTION"
16746 "\n"
16747 "LITERAL"
16748 "\n"
16749 "void main()\n"
16750 "{\n"
16751 " vec4 result = vec4(0, 1, 0, 1);\n"
16752 "\n"
16753 "VERIFICATION"
16754 "\n"
16755 " vs_tcs_result = result;\n"
16756 "}\n"
16757 "\n";
16758
16759 const GLchar *shader_template = 0;
16760
16761 switch (in_stage)
16762 {
16763 case Utils::COMPUTE_SHADER:
16764 shader_template = compute_shader_template;
16765 break;
16766 case Utils::FRAGMENT_SHADER:
16767 shader_template = fragment_shader_template;
16768 break;
16769 case Utils::GEOMETRY_SHADER:
16770 shader_template = geometry_shader_template;
16771 break;
16772 case Utils::TESS_CTRL_SHADER:
16773 shader_template = tess_ctrl_shader_template;
16774 break;
16775 case Utils::TESS_EVAL_SHADER:
16776 shader_template = tess_eval_shader_template;
16777 break;
16778 case Utils::VERTEX_SHADER:
16779 shader_template = vertex_shader_template;
16780 break;
16781 default:
16782 TCU_FAIL("Invalid enum");
16783 }
16784
16785 out_source.m_parts[0].m_code = shader_template;
16786
16787 size_t position = 0;
16788 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16789 out_source.m_parts[0].m_code);
16790
16791 Utils::replaceToken("STRUCTURE", position, structure, out_source.m_parts[0].m_code);
16792
16793 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16794
16795 Utils::replaceToken("FUNCTION", position, function, out_source.m_parts[0].m_code);
16796
16797 Utils::replaceToken("LITERAL", position, literal, out_source.m_parts[0].m_code);
16798
16799 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16800 }
16801
16802 /** Overwritte of prepareUniforms method
16803 *
16804 * @param program Current program
16805 **/
prepareUniforms(Utils::program & program)16806 void ScalarSwizzlersTest::prepareUniforms(Utils::program &program)
16807 {
16808 static const GLfloat variable_data[4] = {0.75f};
16809 static const GLfloat expected_values_data[3] = {0.375f, 0.125f, 0.75f};
16810
16811 program.uniform("variable", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16812 program.uniform("expected_values", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, expected_values_data);
16813 }
16814
16815 /** Constructor
16816 *
16817 * @param context Test context
16818 **/
ScalarSwizzlersInvalidTest(deqp::Context & context)16819 ScalarSwizzlersInvalidTest::ScalarSwizzlersInvalidTest(deqp::Context &context)
16820 : NegativeTestBase(context, "scalar_swizzlers_invalid",
16821 "Verifies if invalid use of swizzlers on scalars is reported as error")
16822 {
16823 /* Nothing to be done here */
16824 }
16825
16826 /** Set up next test case
16827 *
16828 * @param test_case_index Index of next test case
16829 *
16830 * @return false if there is no more test cases, true otherwise
16831 **/
prepareNextTestCase(glw::GLuint test_case_index)16832 bool ScalarSwizzlersInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
16833 {
16834 switch (test_case_index)
16835 {
16836 case (glw::GLuint)-1:
16837 case INVALID_Y:
16838 case INVALID_B:
16839 case INVALID_Q:
16840 case INVALID_XY:
16841 case INVALID_XRS:
16842 case WRONG:
16843 case MISSING_PARENTHESIS:
16844 m_case = (TESTED_CASES)test_case_index;
16845 break;
16846 default:
16847 return false;
16848 }
16849
16850 return true;
16851 }
16852
16853 /** Prepare source for given shader stage
16854 *
16855 * @param in_stage Shader stage, compute shader will use 430
16856 * @param in_use_version_400 Select if 400 or 420 should be used
16857 * @param out_source Prepared shader source instance
16858 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16859 void ScalarSwizzlersInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16860 Utils::shaderSource &out_source)
16861 {
16862 static const GLchar *uniforms = "uniform float variable;\n";
16863
16864 static const GLchar *verification_invalid_y = "\n"
16865 " if (0.125 != variable.y) )\n"
16866 " {\n"
16867 " result = vec4(1, 0, 0, 1);\n"
16868 " }\n";
16869
16870 static const GLchar *verification_invalid_b = "\n"
16871 " if (0.125 != variable.b) )\n"
16872 " {\n"
16873 " result = vec4(1, 0, 0, 1);\n"
16874 " }\n";
16875
16876 static const GLchar *verification_invalid_q = "\n"
16877 " if (0.125 != variable.q) )\n"
16878 " {\n"
16879 " result = vec4(1, 0, 0, 1);\n"
16880 " }\n";
16881
16882 static const GLchar *verification_invalid_xy = "\n"
16883 " if (vec2(0.125, 0.25) != variable.xy) )\n"
16884 " {\n"
16885 " result = vec4(1, 0, 0, 1);\n"
16886 " }\n";
16887
16888 static const GLchar *verification_invalid_xrs = "\n"
16889 " if (vec3(0.125, 0.125, 0.25) != variable.xrs) )\n"
16890 " {\n"
16891 " result = vec4(1, 0, 0, 1);\n"
16892 " }\n";
16893
16894 static const GLchar *verification_wrong_u = "\n"
16895 " if (0.125 != variable.u) )\n"
16896 " {\n"
16897 " result = vec4(1, 0, 0, 1);\n"
16898 " }\n";
16899
16900 static const GLchar *verification_missing_parenthesis = "\n"
16901 " if (variable != 1.x) )\n"
16902 " {\n"
16903 " result = vec4(1, 0, 0, 1);\n"
16904 " }\n";
16905
16906 static const GLchar *compute_shader_template =
16907 "VERSION\n"
16908 "\n"
16909 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16910 "\n"
16911 "writeonly uniform image2D uni_image;\n"
16912 "\n"
16913 "UNIFORMS"
16914 "\n"
16915 "void main()\n"
16916 "{\n"
16917 " vec4 result = vec4(0, 1, 0, 1);\n"
16918 "\n"
16919 "VERIFICATION"
16920 "\n"
16921 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16922 "}\n"
16923 "\n";
16924
16925 static const GLchar *fragment_shader_template = "VERSION\n"
16926 "\n"
16927 "#define FRAGMENT\n"
16928 "\n"
16929 "in vec4 gs_fs_result;\n"
16930 "out vec4 fs_out_result;\n"
16931 "\n"
16932 "UNIFORMS"
16933 "\n"
16934 "void main()\n"
16935 "{\n"
16936 " vec4 result = vec4(0, 1, 0, 1);\n"
16937 "\n"
16938 "VERIFICATION"
16939 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16940 " {\n"
16941 " result = vec4(1, 0, 0, 1);\n"
16942 " }\n"
16943 "\n"
16944 " fs_out_result = result;\n"
16945 "}\n"
16946 "\n";
16947
16948 static const GLchar *geometry_shader_template = "VERSION\n"
16949 "\n"
16950 "layout(points) in;\n"
16951 "layout(triangle_strip, max_vertices = 4) out;\n"
16952 "\n"
16953 "in vec4 tes_gs_result[];\n"
16954 "out vec4 gs_fs_result;\n"
16955 "\n"
16956 "UNIFORMS"
16957 "\n"
16958 "void main()\n"
16959 "{\n"
16960 " vec4 result = vec4(0, 1, 0, 1);\n"
16961 "\n"
16962 "VERIFICATION"
16963 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16964 " {\n"
16965 " result = vec4(1, 0, 0, 1);\n"
16966 " }\n"
16967 "\n"
16968 " gs_fs_result = result;\n"
16969 " gl_Position = vec4(-1, -1, 0, 1);\n"
16970 " EmitVertex();\n"
16971 " gs_fs_result = result;\n"
16972 " gl_Position = vec4(-1, 1, 0, 1);\n"
16973 " EmitVertex();\n"
16974 " gs_fs_result = result;\n"
16975 " gl_Position = vec4(1, -1, 0, 1);\n"
16976 " EmitVertex();\n"
16977 " gs_fs_result = result;\n"
16978 " gl_Position = vec4(1, 1, 0, 1);\n"
16979 " EmitVertex();\n"
16980 "}\n"
16981 "\n";
16982
16983 static const GLchar *tess_ctrl_shader_template =
16984 "VERSION\n"
16985 "\n"
16986 "layout(vertices = 1) out;\n"
16987 "\n"
16988 "in vec4 vs_tcs_result[];\n"
16989 "out vec4 tcs_tes_result[];\n"
16990 "\n"
16991 "UNIFORMS"
16992 "\n"
16993 "void main()\n"
16994 "{\n"
16995 " vec4 result = vec4(0, 1, 0, 1);\n"
16996 "\n"
16997 "VERIFICATION"
16998 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16999 " {\n"
17000 " result = vec4(1, 0, 0, 1);\n"
17001 " }\n"
17002 "\n"
17003 " tcs_tes_result[gl_InvocationID] = result;\n"
17004 "\n"
17005 " gl_TessLevelOuter[0] = 1.0;\n"
17006 " gl_TessLevelOuter[1] = 1.0;\n"
17007 " gl_TessLevelOuter[2] = 1.0;\n"
17008 " gl_TessLevelOuter[3] = 1.0;\n"
17009 " gl_TessLevelInner[0] = 1.0;\n"
17010 " gl_TessLevelInner[1] = 1.0;\n"
17011 "}\n"
17012 "\n";
17013
17014 static const GLchar *tess_eval_shader_template = "VERSION\n"
17015 "\n"
17016 "layout(isolines, point_mode) in;\n"
17017 "\n"
17018 "in vec4 tcs_tes_result[];\n"
17019 "out vec4 tes_gs_result;\n"
17020 "\n"
17021 "UNIFORMS"
17022 "\n"
17023 "void main()\n"
17024 "{\n"
17025 " vec4 result = vec4(0, 1, 0, 1);\n"
17026 "\n"
17027 "VERIFICATION"
17028 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17029 " {\n"
17030 " result = vec4(1, 0, 0, 1);\n"
17031 " }\n"
17032 "\n"
17033 " tes_gs_result = result;\n"
17034 "}\n"
17035 "\n";
17036
17037 static const GLchar *vertex_shader_template = "VERSION\n"
17038 "\n"
17039 "out vec4 vs_tcs_result;\n"
17040 "\n"
17041 "UNIFORMS"
17042 "\n"
17043 "void main()\n"
17044 "{\n"
17045 " vec4 result = vec4(0, 1, 0, 1);\n"
17046 "\n"
17047 "VERIFICATION"
17048 "\n"
17049 " vs_tcs_result = result;\n"
17050 "}\n"
17051 "\n";
17052
17053 const GLchar *shader_template = 0;
17054 const GLchar *verification_snippet = 0;
17055
17056 switch (in_stage)
17057 {
17058 case Utils::COMPUTE_SHADER:
17059 shader_template = compute_shader_template;
17060 break;
17061 case Utils::FRAGMENT_SHADER:
17062 shader_template = fragment_shader_template;
17063 break;
17064 case Utils::GEOMETRY_SHADER:
17065 shader_template = geometry_shader_template;
17066 break;
17067 case Utils::TESS_CTRL_SHADER:
17068 shader_template = tess_ctrl_shader_template;
17069 break;
17070 case Utils::TESS_EVAL_SHADER:
17071 shader_template = tess_eval_shader_template;
17072 break;
17073 case Utils::VERTEX_SHADER:
17074 shader_template = vertex_shader_template;
17075 break;
17076 default:
17077 TCU_FAIL("Invalid enum");
17078 }
17079
17080 switch (m_case)
17081 {
17082 case INVALID_Y:
17083 verification_snippet = verification_invalid_y;
17084 break;
17085 case INVALID_B:
17086 verification_snippet = verification_invalid_b;
17087 break;
17088 case INVALID_Q:
17089 verification_snippet = verification_invalid_q;
17090 break;
17091 case INVALID_XY:
17092 verification_snippet = verification_invalid_xy;
17093 break;
17094 case INVALID_XRS:
17095 verification_snippet = verification_invalid_xrs;
17096 break;
17097 case WRONG:
17098 verification_snippet = verification_wrong_u;
17099 break;
17100 case MISSING_PARENTHESIS:
17101 verification_snippet = verification_missing_parenthesis;
17102 break;
17103 default:
17104 TCU_FAIL("Invalid enum");
17105 }
17106
17107 out_source.m_parts[0].m_code = shader_template;
17108
17109 size_t position = 0;
17110 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17111 out_source.m_parts[0].m_code);
17112
17113 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
17114
17115 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17116 }
17117
17118 /* Constants used by BuiltInValuesTest */
17119 const GLint BuiltInValuesTest::m_min_program_texel_offset_limit = -8;
17120 const GLint BuiltInValuesTest::m_max_program_texel_offset_limit = 7;
17121
17122 /** Constructor
17123 *
17124 * @param context Test context
17125 **/
BuiltInValuesTest(deqp::Context & context)17126 BuiltInValuesTest::BuiltInValuesTest(deqp::Context &context)
17127 : GLSLTestBase(context, "built_in_values", "Test verifies values of gl_Min/Max_ProgramTexelOffset")
17128 {
17129 /* Nothing to be done here */
17130 }
17131
17132 /** Prepare source for given shader stage
17133 *
17134 * @param in_stage Shader stage, compute shader will use 430
17135 * @param in_use_version_400 Select if 400 or 420 should be used
17136 * @param out_source Prepared shader source instance
17137 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17138 void BuiltInValuesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17139 Utils::shaderSource &out_source)
17140 {
17141 static const GLchar *verification_snippet = " if ((expected_values.x != gl_MinProgramTexelOffset) ||\n"
17142 " (expected_values.y != gl_MaxProgramTexelOffset) )\n"
17143 " {\n"
17144 " result = vec4(1, 0, 0, 1);\n"
17145 " }\n";
17146
17147 static const GLchar *compute_shader_template =
17148 "VERSION\n"
17149 "\n"
17150 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17151 "\n"
17152 "writeonly uniform image2D uni_image;\n"
17153 " uniform ivec2 expected_values;\n"
17154 "\n"
17155 "void main()\n"
17156 "{\n"
17157 " vec4 result = vec4(0, 1, 0, 1);\n"
17158 "\n"
17159 "VERIFICATION"
17160 "\n"
17161 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17162 "}\n"
17163 "\n";
17164
17165 static const GLchar *fragment_shader_template = "VERSION\n"
17166 "\n"
17167 "in vec4 gs_fs_result;\n"
17168 "out vec4 fs_out_result;\n"
17169 "\n"
17170 "uniform ivec2 expected_values;\n"
17171 "\n"
17172 "void main()\n"
17173 "{\n"
17174 " vec4 result = vec4(0, 1, 0, 1);\n"
17175 "\n"
17176 "VERIFICATION"
17177 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17178 " {\n"
17179 " result = vec4(1, 0, 0, 1);\n"
17180 " }\n"
17181 "\n"
17182 " fs_out_result = result;\n"
17183 "}\n"
17184 "\n";
17185
17186 static const GLchar *geometry_shader_template = "VERSION\n"
17187 "\n"
17188 "layout(points) in;\n"
17189 "layout(triangle_strip, max_vertices = 4) out;\n"
17190 "\n"
17191 "in vec4 tes_gs_result[];\n"
17192 "out vec4 gs_fs_result;\n"
17193 "\n"
17194 "uniform ivec2 expected_values;\n"
17195 "\n"
17196 "void main()\n"
17197 "{\n"
17198 " vec4 result = vec4(0, 1, 0, 1);\n"
17199 "\n"
17200 "VERIFICATION"
17201 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17202 " {\n"
17203 " result = vec4(1, 0, 0, 1);\n"
17204 " }\n"
17205 "\n"
17206 " gs_fs_result = result;\n"
17207 " gl_Position = vec4(-1, -1, 0, 1);\n"
17208 " EmitVertex();\n"
17209 " gs_fs_result = result;\n"
17210 " gl_Position = vec4(-1, 1, 0, 1);\n"
17211 " EmitVertex();\n"
17212 " gs_fs_result = result;\n"
17213 " gl_Position = vec4(1, -1, 0, 1);\n"
17214 " EmitVertex();\n"
17215 " gs_fs_result = result;\n"
17216 " gl_Position = vec4(1, 1, 0, 1);\n"
17217 " EmitVertex();\n"
17218 "}\n"
17219 "\n";
17220
17221 static const GLchar *tess_ctrl_shader_template =
17222 "VERSION\n"
17223 "\n"
17224 "layout(vertices = 1) out;\n"
17225 "\n"
17226 "in vec4 vs_tcs_result[];\n"
17227 "out vec4 tcs_tes_result[];\n"
17228 "\n"
17229 "uniform ivec2 expected_values;\n"
17230 "\n"
17231 "void main()\n"
17232 "{\n"
17233 " vec4 result = vec4(0, 1, 0, 1);\n"
17234 "\n"
17235 "VERIFICATION"
17236 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17237 " {\n"
17238 " result = vec4(1, 0, 0, 1);\n"
17239 " }\n"
17240 "\n"
17241 " tcs_tes_result[gl_InvocationID] = result;\n"
17242 "\n"
17243 " gl_TessLevelOuter[0] = 1.0;\n"
17244 " gl_TessLevelOuter[1] = 1.0;\n"
17245 " gl_TessLevelOuter[2] = 1.0;\n"
17246 " gl_TessLevelOuter[3] = 1.0;\n"
17247 " gl_TessLevelInner[0] = 1.0;\n"
17248 " gl_TessLevelInner[1] = 1.0;\n"
17249 "}\n"
17250 "\n";
17251
17252 static const GLchar *tess_eval_shader_template = "VERSION\n"
17253 "\n"
17254 "layout(isolines, point_mode) in;\n"
17255 "\n"
17256 "in vec4 tcs_tes_result[];\n"
17257 "out vec4 tes_gs_result;\n"
17258 "\n"
17259 "uniform ivec2 expected_values;\n"
17260 "\n"
17261 "void main()\n"
17262 "{\n"
17263 " vec4 result = vec4(0, 1, 0, 1);\n"
17264 "\n"
17265 "VERIFICATION"
17266 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17267 " {\n"
17268 " result = vec4(1, 0, 0, 1);\n"
17269 " }\n"
17270 "\n"
17271 " tes_gs_result = result;\n"
17272 "}\n"
17273 "\n";
17274
17275 static const GLchar *vertex_shader_template = "VERSION\n"
17276 "\n"
17277 "out vec4 vs_tcs_result;\n"
17278 "\n"
17279 "uniform ivec2 expected_values;\n"
17280 "\n"
17281 "void main()\n"
17282 "{\n"
17283 " vec4 result = vec4(0, 1, 0, 1);\n"
17284 "\n"
17285 "VERIFICATION"
17286 "\n"
17287 " vs_tcs_result = result;\n"
17288 "}\n"
17289 "\n";
17290
17291 const GLchar *shader_template = 0;
17292
17293 switch (in_stage)
17294 {
17295 case Utils::COMPUTE_SHADER:
17296 shader_template = compute_shader_template;
17297 break;
17298 case Utils::FRAGMENT_SHADER:
17299 shader_template = fragment_shader_template;
17300 break;
17301 case Utils::GEOMETRY_SHADER:
17302 shader_template = geometry_shader_template;
17303 break;
17304 case Utils::TESS_CTRL_SHADER:
17305 shader_template = tess_ctrl_shader_template;
17306 break;
17307 case Utils::TESS_EVAL_SHADER:
17308 shader_template = tess_eval_shader_template;
17309 break;
17310 case Utils::VERTEX_SHADER:
17311 shader_template = vertex_shader_template;
17312 break;
17313 default:
17314 TCU_FAIL("Invalid enum");
17315 }
17316
17317 out_source.m_parts[0].m_code = shader_template;
17318
17319 size_t position = 0;
17320 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17321 out_source.m_parts[0].m_code);
17322
17323 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17324 }
17325
17326 /** Overwritte of prepareUniforms method
17327 *
17328 * @param program Current program
17329 **/
prepareUniforms(Utils::program & program)17330 void BuiltInValuesTest::prepareUniforms(Utils::program &program)
17331 {
17332 const GLint expected_values_data[2] = {m_min_program_texel_offset, m_max_program_texel_offset};
17333
17334 program.uniform("expected_values", Utils::INT, 1 /* n_cols */, 2 /* n_rows */, expected_values_data);
17335 }
17336
17337 /** Prepare test cases
17338 *
17339 * @return true
17340 **/
testInit()17341 bool BuiltInValuesTest::testInit()
17342 {
17343 const Functions &gl = m_context.getRenderContext().getFunctions();
17344
17345 gl.getIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, &m_min_program_texel_offset);
17346 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17347
17348 gl.getIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, &m_max_program_texel_offset);
17349 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17350
17351 if ((m_min_program_texel_offset_limit > m_min_program_texel_offset) ||
17352 (m_max_program_texel_offset_limit > m_max_program_texel_offset))
17353 {
17354 m_context.getTestContext().getLog()
17355 << tcu::TestLog::Message << "Invalid GL_PROGRAM_TEXEL_OFFSET values."
17356 << " Min: " << m_min_program_texel_offset << " expected at top: " << m_min_program_texel_offset_limit
17357 << " Max: " << m_min_program_texel_offset << " expected at least: " << m_max_program_texel_offset_limit
17358 << tcu::TestLog::EndMessage;
17359
17360 return false;
17361 }
17362
17363 return true;
17364 }
17365
17366 /** Constructor
17367 *
17368 * @param context Test context
17369 **/
BuiltInAssignmentTest(deqp::Context & context)17370 BuiltInAssignmentTest::BuiltInAssignmentTest(deqp::Context &context)
17371 : NegativeTestBase(context, "built_in_assignment",
17372 "Test verifies that built in gl_Min/MaxProgramTexelOffset cannot be assigned")
17373 {
17374 /* Nothing to be done here */
17375 }
17376
17377 /** Set up next test case
17378 *
17379 * @param test_case_index Index of next test case
17380 *
17381 * @return false if there is no more test cases, true otherwise
17382 **/
prepareNextTestCase(glw::GLuint test_case_index)17383 bool BuiltInAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
17384 {
17385 const GLchar *description = 0;
17386
17387 switch (test_case_index)
17388 {
17389 case (glw::GLuint)-1:
17390 case 0:
17391 description = "Testing gl_MinProgramTexelOffset";
17392 break;
17393 case 1:
17394 description = "Testing gl_MaxProgramTexelOffset";
17395 break;
17396 default:
17397 return false;
17398 }
17399
17400 m_case = test_case_index;
17401
17402 m_context.getTestContext().getLog() << tcu::TestLog::Message << description << tcu::TestLog::EndMessage;
17403
17404 return true;
17405 }
17406
17407 /** Prepare source for given shader stage
17408 *
17409 * @param in_stage Shader stage, compute shader will use 430
17410 * @param in_use_version_400 Select if 400 or 420 should be used
17411 * @param out_source Prepared shader source instance
17412 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17413 void BuiltInAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17414 Utils::shaderSource &out_source)
17415 {
17416 static const GLchar *min_verification_snippet = " gl_MinProgramTexelOffset += gl_MaxProgramTexelOffset\n"
17417 "\n"
17418 " if (expected_value != gl_MinProgramTexelOffset)\n"
17419 " {\n"
17420 " result = vec4(1, 0, 0, 1);\n"
17421 " }\n";
17422
17423 static const GLchar *max_verification_snippet = " gl_MaxProgramTexelOffset += gl_MinProgramTexelOffset\n"
17424 "\n"
17425 " if (expected_value != gl_MaxProgramTexelOffset)\n"
17426 " {\n"
17427 " result = vec4(1, 0, 0, 1);\n"
17428 " }\n";
17429
17430 static const GLchar *compute_shader_template =
17431 "VERSION\n"
17432 "\n"
17433 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17434 "\n"
17435 "writeonly uniform image2D uni_image;\n"
17436 " uniform ivec2 expected_values;\n"
17437 "\n"
17438 "void main()\n"
17439 "{\n"
17440 " vec4 result = vec4(0, 1, 0, 1);\n"
17441 "\n"
17442 "VERIFICATION"
17443 "\n"
17444 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17445 "}\n"
17446 "\n";
17447
17448 static const GLchar *fragment_shader_template = "VERSION\n"
17449 "\n"
17450 "in vec4 gs_fs_result;\n"
17451 "out vec4 fs_out_result;\n"
17452 "\n"
17453 "uniform ivec2 expected_values;\n"
17454 "\n"
17455 "void main()\n"
17456 "{\n"
17457 " vec4 result = vec4(0, 1, 0, 1);\n"
17458 "\n"
17459 "VERIFICATION"
17460 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17461 " {\n"
17462 " result = vec4(1, 0, 0, 1);\n"
17463 " }\n"
17464 "\n"
17465 " fs_out_result = result;\n"
17466 "}\n"
17467 "\n";
17468
17469 static const GLchar *geometry_shader_template = "VERSION\n"
17470 "\n"
17471 "layout(points) in;\n"
17472 "layout(triangle_strip, max_vertices = 4) out;\n"
17473 "\n"
17474 "in vec4 tes_gs_result[];\n"
17475 "out vec4 gs_fs_result;\n"
17476 "\n"
17477 "uniform ivec2 expected_values;\n"
17478 "\n"
17479 "void main()\n"
17480 "{\n"
17481 " vec4 result = vec4(0, 1, 0, 1);\n"
17482 "\n"
17483 "VERIFICATION"
17484 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17485 " {\n"
17486 " result = vec4(1, 0, 0, 1);\n"
17487 " }\n"
17488 "\n"
17489 " gs_fs_result = result;\n"
17490 " gl_Position = vec4(-1, -1, 0, 1);\n"
17491 " EmitVertex();\n"
17492 " gs_fs_result = result;\n"
17493 " gl_Position = vec4(-1, 1, 0, 1);\n"
17494 " EmitVertex();\n"
17495 " gs_fs_result = result;\n"
17496 " gl_Position = vec4(1, -1, 0, 1);\n"
17497 " EmitVertex();\n"
17498 " gs_fs_result = result;\n"
17499 " gl_Position = vec4(1, 1, 0, 1);\n"
17500 " EmitVertex();\n"
17501 "}\n"
17502 "\n";
17503
17504 static const GLchar *tess_ctrl_shader_template =
17505 "VERSION\n"
17506 "\n"
17507 "layout(vertices = 1) out;\n"
17508 "\n"
17509 "in vec4 vs_tcs_result[];\n"
17510 "out vec4 tcs_tes_result[];\n"
17511 "\n"
17512 "uniform ivec2 expected_values;\n"
17513 "\n"
17514 "void main()\n"
17515 "{\n"
17516 " vec4 result = vec4(0, 1, 0, 1);\n"
17517 "\n"
17518 "VERIFICATION"
17519 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17520 " {\n"
17521 " result = vec4(1, 0, 0, 1);\n"
17522 " }\n"
17523 "\n"
17524 " tcs_tes_result[gl_InvocationID] = result;\n"
17525 "\n"
17526 " gl_TessLevelOuter[0] = 1.0;\n"
17527 " gl_TessLevelOuter[1] = 1.0;\n"
17528 " gl_TessLevelOuter[2] = 1.0;\n"
17529 " gl_TessLevelOuter[3] = 1.0;\n"
17530 " gl_TessLevelInner[0] = 1.0;\n"
17531 " gl_TessLevelInner[1] = 1.0;\n"
17532 "}\n"
17533 "\n";
17534
17535 static const GLchar *tess_eval_shader_template = "VERSION\n"
17536 "\n"
17537 "layout(isolines, point_mode) in;\n"
17538 "\n"
17539 "in vec4 tcs_tes_result[];\n"
17540 "out vec4 tes_gs_result;\n"
17541 "\n"
17542 "uniform ivec2 expected_values;\n"
17543 "\n"
17544 "void main()\n"
17545 "{\n"
17546 " vec4 result = vec4(0, 1, 0, 1);\n"
17547 "\n"
17548 "VERIFICATION"
17549 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17550 " {\n"
17551 " result = vec4(1, 0, 0, 1);\n"
17552 " }\n"
17553 "\n"
17554 " tes_gs_result = result;\n"
17555 "}\n"
17556 "\n";
17557
17558 static const GLchar *vertex_shader_template = "VERSION\n"
17559 "\n"
17560 "out vec4 vs_tcs_result;\n"
17561 "\n"
17562 "uniform ivec2 expected_values;\n"
17563 "\n"
17564 "void main()\n"
17565 "{\n"
17566 " vec4 result = vec4(0, 1, 0, 1);\n"
17567 "\n"
17568 "VERIFICATION"
17569 "\n"
17570 " vs_tcs_result = result;\n"
17571 "}\n"
17572 "\n";
17573
17574 const GLchar *shader_template = 0;
17575 const GLchar *verification_snippet = 0;
17576
17577 switch (in_stage)
17578 {
17579 case Utils::COMPUTE_SHADER:
17580 shader_template = compute_shader_template;
17581 break;
17582 case Utils::FRAGMENT_SHADER:
17583 shader_template = fragment_shader_template;
17584 break;
17585 case Utils::GEOMETRY_SHADER:
17586 shader_template = geometry_shader_template;
17587 break;
17588 case Utils::TESS_CTRL_SHADER:
17589 shader_template = tess_ctrl_shader_template;
17590 break;
17591 case Utils::TESS_EVAL_SHADER:
17592 shader_template = tess_eval_shader_template;
17593 break;
17594 case Utils::VERTEX_SHADER:
17595 shader_template = vertex_shader_template;
17596 break;
17597 default:
17598 TCU_FAIL("Invalid enum");
17599 }
17600
17601 switch (m_case)
17602 {
17603 case (glw::GLuint)-1:
17604 case 0:
17605 verification_snippet = min_verification_snippet;
17606 break;
17607 case 1:
17608 verification_snippet = max_verification_snippet;
17609 break;
17610 }
17611
17612 out_source.m_parts[0].m_code = shader_template;
17613
17614 size_t position = 0;
17615 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17616 out_source.m_parts[0].m_code);
17617
17618 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17619 }
17620
17621 /** Constructor.
17622 *
17623 * @param context CTS context.
17624 **/
buffer(deqp::Context & context)17625 Utils::buffer::buffer(deqp::Context &context) : m_id(0), m_context(context), m_target(0)
17626 {
17627 }
17628
17629 /** Destructor
17630 *
17631 **/
~buffer()17632 Utils::buffer::~buffer()
17633 {
17634 release();
17635 }
17636
17637 /** Execute BindBuffer
17638 *
17639 **/
bind() const17640 void Utils::buffer::bind() const
17641 {
17642 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17643
17644 gl.bindBuffer(m_target, m_id);
17645 GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
17646 }
17647
17648 /** Execute BindBufferRange
17649 *
17650 * @param index <index> parameter
17651 * @param offset <offset> parameter
17652 * @param size <size> parameter
17653 **/
bindRange(glw::GLuint index,glw::GLintptr offset,glw::GLsizeiptr size)17654 void Utils::buffer::bindRange(glw::GLuint index, glw::GLintptr offset, glw::GLsizeiptr size)
17655 {
17656 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17657
17658 gl.bindBufferRange(m_target, index, m_id, offset, size);
17659 GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
17660 }
17661
17662 /** Execute GenBuffer
17663 *
17664 * @param target Target that will be used by this buffer
17665 **/
generate(glw::GLenum target)17666 void Utils::buffer::generate(glw::GLenum target)
17667 {
17668 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17669
17670 m_target = target;
17671
17672 gl.genBuffers(1, &m_id);
17673 GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
17674 }
17675
17676 /** Maps buffer content
17677 *
17678 * @param access Access rights for mapped region
17679 *
17680 * @return Mapped memory
17681 **/
map(GLenum access) const17682 void *Utils::buffer::map(GLenum access) const
17683 {
17684 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17685
17686 gl.bindBuffer(m_target, m_id);
17687 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17688
17689 void *result = gl.mapBuffer(m_target, access);
17690 GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
17691
17692 return result;
17693 }
17694
17695 /** Unmaps buffer
17696 *
17697 **/
unmap() const17698 void Utils::buffer::unmap() const
17699 {
17700 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17701
17702 gl.bindBuffer(m_target, m_id);
17703 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17704
17705 gl.unmapBuffer(m_target);
17706 GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
17707 }
17708
17709 /** Execute BufferData
17710 *
17711 * @param size <size> parameter
17712 * @param data <data> parameter
17713 * @param usage <usage> parameter
17714 **/
update(glw::GLsizeiptr size,glw::GLvoid * data,glw::GLenum usage)17715 void Utils::buffer::update(glw::GLsizeiptr size, glw::GLvoid *data, glw::GLenum usage)
17716 {
17717 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17718
17719 gl.bindBuffer(m_target, m_id);
17720 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17721
17722 gl.bufferData(m_target, size, data, usage);
17723 GLU_EXPECT_NO_ERROR(gl.getError(), "bufferData");
17724 }
17725
17726 /** Release buffer
17727 *
17728 **/
release()17729 void Utils::buffer::release()
17730 {
17731 if (0 != m_id)
17732 {
17733 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17734
17735 gl.deleteBuffers(1, &m_id);
17736 m_id = 0;
17737 }
17738 }
17739
17740 /** Constructor
17741 *
17742 * @param context CTS context
17743 **/
framebuffer(deqp::Context & context)17744 Utils::framebuffer::framebuffer(deqp::Context &context) : m_id(0), m_context(context)
17745 {
17746 /* Nothing to be done here */
17747 }
17748
17749 /** Destructor
17750 *
17751 **/
~framebuffer()17752 Utils::framebuffer::~framebuffer()
17753 {
17754 if (0 != m_id)
17755 {
17756 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17757
17758 gl.deleteFramebuffers(1, &m_id);
17759 m_id = 0;
17760 }
17761 }
17762
17763 /** Attach texture to specified attachment
17764 *
17765 * @param attachment Attachment
17766 * @param texture_id Texture id
17767 * @param width Texture width
17768 * @param height Texture height
17769 **/
attachTexture(glw::GLenum attachment,glw::GLuint texture_id,glw::GLuint width,glw::GLuint height)17770 void Utils::framebuffer::attachTexture(glw::GLenum attachment, glw::GLuint texture_id, glw::GLuint width,
17771 glw::GLuint height)
17772 {
17773 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17774
17775 bind();
17776
17777 gl.bindTexture(GL_TEXTURE_2D, texture_id);
17778 GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
17779
17780 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture_id, 0 /* level */);
17781 GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture2D");
17782
17783 gl.viewport(0 /* x */, 0 /* y */, width, height);
17784 GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
17785 }
17786
17787 /** Binds framebuffer to DRAW_FRAMEBUFFER
17788 *
17789 **/
bind()17790 void Utils::framebuffer::bind()
17791 {
17792 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17793
17794 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_id);
17795 GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
17796 }
17797
17798 /** Clear framebuffer
17799 *
17800 * @param mask <mask> parameter of glClear. Decides which shall be cleared
17801 **/
clear(glw::GLenum mask)17802 void Utils::framebuffer::clear(glw::GLenum mask)
17803 {
17804 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17805
17806 gl.clear(mask);
17807 GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
17808 }
17809
17810 /** Specifies clear color
17811 *
17812 * @param red Red channel
17813 * @param green Green channel
17814 * @param blue Blue channel
17815 * @param alpha Alpha channel
17816 **/
clearColor(GLfloat red,GLfloat green,GLfloat blue,GLfloat alpha)17817 void Utils::framebuffer::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
17818 {
17819 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17820
17821 gl.clearColor(red, green, blue, alpha);
17822 GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
17823 }
17824
17825 /** Generate framebuffer
17826 *
17827 **/
generate()17828 void Utils::framebuffer::generate()
17829 {
17830 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17831
17832 gl.genFramebuffers(1, &m_id);
17833 GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
17834 }
17835
shaderSource()17836 Utils::shaderSource::shaderSource()
17837 {
17838 }
17839
shaderSource(const shaderSource & source)17840 Utils::shaderSource::shaderSource(const shaderSource &source) : m_parts(source.m_parts), m_use_lengths(false)
17841 {
17842 }
17843
shaderSource(const glw::GLchar * source_code)17844 Utils::shaderSource::shaderSource(const glw::GLchar *source_code) : m_use_lengths(false)
17845 {
17846 if (0 != source_code)
17847 {
17848 m_parts.resize(1);
17849
17850 m_parts[0].m_code = source_code;
17851 }
17852 }
17853
shaderCompilationException(const shaderSource & source,const glw::GLchar * message)17854 Utils::shaderCompilationException::shaderCompilationException(const shaderSource &source, const glw::GLchar *message)
17855 : m_shader_source(source)
17856 , m_error_message(message)
17857 {
17858 /* Nothing to be done */
17859 }
17860
what() const17861 const char *Utils::shaderCompilationException::what() const throw()
17862 {
17863 return "Shader compilation failed";
17864 }
17865
programLinkageException(const glw::GLchar * message)17866 Utils::programLinkageException::programLinkageException(const glw::GLchar *message) : m_error_message(message)
17867 {
17868 /* Nothing to be done */
17869 }
17870
what() const17871 const char *Utils::programLinkageException::what() const throw()
17872 {
17873 return "Program linking failed";
17874 }
17875
17876 const glw::GLenum Utils::program::ARB_COMPUTE_SHADER = 0x91B9;
17877
17878 /** Constructor.
17879 *
17880 * @param context CTS context.
17881 **/
program(deqp::Context & context)17882 Utils::program::program(deqp::Context &context)
17883 : m_compute_shader_id(0)
17884 , m_fragment_shader_id(0)
17885 , m_geometry_shader_id(0)
17886 , m_program_object_id(0)
17887 , m_tesselation_control_shader_id(0)
17888 , m_tesselation_evaluation_shader_id(0)
17889 , m_vertex_shader_id(0)
17890 , m_context(context)
17891 {
17892 /* Nothing to be done here */
17893 }
17894
17895 /** Destructor
17896 *
17897 **/
~program()17898 Utils::program::~program()
17899 {
17900 remove();
17901 }
17902
17903 /** Build program
17904 *
17905 * @param compute_shader_code Compute shader source code
17906 * @param fragment_shader_code Fragment shader source code
17907 * @param geometry_shader_code Geometry shader source code
17908 * @param tesselation_control_shader_code Tesselation control shader source code
17909 * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17910 * @param vertex_shader_code Vertex shader source code
17911 * @param varying_names Array of strings containing names of varyings to be captured with transfrom feedback
17912 * @param n_varying_names Number of varyings to be captured with transfrom feedback
17913 * @param is_separable Selects if monolithis or separable program should be built. Defaults to false
17914 **/
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)17915 void Utils::program::build(const glw::GLchar *compute_shader_code, const glw::GLchar *fragment_shader_code,
17916 const glw::GLchar *geometry_shader_code, const glw::GLchar *tesselation_control_shader_code,
17917 const glw::GLchar *tesselation_evaluation_shader_code, const glw::GLchar *vertex_shader_code,
17918 const glw::GLchar *const *varying_names, glw::GLuint n_varying_names, bool is_separable)
17919 {
17920 const shaderSource compute_shader(compute_shader_code);
17921 const shaderSource fragment_shader(fragment_shader_code);
17922 const shaderSource geometry_shader(geometry_shader_code);
17923 const shaderSource tesselation_control_shader(tesselation_control_shader_code);
17924 const shaderSource tesselation_evaluation_shader(tesselation_evaluation_shader_code);
17925 const shaderSource vertex_shader(vertex_shader_code);
17926
17927 build(compute_shader, fragment_shader, geometry_shader, tesselation_control_shader, tesselation_evaluation_shader,
17928 vertex_shader, varying_names, n_varying_names, is_separable);
17929 }
17930
17931 /** Build program
17932 *
17933 * @param compute_shader_code Compute shader source code
17934 * @param fragment_shader_code Fragment shader source code
17935 * @param geometry_shader_code Geometry shader source code
17936 * @param tesselation_control_shader_code Tesselation control shader source code
17937 * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17938 * @param vertex_shader_code Vertex shader source code
17939 * @param varying_names Array of strings containing names of varyings to be captured with transfrom feedback
17940 * @param n_varying_names Number of varyings to be captured with transfrom feedback
17941 * @param is_separable Selects if monolithis or separable program should be built. Defaults to false
17942 **/
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)17943 void Utils::program::build(const shaderSource &compute_shader, const shaderSource &fragment_shader,
17944 const shaderSource &geometry_shader, const shaderSource &tesselation_control_shader,
17945 const shaderSource &tesselation_evaluation_shader, const shaderSource &vertex_shader,
17946 const glw::GLchar *const *varying_names, glw::GLuint n_varying_names, bool is_separable)
17947 {
17948 /* GL entry points */
17949 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
17950
17951 /* Create shader objects and compile */
17952 if (false == compute_shader.m_parts.empty())
17953 {
17954 m_compute_shader_id = gl.createShader(ARB_COMPUTE_SHADER);
17955 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17956
17957 compile(m_compute_shader_id, compute_shader);
17958 }
17959
17960 if (false == fragment_shader.m_parts.empty())
17961 {
17962 m_fragment_shader_id = gl.createShader(GL_FRAGMENT_SHADER);
17963 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17964
17965 compile(m_fragment_shader_id, fragment_shader);
17966 }
17967
17968 if (false == geometry_shader.m_parts.empty())
17969 {
17970 m_geometry_shader_id = gl.createShader(GL_GEOMETRY_SHADER);
17971 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17972
17973 compile(m_geometry_shader_id, geometry_shader);
17974 }
17975
17976 if (false == tesselation_control_shader.m_parts.empty())
17977 {
17978 m_tesselation_control_shader_id = gl.createShader(GL_TESS_CONTROL_SHADER);
17979 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17980
17981 compile(m_tesselation_control_shader_id, tesselation_control_shader);
17982 }
17983
17984 if (false == tesselation_evaluation_shader.m_parts.empty())
17985 {
17986 m_tesselation_evaluation_shader_id = gl.createShader(GL_TESS_EVALUATION_SHADER);
17987 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17988
17989 compile(m_tesselation_evaluation_shader_id, tesselation_evaluation_shader);
17990 }
17991
17992 if (false == vertex_shader.m_parts.empty())
17993 {
17994 m_vertex_shader_id = gl.createShader(GL_VERTEX_SHADER);
17995 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17996
17997 compile(m_vertex_shader_id, vertex_shader);
17998 }
17999
18000 /* Create program object */
18001 m_program_object_id = gl.createProgram();
18002 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
18003
18004 /* Set up captyured varyings' names */
18005 if (0 != n_varying_names)
18006 {
18007 gl.transformFeedbackVaryings(m_program_object_id, n_varying_names, varying_names, GL_INTERLEAVED_ATTRIBS);
18008 GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
18009 }
18010
18011 /* Set separable parameter */
18012 if (true == is_separable)
18013 {
18014 gl.programParameteri(m_program_object_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
18015 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
18016 }
18017
18018 /* Link program */
18019 link();
18020 }
18021
compile(glw::GLuint shader_id,const Utils::shaderSource & source) const18022 void Utils::program::compile(glw::GLuint shader_id, const Utils::shaderSource &source) const
18023 {
18024 /* GL entry points */
18025 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18026
18027 /* Compilation status */
18028 glw::GLint status = GL_FALSE;
18029
18030 /* Source parts and lengths vectors */
18031 std::vector<const GLchar *> parts;
18032 std::vector<GLint> lengths_vector;
18033 GLint *lengths = 0;
18034
18035 /* Prepare storage */
18036 parts.resize(source.m_parts.size());
18037
18038 /* Prepare arrays */
18039 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18040 {
18041 parts[i] = source.m_parts[i].m_code.c_str();
18042 }
18043
18044 if (true == source.m_use_lengths)
18045 {
18046 lengths_vector.resize(source.m_parts.size());
18047
18048 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18049 {
18050 lengths_vector[i] = source.m_parts[i].m_length;
18051 }
18052
18053 lengths = &lengths_vector[0];
18054 }
18055
18056 /* Set source code */
18057 gl.shaderSource(shader_id, static_cast<GLsizei>(source.m_parts.size()), &parts[0], lengths);
18058 GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
18059
18060 /* Compile */
18061 gl.compileShader(shader_id);
18062 GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
18063
18064 /* Get compilation status */
18065 gl.getShaderiv(shader_id, GL_COMPILE_STATUS, &status);
18066 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
18067
18068 /* Log compilation error */
18069 if (GL_TRUE != status)
18070 {
18071 glw::GLint length = 0;
18072 std::vector<glw::GLchar> message;
18073
18074 /* Error log length */
18075 gl.getShaderiv(shader_id, GL_INFO_LOG_LENGTH, &length);
18076 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
18077
18078 /* Prepare storage */
18079 message.resize(length);
18080
18081 /* Get error log */
18082 gl.getShaderInfoLog(shader_id, length, 0, &message[0]);
18083 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
18084
18085 throw shaderCompilationException(source, &message[0]);
18086 }
18087 }
18088
18089 /** Create program from provided binary
18090 *
18091 * @param binary Buffer with binary form of program
18092 * @param binary_format Format of <binary> data
18093 **/
createFromBinary(const std::vector<GLubyte> & binary,GLenum binary_format)18094 void Utils::program::createFromBinary(const std::vector<GLubyte> &binary, GLenum binary_format)
18095 {
18096 /* GL entry points */
18097 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18098
18099 /* Create program object */
18100 m_program_object_id = gl.createProgram();
18101 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
18102
18103 gl.programBinary(m_program_object_id, binary_format, &binary[0], static_cast<GLsizei>(binary.size()));
18104 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramBinary");
18105 }
18106
getAttribLocation(const glw::GLchar * name) const18107 glw::GLint Utils::program::getAttribLocation(const glw::GLchar *name) const
18108 {
18109 /* GL entry points */
18110 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18111
18112 GLint location = gl.getAttribLocation(m_program_object_id, name);
18113 GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
18114
18115 return location;
18116 }
18117
18118 /** Get binary form of program
18119 *
18120 * @param binary Buffer for binary data
18121 * @param binary_format Format of binary data
18122 **/
getBinary(std::vector<GLubyte> & binary,GLenum & binary_format) const18123 void Utils::program::getBinary(std::vector<GLubyte> &binary, GLenum &binary_format) const
18124 {
18125 /* GL entry points */
18126 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18127
18128 /* Get binary size */
18129 GLint length = 0;
18130 gl.getProgramiv(m_program_object_id, GL_PROGRAM_BINARY_LENGTH, &length);
18131 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18132
18133 /* Allocate storage */
18134 binary.resize(length);
18135
18136 /* Get binary */
18137 gl.getProgramBinary(m_program_object_id, static_cast<GLsizei>(binary.size()), &length, &binary_format, &binary[0]);
18138 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramBinary");
18139 }
18140
18141 /** Get subroutine index
18142 *
18143 * @param subroutine_name Subroutine name
18144 *
18145 * @return Index of subroutine
18146 **/
getSubroutineIndex(const glw::GLchar * subroutine_name,glw::GLenum shader_stage) const18147 GLuint Utils::program::getSubroutineIndex(const glw::GLchar *subroutine_name, glw::GLenum shader_stage) const
18148 {
18149 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18150 GLuint index = -1;
18151
18152 index = gl.getSubroutineIndex(m_program_object_id, shader_stage, subroutine_name);
18153 GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineIndex");
18154
18155 if (GL_INVALID_INDEX == index)
18156 {
18157 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine: " << subroutine_name
18158 << " is not available" << tcu::TestLog::EndMessage;
18159
18160 TCU_FAIL("Subroutine is not available");
18161 }
18162
18163 return index;
18164 }
18165
18166 /** Get subroutine uniform location
18167 *
18168 * @param uniform_name Subroutine uniform name
18169 *
18170 * @return Location of subroutine uniform
18171 **/
getSubroutineUniformLocation(const glw::GLchar * uniform_name,glw::GLenum shader_stage) const18172 GLint Utils::program::getSubroutineUniformLocation(const glw::GLchar *uniform_name, glw::GLenum shader_stage) const
18173 {
18174 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18175 GLint location = -1;
18176
18177 location = gl.getSubroutineUniformLocation(m_program_object_id, shader_stage, uniform_name);
18178 GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineUniformLocation");
18179
18180 if (-1 == location)
18181 {
18182 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine uniform: " << uniform_name
18183 << " is not available" << tcu::TestLog::EndMessage;
18184
18185 TCU_FAIL("Subroutine uniform is not available");
18186 }
18187
18188 return location;
18189 }
18190
18191 /** Get integer uniform at given location
18192 *
18193 * @param location Uniform location
18194 *
18195 * @return Value
18196 **/
getUniform1i(GLuint location) const18197 GLint Utils::program::getUniform1i(GLuint location) const
18198 {
18199 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18200
18201 GLint result;
18202
18203 gl.getUniformiv(m_program_object_id, location, &result);
18204 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformiv");
18205
18206 return result;
18207 }
18208
18209 /** Get uniform location
18210 *
18211 * @param uniform_name Subroutine uniform name
18212 *
18213 * @return Location of uniform
18214 **/
getUniformLocation(const glw::GLchar * uniform_name) const18215 GLint Utils::program::getUniformLocation(const glw::GLchar *uniform_name) const
18216 {
18217 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18218 GLint location = -1;
18219
18220 location = gl.getUniformLocation(m_program_object_id, uniform_name);
18221 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
18222
18223 if (-1 == location)
18224 {
18225 m_context.getTestContext().getLog()
18226 << tcu::TestLog::Message << "Uniform: " << uniform_name << " is not available" << tcu::TestLog::EndMessage;
18227
18228 TCU_FAIL("Uniform is not available");
18229 }
18230
18231 return location;
18232 }
18233
18234 /** Attach shaders and link program
18235 *
18236 **/
link() const18237 void Utils::program::link() const
18238 {
18239 /* GL entry points */
18240 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18241
18242 /* Link status */
18243 glw::GLint status = GL_FALSE;
18244
18245 /* Attach shaders */
18246 if (0 != m_compute_shader_id)
18247 {
18248 gl.attachShader(m_program_object_id, m_compute_shader_id);
18249 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18250 }
18251
18252 if (0 != m_fragment_shader_id)
18253 {
18254 gl.attachShader(m_program_object_id, m_fragment_shader_id);
18255 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18256 }
18257
18258 if (0 != m_geometry_shader_id)
18259 {
18260 gl.attachShader(m_program_object_id, m_geometry_shader_id);
18261 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18262 }
18263
18264 if (0 != m_tesselation_control_shader_id)
18265 {
18266 gl.attachShader(m_program_object_id, m_tesselation_control_shader_id);
18267 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18268 }
18269
18270 if (0 != m_tesselation_evaluation_shader_id)
18271 {
18272 gl.attachShader(m_program_object_id, m_tesselation_evaluation_shader_id);
18273 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18274 }
18275
18276 if (0 != m_vertex_shader_id)
18277 {
18278 gl.attachShader(m_program_object_id, m_vertex_shader_id);
18279 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18280 }
18281
18282 /* Link */
18283 gl.linkProgram(m_program_object_id);
18284 GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
18285
18286 /* Get link status */
18287 gl.getProgramiv(m_program_object_id, GL_LINK_STATUS, &status);
18288 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18289
18290 /* Log link error */
18291 if (GL_TRUE != status)
18292 {
18293 glw::GLint length = 0;
18294 std::vector<glw::GLchar> message;
18295
18296 /* Get error log length */
18297 gl.getProgramiv(m_program_object_id, GL_INFO_LOG_LENGTH, &length);
18298 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18299
18300 message.resize(length);
18301
18302 /* Get error log */
18303 gl.getProgramInfoLog(m_program_object_id, length, 0, &message[0]);
18304 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
18305
18306 throw programLinkageException(&message[0]);
18307 }
18308 }
18309
18310 /** Delete program object and all attached shaders
18311 *
18312 **/
remove()18313 void Utils::program::remove()
18314 {
18315 /* GL entry points */
18316 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18317
18318 /* Make sure program object is no longer used by GL */
18319 gl.useProgram(0);
18320
18321 /* Clean program object */
18322 if (0 != m_program_object_id)
18323 {
18324 gl.deleteProgram(m_program_object_id);
18325 m_program_object_id = 0;
18326 }
18327
18328 /* Clean shaders */
18329 if (0 != m_compute_shader_id)
18330 {
18331 gl.deleteShader(m_compute_shader_id);
18332 m_compute_shader_id = 0;
18333 }
18334
18335 if (0 != m_fragment_shader_id)
18336 {
18337 gl.deleteShader(m_fragment_shader_id);
18338 m_fragment_shader_id = 0;
18339 }
18340
18341 if (0 != m_geometry_shader_id)
18342 {
18343 gl.deleteShader(m_geometry_shader_id);
18344 m_geometry_shader_id = 0;
18345 }
18346
18347 if (0 != m_tesselation_control_shader_id)
18348 {
18349 gl.deleteShader(m_tesselation_control_shader_id);
18350 m_tesselation_control_shader_id = 0;
18351 }
18352
18353 if (0 != m_tesselation_evaluation_shader_id)
18354 {
18355 gl.deleteShader(m_tesselation_evaluation_shader_id);
18356 m_tesselation_evaluation_shader_id = 0;
18357 }
18358
18359 if (0 != m_vertex_shader_id)
18360 {
18361 gl.deleteShader(m_vertex_shader_id);
18362 m_vertex_shader_id = 0;
18363 }
18364 }
18365
uniform(const glw::GLchar * uniform_name,TYPES type,glw::GLuint n_columns,glw::GLuint n_rows,const void * data) const18366 void Utils::program::uniform(const glw::GLchar *uniform_name, TYPES type, glw::GLuint n_columns, glw::GLuint n_rows,
18367 const void *data) const
18368 {
18369 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18370
18371 GLuint location = getUniformLocation(uniform_name);
18372
18373 if ((glw::GLuint)-1 == location)
18374 {
18375 TCU_FAIL("Uniform is inactive");
18376 }
18377
18378 switch (type)
18379 {
18380 case DOUBLE:
18381 if (1 == n_columns)
18382 {
18383 getUniformNdv(gl, n_rows)(location, 1 /* count */, (const GLdouble *)data);
18384 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
18385 }
18386 else
18387 {
18388 getUniformMatrixNdv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLdouble *)data);
18389 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
18390 }
18391 break;
18392 case FLOAT:
18393 if (1 == n_columns)
18394 {
18395 getUniformNfv(gl, n_rows)(location, 1 /* count */, (const GLfloat *)data);
18396 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
18397 }
18398 else
18399 {
18400 getUniformMatrixNfv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLfloat *)data);
18401 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
18402 }
18403 break;
18404 case INT:
18405 getUniformNiv(gl, n_rows)(location, 1 /* count */, (const GLint *)data);
18406 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
18407 break;
18408 case UINT:
18409 getUniformNuiv(gl, n_rows)(location, 1 /* count */, (const GLuint *)data);
18410 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
18411 break;
18412 default:
18413 TCU_FAIL("Invalid enum");
18414 }
18415 }
18416
18417 /** Execute UseProgram
18418 *
18419 **/
use() const18420 void Utils::program::use() const
18421 {
18422 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18423
18424 gl.useProgram(m_program_object_id);
18425 GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
18426 }
18427
printShaderSource(const shaderSource & source,tcu::MessageBuilder & log)18428 void Utils::program::printShaderSource(const shaderSource &source, tcu::MessageBuilder &log)
18429 {
18430 GLuint line_number = 0;
18431
18432 log << "Shader source.";
18433
18434 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18435 {
18436 log << "\nLine||Part: " << (i + 1) << "/" << source.m_parts.size();
18437
18438 if (true == source.m_use_lengths)
18439 {
18440 log << " Length: " << source.m_parts[i].m_length;
18441 }
18442
18443 log << "\n";
18444
18445 const GLchar *part = source.m_parts[i].m_code.c_str();
18446
18447 while (0 != part)
18448 {
18449 std::string line;
18450 const GLchar *next_line = strchr(part, '\n');
18451
18452 if (0 != next_line)
18453 {
18454 next_line += 1;
18455 line.assign(part, next_line - part);
18456 }
18457 else
18458 {
18459 line = part;
18460 }
18461
18462 if (0 != *part)
18463 {
18464 log << std::setw(4) << line_number << "||" << line;
18465 }
18466
18467 part = next_line;
18468 line_number += 1;
18469 }
18470 }
18471 }
18472
18473 /** Constructor.
18474 *
18475 * @param context CTS context.
18476 **/
texture(deqp::Context & context)18477 Utils::texture::texture(deqp::Context &context) : m_id(0), m_buffer_id(0), m_context(context), m_texture_type(TEX_2D)
18478 {
18479 /* Nothing to done here */
18480 }
18481
18482 /** Destructor
18483 *
18484 **/
~texture()18485 Utils::texture::~texture()
18486 {
18487 release();
18488 }
18489
18490 /** Bind texture to GL_TEXTURE_2D
18491 *
18492 **/
bind() const18493 void Utils::texture::bind() const
18494 {
18495 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18496
18497 GLenum target = getTextureTartet(m_texture_type);
18498
18499 gl.bindTexture(target, m_id);
18500 GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
18501 }
18502
18503 /** Create 2d texture
18504 *
18505 * @param width Width of texture
18506 * @param height Height of texture
18507 * @param internal_format Internal format of texture
18508 **/
create(glw::GLuint width,glw::GLuint height,glw::GLenum internal_format)18509 void Utils::texture::create(glw::GLuint width, glw::GLuint height, glw::GLenum internal_format)
18510 {
18511 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18512
18513 release();
18514
18515 m_texture_type = TEX_2D;
18516
18517 gl.genTextures(1, &m_id);
18518 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18519
18520 bind();
18521
18522 gl.texStorage2D(GL_TEXTURE_2D, 1 /* levels */, internal_format, width, height);
18523 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18524 }
18525
18526 /** Create texture of given type
18527 *
18528 * @param width Width of texture
18529 * @param height Height of texture
18530 * @param depth Depth of texture
18531 * @param internal_format Internal format of texture
18532 * @param texture_type Type of texture
18533 **/
create(GLuint width,GLuint height,GLuint depth,GLenum internal_format,TEXTURE_TYPES texture_type)18534 void Utils::texture::create(GLuint width, GLuint height, GLuint depth, GLenum internal_format,
18535 TEXTURE_TYPES texture_type)
18536 {
18537 static const GLuint levels = 1;
18538
18539 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18540
18541 release();
18542
18543 m_texture_type = texture_type;
18544
18545 GLenum target = getTextureTartet(m_texture_type);
18546
18547 gl.genTextures(1, &m_id);
18548 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18549
18550 bind();
18551
18552 switch (m_texture_type)
18553 {
18554 case TEX_1D:
18555 gl.texStorage1D(target, levels, internal_format, width);
18556 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18557 break;
18558 case TEX_2D:
18559 case TEX_1D_ARRAY:
18560 case TEX_2D_RECT:
18561 case TEX_CUBE:
18562 gl.texStorage2D(target, levels, internal_format, width, height);
18563 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18564 break;
18565 case TEX_3D:
18566 case TEX_2D_ARRAY:
18567 gl.texStorage3D(target, levels, internal_format, width, height, depth);
18568 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18569 break;
18570 default:
18571 TCU_FAIL("Invliad enum");
18572 }
18573 }
18574
18575 /** Create buffer texture
18576 *
18577 * @param internal_format Internal format of texture
18578 * @param buffer_id Id of buffer that will be used as data source
18579 **/
createBuffer(GLenum internal_format,GLuint buffer_id)18580 void Utils::texture::createBuffer(GLenum internal_format, GLuint buffer_id)
18581 {
18582 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18583
18584 release();
18585
18586 m_texture_type = TEX_BUFFER;
18587 m_buffer_id = buffer_id;
18588
18589 gl.genTextures(1, &m_id);
18590 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18591
18592 bind();
18593
18594 gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
18595 GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
18596 }
18597
18598 /** Get contents of texture
18599 *
18600 * @param format Format of image
18601 * @param type Type of image
18602 * @param out_data Buffer for image
18603 **/
get(glw::GLenum format,glw::GLenum type,glw::GLvoid * out_data) const18604 void Utils::texture::get(glw::GLenum format, glw::GLenum type, glw::GLvoid *out_data) const
18605 {
18606 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18607
18608 GLenum target = getTextureTartet(m_texture_type);
18609
18610 bind();
18611
18612 gl.memoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
18613 GLU_EXPECT_NO_ERROR(gl.getError(), "MemoryBarrier");
18614
18615 if (TEX_CUBE != m_texture_type)
18616 {
18617 gl.getTexImage(target, 0 /* level */, format, type, out_data);
18618 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18619 }
18620 else
18621 {
18622 GLint width;
18623 GLint height;
18624
18625 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
18626 {
18627 TCU_FAIL("Not implemented");
18628 }
18629
18630 GLuint texel_size = 4;
18631
18632 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
18633 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18634
18635 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
18636 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18637
18638 const GLuint image_size = width * height * texel_size;
18639
18640 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
18641 (GLvoid *)((GLchar *)out_data + (image_size * 0)));
18642 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
18643 (GLvoid *)((GLchar *)out_data + (image_size * 1)));
18644 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
18645 (GLvoid *)((GLchar *)out_data + (image_size * 2)));
18646 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
18647 (GLvoid *)((GLchar *)out_data + (image_size * 3)));
18648 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
18649 (GLvoid *)((GLchar *)out_data + (image_size * 4)));
18650 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
18651 (GLvoid *)((GLchar *)out_data + (image_size * 5)));
18652 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18653 }
18654 }
18655
18656 /** Delete texture
18657 *
18658 **/
release()18659 void Utils::texture::release()
18660 {
18661 if (0 != m_id)
18662 {
18663 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18664
18665 gl.deleteTextures(1, &m_id);
18666 m_id = 0;
18667
18668 if ((m_texture_type == TEX_BUFFER) && (0 != m_buffer_id))
18669 {
18670 gl.deleteBuffers(1, &m_buffer_id);
18671 m_buffer_id = 0;
18672 }
18673 }
18674 }
18675
18676 /** Update contents of texture
18677 *
18678 * @param width Width of texture
18679 * @param height Height of texture
18680 * @param format Format of data
18681 * @param type Type of data
18682 * @param data Buffer with image
18683 **/
update(glw::GLuint width,glw::GLuint height,glw::GLuint depth,glw::GLenum format,glw::GLenum type,glw::GLvoid * data)18684 void Utils::texture::update(glw::GLuint width, glw::GLuint height, glw::GLuint depth, glw::GLenum format,
18685 glw::GLenum type, glw::GLvoid *data)
18686 {
18687 static const GLuint level = 0;
18688
18689 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18690
18691 GLenum target = getTextureTartet(m_texture_type);
18692
18693 bind();
18694
18695 switch (m_texture_type)
18696 {
18697 case TEX_1D:
18698 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
18699 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18700 break;
18701 case TEX_2D:
18702 case TEX_1D_ARRAY:
18703 case TEX_2D_RECT:
18704 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
18705 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18706 break;
18707 case TEX_CUBE:
18708 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18709 data);
18710 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18711 data);
18712 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18713 data);
18714 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18715 data);
18716 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18717 data);
18718 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18719 data);
18720 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18721 break;
18722 case TEX_3D:
18723 case TEX_2D_ARRAY:
18724 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
18725 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18726 break;
18727 default:
18728 TCU_FAIL("Invliad enum");
18729 }
18730 }
18731
18732 /** Constructor.
18733 *
18734 * @param context CTS context.
18735 **/
vertexArray(deqp::Context & context)18736 Utils::vertexArray::vertexArray(deqp::Context &context) : m_id(0), m_context(context)
18737 {
18738 }
18739
18740 /** Destructor
18741 *
18742 **/
~vertexArray()18743 Utils::vertexArray::~vertexArray()
18744 {
18745 if (0 != m_id)
18746 {
18747 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18748
18749 gl.deleteVertexArrays(1, &m_id);
18750
18751 m_id = 0;
18752 }
18753 }
18754
18755 /** Execute BindVertexArray
18756 *
18757 **/
bind()18758 void Utils::vertexArray::bind()
18759 {
18760 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18761
18762 gl.bindVertexArray(m_id);
18763 GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
18764 }
18765
18766 /** Execute GenVertexArrays
18767 *
18768 **/
generate()18769 void Utils::vertexArray::generate()
18770 {
18771 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
18772
18773 gl.genVertexArrays(1, &m_id);
18774 GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
18775 }
18776 } // namespace GLSL420Pack
18777
18778 /** Constructor.
18779 *
18780 * @param context Rendering context.
18781 **/
ShadingLanguage420PackTests(deqp::Context & context)18782 ShadingLanguage420PackTests::ShadingLanguage420PackTests(deqp::Context &context)
18783 : TestCaseGroup(context, "shading_language_420pack", "Verifies \"shading_language_420pack\" functionality")
18784 {
18785 /* Left blank on purpose */
18786 }
18787
18788 /** Initializes a texture_storage_multisample test group.
18789 *
18790 **/
init(void)18791 void ShadingLanguage420PackTests::init(void)
18792 {
18793 addChild(new GLSL420Pack::BindingSamplerSingleTest(m_context));
18794 addChild(new GLSL420Pack::BindingImageSingleTest(m_context));
18795 addChild(new GLSL420Pack::UTF8CharactersTest(m_context));
18796 addChild(new GLSL420Pack::UTF8InSourceTest(m_context));
18797 addChild(new GLSL420Pack::QualifierOrderTest(m_context));
18798 addChild(new GLSL420Pack::QualifierOrderBlockTest(m_context));
18799 addChild(new GLSL420Pack::LineContinuationTest(m_context));
18800 addChild(new GLSL420Pack::LineNumberingTest(m_context));
18801 addChild(new GLSL420Pack::ImplicitConversionsValidTest(m_context));
18802 addChild(new GLSL420Pack::ImplicitConversionsInvalidTest(m_context));
18803 addChild(new GLSL420Pack::ConstDynamicValueTest(m_context));
18804 addChild(new GLSL420Pack::ConstAssignmentTest(m_context));
18805 addChild(new GLSL420Pack::ConstDynamicValueAsConstExprTest(m_context));
18806 addChild(new GLSL420Pack::QualifierOrderUniformTest(m_context));
18807 addChild(new GLSL420Pack::QualifierOrderFunctionInoutTest(m_context));
18808 addChild(new GLSL420Pack::QualifierOrderFunctionInputTest(m_context));
18809 addChild(new GLSL420Pack::QualifierOrderFunctionOutputTest(m_context));
18810 addChild(new GLSL420Pack::QualifierOverrideLayoutTest(m_context));
18811 addChild(new GLSL420Pack::BindingUniformBlocksTest(m_context));
18812 addChild(new GLSL420Pack::BindingUniformSingleBlockTest(m_context));
18813 addChild(new GLSL420Pack::BindingUniformBlockArrayTest(m_context));
18814 addChild(new GLSL420Pack::BindingUniformDefaultTest(m_context));
18815 addChild(new GLSL420Pack::BindingUniformAPIOverirdeTest(m_context));
18816 addChild(new GLSL420Pack::BindingUniformGlobalBlockTest(m_context));
18817 addChild(new GLSL420Pack::BindingUniformInvalidTest(m_context));
18818 addChild(new GLSL420Pack::BindingSamplersTest(m_context));
18819 addChild(new GLSL420Pack::BindingSamplerArrayTest(m_context));
18820 addChild(new GLSL420Pack::BindingSamplerDefaultTest(m_context));
18821 addChild(new GLSL420Pack::BindingSamplerAPIOverrideTest(m_context));
18822 addChild(new GLSL420Pack::BindingSamplerInvalidTest(m_context));
18823 addChild(new GLSL420Pack::BindingImagesTest(m_context));
18824 addChild(new GLSL420Pack::BindingImageArrayTest(m_context));
18825 addChild(new GLSL420Pack::BindingImageDefaultTest(m_context));
18826 addChild(new GLSL420Pack::BindingImageAPIOverrideTest(m_context));
18827 addChild(new GLSL420Pack::BindingImageInvalidTest(m_context));
18828 addChild(new GLSL420Pack::InitializerListTest(m_context));
18829 addChild(new GLSL420Pack::InitializerListNegativeTest(m_context));
18830 addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context));
18831 addChild(new GLSL420Pack::LengthOfComputeResultTest(m_context));
18832 addChild(new GLSL420Pack::ScalarSwizzlersTest(m_context));
18833 addChild(new GLSL420Pack::ScalarSwizzlersInvalidTest(m_context));
18834 addChild(new GLSL420Pack::BuiltInValuesTest(m_context));
18835 addChild(new GLSL420Pack::BuiltInAssignmentTest(m_context));
18836 }
18837
18838 } // namespace gl4cts
18839