Commit 23a8a433 by Jamie Madill

Store compact and expanded shader variables.

The current shader API ShGetVariableInfo relies on an expanded list of shader variables. That means that struct, or user-defined variables, are expanded into separate entries for the app to easily query struct members. The new API will preserve the struct layout, so we can store both to support both the old and new queries. BUG=angle:466 Change-Id: Id30a1d7d1bb49c7e745510e0d699f94ad3184b9c Reviewed-on: https://chromium-review.googlesource.com/206569Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent aae65a4e
...@@ -360,7 +360,9 @@ void TCompiler::clearResults() ...@@ -360,7 +360,9 @@ void TCompiler::clearResults()
attributes.clear(); attributes.clear();
outputVariables.clear(); outputVariables.clear();
uniforms.clear(); uniforms.clear();
expandedUniforms.clear();
varyings.clear(); varyings.clear();
expandedVaryings.clear();
interfaceBlocks.clear(); interfaceBlocks.clear();
builtInFunctionEmulator.Cleanup(); builtInFunctionEmulator.Cleanup();
...@@ -487,12 +489,17 @@ void TCompiler::collectVariables(TIntermNode* root) ...@@ -487,12 +489,17 @@ void TCompiler::collectVariables(TIntermNode* root)
{ {
CollectVariables collect(&attributes, &uniforms, &varyings, hashFunction); CollectVariables collect(&attributes, &uniforms, &varyings, hashFunction);
root->traverse(&collect); root->traverse(&collect);
// For backwards compatiblity with ShGetVariableInfo, expand struct
// uniforms and varyings into separate variables for each field.
ExpandVariables(uniforms, &expandedUniforms);
ExpandVariables(varyings, &expandedVaryings);
} }
bool TCompiler::enforcePackingRestrictions() bool TCompiler::enforcePackingRestrictions()
{ {
VariablePacker packer; VariablePacker packer;
return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, uniforms); return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms);
} }
void TCompiler::initializeGLPosition(TIntermNode* root) void TCompiler::initializeGLPosition(TIntermNode* root)
......
...@@ -71,7 +71,9 @@ class TCompiler : public TShHandleBase ...@@ -71,7 +71,9 @@ class TCompiler : public TShHandleBase
const std::vector<sh::Attribute> &getAttributes() const { return attributes; } const std::vector<sh::Attribute> &getAttributes() const { return attributes; }
const std::vector<sh::Attribute> &getOutputVariables() const { return outputVariables; } const std::vector<sh::Attribute> &getOutputVariables() const { return outputVariables; }
const std::vector<sh::Uniform> &getUniforms() const { return uniforms; } const std::vector<sh::Uniform> &getUniforms() const { return uniforms; }
const std::vector<sh::Uniform> &getExpandedUniforms() const { return expandedUniforms; }
const std::vector<sh::Varying> &getVaryings() const { return varyings; } const std::vector<sh::Varying> &getVaryings() const { return varyings; }
const std::vector<sh::Varying> &getExpandedVaryings() const { return expandedVaryings; }
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return interfaceBlocks; } const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return interfaceBlocks; }
ShHashFunction64 getHashFunction() const { return hashFunction; } ShHashFunction64 getHashFunction() const { return hashFunction; }
...@@ -136,7 +138,9 @@ class TCompiler : public TShHandleBase ...@@ -136,7 +138,9 @@ class TCompiler : public TShHandleBase
std::vector<sh::Attribute> attributes; std::vector<sh::Attribute> attributes;
std::vector<sh::Attribute> outputVariables; std::vector<sh::Attribute> outputVariables;
std::vector<sh::Uniform> uniforms; std::vector<sh::Uniform> uniforms;
std::vector<sh::Uniform> expandedUniforms;
std::vector<sh::Varying> varyings; std::vector<sh::Varying> varyings;
std::vector<sh::Varying> expandedVaryings;
std::vector<sh::InterfaceBlock> interfaceBlocks; std::vector<sh::InterfaceBlock> interfaceBlocks;
private: private:
......
...@@ -64,9 +64,9 @@ static const sh::ShaderVariable *GetVariable(const TCompiler *compiler, ShShader ...@@ -64,9 +64,9 @@ static const sh::ShaderVariable *GetVariable(const TCompiler *compiler, ShShader
case SH_ACTIVE_ATTRIBUTES: case SH_ACTIVE_ATTRIBUTES:
return ReturnVariable(compiler->getAttributes(), index); return ReturnVariable(compiler->getAttributes(), index);
case SH_ACTIVE_UNIFORMS: case SH_ACTIVE_UNIFORMS:
return ReturnVariable(compiler->getUniforms(), index); return ReturnVariable(compiler->getExpandedUniforms(), index);
case SH_VARYINGS: case SH_VARYINGS:
return ReturnVariable(compiler->getVaryings(), index); return ReturnVariable(compiler->getExpandedVaryings(), index);
default: default:
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
...@@ -250,7 +250,7 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params) ...@@ -250,7 +250,7 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
*params = compiler->getInfoSink().obj.size() + 1; *params = compiler->getInfoSink().obj.size() + 1;
break; break;
case SH_ACTIVE_UNIFORMS: case SH_ACTIVE_UNIFORMS:
*params = compiler->getUniforms().size(); *params = compiler->getExpandedUniforms().size();
break; break;
case SH_ACTIVE_UNIFORM_MAX_LENGTH: case SH_ACTIVE_UNIFORM_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
...@@ -262,7 +262,7 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params) ...@@ -262,7 +262,7 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break; break;
case SH_VARYINGS: case SH_VARYINGS:
*params = compiler->getVaryings().size(); *params = compiler->getExpandedVaryings().size();
break; break;
case SH_VARYING_MAX_LENGTH: case SH_VARYING_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec()); *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
......
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
#include "common/shadervars.h" #include "common/shadervars.h"
// 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(std::vector<sh::Attribute> *attribs, CollectVariables(std::vector<sh::Attribute> *attribs,
std::vector<sh::Uniform> *uniforms, std::vector<sh::Uniform> *uniforms,
std::vector<sh::Varying> *varyings, std::vector<sh::Varying> *varyings,
...@@ -21,7 +22,7 @@ public: ...@@ -21,7 +22,7 @@ public:
virtual void visitSymbol(TIntermSymbol *symbol); virtual void visitSymbol(TIntermSymbol *symbol);
virtual bool visitAggregate(Visit, TIntermAggregate *node); virtual bool visitAggregate(Visit, TIntermAggregate *node);
private: private:
std::vector<sh::Attribute> *mAttribs; std::vector<sh::Attribute> *mAttribs;
std::vector<sh::Uniform> *mUniforms; std::vector<sh::Uniform> *mUniforms;
std::vector<sh::Varying> *mVaryings; std::vector<sh::Varying> *mVaryings;
...@@ -39,4 +40,9 @@ private: ...@@ -39,4 +40,9 @@ private:
void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const; void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const;
}; };
// Expand struct variables to flattened lists of split variables
// Implemented for sh::Varying and sh::Uniform.
template <typename VarT>
void ExpandVariables(const std::vector<VarT> &compact, std::vector<VarT> *expanded);
#endif // COMPILER_VARIABLE_INFO_H_ #endif // COMPILER_VARIABLE_INFO_H_
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