glsl-1.10: test mesa bug conflict between globals
[piglit.git] / tests / spec / glsl-1.20 / negative-mult-matNxN-matNxN.c
blob7c9eaf0baf5139b620da70d2cab6e947a066f6a9
1 /*
2 * Copyright © 2019 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /** @file mult-matNxN-matNxN.c
27 /* From section 5.9 of the GLSL spec:
28 * "The operator is multiply (*), where both operands are matrices or one operand is a vector and the
29 * other a matrix. A right vector operand is treated as a column vector and a left vector operand as a
30 * row vector. In all these cases, it is required that the number of columns of the left operand is equal
31 * to the number of rows of the right operand. Then, the multiply (*) operation does a linear
32 * algebraic multiply, yielding an object that has the same number of rows as the left operand and the
33 * same number of columns as the right operand. Section 5.10 “Vector and Matrix Operations”
34 * explains in more detail how vectors and matrices are operated on."
36 * This test checks just invalid matrix combinations because
37 * we already have tests which check valid combinations
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 12;
46 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
48 PIGLIT_GL_TEST_CONFIG_END
50 typedef
51 struct glsl_mat {
52 unsigned col, row;
53 } glsl_mat_t;
55 static void
56 make_mat_type_name(glsl_mat_t m, char* buffer)
58 if(m.col == m.row)
59 sprintf(buffer, "mat%u", m.col);
60 else
61 sprintf(buffer, "mat%ux%u", m.col, m.row);
64 static const char*
65 make_shader_mult(glsl_mat_t first_type,
66 glsl_mat_t second_type)
68 static char first_mat_name[32];
69 static char second_mat_name[32];
70 static char buffer[512];
71 static char code[] =
72 "#version 120\n"
73 "void main() {\n"
74 " float t = (%s(1.3) * %s(1.3))[0][0];\n"
75 "}\n"
77 make_mat_type_name(first_type, first_mat_name);
78 make_mat_type_name(second_type, second_mat_name);
79 sprintf(buffer, code, first_mat_name, second_mat_name);
80 return buffer;
83 static const char*
84 make_shader_assignment_mult(glsl_mat_t first_type,
85 glsl_mat_t second_type)
87 static char first_mat_name[32];
88 static char second_mat_name[32];
89 static char buffer[512];
90 static char code[] =
91 "#version 120\n"
92 "void main() {\n"
93 " %s p1;\n"
94 " p1 = %s(1.0);\n"
95 " %s p2;\n"
96 " p2 = %s(1.0);\n"
97 " p1 *= p2;\n"
98 "}\n"
100 make_mat_type_name(first_type, first_mat_name);
101 make_mat_type_name(second_type, second_mat_name);
102 sprintf(buffer, code, first_mat_name, first_mat_name,
103 second_mat_name, second_mat_name);
104 return buffer;
107 static bool
108 check_compilation(GLenum shader_type, const char *shader_source)
110 int compile_status = 0;
111 GLint sh = glCreateShader(shader_type);
112 if (!sh)
113 return false;
115 glShaderSource(sh, 1, &shader_source, NULL);
116 glCompileShader(sh);
117 glGetShaderiv(sh, GL_COMPILE_STATUS, &compile_status);
118 glDeleteShader(sh);
119 return (compile_status == GL_TRUE);
122 static bool
123 test(GLenum shader_type, const char* (*mkshader)(glsl_mat_t, glsl_mat_t))
125 bool pass = true;
126 /* test all invalid matrix combinations */
127 glsl_mat_t a;
128 for (a.col = 2; a.col < 5; a.col++) {
129 for (a.row = 2; a.row < 5; a.row++) {
131 glsl_mat_t b;
132 for (b.col = 2; b.col < 5; b.col++) {
133 for (b.row = 2; b.row < 5; b.row++) {
135 if (a.col == b.row)
136 continue;
138 const char *shader_source = mkshader(a, b);
140 if (!check_compilation(shader_type, shader_source))
141 continue;
143 fprintf(stderr,
144 "error: the following %s shader must fail compilation:\n%s\n",
145 (shader_type == GL_VERTEX_SHADER) ? "vertex" : "fragment",
146 shader_source);
147 pass = false;
152 return pass;
155 void
156 piglit_init(int argc, char **argv)
158 bool pass = true;
159 piglit_require_GLSL_version(120);
160 pass = test(GL_VERTEX_SHADER, make_shader_mult) && pass;
161 pass = test(GL_FRAGMENT_SHADER, make_shader_mult) && pass;
162 pass = test(GL_VERTEX_SHADER, make_shader_assignment_mult) && pass;
163 pass = test(GL_FRAGMENT_SHADER, make_shader_assignment_mult) && pass;
164 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
167 enum piglit_result
168 piglit_display(void)
170 /* UNREACHED */
171 return PIGLIT_FAIL;