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
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
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
56 make_mat_type_name(glsl_mat_t m
, char* buffer
)
59 sprintf(buffer
, "mat%u", m
.col
);
61 sprintf(buffer
, "mat%ux%u", m
.col
, m
.row
);
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];
74 " float t = (%s(1.3) * %s(1.3))[0][0];\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
);
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];
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
);
108 check_compilation(GLenum shader_type
, const char *shader_source
)
110 int compile_status
= 0;
111 GLint sh
= glCreateShader(shader_type
);
115 glShaderSource(sh
, 1, &shader_source
, NULL
);
117 glGetShaderiv(sh
, GL_COMPILE_STATUS
, &compile_status
);
119 return (compile_status
== GL_TRUE
);
123 test(GLenum shader_type
, const char* (*mkshader
)(glsl_mat_t
, glsl_mat_t
))
126 /* test all invalid matrix combinations */
128 for (a
.col
= 2; a
.col
< 5; a
.col
++) {
129 for (a
.row
= 2; a
.row
< 5; a
.row
++) {
132 for (b
.col
= 2; b
.col
< 5; b
.col
++) {
133 for (b
.row
= 2; b
.row
< 5; b
.row
++) {
138 const char *shader_source
= mkshader(a
, b
);
140 if (!check_compilation(shader_type
, shader_source
))
144 "error: the following %s shader must fail compilation:\n%s\n",
145 (shader_type
== GL_VERTEX_SHADER
) ? "vertex" : "fragment",
156 piglit_init(int argc
, char **argv
)
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
);