View Full Version : KIL (Kill fragment) instruction?

06-30-2005, 08:22 AM
I've some problems with the kil instruction.
The documentation says, for KIL v1 that if v1.x or v1.y or v1.z or v1.w is negatif, then the fragment will be killed (and so, never displayed).
But does it then exit the fragment program? Because i'm actually using KIL in a loop, and I've the feeling that KIL doesn't break the loop. Is it normal?

My pseudo code:

Loop ....
SUBC val1, val2, val3;
KIL val1

If val1 is negatif, I want to kill the fragment and exit the loop (there is no interest to stay in the loop, if the fragment is killed).


06-30-2005, 10:39 AM
Kil does not exist to give you performance. It exists to discard the results of the fragment. On most, if not all, hardware, all it does is set a little bit flag in the pipeline telling the system to ignore the results. It will still execute everything after that command.

06-30-2005, 10:35 PM
But why? What does it bring?

So, it mean i have to:

SUBC val.x, val1.x, val2.x
IF lt.x



06-30-2005, 11:42 PM
The reasons for KIL being there are obvious - you want to be able to discard fragments.

The reason for KIL not exiting the fragment program is the hardware. It is simply not (yet) able to take advantage from KIL. It is not defined in the spec, that everything after KIL still needs to be executed, the spec simply says, that after a KIL the fragment needs to be discarded. But since hardware is very complex there are difficulties to implement KIL in a way which improves performance.

So, yes, if you want to speedup your shader you need to use an if. However, this restricts you to SM 3.0 hardware AND it is not said, that it will improve performance in general, only if you're lucky.


07-01-2005, 04:38 AM
Thank you very much!