Commit e4497d60 by Jamie Madill Committed by Commit Bot

Program: Move more common code to ProgramLinkedResources.

Refactoring change only. Bug: angleproject:5496 Change-Id: Ic1c8301a070e91ad28791c23831b8236058ab9ab Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2606535 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent 68f35f24
...@@ -758,13 +758,6 @@ class Program final : public LabeledObject, public angle::Subject, public HasAtt ...@@ -758,13 +758,6 @@ class Program final : public LabeledObject, public angle::Subject, public HasAtt
return mState; return mState;
} }
static LinkMismatchError LinkValidateVariablesBase(
const sh::ShaderVariable &variable1,
const sh::ShaderVariable &variable2,
bool validatePrecision,
bool validateArraySize,
std::string *mismatchedStructOrBlockMemberName);
GLuint getInputResourceIndex(const GLchar *name) const; GLuint getInputResourceIndex(const GLchar *name) const;
GLuint getOutputResourceIndex(const GLchar *name) const; GLuint getOutputResourceIndex(const GLchar *name) const;
void getInputResourceName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const; void getInputResourceName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const;
...@@ -842,34 +835,6 @@ class Program final : public LabeledObject, public angle::Subject, public HasAtt ...@@ -842,34 +835,6 @@ class Program final : public LabeledObject, public angle::Subject, public HasAtt
const ProgramExecutable &getExecutable() const { return mState.getExecutable(); } const ProgramExecutable &getExecutable() const { return mState.getExecutable(); }
ProgramExecutable &getExecutable() { return mState.getExecutable(); } ProgramExecutable &getExecutable() { return mState.getExecutable(); }
const char *validateDrawStates(const State &state, const gl::Extensions &extensions) const;
static void getFilteredVaryings(const std::vector<sh::ShaderVariable> &varyings,
std::vector<const sh::ShaderVariable *> *filteredVaryingsOut);
static bool doShaderVariablesMatch(int outputShaderVersion,
ShaderType outputShaderType,
ShaderType inputShaderType,
const sh::ShaderVariable &input,
const sh::ShaderVariable &output,
bool validateGeometryShaderInputs,
bool isSeparable,
gl::InfoLog &infoLog);
static bool linkValidateShaderInterfaceMatching(
const std::vector<sh::ShaderVariable> &outputVaryings,
const std::vector<sh::ShaderVariable> &inputVaryings,
ShaderType outputShaderType,
ShaderType inputShaderType,
int outputShaderVersion,
int inputShaderVersion,
bool isSeparable,
InfoLog &infoLog);
static bool linkValidateBuiltInVaryings(const std::vector<sh::ShaderVariable> &vertexVaryings,
const std::vector<sh::ShaderVariable> &fragmentVaryings,
int vertexShaderVersion,
InfoLog &infoLog);
void fillProgramStateMap(ShaderMap<const ProgramState *> *programStatesOut);
private: private:
struct LinkingState; struct LinkingState;
...@@ -903,13 +868,6 @@ class Program final : public LabeledObject, public angle::Subject, public HasAtt ...@@ -903,13 +868,6 @@ class Program final : public LabeledObject, public angle::Subject, public HasAtt
void updateLinkedShaderStages(); void updateLinkedShaderStages();
static LinkMismatchError LinkValidateVaryings(const sh::ShaderVariable &outputVarying,
const sh::ShaderVariable &inputVarying,
int shaderVersion,
bool validateGeometryShaderInputVarying,
bool isSeparable,
std::string *mismatchedStructFieldName);
bool linkValidateTransformFeedback(const Version &version, bool linkValidateTransformFeedback(const Version &version,
InfoLog &infoLog, InfoLog &infoLog,
const ProgramMergedVaryings &linkedVaryings, const ProgramMergedVaryings &linkedVaryings,
......
...@@ -416,127 +416,6 @@ void ProgramExecutable::setSamplerUniformTextureTypeAndFormat( ...@@ -416,127 +416,6 @@ void ProgramExecutable::setSamplerUniformTextureTypeAndFormat(
mActiveSamplerFormats[textureUnitIndex] = foundFormat; mActiveSamplerFormats[textureUnitIndex] = foundFormat;
} }
bool ProgramExecutable::linkValidateGlobalNames(
InfoLog &infoLog,
const ShaderMap<const ProgramState *> &programStates) const
{
angle::HashMap<std::string, const sh::ShaderVariable *> uniformMap;
using BlockAndFieldPair = std::pair<const sh::InterfaceBlock *, const sh::ShaderVariable *>;
angle::HashMap<std::string, std::vector<BlockAndFieldPair>> uniformBlockFieldMap;
for (ShaderType shaderType : kAllGraphicsShaderTypes)
{
const ProgramState *programState = programStates[shaderType];
if (!programState)
{
continue;
}
Shader *shader = programState->getAttachedShader(shaderType);
if (!shader)
{
continue;
}
// Build a map of Uniforms
const std::vector<sh::ShaderVariable> uniforms = shader->getUniforms();
for (const auto &uniform : uniforms)
{
uniformMap[uniform.name] = &uniform;
}
// Build a map of Uniform Blocks
// This will also detect any field name conflicts between Uniform Blocks without instance
// names
const std::vector<sh::InterfaceBlock> &uniformBlocks = shader->getUniformBlocks();
for (const auto &uniformBlock : uniformBlocks)
{
// Only uniform blocks without an instance name can create a conflict with their field
// names
if (!uniformBlock.instanceName.empty())
{
continue;
}
for (const auto &field : uniformBlock.fields)
{
if (!uniformBlockFieldMap.count(field.name))
{
// First time we've seen this uniform block field name, so add the
// (Uniform Block, Field) pair immediately since there can't be a conflict yet
BlockAndFieldPair blockAndFieldPair(&uniformBlock, &field);
std::vector<BlockAndFieldPair> newUniformBlockList;
newUniformBlockList.push_back(blockAndFieldPair);
uniformBlockFieldMap[field.name] = newUniformBlockList;
continue;
}
// We've seen this name before.
// We need to check each of the uniform blocks that contain a field with this name
// to see if there's a conflict or not.
std::vector<BlockAndFieldPair> prevBlockFieldPairs =
uniformBlockFieldMap[field.name];
for (const auto &prevBlockFieldPair : prevBlockFieldPairs)
{
const sh::InterfaceBlock *prevUniformBlock = prevBlockFieldPair.first;
const sh::ShaderVariable *prevUniformBlockField = prevBlockFieldPair.second;
if (uniformBlock.isSameInterfaceBlockAtLinkTime(*prevUniformBlock))
{
// The same uniform block should, by definition, contain the same field name
continue;
}
// The uniform blocks don't match, so check if the necessary field properties
// also match
if ((field.name == prevUniformBlockField->name) &&
(field.type == prevUniformBlockField->type) &&
(field.precision == prevUniformBlockField->precision))
{
infoLog << "Name conflicts between uniform block field names: "
<< field.name;
return false;
}
}
// No conflict, so record this pair
BlockAndFieldPair blockAndFieldPair(&uniformBlock, &field);
uniformBlockFieldMap[field.name].push_back(blockAndFieldPair);
}
}
}
// Validate no uniform names conflict with attribute names
const ProgramState *programState = programStates[ShaderType::Vertex];
if (programState)
{
Shader *vertexShader = programState->getAttachedShader(ShaderType::Vertex);
if (vertexShader)
{
for (const auto &attrib : vertexShader->getActiveAttributes())
{
if (uniformMap.count(attrib.name))
{
infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name;
return false;
}
}
}
}
// Validate no Uniform Block fields conflict with other Uniforms
for (const auto &uniformBlockField : uniformBlockFieldMap)
{
const std::string &fieldName = uniformBlockField.first;
if (uniformMap.count(fieldName))
{
infoLog << "Name conflicts between a uniform and a uniform block field: " << fieldName;
return false;
}
}
return true;
}
void ProgramExecutable::updateCanDrawWith() void ProgramExecutable::updateCanDrawWith()
{ {
mCanDrawWith = mCanDrawWith =
......
...@@ -220,9 +220,6 @@ class ProgramExecutable final : public angle::Subject ...@@ -220,9 +220,6 @@ class ProgramExecutable final : public angle::Subject
// Count the number of uniform and storage buffer declarations, counting arrays as one. // Count the number of uniform and storage buffer declarations, counting arrays as one.
size_t getTransformFeedbackBufferCount() const { return mTransformFeedbackStrides.size(); } size_t getTransformFeedbackBufferCount() const { return mTransformFeedbackStrides.size(); }
bool linkValidateGlobalNames(InfoLog &infoLog,
const ShaderMap<const ProgramState *> &programStates) const;
void updateCanDrawWith(); void updateCanDrawWith();
bool hasVertexAndFragmentShader() const { return mCanDrawWith; } bool hasVertexAndFragmentShader() const { return mCanDrawWith; }
...@@ -427,7 +424,6 @@ class ProgramExecutable final : public angle::Subject ...@@ -427,7 +424,6 @@ class ProgramExecutable final : public angle::Subject
int mGeometryShaderInvocations; int mGeometryShaderInvocations;
int mGeometryShaderMaxVertices; int mGeometryShaderMaxVertices;
}; };
} // namespace gl } // namespace gl
#endif // LIBANGLE_PROGRAMEXECUTABLE_H_ #endif // LIBANGLE_PROGRAMEXECUTABLE_H_
...@@ -256,6 +256,26 @@ class ProgramLinkedResourcesLinker final : angle::NonCopyable ...@@ -256,6 +256,26 @@ class ProgramLinkedResourcesLinker final : angle::NonCopyable
CustomBlockLayoutEncoderFactory *mCustomEncoderFactory; CustomBlockLayoutEncoderFactory *mCustomEncoderFactory;
}; };
bool LinkValidateProgramGlobalNames(InfoLog &infoLog, const HasAttachedShaders &programOrPipeline);
bool LinkValidateShaderInterfaceMatching(const std::vector<sh::ShaderVariable> &outputVaryings,
const std::vector<sh::ShaderVariable> &inputVaryings,
ShaderType outputShaderType,
ShaderType inputShaderType,
int outputShaderVersion,
int inputShaderVersion,
bool isSeparable,
InfoLog &infoLog);
bool LinkValidateBuiltInVaryings(const std::vector<sh::ShaderVariable> &vertexVaryings,
const std::vector<sh::ShaderVariable> &fragmentVaryings,
int vertexShaderVersion,
InfoLog &infoLog);
LinkMismatchError LinkValidateProgramVariables(const sh::ShaderVariable &variable1,
const sh::ShaderVariable &variable2,
bool validatePrecision,
bool validateArraySize,
std::string *mismatchedStructOrBlockMemberName);
void AddProgramVariableParentPrefix(const std::string &parentName,
std::string *mismatchedFieldName);
} // namespace gl } // namespace gl
#endif // LIBANGLE_UNIFORMLINKER_H_ #endif // LIBANGLE_UNIFORMLINKER_H_
...@@ -432,9 +432,7 @@ angle::Result ProgramPipeline::link(const Context *context) ...@@ -432,9 +432,7 @@ angle::Result ProgramPipeline::link(const Context *context)
return angle::Result::Stop; return angle::Result::Stop;
} }
gl::ShaderMap<const gl::ProgramState *> programStates; if (!LinkValidateProgramGlobalNames(infoLog, *this))
fillProgramStateMap(&programStates);
if (!mState.mExecutable->linkValidateGlobalNames(infoLog, programStates))
{ {
return angle::Result::Stop; return angle::Result::Stop;
} }
...@@ -473,7 +471,7 @@ bool ProgramPipeline::linkVaryings(InfoLog &infoLog) const ...@@ -473,7 +471,7 @@ bool ProgramPipeline::linkVaryings(InfoLog &infoLog) const
ASSERT(previousProgram); ASSERT(previousProgram);
ProgramExecutable &previousExecutable = previousProgram->getExecutable(); ProgramExecutable &previousExecutable = previousProgram->getExecutable();
if (!Program::linkValidateShaderInterfaceMatching( if (!LinkValidateShaderInterfaceMatching(
previousExecutable.getLinkedOutputVaryings(previousShaderType), previousExecutable.getLinkedOutputVaryings(previousShaderType),
executable.getLinkedInputVaryings(shaderType), previousShaderType, shaderType, executable.getLinkedInputVaryings(shaderType), previousShaderType, shaderType,
previousExecutable.getLinkedShaderVersion(previousShaderType), previousExecutable.getLinkedShaderVersion(previousShaderType),
...@@ -493,7 +491,7 @@ bool ProgramPipeline::linkVaryings(InfoLog &infoLog) const ...@@ -493,7 +491,7 @@ bool ProgramPipeline::linkVaryings(InfoLog &infoLog) const
} }
ProgramExecutable &vertexExecutable = vertexProgram->getExecutable(); ProgramExecutable &vertexExecutable = vertexProgram->getExecutable();
ProgramExecutable &fragmentExecutable = fragmentProgram->getExecutable(); ProgramExecutable &fragmentExecutable = fragmentProgram->getExecutable();
return Program::linkValidateBuiltInVaryings( return LinkValidateBuiltInVaryings(
vertexExecutable.getLinkedOutputVaryings(ShaderType::Vertex), vertexExecutable.getLinkedOutputVaryings(ShaderType::Vertex),
fragmentExecutable.getLinkedInputVaryings(ShaderType::Fragment), fragmentExecutable.getLinkedInputVaryings(ShaderType::Fragment),
vertexExecutable.getLinkedShaderVersion(ShaderType::Vertex), infoLog); vertexExecutable.getLinkedShaderVersion(ShaderType::Vertex), infoLog);
...@@ -576,20 +574,6 @@ void ProgramPipeline::onSubjectStateChange(angle::SubjectIndex index, angle::Sub ...@@ -576,20 +574,6 @@ void ProgramPipeline::onSubjectStateChange(angle::SubjectIndex index, angle::Sub
} }
} }
void ProgramPipeline::fillProgramStateMap(ShaderMap<const ProgramState *> *programStatesOut)
{
for (ShaderType shaderType : AllShaderTypes())
{
(*programStatesOut)[shaderType] = nullptr;
Program *program = getShaderProgram(shaderType);
if (program)
{
(*programStatesOut)[shaderType] = &program->getState();
}
}
}
Shader *ProgramPipeline::getAttachedShader(ShaderType shaderType) const Shader *ProgramPipeline::getAttachedShader(ShaderType shaderType) const
{ {
const Program *program = mState.mPrograms[shaderType]; const Program *program = mState.mPrograms[shaderType];
......
...@@ -143,8 +143,6 @@ class ProgramPipeline final : public RefCountObject<ProgramPipelineID>, ...@@ -143,8 +143,6 @@ class ProgramPipeline final : public RefCountObject<ProgramPipelineID>,
// ObserverInterface implementation. // ObserverInterface implementation.
void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override; void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
void fillProgramStateMap(gl::ShaderMap<const gl::ProgramState *> *programStatesOut);
Shader *getAttachedShader(ShaderType shaderType) const override; Shader *getAttachedShader(ShaderType shaderType) const override;
private: private:
......
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