Merge "Try harder to defeat GLSL compiler dead-code optimizations" into nougat-cts...
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 11 Apr 2017 17:17:48 +0000 (17:17 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Tue, 11 Apr 2017 17:17:48 +0000 (17:17 +0000)
am: a4ddab16dd

Change-Id: I18fe6a8ba3ba328513afdf1f5e5d32db6de32373

1  2 
modules/gles31/functional/es31fProgramInterfaceDefinitionUtil.cpp
modules/gles31/functional/es31fProgramInterfaceDefinitionUtil.hpp
modules/gles31/functional/es31fProgramInterfaceQueryTests.cpp

@@@ -1233,7 -1233,7 +1233,7 @@@ static int getFragmentOutputMaxLocatio
                if (shader->getDefaultBlock().variables[ndx].storage == glu::STORAGE_OUT)
                {
                        // missing location qualifier means location == 0
 -                      const int outputLocation                = (shader->getDefaultBlock().variables[ndx].layout.location == -1)
 +                      const int outputLocation                = (shader->getDefaultBlock().variables[ndx].layout.location == -1)
                                                                                                ? (0)
                                                                                                : (shader->getDefaultBlock().variables[ndx].layout.location);
  
@@@ -1475,6 -1475,21 +1475,21 @@@ std::vector<std::string> getProgramInte
        return resources;
  }
  
+ /**
+  * Name of the dummy uniform added by generateProgramInterfaceProgramSources
+  *
+  * A uniform named "dummyZero" is added by
+  * generateProgramInterfaceProgramSources.  It is used in expressions to
+  * prevent various program resources from being eliminated by the GLSL
+  * compiler's optimizer.
+  *
+  * \sa deqp::gles31::Functional::ProgramInterfaceDefinition::generateProgramInterfaceProgramSources
+  */
+ const char* getDummyZeroUniformName()
+ {
+       return "dummyZero";
+ }
  glu::ProgramSources generateProgramInterfaceProgramSources (const ProgramInterfaceDefinition::Program* program)
  {
        glu::ProgramSources sources;
  
                // Use inputs and outputs so that they won't be removed by the optimizer
  
-               usageBuf <<     "highp vec4 readInputs()\n"
+               usageBuf <<     "highp uniform vec4 " << getDummyZeroUniformName() << "; // Default value is vec4(0.0).\n"
+                                       "highp vec4 readInputs()\n"
                                        "{\n"
-                                       "       highp vec4 retValue = vec4(0.0);\n";
+                                       "       highp vec4 retValue = " << getDummyZeroUniformName() << ";\n";
  
                // User-defined inputs
  
@@@ -162,7 -162,7 +162,7 @@@ struct ProgramResourceUsag
  
  enum ResourceNameGenerationFlag
  {
 -      RESOURCE_NAME_GENERATION_FLAG_DEFAULT                                           = 0x0,
 +      RESOURCE_NAME_GENERATION_FLAG_DEFAULT                                           = 0x0,
        RESOURCE_NAME_GENERATION_FLAG_TOP_LEVEL_BUFFER_VARIABLE         = 0x1,
        RESOURCE_NAME_GENERATION_FLAG_TRANSFORM_FEEDBACK_VARIABLE       = 0x2,
  
@@@ -174,6 -174,7 +174,7 @@@ bool                                                                                               shaderContainsIOBlock
  glu::ShaderType                                                                               getProgramTransformFeedbackStage                        (const ProgramInterfaceDefinition::Program* program);
  std::vector<std::string>                                                      getProgramInterfaceResourceList                         (const ProgramInterfaceDefinition::Program* program, ProgramInterface interface);
  std::vector<std::string>                                                      getProgramInterfaceBlockMemberResourceList      (const glu::InterfaceBlock& interfaceBlock);
+ const char*                                                                                   getDummyZeroUniformName                                         ();
  glu::ProgramSources                                                                   generateProgramInterfaceProgramSources          (const ProgramInterfaceDefinition::Program* program);
  bool                                                                                          findProgramVariablePathByPathName                       (std::vector<ProgramInterfaceDefinition::VariablePathComponent>& typePath, const ProgramInterfaceDefinition::Program* program, const std::string& pathName, const ProgramInterfaceDefinition::VariableSearchFilter& filter);
  void                                                                                          generateVariableTypeResourceNames                       (std::vector<std::string>& resources, const std::string& name, const glu::VarType& type, deUint32 resourceNameGenerationFlags);
@@@ -425,6 -425,7 +425,6 @@@ public
        bool            isStagePresent          (glu::ShaderType stage) const;
        bool            isStageReferencing      (glu::ShaderType stage) const;
  
 -      deUint32        getPresentMask          (void) const;
        deUint32        getReferencingMask      (void) const;
  
        const glu::GLSLVersion  m_version;
@@@ -482,6 -483,17 +482,6 @@@ bool ShaderSet::isStageReferencing (glu
        return m_stageReferencing[stage];
  }
  
 -deUint32 ShaderSet::getPresentMask (void) const
 -{
 -      deUint32 mask = 0;
 -      for (deUint32 stage = 0; stage < glu::SHADERTYPE_LAST; ++stage)
 -      {
 -              if (m_stagePresent[stage])
 -                      mask |= (1u << stage);
 -      }
 -      return mask;
 -}
 -
  deUint32 ShaderSet::getReferencingMask (void) const
  {
        deUint32 mask = 0;
@@@ -1014,7 -1026,13 +1014,13 @@@ bool ResourceListTestCase::verifyResour
        m_testCtx.getLog() << tcu::TestLog::Message << "GL returned resources:" << tcu::TestLog::EndMessage;
  
        for (int ndx = 0; ndx < (int)resourceList.size(); ++ndx)
-               m_testCtx.getLog() << tcu::TestLog::Message << "\t" << ndx << ": " << resourceList[ndx] << tcu::TestLog::EndMessage;
+       {
+               // dummyZero is a uniform that may be added by
+               // generateProgramInterfaceProgramSources.  Omit it here to avoid
+               // confusion about the output.
+               if (resourceList[ndx] != getDummyZeroUniformName())
+                       m_testCtx.getLog() << tcu::TestLog::Message << "\t" << ndx << ": " << resourceList[ndx] << tcu::TestLog::EndMessage;
+       }
  
        m_testCtx.getLog() << tcu::TestLog::Message << "Expected list of resources:" << tcu::TestLog::EndMessage;
  
        {
                if (!de::contains(expectedResources.begin(), expectedResources.end(), resourceList[ndx]))
                {
-                       // Ignore all builtin variables, mismatch causes errors otherwise
-                       if (deStringBeginsWith(resourceList[ndx].c_str(), "gl_") == DE_FALSE)
+                       // Ignore all builtin variables or the variable dummyZero,
+                       // mismatch causes errors otherwise.  dummyZero is a uniform that
+                       // may be added by generateProgramInterfaceProgramSources.
+                       if (deStringBeginsWith(resourceList[ndx].c_str(), "gl_") == DE_FALSE &&
+                               resourceList[ndx] != getDummyZeroUniformName())
                        {
                                m_testCtx.getLog() << tcu::TestLog::Message << "Error, resource list contains unexpected resource name " << resourceList[ndx] << tcu::TestLog::EndMessage;
                                error = true;
@@@ -4480,7 -4501,7 +4489,7 @@@ static ResourceDefinition::Node::Shared
                const glu::ShaderType                                           shaderType      = (selector == 0) ? (glu::SHADERTYPE_GEOMETRY)
                                                                                                                                : (selector == 1) ? (glu::SHADERTYPE_TESSELLATION_CONTROL)
                                                                                                                                : (selector == 2) ? (glu::SHADERTYPE_TESSELLATION_EVALUATION)
 -                                                                                                                              :                                       (glu::SHADERTYPE_LAST);
 +                                                                                                                              :                                       (glu::SHADERTYPE_LAST);
  
                return ResourceDefinition::Node::SharedPtr(new ResourceDefinition::Shader(program, shaderType, glu::GLSL_VERSION_310_ES));
        }