Move ShaderVariables to common shared source.

Also move the block layout encoding utilities to the common folder.
The combined changes allow us to include the shader and block code
into both libGLESv2 and the translator separately. This in turn
fixes the Chromium component build, where we were calling internal
translator functions directly from libGLESv2.

BUG=angle:568

Change-Id: Ibcfa2c936a7c737ad515c10bd24061ff39ee5747
Reviewed-on: https://chromium-review.googlesource.com/192891
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/BlockLayoutEncoder.cpp b/src/compiler/translator/BlockLayoutEncoder.cpp
deleted file mode 100644
index ef94d9b..0000000
--- a/src/compiler/translator/BlockLayoutEncoder.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-//
-// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-
-#include "compiler/translator/BlockLayoutEncoder.h"
-#include "compiler/translator/ShaderVariable.h"
-#include "common/mathutil.h"
-#include "common/utilities.h"
-
-namespace sh
-{
-
-BlockLayoutEncoder::BlockLayoutEncoder(std::vector<BlockMemberInfo> *blockInfoOut)
-    : mCurrentOffset(0),
-      mBlockInfoOut(blockInfoOut)
-{
-}
-
-void BlockLayoutEncoder::encodeInterfaceBlockFields(const std::vector<InterfaceBlockField> &fields)
-{
-    for (unsigned int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++)
-    {
-        const InterfaceBlockField &variable = fields[fieldIndex];
-
-        if (variable.fields.size() > 0)
-        {
-            const unsigned int elementCount = std::max(1u, variable.arraySize);
-
-            for (unsigned int elementIndex = 0; elementIndex < elementCount; elementIndex++)
-            {
-                enterAggregateType();
-                encodeInterfaceBlockFields(variable.fields);
-                exitAggregateType();
-            }
-        }
-        else
-        {
-            encodeInterfaceBlockField(variable);
-        }
-    }
-}
-
-void BlockLayoutEncoder::encodeInterfaceBlockField(const InterfaceBlockField &field)
-{
-    int arrayStride;
-    int matrixStride;
-
-    ASSERT(field.fields.empty());
-    getBlockLayoutInfo(field.type, field.arraySize, field.isRowMajorMatrix, &arrayStride, &matrixStride);
-
-    const BlockMemberInfo memberInfo(mCurrentOffset * BytesPerComponent, arrayStride * BytesPerComponent, matrixStride * BytesPerComponent, field.isRowMajorMatrix);
-
-    if (mBlockInfoOut)
-    {
-        mBlockInfoOut->push_back(memberInfo);
-    }
-
-    advanceOffset(field.type, field.arraySize, field.isRowMajorMatrix, arrayStride, matrixStride);
-}
-
-void BlockLayoutEncoder::encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix)
-{
-    int arrayStride;
-    int matrixStride;
-
-    getBlockLayoutInfo(type, arraySize, isRowMajorMatrix, &arrayStride, &matrixStride);
-
-    const BlockMemberInfo memberInfo(mCurrentOffset * BytesPerComponent, arrayStride * BytesPerComponent, matrixStride * BytesPerComponent, isRowMajorMatrix);
-
-    if (mBlockInfoOut)
-    {
-        mBlockInfoOut->push_back(memberInfo);
-    }
-
-    advanceOffset(type, arraySize, isRowMajorMatrix, arrayStride, matrixStride);
-}
-
-void BlockLayoutEncoder::nextRegister()
-{
-    mCurrentOffset = rx::roundUp<size_t>(mCurrentOffset, ComponentsPerRegister);
-}
-
-Std140BlockEncoder::Std140BlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut)
-    : BlockLayoutEncoder(blockInfoOut)
-{
-}
-
-void Std140BlockEncoder::enterAggregateType()
-{
-    nextRegister();
-}
-
-void Std140BlockEncoder::exitAggregateType()
-{
-    nextRegister();
-}
-
-void Std140BlockEncoder::getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut)
-{
-    // We assume we are only dealing with 4 byte components (no doubles or half-words currently)
-    ASSERT(gl::UniformComponentSize(gl::UniformComponentType(type)) == BytesPerComponent);
-
-    size_t baseAlignment = 0;
-    int matrixStride = 0;
-    int arrayStride = 0;
-
-    if (gl::IsMatrixType(type))
-    {
-        baseAlignment = ComponentsPerRegister;
-        matrixStride = ComponentsPerRegister;
-
-        if (arraySize > 0)
-        {
-            const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
-            arrayStride = ComponentsPerRegister * numRegisters;
-        }
-    }
-    else if (arraySize > 0)
-    {
-        baseAlignment = ComponentsPerRegister;
-        arrayStride = ComponentsPerRegister;
-    }
-    else
-    {
-        const int numComponents = gl::UniformComponentCount(type);
-        baseAlignment = (numComponents == 3 ? 4u : static_cast<size_t>(numComponents));
-    }
-
-    mCurrentOffset = rx::roundUp(mCurrentOffset, baseAlignment);
-
-    *matrixStrideOut = matrixStride;
-    *arrayStrideOut = arrayStride;
-}
-
-void Std140BlockEncoder::advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride)
-{
-    if (arraySize > 0)
-    {
-        mCurrentOffset += arrayStride * arraySize;
-    }
-    else if (gl::IsMatrixType(type))
-    {
-        ASSERT(matrixStride == ComponentsPerRegister);
-        const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
-        mCurrentOffset += ComponentsPerRegister * numRegisters;
-    }
-    else
-    {
-        mCurrentOffset += gl::UniformComponentCount(type);
-    }
-}
-
-}
diff --git a/src/compiler/translator/BlockLayoutEncoder.h b/src/compiler/translator/BlockLayoutEncoder.h
deleted file mode 100644
index b6fb7bf..0000000
--- a/src/compiler/translator/BlockLayoutEncoder.h
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-
-#ifndef TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
-#define TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
-
-#include <vector>
-#define GL_APICALL
-#include <GLES3/gl3.h>
-#include <GLES2/gl2.h>
-
-namespace sh
-{
-
-struct ShaderVariable;
-struct InterfaceBlockField;
-struct BlockMemberInfo;
-
-class BlockLayoutEncoder
-{
-  public:
-    BlockLayoutEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
-
-    void encodeInterfaceBlockFields(const std::vector<InterfaceBlockField> &fields);
-    void encodeInterfaceBlockField(const InterfaceBlockField &field);
-    void encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix);
-    size_t getBlockSize() const { return mCurrentOffset * BytesPerComponent; }
-
-    static const size_t BytesPerComponent = 4u;
-    static const unsigned int ComponentsPerRegister = 4u;
-
-  protected:
-    size_t mCurrentOffset;
-
-    void nextRegister();
-
-    virtual void enterAggregateType() = 0;
-    virtual void exitAggregateType() = 0;
-    virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
-    virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
-
-  private:
-    std::vector<BlockMemberInfo> *mBlockInfoOut;
-};
-
-// Block layout according to the std140 block layout
-// See "Standard Uniform Block Layout" in Section 2.11.6 of the OpenGL ES 3.0 specification
-
-class Std140BlockEncoder : public BlockLayoutEncoder
-{
-  public:
-    Std140BlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
-
-  protected:
-    virtual void enterAggregateType();
-    virtual void exitAggregateType();
-    virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
-    virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
-};
-
-}
-
-#endif // TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
diff --git a/src/compiler/translator/HLSLLayoutEncoder.cpp b/src/compiler/translator/HLSLLayoutEncoder.cpp
deleted file mode 100644
index 7868fb9..0000000
--- a/src/compiler/translator/HLSLLayoutEncoder.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-//
-// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-
-#include "compiler/translator/HLSLLayoutEncoder.h"
-#include "compiler/translator/ShaderVariable.h"
-#include "common/mathutil.h"
-#include "common/utilities.h"
-
-namespace sh
-{
-
-HLSLBlockEncoder::HLSLBlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut)
-    : BlockLayoutEncoder(blockInfoOut)
-{
-}
-
-void HLSLBlockEncoder::enterAggregateType()
-{
-    nextRegister();
-}
-
-void HLSLBlockEncoder::exitAggregateType()
-{
-}
-
-void HLSLBlockEncoder::getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut)
-{
-    // We assume we are only dealing with 4 byte components (no doubles or half-words currently)
-    ASSERT(gl::UniformComponentSize(gl::UniformComponentType(type)) == BytesPerComponent);
-
-    int matrixStride = 0;
-    int arrayStride = 0;
-
-    if (gl::IsMatrixType(type))
-    {
-        nextRegister();
-        matrixStride = ComponentsPerRegister;
-
-        if (arraySize > 0)
-        {
-            const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
-            arrayStride = ComponentsPerRegister * numRegisters;
-        }
-    }
-    else if (arraySize > 0)
-    {
-        nextRegister();
-        arrayStride = ComponentsPerRegister;
-    }
-    else
-    {
-        int numComponents = gl::UniformComponentCount(type);
-        if ((numComponents + (mCurrentOffset % ComponentsPerRegister)) > ComponentsPerRegister)
-        {
-            nextRegister();
-        }
-    }
-
-    *matrixStrideOut = matrixStride;
-    *arrayStrideOut = arrayStride;
-}
-
-void HLSLBlockEncoder::advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride)
-{
-    if (arraySize > 0)
-    {
-        mCurrentOffset += arrayStride * (arraySize - 1);
-    }
-
-    if (gl::IsMatrixType(type))
-    {
-        ASSERT(matrixStride == ComponentsPerRegister);
-        const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
-        const int numComponents = gl::MatrixComponentCount(type, isRowMajorMatrix);
-        mCurrentOffset += ComponentsPerRegister * (numRegisters - 1);
-        mCurrentOffset += numComponents;
-    }
-    else
-    {
-        mCurrentOffset += gl::UniformComponentCount(type);
-    }
-}
-
-void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, Uniform *variable, HLSLBlockEncoder *encoder, const std::vector<BlockMemberInfo> &blockInfo)
-{
-    // because this method computes offsets (element indexes) instead of any total sizes,
-    // we can ignore the array size of the variable
-
-    if (variable->isStruct())
-    {
-        encoder->enterAggregateType();
-
-        for (size_t fieldIndex = 0; fieldIndex < variable->fields.size(); fieldIndex++)
-        {
-            HLSLVariableGetRegisterInfo(baseRegisterIndex, &variable->fields[fieldIndex], encoder, blockInfo);
-        }
-
-        encoder->exitAggregateType();
-    }
-    else
-    {
-        encoder->encodeType(variable->type, variable->arraySize, false);
-
-        const size_t registerBytes = (encoder->BytesPerComponent * encoder->ComponentsPerRegister);
-        variable->registerIndex = baseRegisterIndex + (blockInfo.back().offset / registerBytes);
-        variable->elementIndex = (blockInfo.back().offset % registerBytes) / sizeof(float);
-    }
-}
-
-void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, Uniform *variable)
-{
-    std::vector<BlockMemberInfo> blockInfo;
-    HLSLBlockEncoder encoder(&blockInfo);
-    HLSLVariableGetRegisterInfo(baseRegisterIndex, variable, &encoder, blockInfo);
-}
-
-template <class ShaderVarType>
-void HLSLVariableRegisterCount(const ShaderVarType &variable, HLSLBlockEncoder *encoder)
-{
-    if (variable.isStruct())
-    {
-        for (size_t arrayElement = 0; arrayElement < variable.elementCount(); arrayElement++)
-        {
-            encoder->enterAggregateType();
-
-            for (size_t fieldIndex = 0; fieldIndex < variable.fields.size(); fieldIndex++)
-            {
-                HLSLVariableRegisterCount(variable.fields[fieldIndex], encoder);
-            }
-
-            encoder->exitAggregateType();
-        }
-    }
-    else
-    {
-        // We operate only on varyings and uniforms, which do not have matrix layout qualifiers
-        encoder->encodeType(variable.type, variable.arraySize, false);
-    }
-}
-
-unsigned int HLSLVariableRegisterCount(const Varying &variable)
-{
-    HLSLBlockEncoder encoder(NULL);
-    HLSLVariableRegisterCount(variable, &encoder);
-
-    const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister);
-    return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes);
-}
-
-unsigned int HLSLVariableRegisterCount(const Uniform &variable)
-{
-    HLSLBlockEncoder encoder(NULL);
-    HLSLVariableRegisterCount(variable, &encoder);
-
-    const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister);
-    return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes);
-}
-
-}
diff --git a/src/compiler/translator/HLSLLayoutEncoder.h b/src/compiler/translator/HLSLLayoutEncoder.h
deleted file mode 100644
index 95bbb27..0000000
--- a/src/compiler/translator/HLSLLayoutEncoder.h
+++ /dev/null
@@ -1,45 +0,0 @@
-//
-// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-
-#ifndef TRANSLATOR_HLSL_HLSLLAYOUTENCODER_H_
-#define TRANSLATOR_HLSL_HLSLLAYOUTENCODER_H_
-
-#include "compiler/translator/BlockLayoutEncoder.h"
-
-namespace sh
-{
-
-struct Varying;
-struct Uniform;
-
-// Block layout packed according to the default D3D11 register packing rules
-// See http://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx
-
-class HLSLBlockEncoder : public BlockLayoutEncoder
-{
-  public:
-    HLSLBlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
-
-    virtual void enterAggregateType();
-    virtual void exitAggregateType();
-
-  protected:
-    virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
-    virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
-};
-
-// This method assigns values to the variable's "registerIndex" and "elementIndex" fields.
-// "elementIndex" is only used for structures.
-void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, Uniform *variable);
-
-// This method returns the number of used registers for a ShaderVariable. It is dependent on the HLSLBlockEncoder
-// class to count the number of used registers in a struct (which are individually packed according to the same rules).
-unsigned int HLSLVariableRegisterCount(const Varying &variable);
-unsigned int HLSLVariableRegisterCount(const Uniform &variable);
-
-}
-
-#endif // TRANSLATOR_HLSL_HLSLLAYOUTENCODER_H_
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 75df471..37812ff 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -8,12 +8,12 @@
 
 #include "common/angleutils.h"
 #include "common/utilities.h"
+#include "common/blocklayout.h"
 #include "compiler/translator/compilerdebug.h"
 #include "compiler/translator/InfoSink.h"
 #include "compiler/translator/DetectDiscontinuity.h"
 #include "compiler/translator/SearchSymbol.h"
 #include "compiler/translator/UnfoldShortCircuit.h"
-#include "compiler/translator/HLSLLayoutEncoder.h"
 #include "compiler/translator/FlagStd140Structs.h"
 #include "compiler/translator/NodeSearch.h"
 #include "compiler/translator/RewriteElseBlocks.h"
@@ -220,27 +220,27 @@
     return mBody;
 }
 
-const std::vector<Uniform> &OutputHLSL::getUniforms()
+const std::vector<gl::Uniform> &OutputHLSL::getUniforms()
 {
     return mActiveUniforms;
 }
 
-const ActiveInterfaceBlocks &OutputHLSL::getInterfaceBlocks() const
+const std::vector<gl::InterfaceBlock> &OutputHLSL::getInterfaceBlocks() const
 {
     return mActiveInterfaceBlocks;
 }
 
-const std::vector<Attribute> &OutputHLSL::getOutputVariables() const
+const std::vector<gl::Attribute> &OutputHLSL::getOutputVariables() const
 {
     return mActiveOutputVariables;
 }
 
-const std::vector<Attribute> &OutputHLSL::getAttributes() const
+const std::vector<gl::Attribute> &OutputHLSL::getAttributes() const
 {
     return mActiveAttributes;
 }
 
-const std::vector<Varying> &OutputHLSL::getVaryings() const
+const std::vector<gl::Varying> &OutputHLSL::getVaryings() const
 {
     return mActiveVaryings;
 }
@@ -473,25 +473,25 @@
 }
 
 // Use the same layout for packed and shared
-void setBlockLayout(InterfaceBlock *interfaceBlock, BlockLayoutType newLayout)
+void setBlockLayout(gl::InterfaceBlock *interfaceBlock, gl::BlockLayoutType newLayout)
 {
     interfaceBlock->layout = newLayout;
     interfaceBlock->blockInfo.clear();
 
     switch (newLayout)
     {
-      case BLOCKLAYOUT_SHARED:
-      case BLOCKLAYOUT_PACKED:
+      case gl::BLOCKLAYOUT_SHARED:
+      case gl::BLOCKLAYOUT_PACKED:
         {
-            HLSLBlockEncoder hlslEncoder(&interfaceBlock->blockInfo);
+            gl::HLSLBlockEncoder hlslEncoder(&interfaceBlock->blockInfo);
             hlslEncoder.encodeInterfaceBlockFields(interfaceBlock->fields);
             interfaceBlock->dataSize = hlslEncoder.getBlockSize();
         }
         break;
 
-      case BLOCKLAYOUT_STANDARD:
+      case gl::BLOCKLAYOUT_STANDARD:
         {
-            Std140BlockEncoder stdEncoder(&interfaceBlock->blockInfo);
+            gl::Std140BlockEncoder stdEncoder(&interfaceBlock->blockInfo);
             stdEncoder.encodeInterfaceBlockFields(interfaceBlock->fields);
             interfaceBlock->dataSize = stdEncoder.getBlockSize();
         }
@@ -503,14 +503,14 @@
     }
 }
 
-BlockLayoutType convertBlockLayoutType(TLayoutBlockStorage blockStorage)
+gl::BlockLayoutType convertBlockLayoutType(TLayoutBlockStorage blockStorage)
 {
     switch (blockStorage)
     {
-      case EbsPacked: return BLOCKLAYOUT_PACKED;
-      case EbsShared: return BLOCKLAYOUT_SHARED;
-      case EbsStd140: return BLOCKLAYOUT_STANDARD;
-      default: UNREACHABLE(); return BLOCKLAYOUT_SHARED;
+      case EbsPacked: return gl::BLOCKLAYOUT_PACKED;
+      case EbsShared: return gl::BLOCKLAYOUT_SHARED;
+      case EbsStd140: return gl::BLOCKLAYOUT_STANDARD;
+      default: UNREACHABLE(); return gl::BLOCKLAYOUT_SHARED;
     }
 }
 
@@ -599,7 +599,7 @@
         const TFieldList &fieldList = interfaceBlock.fields();
 
         unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize());
-        sh::InterfaceBlock activeBlock(interfaceBlock.name().c_str(), arraySize, mInterfaceBlockRegister);
+        gl::InterfaceBlock activeBlock(interfaceBlock.name().c_str(), arraySize, mInterfaceBlockRegister);
         for (unsigned int typeIndex = 0; typeIndex < fieldList.size(); typeIndex++)
         {
             const TField &field = *fieldList[typeIndex];
@@ -609,7 +609,7 @@
 
         mInterfaceBlockRegister += std::max(1u, arraySize);
 
-        BlockLayoutType blockLayoutType = convertBlockLayoutType(interfaceBlock.blockStorage());
+        gl::BlockLayoutType blockLayoutType = convertBlockLayoutType(interfaceBlock.blockStorage());
         setBlockLayout(&activeBlock, blockLayoutType);
 
         if (interfaceBlock.matrixPacking() == EmpRowMajor)
@@ -668,7 +668,7 @@
 
         attributes += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
 
-        Attribute attributeVar(glVariableType(type), glVariablePrecision(type), name.c_str(),
+        gl::Attribute attributeVar(glVariableType(type), glVariablePrecision(type), name.c_str(),
                                (unsigned int)type.getArraySize(), type.getLayoutQualifier().location);
         mActiveAttributes.push_back(attributeVar);
     }
@@ -713,7 +713,7 @@
                 out << "static " + typeString(variableType) + " out_" + variableName + arrayString(variableType) +
                        " = " + initializer(variableType) + ";\n";
 
-                Attribute outputVar(glVariableType(variableType), glVariablePrecision(variableType), variableName.c_str(),
+                gl::Attribute outputVar(glVariableType(variableType), glVariablePrecision(variableType), variableName.c_str(),
                                     (unsigned int)variableType.getArraySize(), layoutQualifier.location);
                 mActiveOutputVariables.push_back(outputVar);
             }
@@ -3880,20 +3880,20 @@
     return string;
 }
 
-void OutputHLSL::declareInterfaceBlockField(const TType &type, const TString &name, std::vector<InterfaceBlockField>& output)
+void OutputHLSL::declareInterfaceBlockField(const TType &type, const TString &name, std::vector<gl::InterfaceBlockField>& output)
 {
     const TStructure *structure = type.getStruct();
 
     if (!structure)
     {
         const bool isRowMajorMatrix = (type.isMatrix() && type.getLayoutQualifier().matrixPacking == EmpRowMajor);
-        InterfaceBlockField field(glVariableType(type), glVariablePrecision(type), name.c_str(),
-                        (unsigned int)type.getArraySize(), isRowMajorMatrix);
+        gl::InterfaceBlockField field(glVariableType(type), glVariablePrecision(type), name.c_str(),
+                                      (unsigned int)type.getArraySize(), isRowMajorMatrix);
         output.push_back(field);
    }
     else
     {
-        InterfaceBlockField structField(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(), false);
+        gl::InterfaceBlockField structField(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(), false);
 
         const TFieldList &fields = structure->fields();
 
@@ -3912,22 +3912,22 @@
     }
 }
 
-Uniform OutputHLSL::declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<Uniform>& output)
+gl::Uniform OutputHLSL::declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<gl::Uniform>& output)
 {
     const TStructure *structure = type.getStruct();
 
     if (!structure)
     {
-        Uniform uniform(glVariableType(type), glVariablePrecision(type), name.c_str(),
-                        (unsigned int)type.getArraySize(), (unsigned int)registerIndex, 0);
+        gl::Uniform uniform(glVariableType(type), glVariablePrecision(type), name.c_str(),
+                            (unsigned int)type.getArraySize(), (unsigned int)registerIndex, 0);
         output.push_back(uniform);
 
         return uniform;
    }
     else
     {
-        Uniform structUniform(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(),
-                              (unsigned int)registerIndex, GL_INVALID_INDEX);
+        gl::Uniform structUniform(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(),
+                                  (unsigned int)registerIndex, GL_INVALID_INDEX);
 
         const TFieldList &fields = structure->fields();
 
@@ -3948,13 +3948,13 @@
     }
 }
 
-InterpolationType getInterpolationType(TQualifier qualifier)
+gl::InterpolationType getInterpolationType(TQualifier qualifier)
 {
     switch (qualifier)
     {
       case EvqFlatIn:
       case EvqFlatOut:
-        return INTERPOLATION_FLAT;
+        return gl::INTERPOLATION_FLAT;
 
       case EvqSmoothIn:
       case EvqSmoothOut:
@@ -3962,30 +3962,30 @@
       case EvqFragmentIn:
       case EvqVaryingIn:
       case EvqVaryingOut:
-        return INTERPOLATION_SMOOTH;
+        return gl::INTERPOLATION_SMOOTH;
 
       case EvqCentroidIn:
       case EvqCentroidOut:
-        return INTERPOLATION_CENTROID;
+        return gl::INTERPOLATION_CENTROID;
 
       default: UNREACHABLE();
-        return INTERPOLATION_SMOOTH;
+        return gl::INTERPOLATION_SMOOTH;
     }
 }
 
-void OutputHLSL::declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<Varying>& fieldsOut)
+void OutputHLSL::declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<gl::Varying>& fieldsOut)
 {
     const TStructure *structure = type.getStruct();
 
-    InterpolationType interpolation = getInterpolationType(baseTypeQualifier);
+    gl::InterpolationType interpolation = getInterpolationType(baseTypeQualifier);
     if (!structure)
     {
-        Varying varying(glVariableType(type), glVariablePrecision(type), name.c_str(), (unsigned int)type.getArraySize(), interpolation);
+        gl::Varying varying(glVariableType(type), glVariablePrecision(type), name.c_str(), (unsigned int)type.getArraySize(), interpolation);
         fieldsOut.push_back(varying);
     }
     else
     {
-        Varying structVarying(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(), interpolation);
+        gl::Varying structVarying(GL_STRUCT_ANGLEX, GL_NONE, name.c_str(), (unsigned int)type.getArraySize(), interpolation);
         const TFieldList &fields = structure->fields();
 
         structVarying.structName = structure->name().c_str();
@@ -4004,15 +4004,15 @@
 {
     int registerIndex = (IsSampler(type.getBasicType()) ? mSamplerRegister : mUniformRegister);
 
-    const Uniform &uniform = declareUniformToList(type, name, registerIndex, mActiveUniforms);
+    const gl::Uniform &uniform = declareUniformToList(type, name, registerIndex, mActiveUniforms);
 
     if (IsSampler(type.getBasicType()))
     {
-        mSamplerRegister += HLSLVariableRegisterCount(uniform);
+        mSamplerRegister += gl::HLSLVariableRegisterCount(uniform);
     }
     else
     {
-        mUniformRegister += HLSLVariableRegisterCount(uniform);
+        mUniformRegister += gl::HLSLVariableRegisterCount(uniform);
     }
 
     return registerIndex;
diff --git a/src/compiler/translator/OutputHLSL.h b/src/compiler/translator/OutputHLSL.h
index 5d66fc5..ad42f2d 100644
--- a/src/compiler/translator/OutputHLSL.h
+++ b/src/compiler/translator/OutputHLSL.h
@@ -17,7 +17,7 @@
 
 #include "compiler/translator/intermediate.h"
 #include "compiler/translator/ParseContext.h"
-#include "compiler/translator/ShaderVariable.h"
+#include "common/shadervars.h"
 
 namespace sh
 {
@@ -32,11 +32,11 @@
     void output();
 
     TInfoSinkBase &getBodyStream();
-    const std::vector<Uniform> &getUniforms();
-    const ActiveInterfaceBlocks &getInterfaceBlocks() const;
-    const std::vector<Attribute> &getOutputVariables() const;
-    const std::vector<Attribute> &getAttributes() const;
-    const std::vector<Varying> &getVaryings() const;
+    const std::vector<gl::Uniform> &getUniforms();
+    const std::vector<gl::InterfaceBlock> &getInterfaceBlocks() const;
+    const std::vector<gl::Attribute> &getOutputVariables() const;
+    const std::vector<gl::Attribute> &getAttributes() const;
+    const std::vector<gl::Varying> &getVaryings() const;
 
     TString typeString(const TType &type);
     TString textureString(const TType &type);
@@ -184,10 +184,10 @@
     TString registerString(TIntermSymbol *operand);
     int samplerRegister(TIntermSymbol *sampler);
     int uniformRegister(TIntermSymbol *uniform);
-    void declareInterfaceBlockField(const TType &type, const TString &name, std::vector<InterfaceBlockField>& output);
-    Uniform declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<Uniform>& output);
+    void declareInterfaceBlockField(const TType &type, const TString &name, std::vector<gl::InterfaceBlockField>& output);
+    gl::Uniform declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<gl::Uniform>& output);
     void declareUniform(const TType &type, const TString &name, int index);
-    void declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<Varying>& fieldsOut);
+    void declareVaryingToList(const TType &type, TQualifier baseTypeQualifier, const TString &name, std::vector<gl::Varying>& fieldsOut);
 
     // Returns the uniform's register index
     int declareUniformAndAssignRegister(const TType &type, const TString &name);
@@ -210,11 +210,11 @@
     static bool isVaryingOut(TQualifier qualifier);
     static bool isVarying(TQualifier qualifier);
 
-    std::vector<Uniform> mActiveUniforms;
-    ActiveInterfaceBlocks mActiveInterfaceBlocks;
-    std::vector<Attribute> mActiveOutputVariables;
-    std::vector<Attribute> mActiveAttributes;
-    std::vector<Varying> mActiveVaryings;
+    std::vector<gl::Uniform> mActiveUniforms;
+    std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks;
+    std::vector<gl::Attribute> mActiveOutputVariables;
+    std::vector<gl::Attribute> mActiveAttributes;
+    std::vector<gl::Varying> mActiveVaryings;
     std::map<TString, int> mStd140StructElementIndexes;
     std::map<TIntermTyped*, TString> mFlaggedStructMappedNames;
     std::map<TIntermTyped*, TString> mFlaggedStructOriginalNames;
diff --git a/src/compiler/translator/ShaderVariable.cpp b/src/compiler/translator/ShaderVariable.cpp
deleted file mode 100644
index a8a5e93..0000000
--- a/src/compiler/translator/ShaderVariable.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-
-#include "compiler/translator/ShaderVariable.h"
-
-namespace sh
-{
-
-ShaderVariable::ShaderVariable(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn)
-    : type(typeIn),
-      precision(precisionIn),
-      name(nameIn),
-      arraySize(arraySizeIn)
-{
-}
-
-Uniform::Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, unsigned int registerIndexIn, unsigned int elementIndexIn)
-    : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
-      registerIndex(registerIndexIn),
-      elementIndex(elementIndexIn)
-{
-}
-
-Attribute::Attribute()
-    : ShaderVariable(GL_NONE, GL_NONE, "", 0),
-      location(-1)
-{
-}
-
-Attribute::Attribute(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, int locationIn)
-    : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
-      location(locationIn)
-{
-}
-
-InterfaceBlockField::InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix)
-    : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
-      isRowMajorMatrix(isRowMajorMatrix)
-{
-}
-
-Varying::Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn)
-    : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
-      interpolation(interpolationIn),
-      registerIndex(GL_INVALID_INDEX),
-      elementIndex(GL_INVALID_INDEX)
-{
-}
-
-void Varying::resetRegisterAssignment()
-{
-    registerIndex = GL_INVALID_INDEX;
-    elementIndex = GL_INVALID_INDEX;
-}
-
-BlockMemberInfo::BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
-    : offset(offset),
-      arrayStride(arrayStride),
-      matrixStride(matrixStride),
-      isRowMajorMatrix(isRowMajorMatrix)
-{
-}
-
-const BlockMemberInfo BlockMemberInfo::defaultBlockInfo(-1, -1, -1, false);
-
-InterfaceBlock::InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex)
-    : name(name),
-      arraySize(arraySize),
-      layout(BLOCKLAYOUT_SHARED),
-      registerIndex(registerIndex),
-      isRowMajorLayout(false)
-{
-}
-
-}
diff --git a/src/compiler/translator/ShaderVariable.h b/src/compiler/translator/ShaderVariable.h
deleted file mode 100644
index 53c3326..0000000
--- a/src/compiler/translator/ShaderVariable.h
+++ /dev/null
@@ -1,126 +0,0 @@
-//
-// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-
-#ifndef COMPILER_SHADERVARIABLE_H_
-#define COMPILER_SHADERVARIABLE_H_
-
-#include <string>
-#include <vector>
-#include <algorithm>
-
-#define GL_APICALL
-#include <GLES3/gl3.h>
-#include <GLES2/gl2.h>
-
-namespace sh
-{
-
-enum InterpolationType
-{
-    INTERPOLATION_SMOOTH,
-    INTERPOLATION_CENTROID,
-    INTERPOLATION_FLAT
-};
-
-struct ShaderVariable
-{
-    GLenum type;
-    GLenum precision;
-    std::string name;
-    unsigned int arraySize;
-
-    ShaderVariable(GLenum type, GLenum precision, const char *name, unsigned int arraySize);
-    bool isArray() const { return arraySize > 0; }
-    unsigned int elementCount() const { return std::max(1u, arraySize); }
-};
-
-struct Uniform : public ShaderVariable
-{
-    unsigned int registerIndex;
-    unsigned int elementIndex;     // For struct varyings
-    std::vector<Uniform> fields;
-
-    Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
-            unsigned int registerIndexIn, unsigned int elementIndexIn);
-
-    bool isStruct() const { return !fields.empty(); }
-};
-
-struct Attribute : public ShaderVariable
-{
-    int location;
-
-    Attribute();
-    Attribute(GLenum type, GLenum precision, const char *name, unsigned int arraySize, int location);
-};
-
-struct InterfaceBlockField : public ShaderVariable
-{
-    bool isRowMajorMatrix;
-    std::vector<InterfaceBlockField> fields;
-
-    InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix);
-
-    bool isStruct() const { return !fields.empty(); }
-};
-
-struct Varying : public ShaderVariable
-{
-    InterpolationType interpolation;
-    std::vector<Varying> fields;
-    unsigned int registerIndex;    // Assigned during link
-    unsigned int elementIndex;     // First register element for varyings, assigned during link
-    std::string structName;
-
-    Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn);
-
-    bool isStruct() const { return !fields.empty(); }
-    bool registerAssigned() const { return registerIndex != GL_INVALID_INDEX; }
-
-    void resetRegisterAssignment();
-};
-
-struct BlockMemberInfo
-{
-    BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix);
-
-    int offset;
-    int arrayStride;
-    int matrixStride;
-    bool isRowMajorMatrix;
-
-    static const BlockMemberInfo defaultBlockInfo;
-};
-
-typedef std::vector<BlockMemberInfo> BlockMemberInfoArray;
-
-enum BlockLayoutType
-{
-    BLOCKLAYOUT_STANDARD,
-    BLOCKLAYOUT_PACKED,
-    BLOCKLAYOUT_SHARED
-};
-
-struct InterfaceBlock
-{
-    InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex);
-
-    std::string name;
-    unsigned int arraySize;
-    size_t dataSize;
-    BlockLayoutType layout;
-    bool isRowMajorLayout;
-    std::vector<InterfaceBlockField> fields;
-    std::vector<BlockMemberInfo> blockInfo;
-
-    unsigned int registerIndex;
-};
-
-typedef std::vector<InterfaceBlock> ActiveInterfaceBlocks;
-
-}
-
-#endif   // COMPILER_SHADERVARIABLE_H_
diff --git a/src/compiler/translator/TranslatorHLSL.h b/src/compiler/translator/TranslatorHLSL.h
index 796a16c..6020a51 100644
--- a/src/compiler/translator/TranslatorHLSL.h
+++ b/src/compiler/translator/TranslatorHLSL.h
@@ -8,27 +8,27 @@
 #define COMPILER_TRANSLATORHLSL_H_
 
 #include "compiler/translator/ShHandle.h"
-#include "compiler/translator/ShaderVariable.h"
+#include "common/shadervars.h"
 
 class TranslatorHLSL : public TCompiler {
 public:
     TranslatorHLSL(ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
 
     virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; }
-    const std::vector<sh::Uniform> &getUniforms() { return mActiveUniforms; }
-    const sh::ActiveInterfaceBlocks &getInterfaceBlocks() const { return mActiveInterfaceBlocks; }
-    const std::vector<sh::Attribute> &getOutputVariables() { return mActiveOutputVariables; }
-    const std::vector<sh::Attribute> &getAttributes() { return mActiveAttributes; }
-    const std::vector<sh::Varying> &getVaryings() { return mActiveVaryings; }
+    const std::vector<gl::Uniform> &getUniforms() { return mActiveUniforms; }
+    const std::vector<gl::InterfaceBlock> &getInterfaceBlocks() const { return mActiveInterfaceBlocks; }
+    const std::vector<gl::Attribute> &getOutputVariables() { return mActiveOutputVariables; }
+    const std::vector<gl::Attribute> &getAttributes() { return mActiveAttributes; }
+    const std::vector<gl::Varying> &getVaryings() { return mActiveVaryings; }
 
 protected:
     virtual void translate(TIntermNode* root);
 
-    std::vector<sh::Uniform> mActiveUniforms;
-    sh::ActiveInterfaceBlocks mActiveInterfaceBlocks;
-    std::vector<sh::Attribute> mActiveOutputVariables;
-    std::vector<sh::Attribute> mActiveAttributes;
-    std::vector<sh::Varying> mActiveVaryings;
+    std::vector<gl::Uniform> mActiveUniforms;
+    std::vector<gl::InterfaceBlock> mActiveInterfaceBlocks;
+    std::vector<gl::Attribute> mActiveOutputVariables;
+    std::vector<gl::Attribute> mActiveAttributes;
+    std::vector<gl::Varying> mActiveVaryings;
     ShShaderOutput mOutputType;
 };