File: dlist-fp64-uniforms.c

package info (click to toggle)
piglit 0~git20200212-f4710c51b-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 106,972 kB
  • sloc: ansic: 263,763; xml: 48,941; python: 29,918; lisp: 19,789; cpp: 12,142; sh: 22; makefile: 20; pascal: 5
file content (406 lines) | stat: -rw-r--r-- 9,901 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/*
 * Copyright © 2014 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

/**
 * Verify that unsigned glUniform* commands added in ARB_gpu_shader_fp64 are
 * compiled into display lists.
 *
 * This test is adapted from tests/spec/arb_separate_shader_objects/dlist.c
 */
#include "piglit-util-gl.h"

PIGLIT_GL_TEST_CONFIG_BEGIN

	/* No supports_gl_core_version setting because there are no display
	 * lists in core profile.
	 */
	config.supports_gl_compat_version = 32;
	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
	config.khr_no_error_support = PIGLIT_NO_ERRORS;

PIGLIT_GL_TEST_CONFIG_END

static bool Uniformd(void);
static bool UniformMatrixd(void);

void
piglit_init(int argc, char **argv)
{
	bool pass = true;

	piglit_require_extension("GL_ARB_gpu_shader_fp64");

	pass = Uniformd() && pass;
	pass = UniformMatrixd() && pass;

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}

enum mode {
	set_scalar,
	set_vector,
	get_and_compare
};

#define NONMATRIX_UNIFORM(type, n, suffix)			\
	do {							\
		type inbuf[n];					\
		type outbuf[n];					\
		unsigned jjj;					\
								\
		for (jjj = 0; jjj < n; jjj++)			\
			outbuf[jjj] = (type) value++;		\
								\
		switch (m) {					\
		case set_scalar:				\
			switch (n) {				\
			case 1:					\
				glUniform1 ## suffix		\
					(loc,			\
					 outbuf[0]);		\
				break;				\
			case 2:					\
				glUniform2 ## suffix		\
					(loc,			\
					 outbuf[0],		\
					 outbuf[1]);		\
				break;				\
			case 3:					\
				glUniform3 ## suffix		\
					(loc,			\
					 outbuf[0],		\
					 outbuf[1],		\
					 outbuf[2]);		\
				break;				\
			case 4:					\
				glUniform4 ## suffix		\
					(loc,			\
					 outbuf[0],		\
					 outbuf[1],		\
					 outbuf[2],		\
					 outbuf[3]);		\
				break;				\
			default:				\
				printf("internal error - "	\
				       "cannot set_scalar a "	\
				       "%d count\n", n);	\
				pass = false;			\
				break;				\
			}					\
			break;					\
								\
		case set_vector:				\
			glUniform ## n ## suffix ## v		\
				(loc, 1, outbuf);		\
			break;					\
								\
		case get_and_compare:				\
			glGetUniform ## suffix ## v		\
				(prog, loc, inbuf);		\
			if (memcmp(inbuf, outbuf,		\
				   sizeof(type) * n) != 0) {	\
				printf("            %s data "	\
				       "does not match.\n",	\
				       name);			\
				pass = false;			\
			}					\
			break;					\
		}						\
	} while (0)

#define glUniformMatrix2x2dv glUniformMatrix2dv
#define glUniformMatrix3x3dv glUniformMatrix3dv
#define glUniformMatrix4x4dv glUniformMatrix4dv

#define MATRIX_UNIFORM(type, r, c, suffix)				\
	do {								\
		type inbuf[r * c];					\
		type outbuf[r * c];					\
		unsigned jjj;						\
									\
		for (jjj = 0; jjj < (r * c); jjj++)			\
			outbuf[jjj] = (type) value++;			\
									\
		switch (m) {						\
		case set_scalar:					\
			printf("internal error - cannot set_scalar a "	\
			       "matrix\n");				\
			pass = false;					\
			break;						\
									\
		case set_vector:					\
			glUniformMatrix ## r ## x ## c ## suffix ## v	\
				(loc, 1, GL_FALSE, outbuf);		\
				break;					\
									\
		case get_and_compare:					\
			glGetUniform ## suffix ## v			\
				(prog, loc, inbuf);			\
			if (memcmp(inbuf, outbuf,			\
				   sizeof(type) * r * c) != 0) {	\
				printf("            %s data "		\
				       "does not match.\n",		\
				       name);				\
				pass = false;				\
			}						\
			break;						\
		}							\
	} while (0)

/**
 * Set or get/verify all the active uniforms in a program
 *
 * \param prog        Program to operate on
 * \param base_value  Value set (or expected) for the first element of the
 *                    first uniform.  Each element expects a successively
 *                    incremented value.
 * \param m           Mode of operation.  Set using scalars (e.g., using
 *                    \c glUniform4f), set using vectors (e.g., using
 *                    \c glUniform4fv), or get and verify.
 */
bool
process_program_uniforms(GLuint prog, unsigned base_value, enum mode m)
{
	unsigned num_uniforms;
	unsigned i;
	unsigned value;
	bool pass = true;

	glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, (GLint *) &num_uniforms);

	value = base_value;
	for (i = 0; i < num_uniforms; i++) {
		GLint size;
		GLenum type;
		char name[64];
		GLuint loc;

		glGetActiveUniform(prog, i, sizeof(name), NULL,
				   &size, &type, name);

		loc = glGetUniformLocation(prog, name);
		if (loc == -1) {
			printf("%s was active, but could not get location.\n",
			       name);
			pass = false;
			continue;
		}

		switch (type) {
		case GL_DOUBLE:
			NONMATRIX_UNIFORM(double, 1, d);
			break;
		case GL_DOUBLE_VEC2:
			NONMATRIX_UNIFORM(double, 2, d);
			break;
		case GL_DOUBLE_VEC3:
			NONMATRIX_UNIFORM(double, 3, d);
			break;
		case GL_DOUBLE_VEC4:
			NONMATRIX_UNIFORM(double, 4, d);
			break;

		case GL_DOUBLE_MAT2:
			MATRIX_UNIFORM(double, 2, 2, d);
			break;
		case GL_DOUBLE_MAT2x3:
			MATRIX_UNIFORM(double, 2, 3, d);
			break;
		case GL_DOUBLE_MAT2x4:
			MATRIX_UNIFORM(double, 2, 4, d);
			break;
		case GL_DOUBLE_MAT3x2:
			MATRIX_UNIFORM(double, 3, 2, d);
			break;
		case GL_DOUBLE_MAT3:
			MATRIX_UNIFORM(double, 3, 3, d);
			break;
		case GL_DOUBLE_MAT3x4:
			MATRIX_UNIFORM(double, 3, 4, d);
			break;
		case GL_DOUBLE_MAT4x2:
			MATRIX_UNIFORM(double, 4, 2, d);
			break;
		case GL_DOUBLE_MAT4x3:
			MATRIX_UNIFORM(double, 4, 3, d);
			break;
		case GL_DOUBLE_MAT4:
			MATRIX_UNIFORM(double, 4, 4, d);
			break;
		}
	}

	return pass;
}

static bool
process_shader(const char *func, const char *source, bool matrix)
{
	static const struct {
		GLenum list_mode;
		enum mode setter_mode;
		const char *setter_mode_name;
		unsigned base_value;
	} tests[] = {
		{
			GL_COMPILE,
			set_scalar, "scalar",
			5
		},
		{
			GL_COMPILE,
			set_vector, "vector",
			7
		},
		{
			GL_COMPILE_AND_EXECUTE,
			set_scalar, "scalar",
			11
		},
		{
			GL_COMPILE_AND_EXECUTE,
			set_vector, "vector",
			13
		}
	};

	bool pass = true;

	printf("Testing gl%s\n", func);

	GLuint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
	GLuint prog = piglit_link_simple_program(vs, 0);

	glUseProgram(prog);

	GLuint list = glGenLists(1);

	for (unsigned i = 0; i < ARRAY_SIZE(tests); i++) {
		const unsigned post_compile_base_value =
			(tests[i].list_mode == GL_COMPILE)
			? 0 : tests[i].base_value;

		if (matrix && tests[i].setter_mode == set_scalar)
			continue;

		printf("    %s: %s mode\n",
		       piglit_get_gl_enum_name(tests[i].list_mode),
		       tests[i].setter_mode_name);

		printf("        pre-initialize\n");
		pass = process_program_uniforms(prog, 0, tests[i].setter_mode)
			&& pass;
		pass = process_program_uniforms(prog, 0, get_and_compare)
			&& pass;

		glNewList(list, tests[i].list_mode);
		printf("        compiling\n");
		pass = process_program_uniforms(prog,
						tests[i].base_value,
						tests[i].setter_mode)
			&& pass;
		glEndList();

		printf("        post-compile verify\n");
		pass = process_program_uniforms(prog, post_compile_base_value,
						get_and_compare)
			&& pass;

		/* Reset the values back.  This is useful if GL_COMPILE
		 * executed the commands and for GL_COMPILE_AND_EXECUTE.  We
		 * want to know that glCallList changed things.
		 */
		printf("        restore original values\n");
		pass = process_program_uniforms(prog, 0, tests[i].setter_mode)
			&& pass;
		pass = process_program_uniforms(prog, 0, get_and_compare)
			&& pass;

		printf("        post-glCallList verify\n");
		glCallList(list);
		pass = process_program_uniforms(prog, tests[i].base_value,
						get_and_compare)
			&& pass;
	}

	glDeleteLists(list, 1);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	return pass;
}

bool
Uniformd(void)
{
	const char *source =
		"#version 150\n"
		"#extension GL_ARB_gpu_shader_fp64: require\n"
		"uniform double s;\n"
		"uniform dvec2 v2;\n"
		"uniform dvec3 v3;\n"
		"uniform dvec4 v4;\n"
		"\n"
		"void main()\n"
		"{\n"
		"    gl_Position = vec4(v3, s) + vec4(v2, v2) + vec4(v4);\n"
		"}\n"
		;

	return process_shader(__func__, source, false);
}

bool
UniformMatrixd(void)
{
	const char *source =
		"#version 150\n"
		"#extension GL_ARB_gpu_shader_fp64: require\n"
		"uniform dmat2x2 m22;\n"
		"uniform dmat2x3 m23;\n"
		"uniform dmat2x4 m24;\n"
		"uniform dmat3x2 m32;\n"
		"uniform dmat3x3 m33;\n"
		"uniform dmat3x4 m34;\n"
		"uniform dmat4x2 m42;\n"
		"uniform dmat4x3 m43;\n"
		"uniform dmat4x4 m44;\n"
		"\n"
		"void main()\n"
		"{\n"
		"    gl_Position = "
		"vec4(m22[0], 0, 0) + vec4(m32[0], 0, 0) + vec4(m42[0], 0, 0) "
		"+ vec4(m23[0], 0)  + vec4(m33[0], 0)    + vec4(m43[0], 0) "
		"+ vec4(m24[0])     + vec4(m34[0])       + vec4(m44[0]);\n"
		"}\n"
		;

	return process_shader(__func__, source, true);
}

enum piglit_result
piglit_display(void)
{
	/* NOTREACHED */
	return PIGLIT_FAIL;
}