Remove duplicate SH and GL functions.
In several places we were using variable query methods that
were duplicated between the old SH enums and the corresponding
GL enums. We can use the common GL enum versions now.
BUG=angle:466
Change-Id: Ib8797fe6bc75828e05aed37b1f5fbd4b9ba03d22
Reviewed-on: https://chromium-review.googlesource.com/205594
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index 898e3ef..aefbb15 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -23,6 +23,7 @@
#include "compiler/translator/timing/RestrictVertexShaderTiming.h"
#include "third_party/compiler/ArrayBoundsClamper.h"
#include "angle_gl.h"
+#include "common/utilities.h"
bool IsWebGLBasedSpec(ShShaderSpec spec)
{
@@ -510,35 +511,8 @@
const TVariableInfo& varying = varyings[ii];
if (varying.staticUse)
continue;
- unsigned char primarySize = 1, secondarySize = 1;
- switch (varying.type)
- {
- case GL_FLOAT:
- break;
- case GL_FLOAT_VEC2:
- primarySize = 2;
- break;
- case GL_FLOAT_VEC3:
- primarySize = 3;
- break;
- case GL_FLOAT_VEC4:
- primarySize = 4;
- break;
- case GL_FLOAT_MAT2:
- primarySize = 2;
- secondarySize = 2;
- break;
- case GL_FLOAT_MAT3:
- primarySize = 3;
- secondarySize = 3;
- break;
- case GL_FLOAT_MAT4:
- primarySize = 4;
- secondarySize = 4;
- break;
- default:
- ASSERT(false);
- }
+ unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type));
+ unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type));
TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray);
TString name = varying.name.c_str();
if (varying.isArray)
diff --git a/src/compiler/translator/VariableInfo.cpp b/src/compiler/translator/VariableInfo.cpp
index 536aa14..b2c3205 100644
--- a/src/compiler/translator/VariableInfo.cpp
+++ b/src/compiler/translator/VariableInfo.cpp
@@ -5,6 +5,7 @@
//
#include "compiler/translator/VariableInfo.h"
+#include "compiler/translator/util.h"
#include "angle_gl.h"
namespace {
@@ -16,110 +17,6 @@
return stream.str();
}
-// Returns the data type for an attribute, uniform, or varying.
-sh::GLenum getVariableDataType(const TType& type)
-{
- switch (type.getBasicType()) {
- case EbtFloat:
- if (type.isMatrix()) {
- switch (type.getCols())
- {
- case 2:
- switch (type.getRows())
- {
- case 2: return GL_FLOAT_MAT2;
- case 3: return GL_FLOAT_MAT2x3;
- case 4: return GL_FLOAT_MAT2x4;
- default: UNREACHABLE();
- }
- case 3:
- switch (type.getRows())
- {
- case 2: return GL_FLOAT_MAT3x2;
- case 3: return GL_FLOAT_MAT3;
- case 4: return GL_FLOAT_MAT3x4;
- default: UNREACHABLE();
- }
- case 4:
- switch (type.getRows())
- {
- case 2: return GL_FLOAT_MAT4x2;
- case 3: return GL_FLOAT_MAT4x3;
- case 4: return GL_FLOAT_MAT4;
- default: UNREACHABLE();
- }
- }
- } else if (type.isVector()) {
- switch (type.getNominalSize()) {
- case 2: return GL_FLOAT_VEC2;
- case 3: return GL_FLOAT_VEC3;
- case 4: return GL_FLOAT_VEC4;
- default: UNREACHABLE();
- }
- } else {
- return GL_FLOAT;
- }
- case EbtInt:
- if (type.isMatrix()) {
- UNREACHABLE();
- } else if (type.isVector()) {
- switch (type.getNominalSize()) {
- case 2: return GL_INT_VEC2;
- case 3: return GL_INT_VEC3;
- case 4: return GL_INT_VEC4;
- default: UNREACHABLE();
- }
- } else {
- return GL_INT;
- }
- case EbtUInt:
- if (type.isMatrix()) {
- UNREACHABLE();
- } else if (type.isVector()) {
- switch (type.getNominalSize()) {
- case 2: return GL_UNSIGNED_INT_VEC2;
- case 3: return GL_UNSIGNED_INT_VEC3;
- case 4: return GL_UNSIGNED_INT_VEC4;
- default: UNREACHABLE();
- }
- } else {
- return GL_UNSIGNED_INT;
- }
- case EbtBool:
- if (type.isMatrix()) {
- UNREACHABLE();
- } else if (type.isVector()) {
- switch (type.getNominalSize()) {
- case 2: return GL_BOOL_VEC2;
- case 3: return GL_BOOL_VEC3;
- case 4: return GL_BOOL_VEC4;
- default: UNREACHABLE();
- }
- } else {
- return GL_BOOL;
- }
- case EbtSampler2D: return GL_SAMPLER_2D;
- case EbtSampler3D: return GL_SAMPLER_3D;
- case EbtSamplerCube: return GL_SAMPLER_CUBE;
- case EbtSamplerExternalOES: return GL_SAMPLER_EXTERNAL_OES;
- case EbtSampler2DRect: return GL_SAMPLER_2D_RECT_ARB;
- case EbtSampler2DArray: return GL_SAMPLER_2D_ARRAY;
- case EbtISampler2D: return GL_INT_SAMPLER_2D;
- case EbtISampler3D: return GL_INT_SAMPLER_3D;
- case EbtISamplerCube: return GL_INT_SAMPLER_CUBE;
- case EbtISampler2DArray: return GL_INT_SAMPLER_2D_ARRAY;
- case EbtUSampler2D: return GL_UNSIGNED_INT_SAMPLER_2D;
- case EbtUSampler3D: return GL_UNSIGNED_INT_SAMPLER_3D;
- case EbtUSamplerCube: return GL_UNSIGNED_INT_SAMPLER_CUBE;
- case EbtUSampler2DArray: return GL_UNSIGNED_INT_SAMPLER_2D_ARRAY;
- case EbtSampler2DShadow: return GL_SAMPLER_2D_SHADOW;
- case EbtSamplerCubeShadow: return GL_SAMPLER_CUBE_SHADOW;
- case EbtSampler2DArrayShadow: return GL_SAMPLER_2D_ARRAY_SHADOW;
- default: UNREACHABLE();
- }
- return GL_NONE;
-}
-
void getBuiltInVariableInfo(const TType& type,
const TString& name,
const TString& mappedName,
@@ -172,7 +69,7 @@
varInfo.isArray = false;
}
varInfo.precision = type.getPrecision();
- varInfo.type = getVariableDataType(type);
+ varInfo.type = sh::GLVariableType(type);
infoList.push_back(varInfo);
}
diff --git a/src/compiler/translator/VariablePacker.cpp b/src/compiler/translator/VariablePacker.cpp
index 6cc7198..7186cb9 100644
--- a/src/compiler/translator/VariablePacker.cpp
+++ b/src/compiler/translator/VariablePacker.cpp
@@ -5,10 +5,13 @@
//
#include "compiler/translator/VariablePacker.h"
#include "angle_gl.h"
+#include "common/utilities.h"
#include <algorithm>
-namespace {
+namespace
+{
+
int GetSortOrder(sh::GLenum type)
{
switch (type) {
@@ -49,81 +52,62 @@
return 7;
}
}
+
} // namespace
int VariablePacker::GetNumComponentsPerRow(sh::GLenum type)
{
- switch (type) {
- case GL_FLOAT_MAT4:
- case GL_FLOAT_MAT2:
- case GL_FLOAT_MAT2x4:
- case GL_FLOAT_MAT3x4:
- case GL_FLOAT_MAT4x2:
- case GL_FLOAT_MAT4x3:
- case GL_FLOAT_VEC4:
- case GL_INT_VEC4:
- case GL_BOOL_VEC4:
- return 4;
- case GL_FLOAT_MAT3:
- case GL_FLOAT_MAT2x3:
- case GL_FLOAT_MAT3x2:
- case GL_FLOAT_VEC3:
- case GL_INT_VEC3:
- case GL_BOOL_VEC3:
- return 3;
- case GL_FLOAT_VEC2:
- case GL_INT_VEC2:
- case GL_BOOL_VEC2:
- return 2;
- case GL_FLOAT:
- case GL_INT:
- case GL_BOOL:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_EXTERNAL_OES:
- case GL_SAMPLER_2D_RECT_ARB:
- return 1;
- default:
- ASSERT(false);
- return 5;
+ switch (type)
+ {
+ case GL_FLOAT_MAT4:
+ case GL_FLOAT_MAT2:
+ case GL_FLOAT_MAT2x4:
+ case GL_FLOAT_MAT3x4:
+ case GL_FLOAT_MAT4x2:
+ case GL_FLOAT_MAT4x3:
+ case GL_FLOAT_VEC4:
+ case GL_INT_VEC4:
+ case GL_BOOL_VEC4:
+ case GL_UNSIGNED_INT_VEC4:
+ return 4;
+ case GL_FLOAT_MAT3:
+ case GL_FLOAT_MAT2x3:
+ case GL_FLOAT_MAT3x2:
+ case GL_FLOAT_VEC3:
+ case GL_INT_VEC3:
+ case GL_BOOL_VEC3:
+ case GL_UNSIGNED_INT_VEC3:
+ return 3;
+ case GL_FLOAT_VEC2:
+ case GL_INT_VEC2:
+ case GL_BOOL_VEC2:
+ case GL_UNSIGNED_INT_VEC2:
+ return 2;
+ default:
+ ASSERT(gl::VariableComponentCount(type) == 1);
+ return 1;
}
}
int VariablePacker::GetNumRows(sh::GLenum type)
{
- switch (type) {
- case GL_FLOAT_MAT4:
- case GL_FLOAT_MAT2x4:
- case GL_FLOAT_MAT3x4:
- case GL_FLOAT_MAT4x3:
- case GL_FLOAT_MAT4x2:
- return 4;
- case GL_FLOAT_MAT3:
- case GL_FLOAT_MAT2x3:
- case GL_FLOAT_MAT3x2:
- return 3;
- case GL_FLOAT_MAT2:
- return 2;
- case GL_FLOAT_VEC4:
- case GL_INT_VEC4:
- case GL_BOOL_VEC4:
- case GL_FLOAT_VEC3:
- case GL_INT_VEC3:
- case GL_BOOL_VEC3:
- case GL_FLOAT_VEC2:
- case GL_INT_VEC2:
- case GL_BOOL_VEC2:
- case GL_FLOAT:
- case GL_INT:
- case GL_BOOL:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_EXTERNAL_OES:
- case GL_SAMPLER_2D_RECT_ARB:
- return 1;
- default:
- ASSERT(false);
- return 100000;
+ switch (type)
+ {
+ case GL_FLOAT_MAT4:
+ case GL_FLOAT_MAT2x4:
+ case GL_FLOAT_MAT3x4:
+ case GL_FLOAT_MAT4x3:
+ case GL_FLOAT_MAT4x2:
+ return 4;
+ case GL_FLOAT_MAT3:
+ case GL_FLOAT_MAT2x3:
+ case GL_FLOAT_MAT3x2:
+ return 3;
+ case GL_FLOAT_MAT2:
+ return 2;
+ default:
+ ASSERT(gl::VariableRowCount(type) == 1);
+ return 1;
}
}
diff --git a/src/compiler/translator/VariablePacker.h b/src/compiler/translator/VariablePacker.h
index d66b0fc..4e33101 100644
--- a/src/compiler/translator/VariablePacker.h
+++ b/src/compiler/translator/VariablePacker.h
@@ -24,7 +24,7 @@
// Gets how many rows a data type takes.
static int GetNumRows(sh::GLenum type);
- private:
+ private:
static const int kNumColumns = 4;
static const unsigned kColumnMask = (1 << kNumColumns) - 1;
diff --git a/src/compiler/translator/util.cpp b/src/compiler/translator/util.cpp
index bd13364..fabf22a 100644
--- a/src/compiler/translator/util.cpp
+++ b/src/compiler/translator/util.cpp
@@ -144,6 +144,8 @@
case EbtSampler2D: return GL_SAMPLER_2D;
case EbtSampler3D: return GL_SAMPLER_3D;
case EbtSamplerCube: return GL_SAMPLER_CUBE;
+ case EbtSamplerExternalOES: return GL_SAMPLER_EXTERNAL_OES;
+ case EbtSampler2DRect: return GL_SAMPLER_2D_RECT_ARB;
case EbtSampler2DArray: return GL_SAMPLER_2D_ARRAY;
case EbtISampler2D: return GL_INT_SAMPLER_2D;
case EbtISampler3D: return GL_INT_SAMPLER_3D;