Revert "Re-land "Move sampler validation to the GL layer.""

Build failure on Linux:

In file included from ../../third_party/angle/src/tests/gl_tests/UniformTest.cpp:7:
In file included from ../../third_party/angle/src/tests/test_utils/ANGLETest.h:10:
../../testing/gtest/include/gtest/gtest.h:1392:16: error: comparison of integers of different signs: 'const int' and 'const unsigned int' [-Werror,-Wsign-compare]
  if (expected == actual) {
      ~~~~~~~~ ^  ~~~~~~
../../testing/gtest/include/gtest/gtest.h:1422:12: note: in instantiation of function template specialization 'testing::internal::CmpHelperEQ<int, unsigned int>' requested here
    return CmpHelperEQ(expected_expression, actual_expression, expected,
           ^
../../third_party/angle/src/tests/gl_tests/UniformTest.cpp:487:5: note: in instantiation of function template specialization 'testing::internal::EqHelper<false>::Compare<int, unsigned int>' requested here
    EXPECT_EQ(GL_SAMPLER_2D, type);
    ^

BUG=angleproject:1123

This reverts commit 6cbf4385280c4c1dd97f0882ecb18dbc4c341fd4.

Change-Id: I95279b37d253e3ea78faa53f3773f2dc3d17df95
Reviewed-on: https://chromium-review.googlesource.com/302030
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index 14a50ba..6922adf 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -174,17 +174,6 @@
     }
 }
 
-bool UniformInList(const std::vector<LinkedUniform> &list, const std::string &name)
-{
-    for (const LinkedUniform &uniform : list)
-    {
-        if (uniform.name == name)
-            return true;
-    }
-
-    return false;
-}
-
 }  // anonymous namespace
 
 AttributeBindings::AttributeBindings()
@@ -370,8 +359,7 @@
       mDeleteStatus(false),
       mRefCount(0),
       mResourceManager(manager),
-      mHandle(handle),
-      mSamplerUniformRange(0, 0)
+      mHandle(handle)
 {
     ASSERT(mProgram);
 
@@ -686,15 +674,12 @@
     {
         int locationIndex = stream.readInt<int>();
         VariableLocation locationData;
-        stream.readInt(&locationData.element);
-        stream.readInt(&locationData.index);
-        stream.readString(&locationData.name);
+        locationData.element                  = stream.readInt<unsigned int>();
+        locationData.index                    = stream.readInt<unsigned int>();
+        locationData.name                     = stream.readString();
         mData.mOutputVariables[locationIndex] = locationData;
     }
 
-    stream.readInt(&mSamplerUniformRange.start);
-    stream.readInt(&mSamplerUniformRange.end);
-
     rx::LinkResult result = mProgram->load(mInfoLog, &stream);
     if (result.error.isError() || !result.linkSuccess)
     {
@@ -784,9 +769,6 @@
         stream.writeString(outputPair.second.name);
     }
 
-    stream.writeInt(mSamplerUniformRange.start);
-    stream.writeInt(mSamplerUniformRange.end);
-
     gl::Error error = mProgram->save(&stream);
     if (error.isError())
     {
@@ -1315,78 +1297,7 @@
 
 bool Program::validateSamplers(InfoLog *infoLog, const Caps &caps)
 {
-    // Skip cache if we're using an infolog, so we get the full error.
-    // Also skip the cache if the sample mapping has changed, or if we haven't ever validated.
-    if (infoLog == nullptr && mCachedValidateSamplersResult.valid())
-    {
-        return mCachedValidateSamplersResult.value();
-    }
-
-    if (mTextureUnitTypesCache.empty())
-    {
-        mTextureUnitTypesCache.resize(caps.maxCombinedTextureImageUnits, GL_NONE);
-    }
-    else
-    {
-        std::fill(mTextureUnitTypesCache.begin(), mTextureUnitTypesCache.end(), GL_NONE);
-    }
-
-    // if any two active samplers in a program are of different types, but refer to the same
-    // texture image unit, and this is the current program, then ValidateProgram will fail, and
-    // DrawArrays and DrawElements will issue the INVALID_OPERATION error.
-    for (unsigned int samplerIndex = mSamplerUniformRange.start;
-         samplerIndex < mSamplerUniformRange.end; ++samplerIndex)
-    {
-        const LinkedUniform &uniform = mData.mUniforms[samplerIndex];
-        ASSERT(uniform.isSampler());
-
-        if (!uniform.staticUse)
-            continue;
-
-        const GLuint *dataPtr = reinterpret_cast<const GLuint *>(uniform.getDataPtrToElement(0));
-        GLenum textureType    = SamplerTypeToTextureType(uniform.type);
-
-        for (unsigned int arrayElement = 0; arrayElement < uniform.elementCount(); ++arrayElement)
-        {
-            GLuint textureUnit = dataPtr[arrayElement];
-
-            if (textureUnit >= caps.maxCombinedTextureImageUnits)
-            {
-                if (infoLog)
-                {
-                    (*infoLog) << "Sampler uniform (" << textureUnit
-                               << ") exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS ("
-                               << caps.maxCombinedTextureImageUnits << ")";
-                }
-
-                mCachedValidateSamplersResult = false;
-                return false;
-            }
-
-            if (mTextureUnitTypesCache[textureUnit] != GL_NONE)
-            {
-                if (textureType != mTextureUnitTypesCache[textureUnit])
-                {
-                    if (infoLog)
-                    {
-                        (*infoLog) << "Samplers of conflicting types refer to the same texture "
-                                      "image unit ("
-                                   << textureUnit << ").";
-                    }
-
-                    mCachedValidateSamplersResult = false;
-                    return false;
-                }
-            }
-            else
-            {
-                mTextureUnitTypesCache[textureUnit] = textureType;
-            }
-        }
-    }
-
-    mCachedValidateSamplersResult = true;
-    return true;
+    return mProgram->validateSamplers(infoLog, caps);
 }
 
 bool Program::isValidated() const
@@ -2175,13 +2086,11 @@
     const gl::Shader *vertexShader = mData.getAttachedVertexShader();
     VectorAndSamplerCount vsCounts;
 
-    std::vector<LinkedUniform> samplerUniforms;
-
     for (const sh::Uniform &uniform : vertexShader->getUniforms())
     {
         if (uniform.staticUse)
         {
-            vsCounts += flattenUniform(uniform, uniform.name, &samplerUniforms);
+            vsCounts += flattenUniform(uniform, uniform.name);
         }
     }
 
@@ -2206,7 +2115,7 @@
     {
         if (uniform.staticUse)
         {
-            fsCounts += flattenUniform(uniform, uniform.name, &samplerUniforms);
+            fsCounts += flattenUniform(uniform, uniform.name);
         }
     }
 
@@ -2224,18 +2133,11 @@
         return false;
     }
 
-    mSamplerUniformRange.start = static_cast<unsigned int>(mData.mUniforms.size());
-    mSamplerUniformRange.end =
-        mSamplerUniformRange.start + static_cast<unsigned int>(samplerUniforms.size());
-
-    mData.mUniforms.insert(mData.mUniforms.end(), samplerUniforms.begin(), samplerUniforms.end());
-
     return true;
 }
 
 Program::VectorAndSamplerCount Program::flattenUniform(const sh::ShaderVariable &uniform,
-                                                       const std::string &fullName,
-                                                       std::vector<LinkedUniform> *samplerUniforms)
+                                                       const std::string &fullName)
 {
     VectorAndSamplerCount vectorAndSamplerCount;
 
@@ -2250,7 +2152,7 @@
                 const sh::ShaderVariable &field  = uniform.fields[fieldIndex];
                 const std::string &fieldFullName = (fullName + elementString + "." + field.name);
 
-                vectorAndSamplerCount += flattenUniform(field, fieldFullName, samplerUniforms);
+                vectorAndSamplerCount += flattenUniform(field, fieldFullName);
             }
         }
 
@@ -2258,28 +2160,18 @@
     }
 
     // Not a struct
-    bool isSampler = IsSamplerType(uniform.type);
-    if (!UniformInList(mData.getUniforms(), fullName) && !UniformInList(*samplerUniforms, fullName))
+    if (mData.getUniformByName(fullName) == nullptr)
     {
         gl::LinkedUniform linkedUniform(uniform.type, uniform.precision, fullName,
                                         uniform.arraySize, -1,
                                         sh::BlockMemberInfo::getDefaultBlockInfo());
         linkedUniform.staticUse = true;
-
-        // Store sampler uniforms separately, so we'll append them to the end of the list.
-        if (isSampler)
-        {
-            samplerUniforms->push_back(linkedUniform);
-        }
-        else
-        {
-            mData.mUniforms.push_back(linkedUniform);
-        }
+        mData.mUniforms.push_back(linkedUniform);
     }
 
-    unsigned int elementCount          = uniform.elementCount();
-    vectorAndSamplerCount.vectorCount  = (VariableRegisterCount(uniform.type) * elementCount);
-    vectorAndSamplerCount.samplerCount = (isSampler ? elementCount : 0);
+    vectorAndSamplerCount.vectorCount =
+        (VariableRegisterCount(uniform.type) * uniform.elementCount());
+    vectorAndSamplerCount.samplerCount = (IsSamplerType(uniform.type) ? uniform.elementCount() : 0);
 
     return vectorAndSamplerCount;
 }
@@ -2402,12 +2294,6 @@
     }
     else
     {
-        // Invalide the validation cache if we modify the sampler data.
-        if (linkedUniform->isSampler() && memcmp(destPointer, v, sizeof(T) * count) != 0)
-        {
-            mCachedValidateSamplersResult.reset();
-        }
-
         memcpy(destPointer, v, sizeof(T) * count);
     }
 }