Commit 9515707b by Philip Lamoureux

Move ShaderVariable utility function from utilities.cpp ShaderVars.cpp.

Fixes an implied dependency cycle between translator and angle_common. This will also allow us to be more strict about declaring dependencies on GLSLANG headers. Tested by building and running angle_unit_tests on Linux. Bug: angleproject:4672 Change-Id: I331230d2cf179ccea140ee7a0d5a3c8768c58cb1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2222682Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent b3693762
......@@ -26,7 +26,7 @@
// Version number for shader translation API.
// It is incremented every time the API changes.
#define ANGLE_SH_VERSION 229
#define ANGLE_SH_VERSION 230
enum ShShaderSpec
{
......
......@@ -120,6 +120,10 @@ struct ShaderVariable
const ShaderVariable **leafVar,
std::string *originalFullName) const;
// Find the child field which matches 'fullName' == var.name + "." + field.name.
// Return nullptr if not found.
const sh::ShaderVariable *findField(const std::string &fullName, uint32_t *fieldIndexOut) const;
bool isBuiltIn() const;
bool isEmulatedBuiltIn() const;
......
......@@ -7,7 +7,6 @@
// utilities.cpp: Conversion functions and other utility routines.
#include "common/utilities.h"
#include <GLSLANG/ShaderVars.h>
#include "GLES3/gl3.h"
#include "common/mathutil.h"
#include "common/platform.h"
......@@ -914,40 +913,6 @@ bool SamplerNameContainsNonZeroArrayElement(const std::string &name)
return false;
}
const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var,
const std::string &fullName,
GLuint *fieldIndexOut)
{
if (var.fields.empty())
{
return nullptr;
}
size_t pos = fullName.find_first_of(".");
if (pos == std::string::npos)
{
return nullptr;
}
std::string topName = fullName.substr(0, pos);
if (topName != var.name)
{
return nullptr;
}
std::string fieldName = fullName.substr(pos + 1);
if (fieldName.empty())
{
return nullptr;
}
for (size_t field = 0; field < var.fields.size(); ++field)
{
if (var.fields[field].name == fieldName)
{
*fieldIndexOut = static_cast<GLuint>(field);
return &var.fields[field];
}
}
return nullptr;
}
unsigned int ArraySizeProduct(const std::vector<unsigned int> &arraySizes)
{
unsigned int arraySizeProduct = 1u;
......
......@@ -66,12 +66,6 @@ std::string StripLastArrayIndex(const std::string &name);
bool SamplerNameContainsNonZeroArrayElement(const std::string &name);
// Find the child field which matches 'fullName' == var.name + "." + field.name.
// Return nullptr if not found.
const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var,
const std::string &fullName,
GLuint *fieldIndexOut);
// Find the range of index values in the provided indices pointer. Primitive restart indices are
// only counted in the range if primitive restart is disabled.
IndexRange ComputeIndexRange(DrawElementsType indexType,
......
......@@ -282,6 +282,39 @@ bool ShaderVariable::findInfoByMappedName(const std::string &mappedFullName,
}
}
const sh::ShaderVariable *ShaderVariable::findField(const std::string &fullName,
uint32_t *fieldIndexOut) const
{
if (fields.empty())
{
return nullptr;
}
size_t pos = fullName.find_first_of(".");
if (pos == std::string::npos)
{
return nullptr;
}
std::string topName = fullName.substr(0, pos);
if (topName != name)
{
return nullptr;
}
std::string fieldName = fullName.substr(pos + 1);
if (fieldName.empty())
{
return nullptr;
}
for (size_t field = 0; field < fields.size(); ++field)
{
if (fields[field].name == fieldName)
{
*fieldIndexOut = static_cast<GLuint>(field);
return &fields[field];
}
}
return nullptr;
}
bool ShaderVariable::isBuiltIn() const
{
return (name.size() >= 4 && name[0] == 'g' && name[1] == 'l' && name[2] == '_');
......
......@@ -425,7 +425,7 @@ const sh::ShaderVariable *FindOutputVaryingOrField(const ProgramMergedVaryings &
break;
}
GLuint fieldIndex = 0;
var = FindShaderVarField(*varying, name, &fieldIndex);
var = varying->findField(name, &fieldIndex);
if (var != nullptr)
{
break;
......@@ -4383,7 +4383,7 @@ void Program::gatherTransformFeedbackVaryings(const ProgramMergedVaryings &varyi
else if (varying->isStruct())
{
GLuint fieldIndex = 0;
const auto *field = FindShaderVarField(*varying, tfVaryingName, &fieldIndex);
const auto *field = varying->findField(tfVaryingName, &fieldIndex);
if (field != nullptr)
{
mState.mExecutable->mLinkedTransformFeedbackVaryings.emplace_back(*field,
......
......@@ -654,7 +654,7 @@ std::string Shader::getTransformFeedbackVaryingMappedName(const std::string &tfV
else if (varying.isStruct())
{
GLuint fieldIndex = 0;
const auto *field = FindShaderVarField(varying, tfVaryingName, &fieldIndex);
const auto *field = varying.findField(tfVaryingName, &fieldIndex);
ASSERT(field != nullptr && !field->isStruct() && !field->isArray());
return varying.mappedName + "." + field->mappedName;
}
......
......@@ -530,9 +530,8 @@ bool VaryingPacking::collectAndPackUserVaryings(gl::InfoLog &infoLog,
}
if (input->isStruct())
{
GLuint fieldIndex = 0;
const sh::ShaderVariable *field =
FindShaderVarField(*input, tfVarying, &fieldIndex);
GLuint fieldIndex = 0;
const sh::ShaderVariable *field = input->findField(tfVarying, &fieldIndex);
if (field != nullptr)
{
ASSERT(!field->isStruct() && !field->isArray());
......
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