2 * Copyright © 2009 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 * \file vp-max-array.c
26 * Validate creation of a single maximally sized parameter array.
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
39 PIGLIT_GL_TEST_CONFIG_END
41 static const char template_header
[] =
43 "OPTION ARB_position_invariant;\n"
44 "PARAM colors[%d] = {\n"
47 static const char template_footer
[] =
49 "MOV result.color, colors[0];\n"
53 static const char max_native_template_footer
[] =
56 "ARL a.x, vertex.position.x;\n"
57 "MOV result.color, colors[a.x];\n"
61 static const char max_local_template
[] =
63 "OPTION ARB_position_invariant;\n"
64 "PARAM colors[96] = {\n"
65 " program.%s[0..48],\n"
66 " program.%s[%d..%d]\n"
69 "ARL a.x, vertex.position.x;\n"
70 "MOV result.color, colors[a.x];\n"
82 query_and_require_limit(GLenum pname
, GLint
*param
, GLint minimum_maximum
)
84 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB
, pname
, param
);
85 if (*param
< minimum_maximum
) {
86 fprintf(stderr
, "%s: Expected at least %d, got %d\n",
87 piglit_get_gl_enum_name(pname
),
88 minimum_maximum
, *param
);
96 piglit_init(int argc
, char **argv
)
99 GLint max_native_parameters
;
100 GLint max_local_parameters
;
101 GLint max_env_parameters
;
111 piglit_require_vertex_program();
113 /* First, query all of the limits.
115 pass
= query_and_require_limit(GL_MAX_PROGRAM_PARAMETERS_ARB
,
119 pass
= query_and_require_limit(GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
,
120 & max_native_parameters
,
123 pass
= query_and_require_limit(GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
,
124 & max_local_parameters
,
127 pass
= query_and_require_limit(GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
,
128 & max_env_parameters
,
132 piglit_report_result(PIGLIT_FAIL
);
135 /* Allocate a buffer big enough to hold any program that this test
138 len
= sizeof(template_header
)
139 + sizeof(template_footer
)
140 + sizeof(max_native_template_footer
)
141 + (80 * max_parameters
) + 1;
142 shader_source
= malloc(len
);
143 if (shader_source
== NULL
)
144 piglit_report_result(PIGLIT_FAIL
);
146 /* Generate a program that uses the full parameter space using an
147 * array of constants. Since only one parameter is statically used,
148 * this exercises GL_MAX_PROGRAM_PARAMETERS_ARB and *not*
149 * GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB.
151 offset
= snprintf(shader_source
, len
, template_header
, max_parameters
);
152 for (i
= 0; i
< max_parameters
; i
++) {
153 int comma
= (i
< (max_parameters
- 1)) ? ',' : ' ';
154 int used
= snprintf(& shader_source
[offset
],
156 "\t\t{ %.1f, %.1f, %.1f, %.1f }%c\n",
165 memcpy(& shader_source
[offset
], template_footer
,
166 sizeof(template_footer
));
168 (void) piglit_compile_program(GL_VERTEX_PROGRAM_ARB
, shader_source
);
170 /* Generate a program that uses the full native parameter space using
171 * an array of constants. The array is accessed indirectly, so the
172 * assembler cannot know which elements may be used. As a result, it
173 * has to upload all of them. This exercises
174 * GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB.
176 offset
= snprintf(shader_source
, len
, template_header
,
177 max_native_parameters
);
178 for (i
= 0; i
< max_native_parameters
; i
++) {
179 int comma
= (i
< (max_native_parameters
- 1)) ? ',' : ' ';
180 int used
= snprintf(& shader_source
[offset
],
182 "\t\t{ %.1f, %.1f, %.1f, %.1f }%c\n",
191 memcpy(& shader_source
[offset
], max_native_template_footer
,
192 sizeof(max_native_template_footer
));
194 (void) piglit_compile_program(GL_VERTEX_PROGRAM_ARB
, shader_source
);
196 /* Generate a program that uses as much of the local parameter space
197 * as possible. This basically tries to hit both ends of the
198 * program.local array without making assumptions about the relative
199 * amount of parameter space. We only assume that the
200 * minimum-maximums of 96 are respected by the GL implementation.
202 snprintf(shader_source
, len
, max_local_template
,
204 "local", max_local_parameters
- 47, max_local_parameters
- 1);
206 (void) piglit_compile_program(GL_VERTEX_PROGRAM_ARB
, shader_source
);
208 /* Generate a program that uses as much of the env parameter space
209 * as possible. This basically tries to hit both ends of the
210 * program.env array without making assumptions about the relative
211 * amount of parameter space. We only assume that the
212 * minimum-maximums of 96 are respected by the GL implementation.
214 snprintf(shader_source
, len
, max_local_template
,
216 "env", max_env_parameters
- 47, max_env_parameters
- 1);
218 (void) piglit_compile_program(GL_VERTEX_PROGRAM_ARB
, shader_source
);