Commit 4e1fd412 by Jamie Madill

Store a map of interface block registers.

The shader translator can return the assigned register for a block via a new API. This will let us delete the member variable in interface blocks for the register -- a nice thing for GLSL. BUG=angle:466 Change-Id: I9bc38e0cd031e32f90787be42c2324fc7c79dbf9 Reviewed-on: https://chromium-review.googlesource.com/206828Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 829e89ef
...@@ -43,7 +43,7 @@ extern "C" { ...@@ -43,7 +43,7 @@ extern "C" {
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented every time the API changes. // It is incremented every time the API changes.
#define ANGLE_SH_VERSION 126 #define ANGLE_SH_VERSION 127
typedef enum { typedef enum {
SH_GLES2_SPEC = 0x8B40, SH_GLES2_SPEC = 0x8B40,
...@@ -480,6 +480,17 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits( ...@@ -480,6 +480,17 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
ShVariableInfo* varInfoArray, ShVariableInfo* varInfoArray,
size_t varInfoArraySize); size_t varInfoArraySize);
// Gives the compiler-assigned register for an interface block.
// The method writes the value to the output variable "indexOut".
// Returns true if it found a valid interface block, false otherwise.
// Parameters:
// handle: Specifies the compiler
// interfaceBlockName: Specifies the interface block
// indexOut: output variable that stores the assigned register
COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
const char *interfaceBlockName,
unsigned int *indexOut);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -237,6 +237,11 @@ const std::vector<sh::Varying> &OutputHLSL::getVaryings() const ...@@ -237,6 +237,11 @@ const std::vector<sh::Varying> &OutputHLSL::getVaryings() const
return mActiveVaryings; return mActiveVaryings;
} }
const std::map<std::string, unsigned int> &OutputHLSL::getInterfaceBlockRegisterMap() const
{
return mUniformHLSL->getInterfaceBlockRegisterMap();
}
int OutputHLSL::vectorSize(const TType &type) const int OutputHLSL::vectorSize(const TType &type) const
{ {
int elementSize = type.isMatrix() ? type.getCols() : 1; int elementSize = type.isMatrix() ? type.getCols() : 1;
......
...@@ -39,6 +39,8 @@ class OutputHLSL : public TIntermTraverser ...@@ -39,6 +39,8 @@ class OutputHLSL : public TIntermTraverser
const std::vector<sh::Attribute> &getAttributes() const; const std::vector<sh::Attribute> &getAttributes() const;
const std::vector<sh::Varying> &getVaryings() const; const std::vector<sh::Varying> &getVaryings() const;
const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const;
static TString initializer(const TType &type); static TString initializer(const TType &type);
protected: protected:
......
...@@ -474,3 +474,28 @@ int ShCheckVariablesWithinPackingLimits( ...@@ -474,3 +474,28 @@ int ShCheckVariablesWithinPackingLimits(
VariablePacker packer; VariablePacker packer;
return packer.CheckVariablesWithinPackingLimits(maxVectors, variables) ? 1 : 0; return packer.CheckVariablesWithinPackingLimits(maxVectors, variables) ? 1 : 0;
} }
bool ShGetInterfaceBlockRegister(const ShHandle handle,
const char *interfaceBlockName,
unsigned int *indexOut)
{
if (!handle || !interfaceBlockName || !indexOut)
{
return false;
}
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TranslatorHLSL* translator = base->getAsTranslatorHLSL();
if (!translator)
{
return false;
}
if (!translator->hasInterfaceBlock(interfaceBlockName))
{
return false;
}
*indexOut = translator->getInterfaceBlockRegister(interfaceBlockName);
return true;
}
...@@ -26,4 +26,17 @@ void TranslatorHLSL::translate(TIntermNode *root) ...@@ -26,4 +26,17 @@ void TranslatorHLSL::translate(TIntermNode *root)
uniforms = outputHLSL.getUniforms(); uniforms = outputHLSL.getUniforms();
varyings = outputHLSL.getVaryings(); varyings = outputHLSL.getVaryings();
interfaceBlocks = outputHLSL.getInterfaceBlocks(); interfaceBlocks = outputHLSL.getInterfaceBlocks();
mInterfaceBlockRegisterMap = outputHLSL.getInterfaceBlockRegisterMap();
}
bool TranslatorHLSL::hasInterfaceBlock(const std::string &interfaceBlockName) const
{
return (mInterfaceBlockRegisterMap.count(interfaceBlockName) > 0);
}
unsigned int TranslatorHLSL::getInterfaceBlockRegister(const std::string &interfaceBlockName) const
{
ASSERT(hasInterfaceBlock(interfaceBlockName));
return mInterfaceBlockRegisterMap.find(interfaceBlockName)->second;
} }
...@@ -16,8 +16,13 @@ class TranslatorHLSL : public TCompiler ...@@ -16,8 +16,13 @@ class TranslatorHLSL : public TCompiler
TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output); TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; } virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; }
bool hasInterfaceBlock(const std::string &interfaceBlockName) const;
unsigned int getInterfaceBlockRegister(const std::string &interfaceBlockName) const;
protected: protected:
virtual void translate(TIntermNode* root); virtual void translate(TIntermNode* root);
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
}; };
#endif // COMPILER_TRANSLATORHLSL_H_ #endif // COMPILER_TRANSLATORHLSL_H_
...@@ -236,6 +236,7 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn ...@@ -236,6 +236,7 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
traverser.traverse(*field.type(), fullFieldName); traverser.traverse(*field.type(), fullFieldName);
} }
mInterfaceBlockRegisterMap[activeBlock.name] = mInterfaceBlockRegister;
mInterfaceBlockRegister += std::max(1u, arraySize); mInterfaceBlockRegister += std::max(1u, arraySize);
BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage()); BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage());
......
...@@ -32,6 +32,10 @@ class UniformHLSL ...@@ -32,6 +32,10 @@ class UniformHLSL
const std::vector<Uniform> &getUniforms() const { return mActiveUniforms; } const std::vector<Uniform> &getUniforms() const { return mActiveUniforms; }
const std::vector<InterfaceBlock> &getInterfaceBlocks() const { return mActiveInterfaceBlocks; } const std::vector<InterfaceBlock> &getInterfaceBlocks() const { return mActiveInterfaceBlocks; }
const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const
{
return mInterfaceBlockRegisterMap;
}
private: private:
TString interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex); TString interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex);
...@@ -50,6 +54,7 @@ class UniformHLSL ...@@ -50,6 +54,7 @@ class UniformHLSL
std::vector<Uniform> mActiveUniforms; std::vector<Uniform> mActiveUniforms;
std::vector<InterfaceBlock> mActiveInterfaceBlocks; std::vector<InterfaceBlock> mActiveInterfaceBlocks;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
}; };
} }
......
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