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
|
/*
* Copyright © 2008 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.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include "piglit-util-gl.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_compat_version = 10;
config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
PIGLIT_GL_TEST_CONFIG_END
static int get_program_i(GLenum pname)
{
GLint val;
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, pname, &val);
return val;
}
/**
* Generate a program that samples the texture into the same temporary over
* and over..
*
* This should excersize case (2) of question (24) of the ARB_fragment_program
* spec.
*
* Note that the compiler could optimize out our inner TEX instructions
* since they've got the same coordinates. Assume the compiler isn't
* for now.
*/
static char *gen_temporary_dest_indirections(int sample_count,
GLuint *progname)
{
char *prog;
char *pre =
"!!ARBfp1.0\n"
"TEMP val, sample;\n"
"MOV val, fragment.color;\n";
char *sample =
"TEX sample, fragment.color, texture[0], 2D;\n"
"MUL val, val, sample;\n";
char *post =
"MOV result.color, val;\n"
"END";
int i, instr_count;
prog = malloc(strlen(pre) + strlen(sample) * sample_count +
strlen(post) + 1);
if (prog == 0) {
printf("malloc failed.\n");
piglit_report_result(PIGLIT_FAIL);
exit(1);
}
sprintf(prog, "%s", pre);
for (i = 0; i < sample_count; i++)
strcat(prog, sample);
strcat(prog, post);
instr_count = 2 + 2 * (sample_count - 1) + 1;
if (get_program_i(GL_MAX_PROGRAM_INSTRUCTIONS_ARB) < instr_count) {
printf("indirection count %d too low to generate program with "
"%d indirections and %d instructions\n",
get_program_i(GL_MAX_PROGRAM_INSTRUCTIONS_ARB),
sample_count, instr_count);
free(prog);
return NULL;
}
*progname = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, prog);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, *progname);
return prog;
}
/**
* Generate a program that samples two textures into a pair of temporaries
* over and over.
*
* This should excersize case (1) of question (24) of the ARB_fragment_program
* spec without hitting case (2) at the same time.
*
* Note that the compiler could optimize out our inner TEX instructions
* since they've got the same coordinates. Assume the compiler isn't
* for now.
*/
static char *gen_temporary_source_indirections(int sample_count,
GLuint *progname)
{
char *prog;
char *pre =
"!!ARBfp1.0\n"
"TEMP val, val2, sample, sample2;\n"
"MOV val, fragment.color;\n"
"MOV val2, fragment.color;\n";
char *sample =
"TEX sample, val, texture[0], 2D;\n"
"TEX sample2, val2, texture[1], 2D;\n"
"MUL val, sample, sample2;\n"
"MUL val2, val2, val;\n";
char *post =
"MOV result.color, val;\n"
"END";
int i, instr_count;
instr_count = 2 + 4 * (sample_count - 1) + 1;
if (get_program_i(GL_MAX_PROGRAM_INSTRUCTIONS_ARB) < instr_count) {
printf("indirection count %d too low to generate program with "
"%d indirections and %d instructions\n",
get_program_i(GL_MAX_PROGRAM_INSTRUCTIONS_ARB),
sample_count, instr_count);
return NULL;
}
prog = malloc(strlen(pre) + strlen(sample) * (sample_count - 1) +
strlen(post) + 1);
if (prog == 0) {
printf("malloc failed.\n");
piglit_report_result(PIGLIT_FAIL);
exit(1);
}
sprintf(prog, "%s", pre);
for (i = 0; i < sample_count - 1; i++)
strcat(prog, sample);
strcat(prog, post);
*progname = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, prog);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, *progname);
return prog;
}
void
print_program_info(char *program)
{
printf("Program:\n");
printf("%s", program);
printf("\n");
printf("tex instructions: %d\n",
get_program_i(GL_PROGRAM_TEX_INSTRUCTIONS_ARB));
printf("native tex instructions: %d\n",
get_program_i(GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB));
printf("tex indirections: %d\n",
get_program_i(GL_PROGRAM_TEX_INDIRECTIONS_ARB));
printf("native tex indirections: %d\n",
get_program_i(GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB));
printf("\n");
}
/**
* Test that we can emit a whole load of samples as long as the indirection
* count is low.
*/
GLboolean test_temporary_dest_indirections(void)
{
GLboolean pass = GL_TRUE;
GLuint progname;
char *prog;
GLint indirections_limit, use_limit;
GLint count;
indirections_limit = get_program_i(GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB);
use_limit = MIN2(indirections_limit, 1024);
count = use_limit - 1;
printf("testing program with %d indirections from temporary dests\n",
count);
prog = gen_temporary_dest_indirections(count, &progname);
if (prog != NULL) {
if (!get_program_i(GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB)) {
printf("Program with %d indirections unexpectedly "
"exceeded native limits.\n", count);
print_program_info(prog);
pass = GL_FALSE;
}
free(prog);
}
count = use_limit + 1;
printf("testing program with %d indirections from temporary dests\n",
count);
prog = gen_temporary_dest_indirections(count, &progname);
if (prog != NULL && count > indirections_limit) {
if (get_program_i(GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB)) {
printf("Program with %d indirections unexpectedly "
"met native limits.\n", count);
print_program_info(prog);
}
free(prog);
}
return pass;
}
/**
* Test that we can emit a whole load of samples as long as the indirection
* count is low.
*/
GLboolean test_temporary_source_indirections(void)
{
GLboolean pass = GL_TRUE;
GLuint progname;
char *prog;
GLint indirections_limit, use_limit;
GLint count;
indirections_limit = get_program_i(GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB);
use_limit = MIN2(indirections_limit, 1024);
count = use_limit - 1;
printf("testing program with %d indirections from temporary sources\n",
count);
prog = gen_temporary_source_indirections(count, &progname);
if (prog != NULL) {
if (!get_program_i(GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB)) {
printf("Program with %d indirections unexpectedly "
"exceeded native limits.\n", count);
print_program_info(prog);
pass = GL_FALSE;
}
free(prog);
}
count = use_limit + 1;
printf("testing program with %d indirections from temporary sources\n",
count);
prog = gen_temporary_source_indirections(count, &progname);
if (prog != NULL && count > indirections_limit) {
if (get_program_i(GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB)) {
printf("Program with %d indirections unexpectedly "
"met native limits.\n", count);
print_program_info(prog);
}
free(prog);
}
return pass;
}
enum piglit_result
piglit_display(void)
{
GLboolean pass = GL_TRUE;
pass = test_temporary_dest_indirections() && pass;
pass = test_temporary_source_indirections() && pass;
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
void
piglit_init(int argc, char **argv)
{
piglit_require_fragment_program();
glEnable(GL_FRAGMENT_PROGRAM_ARB);
printf("Maximum tex instructions: %d\n",
get_program_i(GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB));
printf("Maximum native tex instructions: %d\n",
get_program_i(GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB));
printf("Maximum tex indirections: %d\n",
get_program_i(GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB));
printf("Maximum native tex indirections: %d\n",
get_program_i(GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB));
/* If the GL reports more than 10000 texture indirections, then we're probably
* running on hardware with no limitations - the driver just picked some
* arbitrary large number to report back. The test isn't meaningful, and
* the run time explodes with huge limits, so just skip it.
*
* For reference, Mesa and NVIDIA report 16384; AMD reports 2147483647.
* Pineview hardware (where this test is relevant) has a limit of 4.
*/
if (get_program_i(GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB) > 10000) {
printf("Skipping; the hardware doesn't appear to have real limits.\n");
piglit_report_result(PIGLIT_SKIP);
}
}
|