ATI_fragment_shader - op ordering issues

zeckensack

New member
I've finally managed to wrap my head around the ATI_fragment_shader spec. Nice. But I've ran into my first problem.

I'm working on something that could loosely be described as a shader compiler, ie it takes an abstract mathematical description of the operations and spits out a fragment shader.

It works well but I've started running into unexpected behaviour for some shaders which include conditionals and dot products.

What I'm thinking at the moment, what might be causing that, is that I can't guarantee the same number of ColorFragmentOps and AlphaFragmentOps in these cases.

I can't find any description in the spec detailing the exact order the ops are executed. Now, ColorOps for themselves execute in order, AlphaOps do as well, that's pretty straightforward.

But as I gather these are executed in pairs (ColorOp+AlphaOp). I don't know whether I need 'NOPs' for empty slots to preserve ordering, or if the extension sorts that out for itself.

Example:
Code:
Color Alpha
  X     X   Mul/Mul
  X     -   Sub
  X     X   Dot3/Dot3
  X     X   Mul/CND
This is supposed to be a shader (no dependant reads, just simple stuff), where I need the results of the second color op for the third alpha op. Do I have to issue Alpha-'NOPs' in between (second slot where I put the '-'), or will the extension API solve that dependence.

Sorry for the longwinded post but I think it's kinda hard to describe and wanted to put enough in it to make it easy to understand first shot.
And I really think ATI should add some language regarding the issue to the extension document.
 
Last edited:
Nevermind. I figured it out myself. Explicit 'NOPs' are not required.

All instructions execute in order, issuing two consecutive color ops automatically produces a (true?) internal NOP for the alpha channel.

So this wasn't the problem, but what the heck is going on with the GL_DOT3_ATI and GL_CND0_ATI ops?

I mean, (0;0;0)*(0;0;0) == 0, right?

But according to GL_CND0_ATI it's not ... ???

There's some implicit biasing going on which completely contradicts the spec as written (March 20, 2002), and I haven't figured that out yet. Can someone enlighten me please?

Where does biasing take place? Before DOT3 (r+0.5;g+0.5;b+0.5)*(...), or after DOT3?

It's quite frustrasting to see ATi contradicting their own specs again ...
 
The second issue is figured out as well.

For whomever it may concern:
The GL_CND0_ATI op does not evaluate a3>0 (as is written in the extension document), it evaluates a3>=0.
Aargh! Please, ATi people, correct that fragment shader spec asap!
 
Back
Top