Switch implementation

Implemented switch/case for glsl in OpenGL ES 3.0.
For simplicity, it is implemented as a loop without a condition,
so break statements work properly like so:

begin switch
  if(...) // 1st case
  ...
  else if(...) // other cases
  ...
  else // default case
  ...
end switch // Anchor point for break statements

All related dEQP tests pass, except 7 tests where vertex shaders
contain a switch or a loop within another switch. These 7 failures
have only about 5% of bad pixel and seem to be related to an issue
with int(floor(...)), since the equivalent tests inside the fragment
shader pass.

KNOWN ISSUE: If a switch is within a loop and one of the cases
             contains a "continue" statement, this will not be
             handled correctly at the moment. There are no dEQP
             tests for this at the moment, AFAIK.

Change-Id: I3ba34ab06a759d07e8520f6a87d75036a5cdaef5
Reviewed-on: https://swiftshader-review.googlesource.com/5272
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/PixelProgram.cpp b/src/Shader/PixelProgram.cpp
index d229a92..1c0ffb9 100644
--- a/src/Shader/PixelProgram.cpp
+++ b/src/Shader/PixelProgram.cpp
@@ -307,12 +307,14 @@
 			case Shader::OPCODE_ENDLOOP:    ENDLOOP();                                     break;
 			case Shader::OPCODE_ENDREP:     ENDREP();                                      break;
 			case Shader::OPCODE_ENDWHILE:   ENDWHILE();                                    break;
+			case Shader::OPCODE_ENDSWITCH:  ENDSWITCH();                                   break;
 			case Shader::OPCODE_IF:         IF(src0);                                      break;
 			case Shader::OPCODE_IFC:        IFC(s0, s1, control);                          break;
 			case Shader::OPCODE_LABEL:      LABEL(dst.index);                              break;
 			case Shader::OPCODE_LOOP:       LOOP(src1);                                    break;
 			case Shader::OPCODE_REP:        REP(src0);                                     break;
 			case Shader::OPCODE_WHILE:      WHILE(src0);                                   break;
+			case Shader::OPCODE_SWITCH:     SWITCH();                                      break;
 			case Shader::OPCODE_RET:        RET();                                         break;
 			case Shader::OPCODE_LEAVE:      LEAVE();                                       break;
 			case Shader::OPCODE_CMP:        cmp(d, s0, s1, control);                       break;
@@ -1475,6 +1477,19 @@
 		whileTest = false;
 	}
 
+	void PixelProgram::ENDSWITCH()
+	{
+		loopRepDepth--;
+
+		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth];
+
+		Nucleus::createBr(loopRepEndBlock[loopRepDepth]);
+		Nucleus::setInsertBlock(endBlock);
+
+		enableIndex--;
+		enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
+	}
+
 	void PixelProgram::IF(const Src &src)
 	{
 		if(src.type == Shader::PARAMETER_CONSTBOOL)
@@ -1674,6 +1689,20 @@
 		breakDepth = 0;
 	}
 
+	void PixelProgram::SWITCH()
+	{
+		enableIndex++;
+		enableStack[enableIndex] = Int4(0xFFFFFFFF);
+
+		llvm::BasicBlock *endBlock = Nucleus::createBasicBlock();
+
+		loopRepTestBlock[loopRepDepth] = nullptr;
+		loopRepEndBlock[loopRepDepth] = endBlock;
+
+		loopRepDepth++;
+		breakDepth = 0;
+	}
+
 	void PixelProgram::RET()
 	{
 		if(currentLabel == -1)