Commit 94dac46a authored by Emma Anholt's avatar Emma Anholt
Browse files

Add a test for ARB_fp texture indirection accounting.

This catches bug #17865 on i915.  It's not a terribly complete test, and the
allowance for the driver to count indirections differently from the spec for
its native numbers means we don't get to justifiably fail very often.
parent 3f0804af
......@@ -65,6 +65,7 @@ shaders['fp-lit-mask'] = PlainExecTest([testBinDir + 'fp-lit-mask', '-auto'])
shaders['fp-fragment-position'] = PlainExecTest([testBinDir + 'fp-fragment-position', '-auto'])
shaders['fp-kil'] = PlainExecTest([testBinDir + 'fp-kil', '-auto'])
shaders['fp-incomplete-tex'] = PlainExecTest([testBinDir + 'fp-incomplete-tex', '-auto'])
shaders['fp-indirections'] = PlainExecTest([testBinDir + 'fp-indirections', '-auto'])
shaders['vp-bad-program'] = PlainExecTest([testBinDir + 'vp-bad-program', '-auto'])
fpgeneric = Group()
......
......@@ -26,4 +26,5 @@ add_executable (fp-fragment-position fp-fragment-position.c)
add_executable (fp-generic fp-generic.c)
add_executable (fp-kil fp-kil.c)
add_executable (fp-incomplete-tex fp-incomplete-tex.c)
add_executable (fp-indirections fp-indirections.c)
add_executable (vp-bad-program vp-bad-program.c)
/*
* 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 <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include "piglit-util.h"
static int Automatic = 0;
#define WIN_WIDTH 100
#define WIN_HEIGHT 100
static int get_program_i(GLenum pname)
{
GLint val;
pglGetProgramivARB(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);
sprintf(prog, 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);
return NULL;
}
*progname = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, prog);
pglBindProgramARB(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);
sprintf(prog, pre);
for (i = 0; i < sample_count - 1; i++)
strcat(prog, sample);
strcat(prog, post);
*progname = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, prog);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, *progname);
return prog;
}
void
print_program_info(char *program)
{
printf("Program:\n");
printf(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;
GLint count;
indirections_limit = get_program_i(GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB);
count = indirections_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 = indirections_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 "
"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;
GLint count;
indirections_limit = get_program_i(GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB);
count = indirections_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 = indirections_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 "
"met native limits.\n", count);
print_program_info(prog);
}
free(prog);
}
return pass;
}
void display(void)
{
GLboolean pass = GL_TRUE;
pass = test_temporary_dest_indirections() && pass;
pass = test_temporary_source_indirections() && pass;
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
exit(0);
}
void init(void)
{
GLboolean pass = GL_FALSE;
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));
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
if (argc == 2 && !strcmp(argv[1], "-auto"))
Automatic = 1;
glutInitWindowPosition(0, 0);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
......@@ -140,6 +140,7 @@ PFNGLISPROGRAMARBPROC pglIsProgramARB = 0;
PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB = 0;
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pglProgramLocalParameter4fvARB = 0;
PFNGLPROGRAMLOCALPARAMETER4DARBPROC pglProgramLocalParameter4dARB = 0;
PFNGLGETPROGRAMIVARBPROC pglGetProgramivARB = 0;
PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC pglGetProgramLocalParameterdvARB = 0;
static void get_program_functions()
......@@ -167,6 +168,9 @@ static void get_program_functions()
pglGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) glutGetProcAddress("glGetProgramLocalParameterdvARB");
assert(pglGetProgramLocalParameterdvARB);
pglGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) glutGetProcAddress("glGetProgramivARB");
assert(pglGetProgramivARB);
}
int piglit_use_fragment_program()
......
......@@ -43,6 +43,7 @@ extern PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB;
extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pglProgramLocalParameter4fvARB;
extern PFNGLPROGRAMLOCALPARAMETER4DARBPROC pglProgramLocalParameter4dARB;
extern PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC pglGetProgramLocalParameterdvARB;
extern PFNGLGETPROGRAMIVARBPROC pglGetProgramivARB;
int piglit_use_fragment_program();
int piglit_use_vertex_program();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment