framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_gpu_shader_fp64 / dlist-fp64-uniforms.c
blobb4f07d70920458b5aca0b2aa1a27d4945ace5e21
1 /*
2 * Copyright © 2014 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 /**
25 * Verify that unsigned glUniform* commands added in ARB_gpu_shader_fp64 are
26 * compiled into display lists.
28 * This test is adapted from tests/spec/arb_separate_shader_objects/dlist.c
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 /* No supports_gl_core_version setting because there are no display
35 * lists in core profile.
37 config.supports_gl_compat_version = 32;
38 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
43 static bool Uniformd(void);
44 static bool UniformMatrixd(void);
46 void
47 piglit_init(int argc, char **argv)
49 bool pass = true;
51 piglit_require_extension("GL_ARB_gpu_shader_fp64");
53 pass = Uniformd() && pass;
54 pass = UniformMatrixd() && pass;
56 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
59 enum mode {
60 set_scalar,
61 set_vector,
62 get_and_compare
65 #define NONMATRIX_UNIFORM(type, n, suffix) \
66 do { \
67 type inbuf[n]; \
68 type outbuf[n]; \
69 unsigned jjj; \
71 for (jjj = 0; jjj < n; jjj++) \
72 outbuf[jjj] = (type) value++; \
74 switch (m) { \
75 case set_scalar: \
76 switch (n) { \
77 case 1: \
78 glUniform1 ## suffix \
79 (loc, \
80 outbuf[0]); \
81 break; \
82 case 2: \
83 glUniform2 ## suffix \
84 (loc, \
85 outbuf[0], \
86 outbuf[1]); \
87 break; \
88 case 3: \
89 glUniform3 ## suffix \
90 (loc, \
91 outbuf[0], \
92 outbuf[1], \
93 outbuf[2]); \
94 break; \
95 case 4: \
96 glUniform4 ## suffix \
97 (loc, \
98 outbuf[0], \
99 outbuf[1], \
100 outbuf[2], \
101 outbuf[3]); \
102 break; \
103 default: \
104 printf("internal error - " \
105 "cannot set_scalar a " \
106 "%d count\n", n); \
107 pass = false; \
108 break; \
110 break; \
112 case set_vector: \
113 glUniform ## n ## suffix ## v \
114 (loc, 1, outbuf); \
115 break; \
117 case get_and_compare: \
118 glGetUniform ## suffix ## v \
119 (prog, loc, inbuf); \
120 if (memcmp(inbuf, outbuf, \
121 sizeof(type) * n) != 0) { \
122 printf(" %s data " \
123 "does not match.\n", \
124 name); \
125 pass = false; \
127 break; \
129 } while (0)
131 #define glUniformMatrix2x2dv glUniformMatrix2dv
132 #define glUniformMatrix3x3dv glUniformMatrix3dv
133 #define glUniformMatrix4x4dv glUniformMatrix4dv
135 #define MATRIX_UNIFORM(type, r, c, suffix) \
136 do { \
137 type inbuf[r * c]; \
138 type outbuf[r * c]; \
139 unsigned jjj; \
141 for (jjj = 0; jjj < (r * c); jjj++) \
142 outbuf[jjj] = (type) value++; \
144 switch (m) { \
145 case set_scalar: \
146 printf("internal error - cannot set_scalar a " \
147 "matrix\n"); \
148 pass = false; \
149 break; \
151 case set_vector: \
152 glUniformMatrix ## r ## x ## c ## suffix ## v \
153 (loc, 1, GL_FALSE, outbuf); \
154 break; \
156 case get_and_compare: \
157 glGetUniform ## suffix ## v \
158 (prog, loc, inbuf); \
159 if (memcmp(inbuf, outbuf, \
160 sizeof(type) * r * c) != 0) { \
161 printf(" %s data " \
162 "does not match.\n", \
163 name); \
164 pass = false; \
166 break; \
168 } while (0)
171 * Set or get/verify all the active uniforms in a program
173 * \param prog Program to operate on
174 * \param base_value Value set (or expected) for the first element of the
175 * first uniform. Each element expects a successively
176 * incremented value.
177 * \param m Mode of operation. Set using scalars (e.g., using
178 * \c glUniform4f), set using vectors (e.g., using
179 * \c glUniform4fv), or get and verify.
181 bool
182 process_program_uniforms(GLuint prog, unsigned base_value, enum mode m)
184 unsigned num_uniforms;
185 unsigned i;
186 unsigned value;
187 bool pass = true;
189 glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, (GLint *) &num_uniforms);
191 value = base_value;
192 for (i = 0; i < num_uniforms; i++) {
193 GLint size;
194 GLenum type;
195 char name[64];
196 GLuint loc;
198 glGetActiveUniform(prog, i, sizeof(name), NULL,
199 &size, &type, name);
201 loc = glGetUniformLocation(prog, name);
202 if (loc == -1) {
203 printf("%s was active, but could not get location.\n",
204 name);
205 pass = false;
206 continue;
209 switch (type) {
210 case GL_DOUBLE:
211 NONMATRIX_UNIFORM(double, 1, d);
212 break;
213 case GL_DOUBLE_VEC2:
214 NONMATRIX_UNIFORM(double, 2, d);
215 break;
216 case GL_DOUBLE_VEC3:
217 NONMATRIX_UNIFORM(double, 3, d);
218 break;
219 case GL_DOUBLE_VEC4:
220 NONMATRIX_UNIFORM(double, 4, d);
221 break;
223 case GL_DOUBLE_MAT2:
224 MATRIX_UNIFORM(double, 2, 2, d);
225 break;
226 case GL_DOUBLE_MAT2x3:
227 MATRIX_UNIFORM(double, 2, 3, d);
228 break;
229 case GL_DOUBLE_MAT2x4:
230 MATRIX_UNIFORM(double, 2, 4, d);
231 break;
232 case GL_DOUBLE_MAT3x2:
233 MATRIX_UNIFORM(double, 3, 2, d);
234 break;
235 case GL_DOUBLE_MAT3:
236 MATRIX_UNIFORM(double, 3, 3, d);
237 break;
238 case GL_DOUBLE_MAT3x4:
239 MATRIX_UNIFORM(double, 3, 4, d);
240 break;
241 case GL_DOUBLE_MAT4x2:
242 MATRIX_UNIFORM(double, 4, 2, d);
243 break;
244 case GL_DOUBLE_MAT4x3:
245 MATRIX_UNIFORM(double, 4, 3, d);
246 break;
247 case GL_DOUBLE_MAT4:
248 MATRIX_UNIFORM(double, 4, 4, d);
249 break;
253 return pass;
256 static bool
257 process_shader(const char *func, const char *source, bool matrix)
259 static const struct {
260 GLenum list_mode;
261 enum mode setter_mode;
262 const char *setter_mode_name;
263 unsigned base_value;
264 } tests[] = {
266 GL_COMPILE,
267 set_scalar, "scalar",
271 GL_COMPILE,
272 set_vector, "vector",
276 GL_COMPILE_AND_EXECUTE,
277 set_scalar, "scalar",
281 GL_COMPILE_AND_EXECUTE,
282 set_vector, "vector",
287 bool pass = true;
289 printf("Testing gl%s\n", func);
291 GLuint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
292 GLuint prog = piglit_link_simple_program(vs, 0);
294 glUseProgram(prog);
296 GLuint list = glGenLists(1);
298 for (unsigned i = 0; i < ARRAY_SIZE(tests); i++) {
299 const unsigned post_compile_base_value =
300 (tests[i].list_mode == GL_COMPILE)
301 ? 0 : tests[i].base_value;
303 if (matrix && tests[i].setter_mode == set_scalar)
304 continue;
306 printf(" %s: %s mode\n",
307 piglit_get_gl_enum_name(tests[i].list_mode),
308 tests[i].setter_mode_name);
310 printf(" pre-initialize\n");
311 pass = process_program_uniforms(prog, 0, tests[i].setter_mode)
312 && pass;
313 pass = process_program_uniforms(prog, 0, get_and_compare)
314 && pass;
316 glNewList(list, tests[i].list_mode);
317 printf(" compiling\n");
318 pass = process_program_uniforms(prog,
319 tests[i].base_value,
320 tests[i].setter_mode)
321 && pass;
322 glEndList();
324 printf(" post-compile verify\n");
325 pass = process_program_uniforms(prog, post_compile_base_value,
326 get_and_compare)
327 && pass;
329 /* Reset the values back. This is useful if GL_COMPILE
330 * executed the commands and for GL_COMPILE_AND_EXECUTE. We
331 * want to know that glCallList changed things.
333 printf(" restore original values\n");
334 pass = process_program_uniforms(prog, 0, tests[i].setter_mode)
335 && pass;
336 pass = process_program_uniforms(prog, 0, get_and_compare)
337 && pass;
339 printf(" post-glCallList verify\n");
340 glCallList(list);
341 pass = process_program_uniforms(prog, tests[i].base_value,
342 get_and_compare)
343 && pass;
346 glDeleteLists(list, 1);
348 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
350 return pass;
353 bool
354 Uniformd(void)
356 const char *source =
357 "#version 150\n"
358 "#extension GL_ARB_gpu_shader_fp64: require\n"
359 "uniform double s;\n"
360 "uniform dvec2 v2;\n"
361 "uniform dvec3 v3;\n"
362 "uniform dvec4 v4;\n"
363 "\n"
364 "void main()\n"
365 "{\n"
366 " gl_Position = vec4(v3, s) + vec4(v2, v2) + vec4(v4);\n"
367 "}\n"
370 return process_shader(__func__, source, false);
373 bool
374 UniformMatrixd(void)
376 const char *source =
377 "#version 150\n"
378 "#extension GL_ARB_gpu_shader_fp64: require\n"
379 "uniform dmat2x2 m22;\n"
380 "uniform dmat2x3 m23;\n"
381 "uniform dmat2x4 m24;\n"
382 "uniform dmat3x2 m32;\n"
383 "uniform dmat3x3 m33;\n"
384 "uniform dmat3x4 m34;\n"
385 "uniform dmat4x2 m42;\n"
386 "uniform dmat4x3 m43;\n"
387 "uniform dmat4x4 m44;\n"
388 "\n"
389 "void main()\n"
390 "{\n"
391 " gl_Position = "
392 "vec4(m22[0], 0, 0) + vec4(m32[0], 0, 0) + vec4(m42[0], 0, 0) "
393 "+ vec4(m23[0], 0) + vec4(m33[0], 0) + vec4(m43[0], 0) "
394 "+ vec4(m24[0]) + vec4(m34[0]) + vec4(m44[0]);\n"
395 "}\n"
398 return process_shader(__func__, source, true);
401 enum piglit_result
402 piglit_display(void)
404 /* NOTREACHED */
405 return PIGLIT_FAIL;