ARB_vertex_program string building syntax

Is this a valid string to hand to glProgramStringARB:

char * vtx_prog_str = “!!ARBvp1.0
ATTRIB pos = vertex.position;
TEMP result, temp;
PARAM mat[4] = { state.matrix.modelview };
DP4 result.w, pos, mat[3];
DP4 result.x, pos, mat[0];
DP4 result.y, pos, mat[1];
DP4 result.z, pos, mat[2];
RCP temp.w, result.w;
MUL result, result, temp.w;
END”;

I finally had some time to play with the extension, but the string assembly is giving me ails. Any suggestions would be much appreciated.

The last MUL is incorrect. You can’t read from an output register.

Also you can query PROGRAM_ERROR_POSITION_ARB and PROGRAM_ERROR_STRING_ARB to get a hint of what’s wrong…doesn’t work all the time though, because sometimes you get very cryptic error messages…but then again, that might evolve in future driver releases.

The program is fine, the problem is you haven’t written any vertex position. Either do that, or use invariant programs.

Actually, the biggest problem is that ‘result’ is a keyword, so you’ll need another name for your TEMP register. I think this example was added to the ARB_vertex_program issues list before ‘result’ was made a keyword and the example wasn’t ever updated.

The last MUL is fine, since both operands are TEMP registers.

[edit - spelling]

[This message has been edited by secnuop (edited 09-24-2002).]

The last MUL is fine, since both operands are TEMP registers.

True, my mistake. Didn’t see he was declaring it with a TEMP statement before and I didn’t even notice that he didn’t write to result.position or something…ah well, guess I should drink a cup of coffee to wake up before posting

[This message has been edited by Asgard (edited 09-24-2002).]

The problem with this code is that “result” is not a valid variable name. “result” is also used for program result bindings (i.e., “result.position” holds the transformed vertex position, “result.color” the final color, and so on). We reserved it to simplify parsing.

As Asgard points out earlier, query VERTEX_PROGRAM_ERROR_POSITION_ARB and VERTEX_PROGRAM_ERROR_STRING_ARB.

The cryptic error string on the NVIDIA implementation should say “reserved keyword”, and the error position should point to the beginning of “result”.

My little programs usually do something like:

query errorPos;
if (errorPos != -1) {
int i;
query errorString;
printf(“Error: %s
“, errorString);
for (i = 0; i < errorPos; i++) {
putch(string[i]);
}
printf(”***”);
for (; i < stringLen; i++) {
putch(string[i]);
}
printf("
");
}

Pat (ARB_vertex_program spec editor)

[This message has been edited by pbrown (edited 09-24-2002).]

My apologies for not posting earlier. I actually got this working (at least without errors in the syntax) yesterday afternoon.

char * vtx_prog_str = “!!ARBvp1.0
ATTRIB iPos = vertex.position;
PARAM mat[4] = {state.matrix.modelview};
OUTPUT oPos = result.position;
DP4 oPos.x, mat[0], iPos;
DP4 oPos.y, mat[1], iPos;
DP4 oPos.z, mat[2], iPos;
DP4 oPos.w, mat[3], iPos;
END”;

Thanks for the assistance!

You can also write directly to the results.

eg:

char * vtx_prog_str = “!!ARBvp1.0
PARAM mat[4] = {state.matrix.modelview};
DP4 result.x, mat[0], vertex.position;
DP4 result.y, mat[1], vertex.position;
DP4 result.z, mat[2], vertex.position;
DP4 result.w, mat[3], vertex.position;
END”;

Now weather or not there are preformance issues with doing that, I don’t know. But it does work (at least it does on my 9700).

Originally posted by NitroGL:
Now weather or not there are preformance issues with doing that, I don’t know.

There are no performance issues, except that maybe the parsing of the string will take a couple of microseconds longer :wink:
The OUTPUT statement simply aliases user-defined names with result registers and has no impact on the program execution on the GPU.

Also your program won’t compile as it has to be result.position.x (or some other result register) and not just result.x.

[edit - typos]

[This message has been edited by Asgard (edited 09-25-2002).]

Asgard,

I’m getting an invalid constant error on a line where I’m trying to grab and store the half vector, like so:

PARAM halfDir = {state.light[0].half};\

Disregard. Found it. Corrected the error. Shouldn’t have used {} brackets. Woops.

TIA

[This message has been edited by Glossifah (edited 09-25-2002).]

Originally posted by Asgard:
Also your program won’t compile as it has to be result.position.x (or some other result register) and not just result.x.

Oops, didn’t catch that.
Guess that’s what I get for only sleeping 6 hours…

6 hours? THAT_LONG ?! thats not good, really!

Haven’t had my Code Red fix yet today either…