Commit f5557acc by Jamie Madill

translator: Store symbol type in TField.

This allows us to keep a separate symbol type for each field in a struct. This can allow us to assign internal names to struct types. It could also allow us to add internal fields to user defined stucts. Bug: angleproject:2665 Change-Id: I6a129107d9db66c54b98b07684c3ead5801712ba Reviewed-on: https://chromium-review.googlesource.com/1101565Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 17cee572
...@@ -581,7 +581,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node) ...@@ -581,7 +581,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion(); const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
const TField *field = structure->fields()[index->getIConst(0)]; const TField *field = structure->fields()[index->getIConst(0)];
out << hashFieldName(structure, field->name()); out << hashFieldName(field);
visitChildren = false; visitChildren = false;
} }
break; break;
...@@ -595,7 +595,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node) ...@@ -595,7 +595,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
const TField *field = interfaceBlock->fields()[index->getIConst(0)]; const TField *field = interfaceBlock->fields()[index->getIConst(0)];
ASSERT(interfaceBlock->symbolType() == SymbolType::UserDefined || ASSERT(interfaceBlock->symbolType() == SymbolType::UserDefined ||
interfaceBlock->name() == "gl_PerVertex"); interfaceBlock->name() == "gl_PerVertex");
out << hashFieldName(interfaceBlock, field->name()); out << hashFieldName(field);
visitChildren = false; visitChildren = false;
} }
break; break;
...@@ -1115,18 +1115,15 @@ ImmutableString TOutputGLSLBase::hashName(const TSymbol *symbol) ...@@ -1115,18 +1115,15 @@ ImmutableString TOutputGLSLBase::hashName(const TSymbol *symbol)
return HashName(symbol, mHashFunction, &mNameMap); return HashName(symbol, mHashFunction, &mNameMap);
} }
ImmutableString TOutputGLSLBase::hashFieldName(const TSymbol *containingStruct, ImmutableString TOutputGLSLBase::hashFieldName(const TField *field)
const ImmutableString &fieldName)
{ {
if (containingStruct->symbolType() == SymbolType::UserDefined || ASSERT(field->symbolType() != SymbolType::Empty);
containingStruct->symbolType() == SymbolType::Empty) if (field->symbolType() == SymbolType::UserDefined)
{ {
return HashName(fieldName, mHashFunction, &mNameMap); return HashName(field->name(), mHashFunction, &mNameMap);
}
else
{
return fieldName;
} }
return field->name();
} }
ImmutableString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunction *func) ImmutableString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunction *func)
...@@ -1169,7 +1166,7 @@ void TOutputGLSLBase::declareStruct(const TStructure *structure) ...@@ -1169,7 +1166,7 @@ void TOutputGLSLBase::declareStruct(const TStructure *structure)
const TField *field = fields[i]; const TField *field = fields[i];
if (writeVariablePrecision(field->type()->getPrecision())) if (writeVariablePrecision(field->type()->getPrecision()))
out << " "; out << " ";
out << getTypeName(*field->type()) << " " << hashFieldName(structure, field->name()); out << getTypeName(*field->type()) << " " << hashFieldName(field);
if (field->type()->isArray()) if (field->type()->isArray())
out << ArrayString(*field->type()); out << ArrayString(*field->type());
out << ";\n"; out << ";\n";
...@@ -1254,7 +1251,7 @@ void TOutputGLSLBase::declareInterfaceBlock(const TInterfaceBlock *interfaceBloc ...@@ -1254,7 +1251,7 @@ void TOutputGLSLBase::declareInterfaceBlock(const TInterfaceBlock *interfaceBloc
if (writeVariablePrecision(field->type()->getPrecision())) if (writeVariablePrecision(field->type()->getPrecision()))
out << " "; out << " ";
out << getTypeName(*field->type()) << " " << hashFieldName(interfaceBlock, field->name()); out << getTypeName(*field->type()) << " " << hashFieldName(field);
if (field->type()->isArray()) if (field->type()->isArray())
out << ArrayString(*field->type()); out << ArrayString(*field->type());
out << ";\n"; out << ";\n";
......
...@@ -69,8 +69,7 @@ class TOutputGLSLBase : public TIntermTraverser ...@@ -69,8 +69,7 @@ class TOutputGLSLBase : public TIntermTraverser
void visitCodeBlock(TIntermBlock *node); void visitCodeBlock(TIntermBlock *node);
ImmutableString hashFieldName(const TSymbol *containingStruct, ImmutableString hashFieldName(const TField *field);
const ImmutableString &fieldName);
// Same as hashName(), but without hashing "main". // Same as hashName(), but without hashing "main".
ImmutableString hashFunctionNameIfNeeded(const TFunction *func); ImmutableString hashFunctionNameIfNeeded(const TFunction *func);
// Used to translate function names for differences between ESSL and GLSL // Used to translate function names for differences between ESSL and GLSL
......
...@@ -4714,7 +4714,8 @@ TFieldList *TParseContext::addStructDeclaratorList(const TPublicType &typeSpecif ...@@ -4714,7 +4714,8 @@ TFieldList *TParseContext::addStructDeclaratorList(const TPublicType &typeSpecif
type->makeArrays(*declarator->arraySizes()); type->makeArrays(*declarator->arraySizes());
} }
TField *field = new TField(type, declarator->name(), declarator->line()); TField *field =
new TField(type, declarator->name(), declarator->line(), SymbolType::UserDefined);
checkIsBelowStructNestingLimit(typeSpecifier.getLine(), *field); checkIsBelowStructNestingLimit(typeSpecifier.getLine(), *field);
fieldList->push_back(field); fieldList->push_back(field);
} }
......
...@@ -20,22 +20,6 @@ namespace sh ...@@ -20,22 +20,6 @@ namespace sh
class TSymbolTable; class TSymbolTable;
enum class SymbolType
{
BuiltIn,
UserDefined,
AngleInternal,
Empty // Meaning symbol without a name.
};
enum class SymbolClass
{
Function,
Variable,
Struct,
InterfaceBlock
};
// Symbol base class. (Can build functions or variables out of these...) // Symbol base class. (Can build functions or variables out of these...)
class TSymbol : angle::NonCopyable class TSymbol : angle::NonCopyable
{ {
......
...@@ -10344,12 +10344,15 @@ void TSymbolTable::initializeBuiltInVariables(sh::GLenum shaderType, ...@@ -10344,12 +10344,15 @@ void TSymbolTable::initializeBuiltInVariables(sh::GLenum shaderType,
{ {
const TSourceLoc zeroSourceLoc = {0, 0, 0, 0}; const TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
TFieldList *fields_gl_DepthRangeParameters = new TFieldList(); TFieldList *fields_gl_DepthRangeParameters = new TFieldList();
fields_gl_DepthRangeParameters->push_back(new TField(
new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), BuiltInName::near, zeroSourceLoc));
fields_gl_DepthRangeParameters->push_back( fields_gl_DepthRangeParameters->push_back(
new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), BuiltInName::far, zeroSourceLoc)); new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), BuiltInName::near, zeroSourceLoc,
fields_gl_DepthRangeParameters->push_back(new TField( SymbolType::BuiltIn));
new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), BuiltInName::diff, zeroSourceLoc)); fields_gl_DepthRangeParameters->push_back(
new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), BuiltInName::far, zeroSourceLoc,
SymbolType::BuiltIn));
fields_gl_DepthRangeParameters->push_back(
new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), BuiltInName::diff, zeroSourceLoc,
SymbolType::BuiltIn));
TStructure *gl_DepthRangeParameters = TStructure *gl_DepthRangeParameters =
new TStructure(BuiltInId::gl_DepthRangeParameters, BuiltInName::gl_DepthRangeParameters, new TStructure(BuiltInId::gl_DepthRangeParameters, BuiltInName::gl_DepthRangeParameters,
TExtension::UNDEFINED, fields_gl_DepthRangeParameters); TExtension::UNDEFINED, fields_gl_DepthRangeParameters);
...@@ -10789,7 +10792,8 @@ void TSymbolTable::initializeBuiltInVariables(sh::GLenum shaderType, ...@@ -10789,7 +10792,8 @@ void TSymbolTable::initializeBuiltInVariables(sh::GLenum shaderType,
TExtension::NV_shader_framebuffer_fetch, type_gl_LastFragDataNV); TExtension::NV_shader_framebuffer_fetch, type_gl_LastFragDataNV);
TFieldList *fields_gl_PerVertex = new TFieldList(); TFieldList *fields_gl_PerVertex = new TFieldList();
fields_gl_PerVertex->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqPosition, 4, 1), fields_gl_PerVertex->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqPosition, 4, 1),
BuiltInName::gl_Position, zeroSourceLoc)); BuiltInName::gl_Position, zeroSourceLoc,
SymbolType::BuiltIn));
TInterfaceBlock *gl_PerVertex = TInterfaceBlock *gl_PerVertex =
new TInterfaceBlock(BuiltInId::gl_PerVertex, BuiltInName::gl_PerVertex, new TInterfaceBlock(BuiltInId::gl_PerVertex, BuiltInName::gl_PerVertex,
TExtension::EXT_geometry_shader, fields_gl_PerVertex); TExtension::EXT_geometry_shader, fields_gl_PerVertex);
...@@ -10803,8 +10807,9 @@ void TSymbolTable::initializeBuiltInVariables(sh::GLenum shaderType, ...@@ -10803,8 +10807,9 @@ void TSymbolTable::initializeBuiltInVariables(sh::GLenum shaderType,
TExtension::EXT_geometry_shader, type_gl_in); TExtension::EXT_geometry_shader, type_gl_in);
} }
TFieldList *fields_gl_PerVertexOutBlock = new TFieldList(); TFieldList *fields_gl_PerVertexOutBlock = new TFieldList();
fields_gl_PerVertexOutBlock->push_back(new TField( fields_gl_PerVertexOutBlock->push_back(
new TType(EbtFloat, EbpHigh, EvqPosition, 4, 1), BuiltInName::gl_Position, zeroSourceLoc)); new TField(new TType(EbtFloat, EbpHigh, EvqPosition, 4, 1), BuiltInName::gl_Position,
zeroSourceLoc, SymbolType::BuiltIn));
TInterfaceBlock *gl_PerVertexOutBlock = TInterfaceBlock *gl_PerVertexOutBlock =
new TInterfaceBlock(BuiltInId::gl_PerVertexOutBlock, BuiltInName::gl_PerVertex, new TInterfaceBlock(BuiltInId::gl_PerVertexOutBlock, BuiltInName::gl_PerVertex,
TExtension::EXT_geometry_shader, fields_gl_PerVertexOutBlock); TExtension::EXT_geometry_shader, fields_gl_PerVertexOutBlock);
......
...@@ -37,6 +37,22 @@ class TSymbolUniqueId ...@@ -37,6 +37,22 @@ class TSymbolUniqueId
int mId; int mId;
}; };
enum class SymbolType
{
BuiltIn,
UserDefined,
AngleInternal,
Empty // Meaning symbol without a name.
};
enum class SymbolClass
{
Function,
Variable,
Struct,
InterfaceBlock
};
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_SYMBOLUNIQUEID_H_ #endif // COMPILER_TRANSLATOR_SYMBOLUNIQUEID_H_
...@@ -31,9 +31,10 @@ class TField : angle::NonCopyable ...@@ -31,9 +31,10 @@ class TField : angle::NonCopyable
{ {
public: public:
POOL_ALLOCATOR_NEW_DELETE(); POOL_ALLOCATOR_NEW_DELETE();
TField(TType *type, const ImmutableString &name, const TSourceLoc &line) TField(TType *type, const ImmutableString &name, const TSourceLoc &line, SymbolType symbolType)
: mType(type), mName(name), mLine(line) : mType(type), mName(name), mLine(line), mSymbolType(symbolType)
{ {
ASSERT(mSymbolType != SymbolType::Empty);
} }
// TODO(alokp): We should only return const type. // TODO(alokp): We should only return const type.
...@@ -42,11 +43,13 @@ class TField : angle::NonCopyable ...@@ -42,11 +43,13 @@ class TField : angle::NonCopyable
const TType *type() const { return mType; } const TType *type() const { return mType; }
const ImmutableString &name() const { return mName; } const ImmutableString &name() const { return mName; }
const TSourceLoc &line() const { return mLine; } const TSourceLoc &line() const { return mLine; }
SymbolType symbolType() const { return mSymbolType; }
private: private:
TType *mType; TType *mType;
const ImmutableString mName; const ImmutableString mName;
const TSourceLoc mLine; const TSourceLoc mLine;
const SymbolType mSymbolType;
}; };
typedef TVector<TField *> TFieldList; typedef TVector<TField *> TFieldList;
......
e7cb1a4f677413aec61815b10019f608 35ac43f73bd7b675a938f550d518ea8f
\ No newline at end of file \ No newline at end of file
...@@ -1133,7 +1133,7 @@ def process_single_variable_group(condition, group_name, group): ...@@ -1133,7 +1133,7 @@ def process_single_variable_group(condition, group_name, group):
template_args['field_type'] = TType(field_type).get_dynamic_type_string() template_args['field_type'] = TType(field_type).get_dynamic_type_string()
template_name_declaration = 'constexpr const ImmutableString {field_name}("{field_name}");' template_name_declaration = 'constexpr const ImmutableString {field_name}("{field_name}");'
name_declarations.add(template_name_declaration.format(**template_args)) name_declarations.add(template_name_declaration.format(**template_args))
template_add_field = ' {fields}->push_back(new TField({field_type}, BuiltInName::{field_name}, zeroSourceLoc));' template_add_field = ' {fields}->push_back(new TField({field_type}, BuiltInName::{field_name}, zeroSourceLoc, SymbolType::BuiltIn));'
init_member_variables.append(template_add_field.format(**template_args)) init_member_variables.append(template_add_field.format(**template_args))
template_init_temp_variable = ' {class} *{name_with_suffix} = new {class}(BuiltInId::{name_with_suffix}, BuiltInName::{name}, TExtension::{extension}, {fields});' template_init_temp_variable = ' {class} *{name_with_suffix} = new {class}(BuiltInId::{name_with_suffix}, BuiltInName::{name}, TExtension::{extension}, {fields});'
init_member_variables.append(template_init_temp_variable.format(**template_args)) init_member_variables.append(template_init_temp_variable.format(**template_args))
......
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