Commit dfdf90a7 by Shahbaz Youssefi Committed by Commit Bot

Create helper for identifying builtin names

Bug: angleproject:5405 Change-Id: I652f2d6d3af4468b9662cdea5d2706d36e118239 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2568550Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 8797714c
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "GLES3/gl3.h" #include "GLES3/gl3.h"
#include "common/mathutil.h" #include "common/mathutil.h"
#include "common/platform.h" #include "common/platform.h"
#include "common/string_utils.h"
#include <set> #include <set>
...@@ -920,6 +921,11 @@ std::string ParseResourceName(const std::string &name, std::vector<unsigned int> ...@@ -920,6 +921,11 @@ std::string ParseResourceName(const std::string &name, std::vector<unsigned int>
return name.substr(0, baseNameLength); return name.substr(0, baseNameLength);
} }
bool IsBuiltInName(const char *name)
{
return angle::BeginsWith(name, "gl_");
}
std::string StripLastArrayIndex(const std::string &name) std::string StripLastArrayIndex(const std::string &name)
{ {
size_t strippedNameLength = name.find_last_of('['); size_t strippedNameLength = name.find_last_of('[');
......
...@@ -62,6 +62,12 @@ int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsig ...@@ -62,6 +62,12 @@ int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsig
// outSubscripts. // outSubscripts.
std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts); std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts);
bool IsBuiltInName(const char *name);
ANGLE_INLINE bool IsBuiltInName(const std::string &name)
{
return IsBuiltInName(name.c_str());
}
// Strips only the last array index from a resource name. // Strips only the last array index from a resource name.
std::string StripLastArrayIndex(const std::string &name); std::string StripLastArrayIndex(const std::string &name);
......
...@@ -333,7 +333,7 @@ const sh::ShaderVariable *ShaderVariable::findField(const std::string &fullName, ...@@ -333,7 +333,7 @@ const sh::ShaderVariable *ShaderVariable::findField(const std::string &fullName,
bool ShaderVariable::isBuiltIn() const bool ShaderVariable::isBuiltIn() const
{ {
return (name.size() >= 4 && name[0] == 'g' && name[1] == 'l' && name[2] == '_'); return gl::IsBuiltInName(name);
} }
bool ShaderVariable::isEmulatedBuiltIn() const bool ShaderVariable::isEmulatedBuiltIn() const
...@@ -528,7 +528,7 @@ bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) ...@@ -528,7 +528,7 @@ bool InterfaceBlock::isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other)
bool InterfaceBlock::isBuiltIn() const bool InterfaceBlock::isBuiltIn() const
{ {
return (name.size() >= 4 && name[0] == 'g' && name[1] == 'l' && name[2] == '_'); return gl::IsBuiltInName(name);
} }
void WorkGroupSize::fill(int fillValue) void WorkGroupSize::fill(int fillValue)
......
...@@ -2819,7 +2819,7 @@ void CaptureMidExecutionSetup(const gl::Context *context, ...@@ -2819,7 +2819,7 @@ void CaptureMidExecutionSetup(const gl::Context *context,
{ {
ASSERT(attrib.location != -1); ASSERT(attrib.location != -1);
if (angle::BeginsWith(attrib.name, "gl_")) if (gl::IsBuiltInName(attrib.name))
{ {
// Don't try to bind built-in attributes // Don't try to bind built-in attributes
continue; continue;
......
...@@ -636,7 +636,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -636,7 +636,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
programExecutable.getResources().varyingPacking.getInactiveVaryingMappedNames(); programExecutable.getResources().varyingPacking.getInactiveVaryingMappedNames();
for (const std::string &varyingName : inactiveVaryingMappedNames[shaderType]) for (const std::string &varyingName : inactiveVaryingMappedNames[shaderType])
{ {
ASSERT(!angle::BeginsWith(varyingName, "gl_")); ASSERT(!gl::IsBuiltInName(varyingName));
// If name is already in the map, it will automatically have marked all other stages // If name is already in the map, it will automatically have marked all other stages
// inactive. // inactive.
...@@ -657,7 +657,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -657,7 +657,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
programExecutable.getResources().varyingPacking.getActiveOutputBuiltIns(); programExecutable.getResources().varyingPacking.getActiveOutputBuiltIns();
for (const std::string &builtInName : activeOutputBuiltIns[shaderType]) for (const std::string &builtInName : activeOutputBuiltIns[shaderType])
{ {
ASSERT(angle::BeginsWith(builtInName, "gl_")); ASSERT(gl::IsBuiltInName(builtInName));
ShaderInterfaceVariableInfo *info = &(*variableInfoMapOut)[shaderType][builtInName]; ShaderInterfaceVariableInfo *info = &(*variableInfoMapOut)[shaderType][builtInName];
info->activeStages.set(shaderType); info->activeStages.set(shaderType);
...@@ -670,7 +670,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -670,7 +670,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
{ {
for (const std::string &builtInName : activeOutputBuiltIns[frontShaderType]) for (const std::string &builtInName : activeOutputBuiltIns[frontShaderType])
{ {
ASSERT(angle::BeginsWith(builtInName, "gl_")); ASSERT(gl::IsBuiltInName(builtInName));
ShaderInterfaceVariableInfo *info = &(*variableInfoMapOut)[shaderType][builtInName]; ShaderInterfaceVariableInfo *info = &(*variableInfoMapOut)[shaderType][builtInName];
info->activeStages.set(shaderType); info->activeStages.set(shaderType);
...@@ -1922,9 +1922,9 @@ void SpirvTransformer::visitVariable(const uint32_t *instruction) ...@@ -1922,9 +1922,9 @@ void SpirvTransformer::visitVariable(const uint32_t *instruction)
// Handle builtins, which all start with "gl_". Either the variable name could be an indication // Handle builtins, which all start with "gl_". Either the variable name could be an indication
// of a builtin variable (such as with gl_FragCoord) or the type name (such as with // of a builtin variable (such as with gl_FragCoord) or the type name (such as with
// gl_PerVertex). // gl_PerVertex).
const bool isNameBuiltin = isInOut && angle::BeginsWith(name, "gl_"); const bool isNameBuiltin = isInOut && gl::IsBuiltInName(name);
const bool isTypeBuiltin = const bool isTypeBuiltin =
isInOut && mNamesById[typeId] != nullptr && angle::BeginsWith(mNamesById[typeId], "gl_"); isInOut && mNamesById[typeId] != nullptr && gl::IsBuiltInName(mNamesById[typeId]);
if (isNameBuiltin || isTypeBuiltin) if (isNameBuiltin || isTypeBuiltin)
{ {
// Make all builtins point to this no-op info. Adding this entry allows us to ASSERT that // Make all builtins point to this no-op info. Adding this entry allows us to ASSERT that
...@@ -2294,7 +2294,7 @@ bool SpirvTransformer::transformTypePointer(const uint32_t *instruction, size_t ...@@ -2294,7 +2294,7 @@ bool SpirvTransformer::transformTypePointer(const uint32_t *instruction, size_t
// storage class, in case it may be necessary later. // storage class, in case it may be necessary later.
// Cannot create a Private type declaration from builtins such as gl_PerVertex. // Cannot create a Private type declaration from builtins such as gl_PerVertex.
if (mNamesById[typeId] != nullptr && angle::BeginsWith(mNamesById[typeId], "gl_")) if (mNamesById[typeId] != nullptr && gl::IsBuiltInName(mNamesById[typeId]))
{ {
return false; return false;
} }
......
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