Commit a718c1e0 by Jamie Madill

Use shader variable types for variable collection.

Retire the old TVariableInfoList structure, and use the new objects which we will expose more directly through the API. BUG=angle:466 Change-Id: I999a97369bfb67cf73cd659c4fe885b41429d304 Reviewed-on: https://chromium-review.googlesource.com/205839Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent 47149b13
...@@ -41,7 +41,8 @@ struct ShaderVariable ...@@ -41,7 +41,8 @@ struct ShaderVariable
: type(typeIn), : type(typeIn),
precision(precisionIn), precision(precisionIn),
name(nameIn), name(nameIn),
arraySize(arraySizeIn) arraySize(arraySizeIn),
staticUse(false)
{} {}
bool isArray() const { return arraySize > 0; } bool isArray() const { return arraySize > 0; }
...@@ -50,12 +51,20 @@ struct ShaderVariable ...@@ -50,12 +51,20 @@ struct ShaderVariable
GLenum type; GLenum type;
GLenum precision; GLenum precision;
std::string name; std::string name;
std::string mappedName;
unsigned int arraySize; unsigned int arraySize;
bool staticUse;
}; };
// Uniform registers (and element indices) are assigned when outputting shader code // Uniform registers (and element indices) are assigned when outputting shader code
struct Uniform : public ShaderVariable struct Uniform : public ShaderVariable
{ {
Uniform()
: ShaderVariable(0, 0, "", 0),
registerIndex(-1),
elementIndex(-1)
{}
Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
unsigned int registerIndexIn, unsigned int elementIndexIn) unsigned int registerIndexIn, unsigned int elementIndexIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn), : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
...@@ -75,7 +84,7 @@ struct Uniform : public ShaderVariable ...@@ -75,7 +84,7 @@ struct Uniform : public ShaderVariable
struct Attribute : public ShaderVariable struct Attribute : public ShaderVariable
{ {
Attribute() Attribute()
: ShaderVariable((GLenum)0, (GLenum)0, "", 0), : ShaderVariable(0, 0, "", 0),
location(-1) location(-1)
{} {}
...@@ -102,6 +111,11 @@ struct InterfaceBlockField : public ShaderVariable ...@@ -102,6 +111,11 @@ struct InterfaceBlockField : public ShaderVariable
struct Varying : public ShaderVariable struct Varying : public ShaderVariable
{ {
Varying()
: ShaderVariable(0, 0, "", 0),
interpolation(INTERPOLATION_SMOOTH)
{}
Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn) Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn)
: ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn), : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
interpolation(interpolationIn) interpolation(interpolationIn)
......
...@@ -483,7 +483,7 @@ bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root) ...@@ -483,7 +483,7 @@ bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root)
void TCompiler::collectVariables(TIntermNode* root) void TCompiler::collectVariables(TIntermNode* root)
{ {
CollectVariables collect(attribs, uniforms, varyings, hashFunction); CollectVariables collect(&attribs, &uniforms, &varyings, hashFunction);
root->traverse(&collect); root->traverse(&collect);
} }
...@@ -508,16 +508,16 @@ void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root) ...@@ -508,16 +508,16 @@ void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root)
InitializeVariables::InitVariableInfoList variables; InitializeVariables::InitVariableInfoList variables;
for (size_t ii = 0; ii < varyings.size(); ++ii) for (size_t ii = 0; ii < varyings.size(); ++ii)
{ {
const TVariableInfo& varying = varyings[ii]; const sh::Varying& varying = varyings[ii];
if (varying.staticUse) if (varying.staticUse)
continue; continue;
unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type)); unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type));
unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type)); unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type));
TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray); TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray());
TString name = varying.name.c_str(); TString name = varying.name.c_str();
if (varying.isArray) if (varying.isArray())
{ {
type.setArraySize(varying.size); type.setArraySize(varying.arraySize);
name = name.substr(0, name.find_first_of('[')); name = name.substr(0, name.find_first_of('['));
} }
......
...@@ -52,8 +52,9 @@ protected: ...@@ -52,8 +52,9 @@ protected:
// The base class for the machine dependent compiler to derive from // The base class for the machine dependent compiler to derive from
// for managing object code from the compile. // for managing object code from the compile.
// //
class TCompiler : public TShHandleBase { class TCompiler : public TShHandleBase
public: {
public:
TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output); TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
virtual ~TCompiler(); virtual ~TCompiler();
virtual TCompiler* getAsCompiler() { return this; } virtual TCompiler* getAsCompiler() { return this; }
...@@ -66,9 +67,9 @@ public: ...@@ -66,9 +67,9 @@ public:
// Get results of the last compilation. // Get results of the last compilation.
int getShaderVersion() const { return shaderVersion; } int getShaderVersion() const { return shaderVersion; }
TInfoSink& getInfoSink() { return infoSink; } TInfoSink& getInfoSink() { return infoSink; }
const TVariableInfoList& getAttribs() const { return attribs; } const std::vector<sh::Attribute> &getAttribs() const { return attribs; }
const TVariableInfoList& getUniforms() const { return uniforms; } const std::vector<sh::Uniform> &getUniforms() const { return uniforms; }
const TVariableInfoList& getVaryings() const { return varyings; } const std::vector<sh::Varying> &getVaryings() const { return varyings; }
ShHashFunction64 getHashFunction() const { return hashFunction; } ShHashFunction64 getHashFunction() const { return hashFunction; }
NameMap& getNameMap() { return nameMap; } NameMap& getNameMap() { return nameMap; }
...@@ -77,7 +78,7 @@ public: ...@@ -77,7 +78,7 @@ public:
ShShaderOutput getOutputType() const { return outputType; } ShShaderOutput getOutputType() const { return outputType; }
std::string getBuiltInResourcesString() const { return builtInResourcesString; } std::string getBuiltInResourcesString() const { return builtInResourcesString; }
protected: protected:
sh::GLenum getShaderType() const { return shaderType; } sh::GLenum getShaderType() const { return shaderType; }
// Initialize symbol-table with built-in symbols. // Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
...@@ -129,7 +130,7 @@ protected: ...@@ -129,7 +130,7 @@ protected:
ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const; ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const;
const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const; const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const;
private: private:
sh::GLenum shaderType; sh::GLenum shaderType;
ShShaderSpec shaderSpec; ShShaderSpec shaderSpec;
ShShaderOutput outputType; ShShaderOutput outputType;
...@@ -155,9 +156,9 @@ private: ...@@ -155,9 +156,9 @@ private:
// Results of compilation. // Results of compilation.
int shaderVersion; int shaderVersion;
TInfoSink infoSink; // Output sink. TInfoSink infoSink; // Output sink.
TVariableInfoList attribs; // Active attributes in the compiled shader. std::vector<sh::Attribute> attribs; // Active attributes in the compiled shader.
TVariableInfoList uniforms; // Active uniforms in the compiled shader. std::vector<sh::Uniform> uniforms; // Active uniforms in the compiled shader.
TVariableInfoList varyings; // Varyings in the compiled shader. std::vector<sh::Varying> varyings; // Varyings in the compiled shader.
// name hashing. // name hashing.
ShHashFunction64 hashFunction; ShHashFunction64 hashFunction;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "compiler/translator/length_limits.h" #include "compiler/translator/length_limits.h"
#include "compiler/translator/TranslatorHLSL.h" #include "compiler/translator/TranslatorHLSL.h"
#include "compiler/translator/VariablePacker.h" #include "compiler/translator/VariablePacker.h"
#include "angle_gl.h"
static bool isInitialized = false; static bool isInitialized = false;
...@@ -45,6 +46,52 @@ static bool checkMappedNameMaxLength(const ShHandle handle, size_t expectedValue ...@@ -45,6 +46,52 @@ static bool checkMappedNameMaxLength(const ShHandle handle, size_t expectedValue
return (expectedValue == mappedNameMaxLength); return (expectedValue == mappedNameMaxLength);
} }
template <typename VarT>
static const sh::ShaderVariable *ReturnVariable(const std::vector<VarT> &infoList, int index)
{
if (index < 0 || static_cast<size_t>(index) >= infoList.size())
{
return NULL;
}
return &infoList[index];
}
static const sh::ShaderVariable *GetVariable(const TCompiler *compiler, ShShaderInfo varType, int index)
{
switch (varType)
{
case SH_ACTIVE_ATTRIBUTES:
return ReturnVariable(compiler->getAttribs(), index);
case SH_ACTIVE_UNIFORMS:
return ReturnVariable(compiler->getUniforms(), index);
case SH_VARYINGS:
return ReturnVariable(compiler->getVaryings(), index);
default:
UNREACHABLE();
return NULL;
}
}
static ShPrecisionType ConvertPrecision(sh::GLenum precision)
{
switch (precision)
{
case GL_HIGH_FLOAT:
case GL_HIGH_INT:
return SH_PRECISION_HIGHP;
case GL_MEDIUM_FLOAT:
case GL_MEDIUM_INT:
return SH_PRECISION_HIGHP;
case GL_LOW_FLOAT:
case GL_LOW_INT:
return SH_PRECISION_HIGHP;
default:
UNREACHABLE();
return SH_PRECISION_UNDEFINED;
}
}
// //
// Driver must call this first, once, before doing any other compiler operations. // Driver must call this first, once, before doing any other compiler operations.
// Subsequent calls to this function are no-op. // Subsequent calls to this function are no-op.
...@@ -310,47 +357,32 @@ void ShGetVariableInfo(const ShHandle handle, ...@@ -310,47 +357,32 @@ void ShGetVariableInfo(const ShHandle handle,
if (compiler == 0) if (compiler == 0)
return; return;
const TVariableInfoList& varList = const sh::ShaderVariable *varInfo = GetVariable(compiler, varType, index);
varType == SH_ACTIVE_ATTRIBUTES ? compiler->getAttribs() : if (!varInfo)
(varType == SH_ACTIVE_UNIFORMS ? compiler->getUniforms() : {
compiler->getVaryings());
if (index < 0 || index >= static_cast<int>(varList.size()))
return; return;
const TVariableInfo& varInfo = varList[index];
if (length) *length = varInfo.name.size();
*size = varInfo.size;
*type = varInfo.type;
switch (varInfo.precision) {
case EbpLow:
*precision = SH_PRECISION_LOWP;
break;
case EbpMedium:
*precision = SH_PRECISION_MEDIUMP;
break;
case EbpHigh:
*precision = SH_PRECISION_HIGHP;
break;
default:
// Some types does not support precision, for example, boolean.
*precision = SH_PRECISION_UNDEFINED;
break;
} }
*staticUse = varInfo.staticUse ? 1 : 0;
if (length) *length = varInfo->name.size();
*size = varInfo->elementCount();
*type = varInfo->type;
*precision = ConvertPrecision(varInfo->precision);
*staticUse = varInfo->staticUse ? 1 : 0;
// This size must match that queried by // This size must match that queried by
// SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH // SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH
// in ShGetInfo, below. // in ShGetInfo, below.
size_t variableLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); size_t variableLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
ASSERT(checkVariableMaxLengths(handle, variableLength)); ASSERT(checkVariableMaxLengths(handle, variableLength));
strncpy(name, varInfo.name.c_str(), variableLength); strncpy(name, varInfo->name.c_str(), variableLength);
name[variableLength - 1] = 0; name[variableLength - 1] = 0;
if (mappedName) { if (mappedName)
{
// This size must match that queried by // This size must match that queried by
// SH_MAPPED_NAME_MAX_LENGTH in ShGetInfo, below. // SH_MAPPED_NAME_MAX_LENGTH in ShGetInfo, below.
size_t maxMappedNameLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); size_t maxMappedNameLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
ASSERT(checkMappedNameMaxLength(handle, maxMappedNameLength)); ASSERT(checkMappedNameMaxLength(handle, maxMappedNameLength));
strncpy(mappedName, varInfo.mappedName.c_str(), maxMappedNameLength); strncpy(mappedName, varInfo->mappedName.c_str(), maxMappedNameLength);
mappedName[maxMappedNameLength - 1] = 0; mappedName[maxMappedNameLength - 1] = 0;
} }
} }
...@@ -434,10 +466,10 @@ int ShCheckVariablesWithinPackingLimits( ...@@ -434,10 +466,10 @@ int ShCheckVariablesWithinPackingLimits(
if (varInfoArraySize == 0) if (varInfoArraySize == 0)
return 1; return 1;
ASSERT(varInfoArray); ASSERT(varInfoArray);
TVariableInfoList variables; std::vector<sh::ShaderVariable> variables;
for (size_t ii = 0; ii < varInfoArraySize; ++ii) for (size_t ii = 0; ii < varInfoArraySize; ++ii)
{ {
TVariableInfo var(varInfoArray[ii].type, varInfoArray[ii].size); sh::ShaderVariable var(varInfoArray[ii].type, (sh::GLenum)0, "", varInfoArray[ii].size);
variables.push_back(var); variables.push_back(var);
} }
VariablePacker packer; VariablePacker packer;
......
...@@ -8,44 +8,32 @@ ...@@ -8,44 +8,32 @@
#define COMPILER_VARIABLE_INFO_H_ #define COMPILER_VARIABLE_INFO_H_
#include "compiler/translator/intermediate.h" #include "compiler/translator/intermediate.h"
#include "common/shadervars.h"
// Provides information about a variable.
// It is currently being used to store info about active attribs and uniforms.
struct TVariableInfo {
TVariableInfo(sh::GLenum type, int size);
TVariableInfo();
TPersistString name;
TPersistString mappedName;
sh::GLenum type;
int size;
bool isArray;
TPrecision precision;
bool staticUse;
};
typedef std::vector<TVariableInfo> TVariableInfoList;
// Traverses intermediate tree to collect all attributes, uniforms, varyings. // Traverses intermediate tree to collect all attributes, uniforms, varyings.
class CollectVariables : public TIntermTraverser { class CollectVariables : public TIntermTraverser {
public: public:
CollectVariables(TVariableInfoList& attribs, CollectVariables(std::vector<sh::Attribute> *attribs,
TVariableInfoList& uniforms, std::vector<sh::Uniform> *uniforms,
TVariableInfoList& varyings, std::vector<sh::Varying> *varyings,
ShHashFunction64 hashFunction); ShHashFunction64 hashFunction);
virtual void visitSymbol(TIntermSymbol*); virtual void visitSymbol(TIntermSymbol*);
virtual bool visitAggregate(Visit, TIntermAggregate*); virtual bool visitAggregate(Visit, TIntermAggregate*);
private: private:
TVariableInfoList& mAttribs; std::vector<sh::Attribute> *mAttribs;
TVariableInfoList& mUniforms; std::vector<sh::Uniform> *mUniforms;
TVariableInfoList& mVaryings; std::vector<sh::Varying> *mVaryings;
bool mPointCoordAdded; bool mPointCoordAdded;
bool mFrontFacingAdded; bool mFrontFacingAdded;
bool mFragCoordAdded; bool mFragCoordAdded;
ShHashFunction64 mHashFunction; ShHashFunction64 mHashFunction;
template <typename VarT>
void visitInfoList(const TIntermSequence& sequence, std::vector<VarT> *infoList) const;
}; };
#endif // COMPILER_VARIABLE_INFO_H_ #endif // COMPILER_VARIABLE_INFO_H_
...@@ -67,7 +67,7 @@ int VariablePacker::GetNumRows(sh::GLenum type) ...@@ -67,7 +67,7 @@ int VariablePacker::GetNumRows(sh::GLenum type)
struct TVariableInfoComparer struct TVariableInfoComparer
{ {
bool operator()(const TVariableInfo& lhs, const TVariableInfo& rhs) const bool operator()(const sh::ShaderVariable &lhs, const sh::ShaderVariable &rhs) const
{ {
int lhsSortOrder = gl::VariableSortOrder(lhs.type); int lhsSortOrder = gl::VariableSortOrder(lhs.type);
int rhsSortOrder = gl::VariableSortOrder(rhs.type); int rhsSortOrder = gl::VariableSortOrder(rhs.type);
...@@ -75,7 +75,7 @@ struct TVariableInfoComparer ...@@ -75,7 +75,7 @@ struct TVariableInfoComparer
return lhsSortOrder < rhsSortOrder; return lhsSortOrder < rhsSortOrder;
} }
// Sort by largest first. // Sort by largest first.
return lhs.size > rhs.size; return lhs.arraySize > rhs.arraySize;
} }
}; };
...@@ -146,18 +146,20 @@ bool VariablePacker::searchColumn(int column, int numRows, int* destRow, int* de ...@@ -146,18 +146,20 @@ bool VariablePacker::searchColumn(int column, int numRows, int* destRow, int* de
return true; return true;
} }
bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVariableInfoList& in_variables) template <typename VarT>
bool VariablePacker::CheckVariablesWithinPackingLimits(unsigned int maxVectors,
const std::vector<VarT> &in_variables)
{ {
ASSERT(maxVectors > 0); ASSERT(maxVectors > 0);
maxRows_ = maxVectors; maxRows_ = maxVectors;
topNonFullRow_ = 0; topNonFullRow_ = 0;
bottomNonFullRow_ = maxRows_ - 1; bottomNonFullRow_ = maxRows_ - 1;
TVariableInfoList variables(in_variables); std::vector<VarT> variables(in_variables);
// Check whether each variable fits in the available vectors. // Check whether each variable fits in the available vectors.
for (size_t i = 0; i < variables.size(); i++) { for (size_t i = 0; i < variables.size(); i++) {
const TVariableInfo& variable = variables[i]; const sh::ShaderVariable &variable = variables[i];
if (variable.size > maxVectors / GetNumRows(variable.type)) { if (variable.elementCount() > maxVectors / GetNumRows(variable.type)) {
return false; return false;
} }
} }
...@@ -171,11 +173,11 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa ...@@ -171,11 +173,11 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa
// Packs the 4 column variables. // Packs the 4 column variables.
size_t ii = 0; size_t ii = 0;
for (; ii < variables.size(); ++ii) { for (; ii < variables.size(); ++ii) {
const TVariableInfo& variable = variables[ii]; const sh::ShaderVariable &variable = variables[ii];
if (GetNumComponentsPerRow(variable.type) != 4) { if (GetNumComponentsPerRow(variable.type) != 4) {
break; break;
} }
topNonFullRow_ += GetNumRows(variable.type) * variable.size; topNonFullRow_ += GetNumRows(variable.type) * variable.elementCount();
} }
if (topNonFullRow_ > maxRows_) { if (topNonFullRow_ > maxRows_) {
...@@ -185,11 +187,11 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa ...@@ -185,11 +187,11 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa
// Packs the 3 column variables. // Packs the 3 column variables.
int num3ColumnRows = 0; int num3ColumnRows = 0;
for (; ii < variables.size(); ++ii) { for (; ii < variables.size(); ++ii) {
const TVariableInfo& variable = variables[ii]; const sh::ShaderVariable &variable = variables[ii];
if (GetNumComponentsPerRow(variable.type) != 3) { if (GetNumComponentsPerRow(variable.type) != 3) {
break; break;
} }
num3ColumnRows += GetNumRows(variable.type) * variable.size; num3ColumnRows += GetNumRows(variable.type) * variable.elementCount();
} }
if (topNonFullRow_ + num3ColumnRows > maxRows_) { if (topNonFullRow_ + num3ColumnRows > maxRows_) {
...@@ -204,11 +206,11 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa ...@@ -204,11 +206,11 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa
int rowsAvailableInColumns01 = twoColumnRowsAvailable; int rowsAvailableInColumns01 = twoColumnRowsAvailable;
int rowsAvailableInColumns23 = twoColumnRowsAvailable; int rowsAvailableInColumns23 = twoColumnRowsAvailable;
for (; ii < variables.size(); ++ii) { for (; ii < variables.size(); ++ii) {
const TVariableInfo& variable = variables[ii]; const sh::ShaderVariable &variable = variables[ii];
if (GetNumComponentsPerRow(variable.type) != 2) { if (GetNumComponentsPerRow(variable.type) != 2) {
break; break;
} }
int numRows = GetNumRows(variable.type) * variable.size; int numRows = GetNumRows(variable.type) * variable.elementCount();
if (numRows <= rowsAvailableInColumns01) { if (numRows <= rowsAvailableInColumns01) {
rowsAvailableInColumns01 -= numRows; rowsAvailableInColumns01 -= numRows;
} else if (numRows <= rowsAvailableInColumns23) { } else if (numRows <= rowsAvailableInColumns23) {
...@@ -228,9 +230,9 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa ...@@ -228,9 +230,9 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa
// Packs the 1 column variables. // Packs the 1 column variables.
for (; ii < variables.size(); ++ii) { for (; ii < variables.size(); ++ii) {
const TVariableInfo& variable = variables[ii]; const sh::ShaderVariable &variable = variables[ii];
ASSERT(1 == GetNumComponentsPerRow(variable.type)); ASSERT(1 == GetNumComponentsPerRow(variable.type));
int numRows = GetNumRows(variable.type) * variable.size; int numRows = GetNumRows(variable.type) * variable.elementCount();
int smallestColumn = -1; int smallestColumn = -1;
int smallestSize = maxRows_ + 1; int smallestSize = maxRows_ + 1;
int topRow = -1; int topRow = -1;
...@@ -258,5 +260,8 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa ...@@ -258,5 +260,8 @@ bool VariablePacker::CheckVariablesWithinPackingLimits(int maxVectors, const TVa
return true; return true;
} }
// Instantiate all possible variable packings
template bool VariablePacker::CheckVariablesWithinPackingLimits(unsigned int, const std::vector<sh::ShaderVariable> &);
template bool VariablePacker::CheckVariablesWithinPackingLimits(unsigned int, const std::vector<sh::Attribute> &);
template bool VariablePacker::CheckVariablesWithinPackingLimits(unsigned int, const std::vector<sh::Uniform> &);
template bool VariablePacker::CheckVariablesWithinPackingLimits(unsigned int, const std::vector<sh::Varying> &);
...@@ -14,9 +14,9 @@ class VariablePacker { ...@@ -14,9 +14,9 @@ class VariablePacker {
public: public:
// Returns true if the passed in variables pack in maxVectors following // Returns true if the passed in variables pack in maxVectors following
// the packing rules from the GLSL 1.017 spec, Appendix A, section 7. // the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
bool CheckVariablesWithinPackingLimits( template <typename VarT>
int maxVectors, bool CheckVariablesWithinPackingLimits(unsigned int maxVectors,
const TVariableInfoList& in_variables); const std::vector<VarT> &in_variables);
// Gets how many components in a row a data type takes. // Gets how many components in a row a data type takes.
static int GetNumComponentsPerRow(sh::GLenum type); static int GetNumComponentsPerRow(sh::GLenum type);
......
...@@ -170,15 +170,15 @@ GLenum GLVariablePrecision(const TType &type) ...@@ -170,15 +170,15 @@ GLenum GLVariablePrecision(const TType &type)
{ {
switch (type.getPrecision()) switch (type.getPrecision())
{ {
case EbpHigh: case EbpHigh:
return GL_HIGH_FLOAT; return GL_HIGH_FLOAT;
case EbpMedium: case EbpMedium:
return GL_MEDIUM_FLOAT; return GL_MEDIUM_FLOAT;
case EbpLow: case EbpLow:
return GL_LOW_FLOAT; return GL_LOW_FLOAT;
case EbpUndefined: case EbpUndefined:
// Should be defined as the default precision by the parser // Should be defined as the default precision by the parser
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
......
...@@ -63,9 +63,14 @@ static sh::GLenum nonSqMatTypes[] = { ...@@ -63,9 +63,14 @@ static sh::GLenum nonSqMatTypes[] = {
GL_FLOAT_MAT4x3 GL_FLOAT_MAT4x3
}; };
static sh::ShaderVariable SimpleVar(GLenum type, unsigned int size)
{
return sh::ShaderVariable(type, GL_NONE, "", size == 1 ? 0 : size);
}
TEST(VariablePacking, Pack) { TEST(VariablePacking, Pack) {
VariablePacker packer; VariablePacker packer;
TVariableInfoList vars; std::vector<sh::ShaderVariable> vars;
const int kMaxRows = 16; const int kMaxRows = 16;
// test no vars. // test no vars.
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
...@@ -76,18 +81,18 @@ TEST(VariablePacking, Pack) { ...@@ -76,18 +81,18 @@ TEST(VariablePacking, Pack) {
int num_components_per_row = VariablePacker::GetNumComponentsPerRow(type); int num_components_per_row = VariablePacker::GetNumComponentsPerRow(type);
// Check 1 of the type. // Check 1 of the type.
vars.clear(); vars.clear();
vars.push_back(TVariableInfo(type, 1)); vars.push_back(SimpleVar(type, 1));
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
// Check exactly the right amount of 1 type as an array. // Check exactly the right amount of 1 type as an array.
int num_vars = kMaxRows / num_rows; int num_vars = kMaxRows / num_rows;
vars.clear(); vars.clear();
vars.push_back(TVariableInfo(type, num_vars)); vars.push_back(SimpleVar(type, num_vars));
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
// test too many // test too many
vars.clear(); vars.clear();
vars.push_back(TVariableInfo(type, num_vars + 1)); vars.push_back(SimpleVar(type, num_vars + 1));
EXPECT_FALSE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_FALSE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
// Check exactly the right amount of 1 type as individual vars. // Check exactly the right amount of 1 type as individual vars.
...@@ -95,26 +100,26 @@ TEST(VariablePacking, Pack) { ...@@ -95,26 +100,26 @@ TEST(VariablePacking, Pack) {
((num_components_per_row > 2) ? 1 : (4 / num_components_per_row)); ((num_components_per_row > 2) ? 1 : (4 / num_components_per_row));
vars.clear(); vars.clear();
for (int ii = 0; ii < num_vars; ++ii) { for (int ii = 0; ii < num_vars; ++ii) {
vars.push_back(TVariableInfo(type, 1)); vars.push_back(SimpleVar(type, 1));
} }
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
// Check 1 too many. // Check 1 too many.
vars.push_back(TVariableInfo( type, 1)); vars.push_back(SimpleVar(type, 1));
EXPECT_FALSE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_FALSE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
} }
// Test example from GLSL ES 3.0 spec chapter 11. // Test example from GLSL ES 3.0 spec chapter 11.
vars.clear(); vars.clear();
vars.push_back(TVariableInfo(GL_FLOAT_VEC4, 1)); vars.push_back(SimpleVar(GL_FLOAT_VEC4, 1));
vars.push_back(TVariableInfo(GL_FLOAT_MAT3, 1)); vars.push_back(SimpleVar(GL_FLOAT_MAT3, 1));
vars.push_back(TVariableInfo(GL_FLOAT_MAT3, 1)); vars.push_back(SimpleVar(GL_FLOAT_MAT3, 1));
vars.push_back(TVariableInfo(GL_FLOAT_VEC2, 6)); vars.push_back(SimpleVar(GL_FLOAT_VEC2, 6));
vars.push_back(TVariableInfo(GL_FLOAT_VEC2, 4)); vars.push_back(SimpleVar(GL_FLOAT_VEC2, 4));
vars.push_back(TVariableInfo(GL_FLOAT_VEC2, 1)); vars.push_back(SimpleVar(GL_FLOAT_VEC2, 1));
vars.push_back(TVariableInfo(GL_FLOAT, 3)); vars.push_back(SimpleVar(GL_FLOAT, 3));
vars.push_back(TVariableInfo(GL_FLOAT, 2)); vars.push_back(SimpleVar(GL_FLOAT, 2));
vars.push_back(TVariableInfo(GL_FLOAT, 1)); vars.push_back(SimpleVar(GL_FLOAT, 1));
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars)); EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(kMaxRows, vars));
} }
...@@ -151,13 +156,13 @@ TEST(VariablePacking, NonSquareMats) { ...@@ -151,13 +156,13 @@ TEST(VariablePacking, NonSquareMats) {
int cols = gl::VariableColumnCount(type); int cols = gl::VariableColumnCount(type);
int squareSize = std::max(rows, cols); int squareSize = std::max(rows, cols);
TVariableInfoList vars; std::vector<sh::ShaderVariable> vars;
vars.push_back(TVariableInfo(type, 1)); vars.push_back(SimpleVar(type, 1));
// Fill columns // Fill columns
for (int row = 0; row < squareSize; row++) { for (int row = 0; row < squareSize; row++) {
for (int col = squareSize; col < 4; ++col) { for (int col = squareSize; col < 4; ++col) {
vars.push_back(TVariableInfo(GL_FLOAT, 1)); vars.push_back(SimpleVar(GL_FLOAT, 1));
} }
} }
...@@ -166,7 +171,7 @@ TEST(VariablePacking, NonSquareMats) { ...@@ -166,7 +171,7 @@ TEST(VariablePacking, NonSquareMats) {
EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(squareSize, vars)); EXPECT_TRUE(packer.CheckVariablesWithinPackingLimits(squareSize, vars));
// and one scalar and packing should fail // and one scalar and packing should fail
vars.push_back(TVariableInfo(GL_FLOAT, 1)); vars.push_back(SimpleVar(GL_FLOAT, 1));
EXPECT_FALSE(packer.CheckVariablesWithinPackingLimits(squareSize, vars)); 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