Skip to content

Commit 6a997ce

Browse files
ShabbyXAngle LUCI CQ
authored andcommitted
Vulkan: SPIR-V Gen: Use unique id instead of pointer
Bug: angleproject:349994211 Change-Id: I66d6c3cf58f1e7d850fb19def7aa863774d918a9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/7007612 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 parent 6c4c005 commit 6a997ce

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/compiler/translator/ValidateAST.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ValidateAST : public TIntermTraverser
8989
// For validateVariableReferences:
9090
std::vector<std::set<const TVariable *>> mDeclaredVariables;
9191
std::set<const TInterfaceBlock *> mNamelessInterfaceBlocks;
92-
std::map<ImmutableString, const TVariable *> mReferencedBuiltIns;
92+
std::map<ImmutableString, TSymbolUniqueId> mReferencedBuiltIns;
9393
bool mVariableReferencesFailed = false;
9494

9595
// For validateOps:
@@ -623,11 +623,11 @@ void ValidateAST::visitBuiltInVariable(TIntermSymbol *node)
623623
auto iter = mReferencedBuiltIns.find(name);
624624
if (iter == mReferencedBuiltIns.end())
625625
{
626-
mReferencedBuiltIns[name] = variable;
626+
mReferencedBuiltIns.emplace(name, variable->uniqueId());
627627
return;
628628
}
629629

630-
if (variable != iter->second)
630+
if (variable->uniqueId() != iter->second)
631631
{
632632
mDiagnostics->error(
633633
node->getLine(),

src/compiler/translator/spirv/OutputSPIRV.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class OutputSPIRVTraverser : public TIntermTraverser
393393
// - TVariable, or
394394
// - TInterfaceBlock: because TIntermSymbols referencing a field of an unnamed interface block
395395
// don't reference the TVariable that defines the struct, but the TInterfaceBlock itself.
396-
angle::HashMap<const TSymbol *, spirv::IdRef> mSymbolIdMap;
396+
angle::HashMap<TSymbolUniqueId, spirv::IdRef> mSymbolIdMap;
397397

398398
// A map of TFunction to its various SPIR-V ids.
399399
angle::HashMap<const TFunction *, FunctionIds> mFunctionIdMap;
@@ -544,7 +544,7 @@ spirv::IdRef OutputSPIRVTraverser::getSymbolIdAndStorageClass(const TSymbol *sym
544544
spv::StorageClass *storageClass)
545545
{
546546
*storageClass = GetStorageClass(mCompileOptions, type, mCompiler->getShaderType());
547-
auto iter = mSymbolIdMap.find(symbol);
547+
auto iter = mSymbolIdMap.find(symbol->uniqueId());
548548
if (iter != mSymbolIdMap.end())
549549
{
550550
return iter->second;
@@ -761,7 +761,7 @@ spirv::IdRef OutputSPIRVTraverser::getSymbolIdAndStorageClass(const TSymbol *sym
761761
break;
762762
}
763763

764-
mSymbolIdMap.insert({symbol, varId});
764+
mSymbolIdMap.insert({symbol->uniqueId(), varId});
765765
return varId;
766766
}
767767

@@ -1233,8 +1233,8 @@ void OutputSPIRVTraverser::declareConst(TIntermDeclaration *decl)
12331233
initializer->isConstantNullValue());
12341234

12351235
// Remember the id of the variable for future look up.
1236-
ASSERT(mSymbolIdMap.count(variable) == 0);
1237-
mSymbolIdMap[variable] = constId;
1236+
ASSERT(mSymbolIdMap.count(variable->uniqueId()) == 0);
1237+
mSymbolIdMap.emplace(variable->uniqueId(), constId);
12381238

12391239
if (!mInGlobalScope)
12401240
{
@@ -1267,8 +1267,8 @@ void OutputSPIRVTraverser::declareSpecConst(TIntermDeclaration *decl)
12671267
type.getBasicType(), type.getLayoutQualifier().location, mBuilder.getName(variable).data());
12681268

12691269
// Remember the id of the variable for future look up.
1270-
ASSERT(mSymbolIdMap.count(variable) == 0);
1271-
mSymbolIdMap[variable] = specConstId;
1270+
ASSERT(mSymbolIdMap.count(variable->uniqueId()) == 0);
1271+
mSymbolIdMap.emplace(variable->uniqueId(), specConstId);
12721272
}
12731273

12741274
spirv::IdRef OutputSPIRVTraverser::createConstant(const TType &type,
@@ -4980,8 +4980,8 @@ void OutputSPIRVTraverser::visitSymbol(TIntermSymbol *node)
49804980
type.getQualifier() == EvqSpecConst)
49814981
{
49824982
ASSERT(interfaceBlock == nullptr);
4983-
ASSERT(mSymbolIdMap.count(symbol) > 0);
4984-
nodeDataInitRValue(&mNodeData.back(), mSymbolIdMap[symbol], typeId);
4983+
ASSERT(mSymbolIdMap.count(symbol->uniqueId()) > 0);
4984+
nodeDataInitRValue(&mNodeData.back(), mSymbolIdMap[symbol->uniqueId()], typeId);
49854985
return;
49864986
}
49874987

@@ -5780,8 +5780,8 @@ bool OutputSPIRVTraverser::visitFunctionDefinition(Visit visit, TIntermFunctionD
57805780
ids.parameterTypeIds[paramIndex], paramId);
57815781

57825782
// Remember the id of the variable for future look up.
5783-
ASSERT(mSymbolIdMap.count(paramVariable) == 0);
5784-
mSymbolIdMap[paramVariable] = paramId;
5783+
ASSERT(mSymbolIdMap.count(paramVariable->uniqueId()) == 0);
5784+
mSymbolIdMap.emplace(paramVariable->uniqueId(), paramId);
57855785

57865786
mBuilder.writeDebugName(paramId, mBuilder.getName(paramVariable).data());
57875787
}
@@ -5881,9 +5881,9 @@ bool OutputSPIRVTraverser::visitGlobalQualifierDeclaration(Visit visit,
58815881
ASSERT(node->isInvariant());
58825882

58835883
const TVariable *variable = &node->getSymbol()->variable();
5884-
ASSERT(mSymbolIdMap.count(variable) > 0);
5884+
ASSERT(mSymbolIdMap.count(variable->uniqueId()) > 0);
58855885

5886-
const spirv::IdRef variableId = mSymbolIdMap[variable];
5886+
const spirv::IdRef variableId = mSymbolIdMap[variable->uniqueId()];
58875887

58885888
spirv::WriteDecorate(mBuilder.getSpirvDecorations(), variableId, spv::DecorationInvariant, {});
58895889

@@ -6345,13 +6345,13 @@ bool OutputSPIRVTraverser::visitDeclaration(Visit visit, TIntermDeclaration *nod
63456345

63466346
// Remember the id of the variable for future look up. For interface blocks, also remember the
63476347
// id of the interface block.
6348-
ASSERT(mSymbolIdMap.count(variable) == 0);
6349-
mSymbolIdMap[variable] = variableId;
6348+
ASSERT(mSymbolIdMap.count(variable->uniqueId()) == 0);
6349+
mSymbolIdMap.emplace(variable->uniqueId(), variableId);
63506350

63516351
if (type.isInterfaceBlock())
63526352
{
6353-
ASSERT(mSymbolIdMap.count(type.getInterfaceBlock()) == 0);
6354-
mSymbolIdMap[type.getInterfaceBlock()] = variableId;
6353+
ASSERT(mSymbolIdMap.count(type.getInterfaceBlock()->uniqueId()) == 0);
6354+
mSymbolIdMap.emplace(type.getInterfaceBlock()->uniqueId(), variableId);
63556355
}
63566356

63576357
return false;

0 commit comments

Comments
 (0)