OSDN Git Service

Allow all output to be written to in the vertex shader
authorAlexis Hetu <sugoi@google.com>
Tue, 5 Apr 2016 21:31:32 +0000 (17:31 -0400)
committerAlexis Hétu <sugoi@google.com>
Thu, 15 Sep 2016 14:17:11 +0000 (14:17 +0000)
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>
src/OpenGL/libGLESv2/Program.cpp

index 1da918a..b2d14f7 100644 (file)
@@ -1308,6 +1308,8 @@ namespace es2
 
                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 @@ namespace es2
                                                }
                                        }
 
+                                       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;