cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / vp-max-array.c
blob99abe3c8c3ce6d0c62bc6c9dcb66cc5fb95cb1ee
1 /*
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
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 * \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[] =
42 "!!ARBvp1.0\n"
43 "OPTION ARB_position_invariant;\n"
44 "PARAM colors[%d] = {\n"
47 static const char template_footer[] =
48 " };\n"
49 "MOV result.color, colors[0];\n"
50 "END\n"
53 static const char max_native_template_footer[] =
54 " };\n"
55 "ADDRESS a;\n"
56 "ARL a.x, vertex.position.x;\n"
57 "MOV result.color, colors[a.x];\n"
58 "END\n"
61 static const char max_local_template[] =
62 "!!ARBvp1.0\n"
63 "OPTION ARB_position_invariant;\n"
64 "PARAM colors[96] = {\n"
65 " program.%s[0..48],\n"
66 " program.%s[%d..%d]\n"
67 " };\n"
68 "ADDRESS a;\n"
69 "ARL a.x, vertex.position.x;\n"
70 "MOV result.color, colors[a.x];\n"
71 "END\n"
74 enum piglit_result
75 piglit_display(void)
77 return PIGLIT_PASS;
81 bool
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);
89 return false;
92 return true;
95 void
96 piglit_init(int argc, char **argv)
98 GLint max_parameters;
99 GLint max_native_parameters;
100 GLint max_local_parameters;
101 GLint max_env_parameters;
102 char *shader_source;
103 bool pass = true;
104 size_t len;
105 int offset;
106 unsigned i;
108 (void) argc;
109 (void) argv;
111 piglit_require_vertex_program();
113 /* First, query all of the limits.
115 pass = query_and_require_limit(GL_MAX_PROGRAM_PARAMETERS_ARB,
116 & max_parameters,
118 && pass;
119 pass = query_and_require_limit(GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB,
120 & max_native_parameters,
122 && pass;
123 pass = query_and_require_limit(GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB,
124 & max_local_parameters,
126 && pass;
127 pass = query_and_require_limit(GL_MAX_PROGRAM_ENV_PARAMETERS_ARB,
128 & max_env_parameters,
130 && pass;
131 if (!pass) {
132 piglit_report_result(PIGLIT_FAIL);
135 /* Allocate a buffer big enough to hold any program that this test
136 * might generate.
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],
155 len - offset,
156 "\t\t{ %.1f, %.1f, %.1f, %.1f }%c\n",
157 (float) i,
158 (float) i + 0.2,
159 (float) i + 0.4,
160 (float) i + 0.6,
161 comma);
162 offset += used;
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],
181 len - offset,
182 "\t\t{ %.1f, %.1f, %.1f, %.1f }%c\n",
183 (float) i,
184 (float) i + 0.2,
185 (float) i + 0.4,
186 (float) i + 0.6,
187 comma);
188 offset += used;
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,
203 "local",
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,
215 "env",
216 "env", max_env_parameters - 47, max_env_parameters - 1);
218 (void) piglit_compile_program(GL_VERTEX_PROGRAM_ARB, shader_source);