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
dataSize(0),
layout(BLOCKLAYOUT_PACKED),
isRowMajorLayout(false),
staticUse(false),
registerIndex(-1)
staticUse(false)
{}
InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex)
InterfaceBlock(const char *name, unsigned int arraySize)
: name(name),
arraySize(arraySize),
dataSize(0),
layout(BLOCKLAYOUT_SHARED),
isRowMajorLayout(false),
staticUse(false),
registerIndex(registerIndex)
staticUse(false)
{}
std::string name;
......@@ -188,9 +186,6 @@ struct InterfaceBlock
bool staticUse;
std::vector<InterfaceBlockField> fields;
std::vector<BlockMemberInfo> blockInfo;
// HLSL-specific members
unsigned int registerIndex;
};
}
......
......@@ -225,7 +225,9 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
const TFieldList &fieldList = interfaceBlock.fields();
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++)
{
const TField &field = *fieldList[typeIndex];
......@@ -236,7 +238,7 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
traverser.traverse(*field.type(), fullFieldName);
}
mInterfaceBlockRegisterMap[activeBlock.name] = mInterfaceBlockRegister;
mInterfaceBlockRegisterMap[activeBlock.name] = activeRegister;
mInterfaceBlockRegister += std::max(1u, arraySize);
BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage());
......@@ -258,12 +260,12 @@ TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedIn
{
for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++)
{
interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex + arrayIndex, arrayIndex);
interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex);
}
}
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
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;
}
......@@ -2151,9 +2151,12 @@ bool ProgramBinary::areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::Inter
return true;
}
bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::InterfaceBlock> &vertexInterfaceBlocks,
const std::vector<sh::InterfaceBlock> &fragmentInterfaceBlocks)
bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const VertexShader &vertexShader,
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
typedef std::map<std::string, const sh::InterfaceBlock*> UniformBlockMap;
UniformBlockMap linkedUniformBlocks;
......@@ -2180,7 +2183,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::In
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;
}
......@@ -2188,7 +2191,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<sh::In
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;
}
......@@ -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
if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX)
......@@ -2326,12 +2329,15 @@ bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, GLenum shader, const sh
ASSERT(blockIndex != GL_INVALID_INDEX);
ASSERT(blockIndex + elementCount <= mUniformBlocks.size());
unsigned int interfaceBlockRegister = shader.getInterfaceBlockRegister(interfaceBlock.name);
for (unsigned int uniformBlockElement = 0; uniformBlockElement < elementCount; uniformBlockElement++)
{
UniformBlock *uniformBlock = mUniformBlocks[blockIndex + uniformBlockElement];
ASSERT(uniformBlock->name == interfaceBlock.name);
if (!assignUniformBlockRegister(infoLog, uniformBlock, shader, interfaceBlock.registerIndex + uniformBlockElement))
if (!assignUniformBlockRegister(infoLog, uniformBlock, shader.getType(),
interfaceBlockRegister + uniformBlockElement))
{
return false;
}
......
......@@ -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 defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog);
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,
const std::vector<std::string> &transformFeedbackVaryingNames,
GLenum transformFeedbackBufferMode,
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);
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);
void defineOutputVariables(FragmentShader *fragmentShader);
void initializeUniformStorage();
......
......@@ -115,6 +115,12 @@ void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *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
{
return mActiveUniforms;
......@@ -370,6 +376,18 @@ void Shader::compileToHLSL(void *compiler)
void *activeInterfaceBlocks;
ShGetInfoPointer(compiler, SH_ACTIVE_INTERFACE_BLOCKS_ARRAY, &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
{
......@@ -440,7 +458,7 @@ VertexShader::~VertexShader()
{
}
GLenum VertexShader::getType()
GLenum VertexShader::getType() const
{
return GL_VERTEX_SHADER;
}
......@@ -503,7 +521,7 @@ FragmentShader::~FragmentShader()
{
}
GLenum FragmentShader::getType()
GLenum FragmentShader::getType() const
{
return GL_FRAGMENT_SHADER;
}
......
......@@ -57,7 +57,7 @@ class Shader
virtual ~Shader();
virtual GLenum getType() = 0;
virtual GLenum getType() const = 0;
GLuint getHandle() const;
void deleteSource();
......@@ -87,6 +87,7 @@ class Shader
static void releaseCompiler();
static ShShaderOutput getCompilerOutputType(GLenum shader);
unsigned int getInterfaceBlockRegister(const std::string &blockName) const;
bool usesDepthRange() const { return mUsesDepthRange; }
bool usesPointSize() const { return mUsesPointSize; }
......@@ -135,6 +136,7 @@ class Shader
std::string mInfoLog;
std::vector<sh::Uniform> mActiveUniforms;
std::vector<sh::InterfaceBlock> mActiveInterfaceBlocks;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
ResourceManager *mResourceManager;
};
......@@ -148,7 +150,7 @@ class VertexShader : public Shader
~VertexShader();
virtual GLenum getType();
virtual GLenum getType() const;
virtual void compile();
virtual void uncompile();
int getSemanticIndex(const std::string &attributeName);
......@@ -170,7 +172,7 @@ class FragmentShader : public Shader
~FragmentShader();
virtual GLenum getType();
virtual GLenum getType() const;
virtual void compile();
virtual void uncompile();
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