Allow all output to be written to in the vertex shader

For transform feedback, any vertex shader output can be read from
and which outputs will be read by transform feedback buffers is not
known at compile time. For that reason, any output being written to
in the vertex shader code shouldn't be optimized out.

Change-Id: Ia4322c43b7e3308ec5d930650e70aacf032dc6ec
Reviewed-on: https://swiftshader-review.googlesource.com/5051
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/Program.cpp b/src/OpenGL/libGLESv2/Program.cpp
index 1da918a..b2d14f7 100644
--- a/src/OpenGL/libGLESv2/Program.cpp
+++ b/src/OpenGL/libGLESv2/Program.cpp
@@ -1308,6 +1308,8 @@
 
 		for(glsl::VaryingList::iterator output = vsVaryings.begin(); output != vsVaryings.end(); ++output)
 		{
+			bool matched = false;
+
 			for(glsl::VaryingList::iterator input = psVaryings.begin(); input != psVaryings.end(); ++input)
 			{
 				if(output->name == input->name)
@@ -1346,9 +1348,32 @@
 						}
 					}
 
+					matched = true;
 					break;
 				}
 			}
+
+			// For openGL ES 3.0, we need to still add the vertex shader outputs for unmatched varyings, for transform feedback.
+			if(!matched && (egl::getClientVersion() >= 3))
+			{
+				int out = output->reg;
+				int components = VariableRegisterSize(output->type);
+				int registers = VariableRegisterCount(output->type) * output->size();
+
+				if(out >= 0)
+				{
+					if(out + registers > MAX_VARYING_VECTORS)
+					{
+						appendToInfoLog("Too many varyings");
+						return false;
+					}
+
+					for(int i = 0; i < registers; i++)
+					{
+						vertexBinary->setOutput(out + i, components, sw::Shader::Semantic(sw::Shader::USAGE_COLOR));
+					}
+				}
+			}
 		}
 
 		return true;