Commit fcd00af5 authored by Nicolai Hähnle's avatar Nicolai Hähnle

Add basic tests for NV_vertex_program

Far from exhaustive, but should trip up a driver that makes significant mistakes
in handling program parameters (such as recent r300 *sigh*).
Signed-off-by: Nicolai Hähnle's avatarNicolai Hähnle <nhaehnle@gmail.com>
parent 5ed59893
......@@ -136,6 +136,9 @@ vpfpgeneric['dataflow-bug'] = make_vpfpgeneric('dataflow-bug.vpfp')
vpfpgeneric['fogcoord-dp3'] = make_vpfpgeneric('fogcoord-dp3.vpfp')
vpfpgeneric['fogcoord-dph'] = make_vpfpgeneric('fogcoord-dph.vpfp')
vpfpgeneric['fogcoord-dp4'] = make_vpfpgeneric('fogcoord-dp4.vpfp')
vpfpgeneric['nv-mov'] = make_vpfpgeneric('nv-mov.vpfp')
vpfpgeneric['nv-add'] = make_vpfpgeneric('nv-add.vpfp')
vpfpgeneric['nv-arl'] = make_vpfpgeneric('nv-arl.vpfp')
shaders['vpfp-generic'] = vpfpgeneric
bugs = Group()
......
!!VP1.0
MOV R0, v[OPOS];
DP4 o[HPOS].x, c[0], R0;
DP4 o[HPOS].y, c[1], R0;
DP4 o[HPOS].z, c[2], R0;
DP4 o[HPOS].w, c[3], R0;
ADD o[COL0], v[TEX0], c[17];
END
!!ARBfp1.0
MOV result.color, fragment.color;
END
!!test
texcoord[0] -0.1 0.4 1.7 0.1
NVparameter[17] 0.3 -0.1 -1.2 0.5
expected 0.2 0.3 0.5 0.6
!!VP1.0
MOV R0, v[OPOS];
DP4 o[HPOS].x, c[0], R0;
DP4 o[HPOS].y, c[1], R0;
DP4 o[HPOS].z, c[2], R0;
DP4 o[HPOS].w, c[3], R0;
ARL A0.x, v[TEX0].x;
MOV R0, c[A0.x + 20];
ARL A0.x, v[TEX0].y;
ADD R0, R0, c[A0.x + 20];
ARL A0.x, v[TEX0].z;
ADD R0, R0, c[A0.x + 20];
ARL A0.x, v[TEX0].w;
ADD R0, R0, c[A0.x + 20];
MOV o[COL0], R0;
END
!!ARBfp1.0
MOV result.color, fragment.color;
END
!!test
texcoord[0] -2 2 5 12
NVparameter[18] 0.7 -0.1 -0.1 -0.1
NVparameter[22] -0.1 0.5 -0.1 -0.1
NVparameter[25] -0.1 -0.1 1.1 -0.1
NVparameter[32] -0.1 -0.1 -0.1 0.8
expected 0.4 0.2 0.8 0.5
!!VP1.0
MOV R0, v[OPOS];
DP4 o[HPOS].x, c[0], R0;
DP4 o[HPOS].y, c[1], R0;
DP4 o[HPOS].z, c[2], R0;
DP4 o[HPOS].w, c[3], R0;
MOV o[COL0], v[TEX0];
END
!!ARBfp1.0
MOV result.color, fragment.color;
END
!!test
texcoord[0] 0.1 0.4 0.7 0.1
expected 0.1 0.4 0.7 0.1
......@@ -43,6 +43,12 @@
*
* Arbitrarily many test sections can be given, and in each section,
* arbitrarily many parameters are possible.
*
* Also supports NV_vertex_program by using !!VP1.0 instead of !!ARBvp1.0.
* For NV_vertex_program, parameters can be set by
* NVparameter[<id>] <x> <y> <z> <w>
* Note that the model-view-projection matrix is tracked in parameters
* [0..3].
*/
#include <assert.h>
......@@ -109,6 +115,20 @@ struct ParameterLocal : TestParameter {
GLfloat data[4];
};
struct ParameterNV : TestParameter {
ParameterNV(int _index, GLfloat v[4]) {
index = _index;
memcpy(data, v, sizeof(GLfloat)*4);
}
void setup() {
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, index, data);
}
int index;
GLfloat data[4];
};
struct Test {
Test(const std::string& _name) : name(_name) {
expected[0] = expected[1] = expected[2] = expected[3] = 0;
......@@ -131,7 +151,9 @@ private:
};
struct TestGroup {
TestGroup() {}
TestGroup() {
nv_vertex_program = false;
}
~TestGroup() {
for(vector<Test*>::iterator ptest = tests.begin(); ptest != tests.end(); ++ptest)
delete *ptest;
......@@ -142,6 +164,7 @@ struct TestGroup {
string vertex_program_code;
string fragment_program_code;
bool nv_vertex_program;
vector<Test*> tests;
private:
......@@ -190,17 +213,49 @@ bool TestGroup::run()
{
bool success = true;
GLuint fragprog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fragment_program_code.c_str());
GLuint vertprog = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, vertex_program_code.c_str());
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glEnable(GL_VERTEX_PROGRAM_ARB);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragprog);
pglBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertprog);
if (!nv_vertex_program) {
GLuint vertprog = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, vertex_program_code.c_str());
glEnable(GL_VERTEX_PROGRAM_ARB);
pglBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertprog);
} else {
GLuint vertprog;
glGenProgramsNV(1, &vertprog);
glLoadProgramNV(GL_VERTEX_PROGRAM_NV, vertprog,
vertex_program_code.size(), (const GLubyte*)vertex_program_code.c_str());
GLenum error = glGetError();
if (error != GL_NO_ERROR) {
GLint errorPos;
fprintf(stderr, "Error loading program: %u\n", error);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errorPos);
fprintf(stderr, "Error pos=%d (line=%d) in program:\n%s\n",
errorPos,
FindLine(vertex_program_code.c_str(), errorPos),
vertex_program_code.c_str());
piglit_report_result(PIGLIT_FAILURE);
}
glBindProgramNV(GL_VERTEX_PROGRAM_NV, vertprog);
glEnable(GL_VERTEX_PROGRAM_NV);
glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);
}
for(vector<Test*>::iterator it = tests.begin(); it != tests.end(); ++it)
success = (*it)->run() && success;
glDisable(GL_VERTEX_PROGRAM_ARB);
if (!nv_vertex_program) {
glDisable(GL_VERTEX_PROGRAM_ARB);
} else {
glDisable(GL_VERTEX_PROGRAM_NV);
}
glDisable(GL_FRAGMENT_PROGRAM_ARB);
return success;
......@@ -249,6 +304,8 @@ void Test::readline(const char* filename, int linenum, char* line)
parameters.push_back(new ParameterLocal(GL_VERTEX_PROGRAM_ARB, atoi(line+13), params));
} else if (!strncmp(line, "fragment.local[", 15)) {
parameters.push_back(new ParameterLocal(GL_FRAGMENT_PROGRAM_ARB, atoi(line+15), params));
} else if (!strncmp(line, "NVparameter[", 12)) {
parameters.push_back(new ParameterNV(atoi(line+12), params));
} else {
fprintf(stderr, "%s:%i: unknown parameters %s\n", filename, linenum, line);
piglit_report_result(PIGLIT_FAILURE);
......@@ -293,6 +350,11 @@ void TestGroup::read(const char* filename)
vertex_program_code = "!!";
vertex_program_code += p;
state = ReadVertexProgram;
} else if (!strncmp(p, "VP", 2)) {
vertex_program_code = "!!";
vertex_program_code += p;
nv_vertex_program = true;
state = ReadVertexProgram;
} else if (!strncmp(p, "ARBfp", 5)) {
fragment_program_code = "!!";
fragment_program_code += p;
......@@ -353,7 +415,10 @@ static void Reshape(int width, int height)
static void Init(void)
{
piglit_require_fragment_program();
piglit_require_vertex_program();
if (tests.nv_vertex_program)
piglit_require_extension("GL_NV_vertex_program");
else
piglit_require_vertex_program();
Reshape(Width,Height);
}
......@@ -391,4 +456,3 @@ int main(int argc, char *argv[])
glutMainLoop();
return 0;
}
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