Commit d4116ff3 by Jamie Madill

Remove sh::InterfaceBlock::registerIndex.

This value is HLSL-only and we can use the new query API to hide it from GLSL programs. BUG=angle:466 Change-Id: I75dc2fbbf1b29b1f6d561568174a15dea1f5b130 Reviewed-on: https://chromium-review.googlesource.com/207250Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent f47bebc4
...@@ -165,18 +165,16 @@ struct InterfaceBlock ...@@ -165,18 +165,16 @@ struct InterfaceBlock
dataSize(0), dataSize(0),
layout(BLOCKLAYOUT_PACKED), layout(BLOCKLAYOUT_PACKED),
isRowMajorLayout(false), isRowMajorLayout(false),
staticUse(false), staticUse(false)
registerIndex(-1)
{} {}
InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex) InterfaceBlock(const char *name, unsigned int arraySize)
: name(name), : name(name),
arraySize(arraySize), arraySize(arraySize),
dataSize(0), dataSize(0),
layout(BLOCKLAYOUT_SHARED), layout(BLOCKLAYOUT_SHARED),
isRowMajorLayout(false), isRowMajorLayout(false),
staticUse(false), staticUse(false)
registerIndex(registerIndex)
{} {}
std::string name; std::string name;
...@@ -188,9 +186,6 @@ struct InterfaceBlock ...@@ -188,9 +186,6 @@ struct InterfaceBlock
bool staticUse; bool staticUse;
std::vector<InterfaceBlockField> fields; std::vector<InterfaceBlockField> fields;
std::vector<BlockMemberInfo> blockInfo; std::vector<BlockMemberInfo> blockInfo;
// HLSL-specific members
unsigned int registerIndex;
}; };
} }
......
...@@ -225,7 +225,9 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn ...@@ -225,7 +225,9 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
const TFieldList &fieldList = interfaceBlock.fields(); const TFieldList &fieldList = interfaceBlock.fields();
unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize()); unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize());
InterfaceBlock activeBlock(interfaceBlock.name().c_str(), arraySize, mInterfaceBlockRegister); unsigned int activeRegister = mInterfaceBlockRegister;
InterfaceBlock activeBlock(interfaceBlock.name().c_str(), arraySize);
for (unsigned int typeIndex = 0; typeIndex < fieldList.size(); typeIndex++) for (unsigned int typeIndex = 0; typeIndex < fieldList.size(); typeIndex++)
{ {
const TField &field = *fieldList[typeIndex]; const TField &field = *fieldList[typeIndex];
...@@ -236,7 +238,7 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn ...@@ -236,7 +238,7 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
traverser.traverse(*field.type(), fullFieldName); traverser.traverse(*field.type(), fullFieldName);
} }
mInterfaceBlockRegisterMap[activeBlock.name] = mInterfaceBlockRegister; mInterfaceBlockRegisterMap[activeBlock.name] = activeRegister;
mInterfaceBlockRegister += std::max(1u, arraySize); mInterfaceBlockRegister += std::max(1u, arraySize);
BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage()); BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage());
...@@ -258,12 +260,12 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn ...@@ -258,12 +260,12 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
{ {
for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++)
{ {
interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex + arrayIndex, arrayIndex); interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex);
} }
} }
else else
{ {
interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex, GL_INVALID_INDEX); interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX);
} }
} }
......
...@@ -1631,7 +1631,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin ...@@ -1631,7 +1631,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, sh::BlockMemberInfo::getDefaultBlockInfo())); mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, sh::BlockMemberInfo::getDefaultBlockInfo()));
} }
if (!linkUniformBlocks(infoLog, vertexShader->getInterfaceBlocks(), fragmentShader->getInterfaceBlocks())) if (!linkUniformBlocks(infoLog, *vertexShader, *fragmentShader))
{ {
success = false; success = false;
} }
...@@ -2151,9 +2151,12 @@ bool ProgramBinary::areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::Inter ...@@ -2151,9 +2151,12 @@ bool ProgramBinary::areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::Inter
return true; return true;
} }
bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks, bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const VertexShader &vertexShader,
const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks) const FragmentShader &fragmentShader)
{ {
const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks = vertexShader.getInterfaceBlocks();
const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks = fragmentShader.getInterfaceBlocks();
// Check that interface blocks defined in the vertex and fragment shaders are identical // Check that interface blocks defined in the vertex and fragment shaders are identical
typedef std::map<std::string, const sh::InterfaceBlock*> UniformBlockMap; typedef std::map<std::string, const sh::InterfaceBlock*> UniformBlockMap;
UniformBlockMap linkedUniformBlocks; UniformBlockMap linkedUniformBlocks;
...@@ -2180,7 +2183,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::In ...@@ -2180,7 +2183,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::In
for (unsigned int blockIndex = 0; blockIndex < vertexInterfaceBlocks.size(); blockIndex++) for (unsigned int blockIndex = 0; blockIndex < vertexInterfaceBlocks.size(); blockIndex++)
{ {
if (!defineUniformBlock(infoLog, GL_VERTEX_SHADER, vertexInterfaceBlocks[blockIndex])) if (!defineUniformBlock(infoLog, vertexShader, vertexInterfaceBlocks[blockIndex]))
{ {
return false; return false;
} }
...@@ -2188,7 +2191,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::In ...@@ -2188,7 +2191,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::In
for (unsigned int blockIndex = 0; blockIndex < fragmentInterfaceBlocks.size(); blockIndex++) for (unsigned int blockIndex = 0; blockIndex < fragmentInterfaceBlocks.size(); blockIndex++)
{ {
if (!defineUniformBlock(infoLog, GL_FRAGMENT_SHADER, fragmentInterfaceBlocks[blockIndex])) if (!defineUniformBlock(infoLog, fragmentShader, fragmentInterfaceBlocks[blockIndex]))
{ {
return false; return false;
} }
...@@ -2290,7 +2293,7 @@ void ProgramBinary::defineUniformBlockMembers(const std::vector<sh::InterfaceBlo ...@@ -2290,7 +2293,7 @@ void ProgramBinary::defineUniformBlockMembers(const std::vector<sh::InterfaceBlo
} }
} }
bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, GLenum shader, const sh::InterfaceBlock &interfaceBlock) bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, const Shader &shader, const sh::InterfaceBlock &interfaceBlock)
{ {
// create uniform block entries if they do not exist // create uniform block entries if they do not exist
if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX) if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX)
...@@ -2326,12 +2329,15 @@ bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, GLenum shader, const sh ...@@ -2326,12 +2329,15 @@ bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, GLenum shader, const sh
ASSERT(blockIndex != GL_INVALID_INDEX); ASSERT(blockIndex != GL_INVALID_INDEX);
ASSERT(blockIndex + elementCount <= mUniformBlocks.size()); ASSERT(blockIndex + elementCount <= mUniformBlocks.size());
unsigned int interfaceBlockRegister = shader.getInterfaceBlockRegister(interfaceBlock.name);
for (unsigned int uniformBlockElement = 0; uniformBlockElement < elementCount; uniformBlockElement++) for (unsigned int uniformBlockElement = 0; uniformBlockElement < elementCount; uniformBlockElement++)
{ {
UniformBlock *uniformBlock = mUniformBlocks[blockIndex + uniformBlockElement]; UniformBlock *uniformBlock = mUniformBlocks[blockIndex + uniformBlockElement];
ASSERT(uniformBlock->name == interfaceBlock.name); ASSERT(uniformBlock->name == interfaceBlock.name);
if (!assignUniformBlockRegister(infoLog, uniformBlock, shader, interfaceBlock.registerIndex + uniformBlockElement)) if (!assignUniformBlockRegister(infoLog, uniformBlock, shader.getType(),
interfaceBlockRegister + uniformBlockElement))
{ {
return false; return false;
} }
......
...@@ -194,13 +194,13 @@ class ProgramBinary : public RefCountObject ...@@ -194,13 +194,13 @@ class ProgramBinary : public RefCountObject
bool linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform> &vertexUniforms, const std::vector<sh::Uniform> &fragmentUniforms); bool linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform> &vertexUniforms, const std::vector<sh::Uniform> &fragmentUniforms);
bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog);
bool areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &fragmentInterfaceBlock); bool areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &fragmentInterfaceBlock);
bool linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::InterfaceBlock> &vertexUniformBlocks, const std::vector<sh::InterfaceBlock> &fragmentUniformBlocks); bool linkUniformBlocks(InfoLog &infoLog, const VertexShader &vertexShader, const FragmentShader &fragmentShader);
bool gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings, bool gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings,
const std::vector<std::string> &transformFeedbackVaryingNames, const std::vector<std::string> &transformFeedbackVaryingNames,
GLenum transformFeedbackBufferMode, GLenum transformFeedbackBufferMode,
std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings) const; std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings) const;
void defineUniformBlockMembers(const std::vector<sh::InterfaceBlockField> &fields, const std::string &prefix, int blockIndex, BlockInfoItr *blockInfoItr, std::vector<unsigned int> *blockUniformIndexes); void defineUniformBlockMembers(const std::vector<sh::InterfaceBlockField> &fields, const std::string &prefix, int blockIndex, BlockInfoItr *blockInfoItr, std::vector<unsigned int> *blockUniformIndexes);
bool defineUniformBlock(InfoLog &infoLog, GLenum shader, const sh::InterfaceBlock &interfaceBlock); bool defineUniformBlock(InfoLog &infoLog, const Shader &shader, const sh::InterfaceBlock &interfaceBlock);
bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex); bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex);
void defineOutputVariables(FragmentShader *fragmentShader); void defineOutputVariables(FragmentShader *fragmentShader);
void initializeUniformStorage(); void initializeUniformStorage();
......
...@@ -115,6 +115,12 @@ void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) ...@@ -115,6 +115,12 @@ void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer)
getSourceImpl(mHlsl, bufSize, length, buffer); getSourceImpl(mHlsl, bufSize, length, buffer);
} }
unsigned int Shader::getInterfaceBlockRegister(const std::string &blockName) const
{
ASSERT(mInterfaceBlockRegisterMap.count(blockName) > 0);
return mInterfaceBlockRegisterMap.find(blockName)->second;
}
const std::vector<sh::Uniform> &Shader::getUniforms() const const std::vector<sh::Uniform> &Shader::getUniforms() const
{ {
return mActiveUniforms; return mActiveUniforms;
...@@ -370,6 +376,18 @@ void Shader::compileToHLSL(void *compiler) ...@@ -370,6 +376,18 @@ void Shader::compileToHLSL(void *compiler)
void *activeInterfaceBlocks; void *activeInterfaceBlocks;
ShGetInfoPointer(compiler, SH_ACTIVE_INTERFACE_BLOCKS_ARRAY, &activeInterfaceBlocks); ShGetInfoPointer(compiler, SH_ACTIVE_INTERFACE_BLOCKS_ARRAY, &activeInterfaceBlocks);
mActiveInterfaceBlocks = *(std::vector<sh::InterfaceBlock>*)activeInterfaceBlocks; mActiveInterfaceBlocks = *(std::vector<sh::InterfaceBlock>*)activeInterfaceBlocks;
for (size_t blockIndex = 0; blockIndex < mActiveInterfaceBlocks.size(); blockIndex++)
{
const sh::InterfaceBlock &interfaceBlock = mActiveInterfaceBlocks[blockIndex];
unsigned int index = -1;
bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name.c_str(), &index);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result);
mInterfaceBlockRegisterMap[interfaceBlock.name] = index;
}
} }
else else
{ {
...@@ -440,7 +458,7 @@ VertexShader::~VertexShader() ...@@ -440,7 +458,7 @@ VertexShader::~VertexShader()
{ {
} }
GLenum VertexShader::getType() GLenum VertexShader::getType() const
{ {
return GL_VERTEX_SHADER; return GL_VERTEX_SHADER;
} }
...@@ -503,7 +521,7 @@ FragmentShader::~FragmentShader() ...@@ -503,7 +521,7 @@ FragmentShader::~FragmentShader()
{ {
} }
GLenum FragmentShader::getType() GLenum FragmentShader::getType() const
{ {
return GL_FRAGMENT_SHADER; return GL_FRAGMENT_SHADER;
} }
......
...@@ -57,7 +57,7 @@ class Shader ...@@ -57,7 +57,7 @@ class Shader
virtual ~Shader(); virtual ~Shader();
virtual GLenum getType() = 0; virtual GLenum getType() const = 0;
GLuint getHandle() const; GLuint getHandle() const;
void deleteSource(); void deleteSource();
...@@ -87,6 +87,7 @@ class Shader ...@@ -87,6 +87,7 @@ class Shader
static void releaseCompiler(); static void releaseCompiler();
static ShShaderOutput getCompilerOutputType(GLenum shader); static ShShaderOutput getCompilerOutputType(GLenum shader);
unsigned int getInterfaceBlockRegister(const std::string &blockName) const;
bool usesDepthRange() const { return mUsesDepthRange; } bool usesDepthRange() const { return mUsesDepthRange; }
bool usesPointSize() const { return mUsesPointSize; } bool usesPointSize() const { return mUsesPointSize; }
...@@ -135,6 +136,7 @@ class Shader ...@@ -135,6 +136,7 @@ class Shader
std::string mInfoLog; std::string mInfoLog;
std::vector<sh::Uniform> mActiveUniforms; std::vector<sh::Uniform> mActiveUniforms;
std::vector<sh::InterfaceBlock> mActiveInterfaceBlocks; std::vector<sh::InterfaceBlock> mActiveInterfaceBlocks;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
ResourceManager *mResourceManager; ResourceManager *mResourceManager;
}; };
...@@ -148,7 +150,7 @@ class VertexShader : public Shader ...@@ -148,7 +150,7 @@ class VertexShader : public Shader
~VertexShader(); ~VertexShader();
virtual GLenum getType(); virtual GLenum getType() const;
virtual void compile(); virtual void compile();
virtual void uncompile(); virtual void uncompile();
int getSemanticIndex(const std::string &attributeName); int getSemanticIndex(const std::string &attributeName);
...@@ -170,7 +172,7 @@ class FragmentShader : public Shader ...@@ -170,7 +172,7 @@ class FragmentShader : public Shader
~FragmentShader(); ~FragmentShader();
virtual GLenum getType(); virtual GLenum getType() const;
virtual void compile(); virtual void compile();
virtual void uncompile(); virtual void uncompile();
const std::vector<sh::Attribute> &getOutputVariables() const; const std::vector<sh::Attribute> &getOutputVariables() const;
......
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