Commit aa72d782 by Jamie Madill

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/205594Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent 183bde55
......@@ -17,62 +17,7 @@ namespace gl
int VariableComponentCount(GLenum type)
{
switch (type)
{
case GL_BOOL:
case GL_FLOAT:
case GL_INT:
case GL_SAMPLER_2D:
case GL_SAMPLER_3D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_2D_ARRAY:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_3D:
case GL_INT_SAMPLER_CUBE:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_3D:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_CUBE_SHADOW:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_UNSIGNED_INT:
return 1;
case GL_BOOL_VEC2:
case GL_FLOAT_VEC2:
case GL_INT_VEC2:
case GL_UNSIGNED_INT_VEC2:
return 2;
case GL_INT_VEC3:
case GL_FLOAT_VEC3:
case GL_BOOL_VEC3:
case GL_UNSIGNED_INT_VEC3:
return 3;
case GL_BOOL_VEC4:
case GL_FLOAT_VEC4:
case GL_INT_VEC4:
case GL_UNSIGNED_INT_VEC4:
case GL_FLOAT_MAT2:
return 4;
case GL_FLOAT_MAT2x3:
case GL_FLOAT_MAT3x2:
return 6;
case GL_FLOAT_MAT2x4:
case GL_FLOAT_MAT4x2:
return 8;
case GL_FLOAT_MAT3:
return 9;
case GL_FLOAT_MAT3x4:
case GL_FLOAT_MAT4x3:
return 12;
case GL_FLOAT_MAT4:
return 16;
default:
UNREACHABLE();
}
return 0;
return VariableRowCount(type) * VariableColumnCount(type);
}
GLenum VariableComponentType(GLenum type)
......@@ -209,6 +154,8 @@ int VariableRowCount(GLenum type)
case GL_SAMPLER_3D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_2D_RECT_ARB:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_3D:
case GL_INT_SAMPLER_CUBE:
......@@ -259,6 +206,8 @@ int VariableColumnCount(GLenum type)
case GL_INT_SAMPLER_3D:
case GL_INT_SAMPLER_CUBE:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_2D_RECT_ARB:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_3D:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
......
......@@ -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 @@ void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root)
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)
......
......@@ -5,6 +5,7 @@
//
#include "compiler/translator/VariableInfo.h"
#include "compiler/translator/util.h"
#include "angle_gl.h"
namespace {
......@@ -16,110 +17,6 @@ TString arrayBrackets(int index)
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 @@ void getBuiltInVariableInfo(const TType& type,
varInfo.isArray = false;
}
varInfo.precision = type.getPrecision();
varInfo.type = getVariableDataType(type);
varInfo.type = sh::GLVariableType(type);
infoList.push_back(varInfo);
}
......
......@@ -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 @@ int GetSortOrder(sh::GLenum type)
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;
}
}
......
......@@ -24,7 +24,7 @@ class VariablePacker {
// 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;
......
......@@ -144,6 +144,8 @@ GLenum GLVariableType(const TType &type)
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;
......
......@@ -5,8 +5,41 @@
//
#include "gtest/gtest.h"
#include "angle_gl.h"
#include "common/utilities.h"
#include "common/angleutils.h"
#include "compiler/translator/VariablePacker.h"
static sh::GLenum types[] = {
GL_FLOAT_MAT4, // 0
GL_FLOAT_MAT2, // 1
GL_FLOAT_VEC4, // 2
GL_INT_VEC4, // 3
GL_BOOL_VEC4, // 4
GL_FLOAT_MAT3, // 5
GL_FLOAT_VEC3, // 6
GL_INT_VEC3, // 7
GL_BOOL_VEC3, // 8
GL_FLOAT_VEC2, // 9
GL_INT_VEC2, // 10
GL_BOOL_VEC2, // 11
GL_FLOAT, // 12
GL_INT, // 13
GL_BOOL, // 14
GL_SAMPLER_2D, // 15
GL_SAMPLER_CUBE, // 16
GL_SAMPLER_EXTERNAL_OES, // 17
GL_SAMPLER_2D_RECT_ARB, // 18
};
static sh::GLenum nonSqMatTypes[] = {
GL_FLOAT_MAT2x3,
GL_FLOAT_MAT2x4,
GL_FLOAT_MAT3x2,
GL_FLOAT_MAT3x4,
GL_FLOAT_MAT4x2,
GL_FLOAT_MAT4x3
};
TEST(VariablePacking, Pack) {
VariablePacker packer;
TVariableInfoList vars;
......@@ -14,29 +47,7 @@ TEST(VariablePacking, Pack) {
// test no vars.
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
sh::GLenum types[] = {
GL_FLOAT_MAT4, // 0
GL_FLOAT_MAT2, // 1
GL_FLOAT_VEC4, // 2
GL_INT_VEC4, // 3
GL_BOOL_VEC4, // 4
GL_FLOAT_MAT3, // 5
GL_FLOAT_VEC3, // 6
GL_INT_VEC3, // 7
GL_BOOL_VEC3, // 8
GL_FLOAT_VEC2, // 9
GL_INT_VEC2, // 10
GL_BOOL_VEC2, // 11
GL_FLOAT, // 12
GL_INT, // 13
GL_BOOL, // 14
GL_SAMPLER_2D, // 15
GL_SAMPLER_CUBE, // 16
GL_SAMPLER_EXTERNAL_OES, // 17
GL_SAMPLER_2D_RECT_ARB, // 18
};
for (size_t tt = 0; tt < sizeof(types) / sizeof(types[0]); ++tt) {
for (size_t tt = 0; tt < ArraySize(types); ++tt) {
sh::GLenum type = types[tt];
int num_rows = VariablePacker::GetNumRows(type);
int num_components_per_row = VariablePacker::GetNumComponentsPerRow(type);
......@@ -84,3 +95,55 @@ TEST(VariablePacking, Pack) {
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
}
TEST(VariablePacking, PackSizes) {
for (size_t tt = 0; tt < ArraySize(types); ++tt) {
GLenum type = types[tt];
int expectedComponents = gl::VariableComponentCount(type);
int expectedRows = gl::VariableRowCount(type);
if (type == GL_FLOAT_MAT2) {
expectedComponents = 4;
} else if (gl::IsMatrixType(type)) {
int squareSize = std::max(gl::VariableRowCount(type),
gl::VariableColumnCount(type));
expectedComponents = squareSize;
expectedRows = squareSize;
}
EXPECT_EQ(expectedComponents,
VariablePacker::GetNumComponentsPerRow(type));
EXPECT_EQ(expectedRows, VariablePacker::GetNumRows(type));
}
}
// Check special assumptions about packing non-square mats
TEST(VariablePacking, NonSquareMats) {
for (size_t mt = 0; mt < ArraySize(nonSqMatTypes); ++mt) {
GLenum type = nonSqMatTypes[mt];
int rows = gl::VariableRowCount(type);
int cols = gl::VariableColumnCount(type);
int squareSize = std::max(rows, cols);
TVariableInfoList vars;
vars.push_back(TVariableInfo(type, 1));
// Fill columns
for (int row = 0; row < squareSize; row++) {
for (int col = squareSize; col < 4; ++col) {
vars.push_back(TVariableInfo(GL_FLOAT, 1));
}
}
VariablePacker packer;
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(squareSize, vars));
// and one scalar and packing should fail
vars.push_back(TVariableInfo(GL_FLOAT, 1));
EXPECT_FALSE(packer.CheckVariablesWithinPackingLimits(squareSize, vars));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment