ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_uniform_buffer_object / row-major.c
blobe6ec7d917fb67ac17950f7ce15c8001794c04fd1
1 /*
2 * Copyright © 2012 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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file row-major.c
26 * From the GL_ARB_uniform_buffer_object spec:
28 * "The row_major qualifier overrides only the column_major
29 * qualifier; other qualifiers are inherited. It only affects the
30 * layout of matrices. Elements within a matrix row will be
31 * contiguous in memory.
33 * The column_major qualifier overrides only the row_major
34 * qualifier; other qualifiers are inherited. It only affects the
35 * layout of matrices. Elements within a matrix column will be
36 * contiguous in memory.
38 * When multiple arguments are listed in a layout declaration,
39 * the affect will be the same as if they were declared one at a
40 * time, in order from left to right, each in turn inheriting
41 * from and overriding the result from the previous
42 * qualification.
44 * For example
46 * layout(row_major, column_major)
48 * results in the qualification being column_major."
51 #include "piglit-util-gl.h"
53 PIGLIT_GL_TEST_CONFIG_BEGIN
55 config.supports_gl_compat_version = 10;
56 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
57 config.khr_no_error_support = PIGLIT_NO_ERRORS;
59 PIGLIT_GL_TEST_CONFIG_END
61 static const char *source =
62 "#extension GL_ARB_uniform_buffer_object : enable\n"
63 "\n"
64 "/* Use std140 to avoid needing to ref every single uniform */\n"
65 "layout(std140) uniform;\n"
66 "\n"
67 "layout(column_major) uniform a {\n"
68 " mat4 a_cm1;\n"
69 " layout(column_major) mat4 a_cm2;\n"
70 " layout(row_major) mat4 a_rm1;\n"
71 " layout(row_major, column_major) mat4 a_cm3;\n"
72 " vec4 a_non_matrix;\n"
73 "};\n"
74 "\n"
75 "layout(row_major) uniform b {\n"
76 " mat4 b_rm1;\n"
77 " layout(column_major) mat4 b_cm1;\n"
78 " layout(row_major) mat4 b_rm2;\n"
79 " vec4 b_non_matrix;\n"
80 "};\n"
81 "\n"
82 "uniform c {\n"
83 " mat4 c_cm1;\n"
84 " layout(column_major) mat4 c_cm2;\n"
85 " layout(row_major) mat4 c_rm1;\n"
86 " vec4 c_non_matrix;\n"
87 "};\n"
88 "\n"
89 "/* Set the default layout to row_major. Spam in some block layout\n"
90 " * qualifiers to make sure they don't accidentally clear row_major.\n"
91 " */\n"
92 "layout(row_major, std140) uniform;\n"
93 "layout(std140) uniform;\n"
94 "\n"
95 "layout(column_major) uniform d {\n"
96 " mat4 d_cm1;\n"
97 " layout(column_major) mat4 d_cm2;\n"
98 " layout(row_major) mat4 d_rm1;\n"
99 " vec4 d_non_matrix;\n"
100 "};\n"
101 "\n"
102 "layout(row_major) uniform e {\n"
103 " mat4 e_rm1;\n"
104 " layout(column_major) mat4 e_cm1;\n"
105 " layout(row_major) mat4 e_rm2;\n"
106 " vec4 e_non_matrix;\n"
107 "};\n"
108 "\n"
109 "layout(std140) uniform f {\n"
110 " mat4 f_rm1;\n"
111 " layout(column_major) mat4 f_cm1;\n"
112 " layout(row_major) mat4 f_rm2;\n"
113 " vec4 f_non_matrix;\n"
114 "};\n"
115 "\n"
116 "uniform mat4 non_ubo_mat;\n"
117 "uniform vec4 non_mat;\n"
118 "\n"
119 "void main() {\n"
120 " gl_FragColor = (\n"
121 " non_ubo_mat[0] + \n"
122 " non_mat + \n"
123 " a_cm1[0] + \n"
124 " a_cm2[0] + \n"
125 " a_rm1[0] + \n"
126 " a_cm3[0] + \n"
127 " b_cm1[0] + \n"
128 " b_rm1[0] + \n"
129 " b_rm2[0] + \n"
130 " c_cm1[0] + \n"
131 " c_cm2[0] + \n"
132 " c_rm1[0] + \n"
133 " d_cm1[0] + \n"
134 " d_cm2[0] + \n"
135 " d_rm1[0] + \n"
136 " e_cm1[0] + \n"
137 " e_rm1[0] + \n"
138 " e_rm2[0] + \n"
139 " f_cm1[0] + \n"
140 " f_rm1[0] + \n"
141 " f_rm2[0] + \n"
142 " a_non_matrix + \n"
143 " b_non_matrix + \n"
144 " c_non_matrix + \n"
145 " d_non_matrix + \n"
146 " e_non_matrix + \n"
147 " f_non_matrix);\n"
148 "}\n";
150 static struct {
151 const char *name;
152 bool row_major;
153 } uniforms[] = {
154 { "a_non_matrix", false },
155 { "a_cm1", false },
156 { "a_cm2", false },
157 { "a_cm3", false },
158 { "a_rm1", true },
160 { "b_non_matrix", false },
161 { "b_cm1", false },
162 { "b_rm1", true },
163 { "b_rm2", true },
165 { "c_non_matrix", false },
166 { "c_cm1", false },
167 { "c_cm2", false },
168 { "c_rm1", true },
170 { "d_non_matrix", false },
171 { "d_cm1", false },
172 { "d_cm2", false },
173 { "d_rm1", true },
175 { "e_non_matrix", false },
176 { "e_cm1", false },
177 { "e_rm1", true },
178 { "e_rm2", true },
180 { "f_non_matrix", false },
181 { "f_cm1", false },
182 { "f_rm1", true },
183 { "f_rm2", true },
185 { "non_ubo_mat", false },
186 { "non_mat", false },
189 void
190 piglit_init(int argc, char **argv)
192 bool pass = true;
193 unsigned int i;
194 GLuint prog;
196 piglit_require_extension("GL_ARB_uniform_buffer_object");
197 prog = piglit_build_simple_program(NULL, source);
199 for (i = 0; i < ARRAY_SIZE(uniforms); i++) {
200 GLuint index;
201 GLint row_major;
203 glGetUniformIndices(prog, 1, &uniforms[i].name, &index);
204 if (index == GL_INVALID_INDEX) {
205 printf("Failed to get index for %s\n",
206 uniforms[i].name);
207 pass = false;
208 continue;
211 glGetActiveUniformsiv(prog, 1, &index, GL_UNIFORM_IS_ROW_MAJOR,
212 &row_major);
214 if (row_major != uniforms[i].row_major) {
215 fprintf(stderr, "Uniform %s should %sbe row major\n",
216 uniforms[i].name,
217 uniforms[i].row_major ? "" : "not ");
218 pass = false;
222 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
225 enum piglit_result piglit_display(void)
227 /* UNREACHED */
228 return PIGLIT_FAIL;