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
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
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);
47 piglit_init(int argc
, char **argv
)
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
);
65 #define NONMATRIX_UNIFORM(type, n, suffix) \
71 for (jjj = 0; jjj < n; jjj++) \
72 outbuf[jjj] = (type) value++; \
78 glUniform1 ## suffix \
83 glUniform2 ## suffix \
89 glUniform3 ## suffix \
96 glUniform4 ## suffix \
104 printf("internal error - " \
105 "cannot set_scalar a " \
113 glUniform ## n ## suffix ## v \
117 case get_and_compare: \
118 glGetUniform ## suffix ## v \
119 (prog, loc, inbuf); \
120 if (memcmp(inbuf, outbuf, \
121 sizeof(type) * n) != 0) { \
123 "does not match.\n", \
131 #define glUniformMatrix2x2dv glUniformMatrix2dv
132 #define glUniformMatrix3x3dv glUniformMatrix3dv
133 #define glUniformMatrix4x4dv glUniformMatrix4dv
135 #define MATRIX_UNIFORM(type, r, c, suffix) \
138 type outbuf[r * c]; \
141 for (jjj = 0; jjj < (r * c); jjj++) \
142 outbuf[jjj] = (type) value++; \
146 printf("internal error - cannot set_scalar a " \
152 glUniformMatrix ## r ## x ## c ## suffix ## v \
153 (loc, 1, GL_FALSE, outbuf); \
156 case get_and_compare: \
157 glGetUniform ## suffix ## v \
158 (prog, loc, inbuf); \
159 if (memcmp(inbuf, outbuf, \
160 sizeof(type) * r * c) != 0) { \
162 "does not match.\n", \
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
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.
182 process_program_uniforms(GLuint prog
, unsigned base_value
, enum mode m
)
184 unsigned num_uniforms
;
189 glGetProgramiv(prog
, GL_ACTIVE_UNIFORMS
, (GLint
*) &num_uniforms
);
192 for (i
= 0; i
< num_uniforms
; i
++) {
198 glGetActiveUniform(prog
, i
, sizeof(name
), NULL
,
201 loc
= glGetUniformLocation(prog
, name
);
203 printf("%s was active, but could not get location.\n",
211 NONMATRIX_UNIFORM(double, 1, d
);
214 NONMATRIX_UNIFORM(double, 2, d
);
217 NONMATRIX_UNIFORM(double, 3, d
);
220 NONMATRIX_UNIFORM(double, 4, d
);
224 MATRIX_UNIFORM(double, 2, 2, d
);
226 case GL_DOUBLE_MAT2x3
:
227 MATRIX_UNIFORM(double, 2, 3, d
);
229 case GL_DOUBLE_MAT2x4
:
230 MATRIX_UNIFORM(double, 2, 4, d
);
232 case GL_DOUBLE_MAT3x2
:
233 MATRIX_UNIFORM(double, 3, 2, d
);
236 MATRIX_UNIFORM(double, 3, 3, d
);
238 case GL_DOUBLE_MAT3x4
:
239 MATRIX_UNIFORM(double, 3, 4, d
);
241 case GL_DOUBLE_MAT4x2
:
242 MATRIX_UNIFORM(double, 4, 2, d
);
244 case GL_DOUBLE_MAT4x3
:
245 MATRIX_UNIFORM(double, 4, 3, d
);
248 MATRIX_UNIFORM(double, 4, 4, d
);
257 process_shader(const char *func
, const char *source
, bool matrix
)
259 static const struct {
261 enum mode setter_mode
;
262 const char *setter_mode_name
;
267 set_scalar
, "scalar",
272 set_vector
, "vector",
276 GL_COMPILE_AND_EXECUTE
,
277 set_scalar
, "scalar",
281 GL_COMPILE_AND_EXECUTE
,
282 set_vector
, "vector",
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);
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
)
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
)
313 pass
= process_program_uniforms(prog
, 0, get_and_compare
)
316 glNewList(list
, tests
[i
].list_mode
);
317 printf(" compiling\n");
318 pass
= process_program_uniforms(prog
,
320 tests
[i
].setter_mode
)
324 printf(" post-compile verify\n");
325 pass
= process_program_uniforms(prog
, post_compile_base_value
,
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
)
336 pass
= process_program_uniforms(prog
, 0, get_and_compare
)
339 printf(" post-glCallList verify\n");
341 pass
= process_program_uniforms(prog
, tests
[i
].base_value
,
346 glDeleteLists(list
, 1);
348 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
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"
366 " gl_Position = vec4(v3, s) + vec4(v2, v2) + vec4(v4);\n"
370 return process_shader(__func__
, source
, false);
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"
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"
398 return process_shader(__func__
, source
, true);