Don't continue looping when having returned from shader function.

Previously we would mask instruction execution after hitting a LEAVE,
but still jump back on every loop iteration (even if infinite). This
change applies the enableLeave mask to the loop test condition so we
break out of the loop when all strands have hit LEAVE.

Change-Id: Ia331a91fb363d20743d5b87a468c3cfcaa7b481e
Reviewed-on: https://swiftshader-review.googlesource.com/5250
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp
index 1989c87..492dd41 100644
--- a/src/Shader/VertexProgram.cpp
+++ b/src/Shader/VertexProgram.cpp
@@ -1438,6 +1438,7 @@
 		const Vector4f &src = fetchRegister(temporaryRegister);
 		Int4 condition = As<Int4>(src.x);
 		condition &= enableStack[enableIndex - 1];
+		if(shader->containsLeaveInstruction()) condition &= enableLeave;
 		enableStack[enableIndex] = condition;
 
 		Bool notAllFalse = SignMask(condition) != 0;