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?
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.
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.