Vertex shaders acting strangely...

Hi,

i’ve a piece of code that isn’t working and i don’t know why…
This part of my vertex shader is just clamping a color (no matter it is a color could be anything else…) between 0 and 1 (cause I can get negative value when N.L is negative, don’t ask why )

float zeroValues[4] = { 0.f, 0.f, 0.f, 1.0f};
GLuint intensity;
GLuint temp;
GLuint temp2;
GLuint zero;
[snip]
intensity = glGenSymbolsEXT( GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
temp = glGenSymbolsEXT( GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
temp2 = glGenSymbolsEXT( GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);

zero=glGenSymbolsEXT( GL_VECTOR_EXT, GL_LOCAL_CONSTANT_EXT, GL_FULL_RANGE_EXT, 1);
glSetLocalConstantEXT( zero, GL_FLOAT, &zeroValues);
[snip]

glSwizzleEXT(temp, intensity, GL_ONE_EXT, GL_ONE_EXT, GL_ONE_EXT, GL_ONE_EXT);
glShaderOp3EXT( GL_OP_CLAMP_EXT, temp2, temp2, zero, temp);
glShaderOp2EXT( GL_OP_ADD_EXT, intensity, intensity, temp2);
[snip]

If in glSwizzleEXT(temp, intensity, GL_ONE_EXT, GL_ONE_EXT, GL_ONE_EXT, GL_ONE_EXT); i put anything but intensity the code is working.
With intensity as second parameter the effect i get is the same as if i was clamping in [0, 0] interval.

I don’t seek a solution, as I said it is working if i use another variable. I just want somebody to explain why it doesn’t work with intensity.
Or there is something i totally misunderstood how vertex shaders are working or there is some kind of bug (quite irritating, spent some time before trying another variable).

I do like the swizzling trick where you can make a vector [1,1,1,1] without declaring this vector as you must with NV’s vertex programs. (I know i could have done the same with my zero variable but i didn’t… for now )

Could someone explain me why this doesn’t work ?

Joel.

Couple things come to mind…

1 - Have you enabled vertex shaders and bound the vertex shader name before you try to generate a vector name?

2 - Does “intensity” get used previously somewhere in that [snip]?

3 - If “intensity” doesn’t, try creating another vector name that doesn’t get used in the [snip] either and see if you get the same results.

(I believe the swizzle and write mask commands might not like having undefined data in the input vector parameter)

Dan

Probably in your [snip] section you set something wrong for intensity, so that glSwizzleEXT generates an error (which discards operations).

Apart from that, I can’t see what’s wrong in changing the in parameter since it is not taken in account because all X, Y, Z and W elements are overriden by GL_ONE_EXT.

Dan82181: I think the intensity does not have an undefined data because Joel calls :

glShaderOp2EXT( GL_OP_ADD_EXT, intensity, intensity, temp2);

To my mind he wouldn’t call that addition if intensity was not initialized. Also, I may be wrong and Joel could have forgot the line that initializes intensity.

Then again, he wouldn’t be trying to generate locals without first calling glBeginVertexShaderEXT() either.

From the spec…

If this data is not set before being used the values used are undetermined and may result in unpredictable values being used in the calculation.

True, it’s not actually using any of the parts of the vector, I’m just assuming that it could be complaining about it having undefined values. Yeah, I’d hope he would have something in that register before he goes to add to it as well. Try calling a glGetError() after that swizzle and see if it generates a GL_INVALID_OPERATION.

Dan

I don’t think it will generate an error, because the two errors that glSwizzleEXT generate are :

ILLEGAL_OPERATION is generated if the datatype of the <res> or <in>
parameters to WriteMaskEXT or SwizzleEXT is not VECTOR_EXT.

ILLEGAL_OPERATION is generated if if the <res> parameter of ShaderOPEXT,
SwizzleEXT, or WriteMaskEXT does is not a local or output storage type.

and none of those cases seem to apply to Joel’s piece of code.

Anyway, I agree that unpredicatble results may appear when intensity’s data is not initialized, even if GL_ONE_EXT makes intensity’s data useless.

Thank you all for your answers.

I can’t tell for sure what i’m doing with intensity cause i don’t have my source (yea back home after a looooong day ).
I guess you must be right cause i don’t think i’ve writen to intensity before this one.
It has been a cut past from the version that handled only one light and it’s quite possible I didn’t initiliaze it now.

Can’t see other explanations (and this one didn’t come into my mind…)

I’ll tell you tomorrow if that’s the reason.

Thanks.
Joel.

I’ve just re-read the code i’ve post and i remember that i initiliaze intensity with a [0,0,0,1] vector that i got either from my variable zero or swizzeling.

More info tomorrow.
Good night for those who are concerned

Joel.

lol.

and i remember that i initiliaze intensity with a [0,0,0,1] vector that i got either from my variable zero or swizzeling.

If you initialize intensity with swizzle, for instance glSwizzleEXT(intensity, intensity, GL_ZERO_EXT, GL_ZERO_EXT, GL_ZERO_EXT, GL_ONE_EXT), it may not help that much !

Hi

here are some news to make your brain boil
I’ve tested with a variable that doesn’t get initialized by some values. And it works.
I’ve initiliazed my variable intensity with the variable zero

// initialize intensity to zero
glShaderOp1EXT( GL_OP_MOV_EXT, intensity, zero);

And yes, zero is initialized(think i’ve showed how in my first post).
So AFAIK this a bug from ATI’s drivers.
I can’ explain me how this is possible but it happens…
This week-end i’ll try to make a simple app that i can send to whoever wants, but it will be hard to me to do it cause i don’t have a radeon at home (guess why …)
I also think that this bug will be hard to reproduce cause it should be really dependent of all the context and not just my vertex shader code… will see.

If anyone as an idea, even one that can seem funny, just tell me.

Joel.

Have you tried on another card, or with other drivers ?
If it works with a different configuration, that probably means it’s a bug that your driver/card combo encounter.
Also, have you downloaded the latest drivers ? (be careful, unlike nVidia, ATI have different drivers for different cards).

Originally posted by vincoof:
Have you tried on another card, or with other drivers ?
If it works with a different configuration, that probably means it’s a bug that your driver/card combo encounter.
Also, have you downloaded the latest drivers ? (be careful, unlike nVidia, ATI have different drivers for different cards).

I haven’t tried with another card cause we aren’t that rich . I’ve got the only Radeon 8500 in the firm.
That’s why i’ve suggested that i should do another app that i could send (this one is confidential and is huge).

The drivers are 6094 that i downloaded at most 2 weeks ago, and these are the ones that you can still find in ATI’s site.

I’ll just try to make the bug happens in a simple app and hope that an ATI guy will be interested in it.
Anyway that’s no more problem for me cause I know how to solve it. Was just thinking of the next poor guy that will get the same problem.

To be complete my OS is Windows 2000.

Joel.

Originally posted by Joel:

I’ll just try to make the bug happens in a simple app and hope that an ATI guy will be interested in it.

Hi,

you thought that i forgot, didn’t you ?
I just had a CRC error while getting my app back at work
Now everythig is all right.
I’ve got a very simple app that shows the problem. All the code, libs, exec… are 97 ko.

I’m sorry i don’t have a web site to put this example on. But i will send this app to anyone who is interested in it. Especially if chrisATI or anyone else i forgot from ATI could answer me i’ll be grateful.

Anyone who wants to test the app (who have a radeon 8500 of course ) is also welcome.

Hope it will help someone.

Joel.

I’m sorry, but I’ve read your piece of code again, and I read ATI’s extension specifications again and again and I still can’t get where the hell you’re making something bad.
So I’m thinking of a bug from ATI’s drivers :\

Originally posted by vincoof:
[b]I’m sorry, but I’ve read your piece of code again, and I read ATI’s extension specifications again and again and I still can’t get where the hell you’re making something bad.
So I’m thinking of a bug from ATI’s drivers :[/b]

So do I.
I will send the simple app i’ve done to anyone who wants.
I should try to make a web site this night on which i could put my app for who wants to test it. Hopefully we’ll get ARB_vertex_program “soon”.
Is there a way to report bugs to ATI ? Their site is a little messy and i didn’t search too long .

I’ll look at it if you want.

I found something that seems a bit strange: with the line,

glShaderOp2EXT( GL_OP_MUL_EXT, temp2, temp2, temp);

you are multiplying temp2 ( that contains N.L ) with a temporary that you didn’t initialize ( temp ).

With all three swizzle lines I get a black square.

Also, I would suggest using glGenVertexShadersEXT(…) rather than binding to a specific value ( maybe you only did this for the test but just in case ).

I don’t think this is a driver bug.

Oh, and I’m using the 6118 official drivers ( released yesterday ).

After running it a few times, I suddenly get a blue square for the first two swizzle lines and black for the other. Hmmm…

Initializing ‘temp’ with zero will give a black square. Local temporaries have undefined values, so using them in operations will likely give pretty random results.

Now I don’t get a blue square anymore ( removing the line that I used to initialize temp with ). The problem is with the line I posted above.

Result = clamp( ( N.L ) * <random>, 0, 1 );