Commit c859c0ac by Tim Van Patten Committed by Commit Bot

Batch replace std::unordered_map with angle::HashMap in src/

There are a few places that will remain std::unordered_map due to build or run-time errors, which will need to be evaluated more closely to determine if they should remain std::unordered_map or if there is another Abseil data structure that would be more efficient while still working correctly. Bug: angleproject:4873 Change-Id: Ib04253e3ad6398e63f4cc2bfe12c0f9e57cb112b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2558873 Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCharlie Lao <cclao@google.com>
parent b22b1502
......@@ -130,7 +130,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
key.output = output;
using UniqueTCompiler = std::unique_ptr<TCompiler, TCompilerDeleter>;
static angle::base::NoDestructor<std::unordered_map<TranslatorCacheKey, UniqueTCompiler>>
static angle::base::NoDestructor<angle::HashMap<TranslatorCacheKey, UniqueTCompiler>>
translators;
if (translators->find(key) == translators->end())
......
......@@ -24,7 +24,7 @@ class CollectVariableRefCountsTraverser : public TIntermTraverser
public:
CollectVariableRefCountsTraverser();
using RefCountMap = std::unordered_map<int, unsigned int>;
using RefCountMap = angle::HashMap<int, unsigned int>;
RefCountMap &getSymbolIdRefCounts() { return mSymbolIdRefCounts; }
RefCountMap &getStructIdRefCounts() { return mStructIdRefCounts; }
......
......@@ -191,7 +191,7 @@ struct InstantiationHash
typedef std::map<ImmutableString, std::unordered_map<Instantiation, TFunction *, InstantiationHash>>
FunctionInstantiations;
typedef std::unordered_map<const TFunction *, const TFunction *> FunctionMap;
typedef angle::HashMap<const TFunction *, const TFunction *> FunctionMap;
// Generates a new function from the given function using the given
// instantiation; generatedInstantiations can be null.
......@@ -299,9 +299,9 @@ struct VariableExtraData
{
// The value consists of strides, starting from the outermost array.
// For example, with sampler2D foo[3][6], we would have {1, 6, 18}.
std::unordered_map<const TVariable *, std::vector<size_t>> arrayStrideMap;
angle::HashMap<const TVariable *, std::vector<size_t>> arrayStrideMap;
// For each generated array parameter, holds the offset parameter.
std::unordered_map<const TVariable *, const TVariable *> paramOffsetMap;
angle::HashMap<const TVariable *, const TVariable *> paramOffsetMap;
};
class Traverser final : public TIntermTraverser, public ArrayTraverser
......@@ -489,10 +489,7 @@ class Traverser final : public TIntermTraverser, public ArrayTraverser
FunctionInstantiations *getFunctionInstantiations() { return &mFunctionInstantiations; }
std::unordered_map<const TFunction *, const TFunction *> *getFunctionMap()
{
return &mFunctionMap;
}
angle::HashMap<const TFunction *, const TFunction *> *getFunctionMap() { return &mFunctionMap; }
private:
// This returns the name of a struct sampler reference. References are always TIntermBinary.
......@@ -1024,13 +1021,13 @@ class Traverser final : public TIntermTraverser, public ArrayTraverser
class MonomorphizeTraverser final : public TIntermTraverser
{
public:
typedef std::unordered_map<const TVariable *, const TVariable *> VariableReplacementMap;
typedef angle::HashMap<const TVariable *, const TVariable *> VariableReplacementMap;
explicit MonomorphizeTraverser(
TCompiler *compiler,
TSymbolTable *symbolTable,
FunctionInstantiations *functionInstantiations,
std::unordered_map<const TFunction *, const TFunction *> *functionMap)
angle::HashMap<const TFunction *, const TFunction *> *functionMap)
: TIntermTraverser(true, false, true, symbolTable),
mFunctionInstantiations(*functionInstantiations),
mFunctionMap(functionMap),
......@@ -1131,7 +1128,7 @@ class MonomorphizeTraverser final : public TIntermTraverser
FunctionInstantiations mGeneratedInstantiations;
// New instantiations caused by other instantiations.
FunctionInstantiations mPendingInstantiations;
std::unordered_map<const TFunction *, const TFunction *> *mFunctionMap;
angle::HashMap<const TFunction *, const TFunction *> *mFunctionMap;
TIntermSequence mReplacementPrototypes;
TCompiler *mCompiler;
bool mSubpassesSucceeded;
......@@ -1166,7 +1163,7 @@ class MonomorphizeTraverser final : public TIntermTraverser
TSymbolTable *symbolTable,
FunctionInstantiations *pendingInstantiations,
FunctionInstantiations *generatedInstantiations,
std::unordered_map<const TFunction *, const TFunction *> *functionMap)
angle::HashMap<const TFunction *, const TFunction *> *functionMap)
: TIntermTraverser(true, false, false, symbolTable),
mPendingInstantiations(pendingInstantiations),
mGeneratedInstantiations(generatedInstantiations),
......@@ -1198,7 +1195,7 @@ class MonomorphizeTraverser final : public TIntermTraverser
private:
FunctionInstantiations *mPendingInstantiations;
FunctionInstantiations *mGeneratedInstantiations;
std::unordered_map<const TFunction *, const TFunction *> *mFunctionMap;
angle::HashMap<const TFunction *, const TFunction *> *mFunctionMap;
};
};
} // anonymous namespace
......
......@@ -124,18 +124,18 @@ class RetypeOpaqueVariablesHelper
private:
// A map from the old global variable to the new one.
std::unordered_map<const TVariable *, TVariable *> mReplacedGlobalVariables;
angle::HashMap<const TVariable *, TVariable *> mReplacedGlobalVariables;
// A map from functions with old type parameters to one where that's replaced with the new type.
std::unordered_map<const TFunction *, TFunction *> mReplacedFunctions;
angle::HashMap<const TFunction *, TFunction *> mReplacedFunctions;
// A map from function old type parameters to their replacement new type parameter for the
// current function definition.
std::unordered_map<const TVariable *, TVariable *> mReplacedFunctionParams;
angle::HashMap<const TVariable *, TVariable *> mReplacedFunctionParams;
// A map from function call old type arguments to their replacement for the current function
// call.
std::stack<std::unordered_map<const TIntermNode *, TIntermTyped *>> mReplacedFunctionCallArgs;
std::stack<angle::HashMap<const TIntermNode *, TIntermTyped *>> mReplacedFunctionCallArgs;
};
} // namespace sh
......
......@@ -549,7 +549,7 @@ angle::Result GLES1Renderer::linkProgram(Context *context,
State *glState,
ShaderProgramID vertexShader,
ShaderProgramID fragmentShader,
const std::unordered_map<GLint, std::string> &attribLocs,
const angle::HashMap<GLint, std::string> &attribLocs,
ShaderProgramID *programOut)
{
ShaderProgramID program = mShaderPrograms->createProgram(context->getImplementation());
......@@ -615,7 +615,7 @@ angle::Result GLES1Renderer::initializeRendererProgram(Context *context, State *
ANGLE_TRY(compileShader(context, ShaderType::Fragment, fragmentStream.str().c_str(),
&fragmentShader));
std::unordered_map<GLint, std::string> attribLocs;
angle::HashMap<GLint, std::string> attribLocs;
attribLocs[(GLint)kVertexAttribIndex] = "pos";
attribLocs[(GLint)kNormalAttribIndex] = "normal";
......
......@@ -66,7 +66,7 @@ class GLES1Renderer final : angle::NonCopyable
State *glState,
ShaderProgramID vshader,
ShaderProgramID fshader,
const std::unordered_map<GLint, std::string> &attribLocs,
const angle::HashMap<GLint, std::string> &attribLocs,
ShaderProgramID *programOut);
angle::Result initializeRendererProgram(Context *context, State *glState);
......
......@@ -192,12 +192,12 @@ class ProgramAliasedBindings final : angle::NonCopyable
int getBindingByLocation(GLuint location) const;
int getBinding(const sh::ShaderVariable &variable) const;
using const_iterator = std::unordered_map<std::string, ProgramBinding>::const_iterator;
using const_iterator = angle::HashMap<std::string, ProgramBinding>::const_iterator;
const_iterator begin() const;
const_iterator end() const;
private:
std::unordered_map<std::string, ProgramBinding> mBindings;
angle::HashMap<std::string, ProgramBinding> mBindings;
};
class ProgramState final : angle::NonCopyable
......
......@@ -399,9 +399,9 @@ bool ProgramExecutable::linkValidateGlobalNames(
InfoLog &infoLog,
const ShaderMap<const ProgramState *> &programStates) const
{
std::unordered_map<std::string, const sh::ShaderVariable *> uniformMap;
angle::HashMap<std::string, const sh::ShaderVariable *> uniformMap;
using BlockAndFieldPair = std::pair<const sh::InterfaceBlock *, const sh::ShaderVariable *>;
std::unordered_map<std::string, std::vector<BlockAndFieldPair>> uniformBlockFieldMap;
angle::HashMap<std::string, std::vector<BlockAndFieldPair>> uniformBlockFieldMap;
for (ShaderType shaderType : kAllGraphicsShaderTypes)
{
......
......@@ -47,7 +47,7 @@ class ResourceMap final : angle::NonCopyable
void clear();
using IndexAndResource = std::pair<GLuint, ResourceType *>;
using HashMap = std::unordered_map<GLuint, ResourceType *>;
using HashMap = angle::HashMap<GLuint, ResourceType *>;
class Iterator final
{
......@@ -297,8 +297,8 @@ bool ResourceMap<ResourceType, IDType>::Iterator::operator!=(const Iterator &oth
}
template <typename ResourceType, typename IDType>
typename ResourceMap<ResourceType, IDType>::Iterator &ResourceMap<ResourceType, IDType>::Iterator::
operator++()
typename ResourceMap<ResourceType, IDType>::Iterator &
ResourceMap<ResourceType, IDType>::Iterator::operator++()
{
if (mFlatIndex < static_cast<GLuint>(mOrigin.mFlatResourcesSize))
{
......@@ -313,15 +313,15 @@ operator++()
}
template <typename ResourceType, typename IDType>
const typename ResourceMap<ResourceType, IDType>::IndexAndResource
*ResourceMap<ResourceType, IDType>::Iterator::operator->() const
const typename ResourceMap<ResourceType, IDType>::IndexAndResource *
ResourceMap<ResourceType, IDType>::Iterator::operator->() const
{
return &mValue;
}
template <typename ResourceType, typename IDType>
const typename ResourceMap<ResourceType, IDType>::IndexAndResource
&ResourceMap<ResourceType, IDType>::Iterator::operator*() const
const typename ResourceMap<ResourceType, IDType>::IndexAndResource &
ResourceMap<ResourceType, IDType>::Iterator::operator*() const
{
return mValue;
}
......
......@@ -95,7 +95,7 @@ class ShaderCache : angle::NonCopyable
return mDevice->CreatePixelShader(function, shader);
}
typedef std::unordered_map<std::string, ShaderObject *> Map;
typedef angle::HashMap<std::string, ShaderObject *> Map;
Map mMap;
std::mutex mMutex;
......
......@@ -166,7 +166,7 @@ class RendererGL : angle::NonCopyable
mutable MultiviewImplementationTypeGL mMultiviewImplementationType;
// The thread-to-context mapping for the currently active worker threads.
std::unordered_map<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts;
angle::HashMap<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts;
// The worker contexts available to use.
std::list<std::unique_ptr<WorkerContext>> mWorkerContextPool;
// Protect the concurrent accesses to worker contexts.
......
......@@ -133,7 +133,7 @@ class DisplayEGL : public DisplayGL
EGLSurface surface = EGL_NO_SURFACE;
EGLContext context = EGL_NO_CONTEXT;
};
std::unordered_map<std::thread::id, CurrentNativeContext> mCurrentNativeContexts;
angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentNativeContexts;
private:
void generateCaps(egl::Caps *outCaps) const override;
......
......@@ -125,7 +125,7 @@ class DisplayGLX : public DisplayGL
XVisualInfo *mVisuals;
glx::Context mContext;
glx::Context mSharedContext;
std::unordered_map<std::thread::id, glx::Context> mCurrentContexts;
angle::HashMap<std::thread::id, glx::Context> mCurrentContexts;
// A pbuffer the context is current on during ANGLE initialization
glx::Pbuffer mInitPbuffer;
......
......@@ -118,7 +118,7 @@ class DisplayWGL : public DisplayGL
HDC dc = nullptr;
HGLRC glrc = nullptr;
};
std::unordered_map<std::thread::id, CurrentNativeContext> mCurrentData;
angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentData;
HMODULE mOpenGLModule;
......
......@@ -98,7 +98,7 @@ struct ShaderInterfaceVariableInfo
// TODO: http://anglebug.com/4524: Need a different hash key than a string, since
// that's slow to calculate.
using ShaderInterfaceVariableInfoMap = std::unordered_map<std::string, ShaderInterfaceVariableInfo>;
using ShaderInterfaceVariableInfoMap = angle::HashMap<std::string, ShaderInterfaceVariableInfo>;
using ShaderMapInterfaceVariableInfoMap = gl::ShaderMap<ShaderInterfaceVariableInfoMap>;
void GlslangInitialize();
......
......@@ -162,7 +162,7 @@ class FormatTable final : angle::NonCopyable
void setCompressedFormatCaps(MTLPixelFormat formatId, bool filterable);
std::array<Format, angle::kNumANGLEFormats> mPixelFormatTable;
std::unordered_map<MTLPixelFormat, FormatCaps> mNativePixelFormatCapsTable;
angle::HashMap<MTLPixelFormat, FormatCaps> mNativePixelFormatCapsTable;
// One for tightly packed buffers, one for general cases.
std::array<VertexFormat, angle::kNumANGLEFormats> mVertexFormatTables[2];
......
......@@ -31,7 +31,7 @@ constexpr uint32_t kGlslangShaderResourceDescSet = 3;
// Original mapping of front end from sampler name to multiple sampler slots (in form of
// slot:count pair)
using OriginalSamplerBindingMap =
std::unordered_map<std::string, std::vector<std::pair<uint32_t, uint32_t>>>;
angle::HashMap<std::string, std::vector<std::pair<uint32_t, uint32_t>>>;
angle::Result HandleError(ErrorHandler *context, GlslangError)
{
......@@ -79,8 +79,8 @@ spv::ExecutionModel ShaderTypeToSpvExecutionModel(gl::ShaderType shaderType)
void BindBuffers(spirv_cross::CompilerMSL *compiler,
const spirv_cross::SmallVector<spirv_cross::Resource> &resources,
gl::ShaderType shaderType,
const std::unordered_map<std::string, uint32_t> &uboOriginalBindings,
const std::unordered_map<uint32_t, uint32_t> &xfbOriginalBindings,
const angle::HashMap<std::string, uint32_t> &uboOriginalBindings,
const angle::HashMap<uint32_t, uint32_t> &xfbOriginalBindings,
std::array<uint32_t, kMaxGLUBOBindings> *uboBindingsRemapOut,
std::array<uint32_t, kMaxShaderXFBs> *xfbBindingRemapOut,
bool *uboArgumentBufferUsed)
......@@ -275,8 +275,8 @@ class SpirvToMslCompiler : public spirv_cross::CompilerMSL
SpirvToMslCompiler(std::vector<uint32_t> &&spriv) : spirv_cross::CompilerMSL(spriv) {}
void compileEx(gl::ShaderType shaderType,
const std::unordered_map<std::string, uint32_t> &uboOriginalBindings,
const std::unordered_map<uint32_t, uint32_t> &xfbOriginalBindings,
const angle::HashMap<std::string, uint32_t> &uboOriginalBindings,
const angle::HashMap<uint32_t, uint32_t> &xfbOriginalBindings,
const OriginalSamplerBindingMap &originalSamplerBindings,
TranslatedShaderInfo *mslShaderInfoOut)
{
......@@ -350,14 +350,13 @@ class SpirvToMslCompiler : public spirv_cross::CompilerMSL
}
};
angle::Result ConvertSpirvToMsl(
Context *context,
gl::ShaderType shaderType,
const std::unordered_map<std::string, uint32_t> &uboOriginalBindings,
const std::unordered_map<uint32_t, uint32_t> &xfbOriginalBindings,
const OriginalSamplerBindingMap &originalSamplerBindings,
std::vector<uint32_t> *sprivCode,
TranslatedShaderInfo *translatedShaderInfoOut)
angle::Result ConvertSpirvToMsl(Context *context,
gl::ShaderType shaderType,
const angle::HashMap<std::string, uint32_t> &uboOriginalBindings,
const angle::HashMap<uint32_t, uint32_t> &xfbOriginalBindings,
const OriginalSamplerBindingMap &originalSamplerBindings,
std::vector<uint32_t> *sprivCode,
TranslatedShaderInfo *translatedShaderInfoOut)
{
if (!sprivCode || sprivCode->empty())
{
......@@ -479,7 +478,7 @@ angle::Result SpirvCodeToMsl(Context *context,
TranslatedShaderInfo *mslXfbOnlyShaderInfoOut /** nullable */)
{
// Retrieve original uniform buffer bindings generated by front end. We will need to do a remap.
std::unordered_map<std::string, uint32_t> uboOriginalBindings;
angle::HashMap<std::string, uint32_t> uboOriginalBindings;
const std::vector<gl::InterfaceBlock> &blocks = programState.getUniformBlocks();
for (uint32_t bufferIdx = 0; bufferIdx < blocks.size(); ++bufferIdx)
{
......@@ -490,7 +489,7 @@ angle::Result SpirvCodeToMsl(Context *context,
}
}
// Retrieve original XFB buffers bindings produced by front end.
std::unordered_map<uint32_t, uint32_t> xfbOriginalBindings;
angle::HashMap<uint32_t, uint32_t> xfbOriginalBindings;
for (uint32_t bufferIdx = 0; bufferIdx < kMaxShaderXFBs; ++bufferIdx)
{
std::string bufferName = rx::GetXfbBufferName(bufferIdx);
......
......@@ -475,7 +475,7 @@ class RenderPipelineCache final : angle::NonCopyable
bool hasDefaultAttribs(const RenderPipelineDesc &desc) const;
// One table with default attrib and one table without.
std::unordered_map<RenderPipelineDesc, AutoObjCPtr<id<MTLRenderPipelineState>>>
angle::HashMap<RenderPipelineDesc, AutoObjCPtr<id<MTLRenderPipelineState>>>
mRenderPipelineStates[2];
RenderPipelineCacheSpecializeShaderFactory *mSpecializedShaderFactory;
......@@ -503,8 +503,8 @@ class StateCache final : angle::NonCopyable
private:
AutoObjCPtr<id<MTLDepthStencilState>> mNullDepthStencilState = nil;
std::unordered_map<DepthStencilDesc, AutoObjCPtr<id<MTLDepthStencilState>>> mDepthStencilStates;
std::unordered_map<SamplerDesc, AutoObjCPtr<id<MTLSamplerState>>> mSamplerStates;
angle::HashMap<DepthStencilDesc, AutoObjCPtr<id<MTLDepthStencilState>>> mDepthStencilStates;
angle::HashMap<SamplerDesc, AutoObjCPtr<id<MTLSamplerState>>> mSamplerStates;
};
} // namespace mtl
......
......@@ -1184,7 +1184,7 @@ angle::Result ProgramExecutableVk::updateImagesDescriptorSet(
const gl::ActiveTextureArray<TextureVk *> &activeImages = contextVk->getActiveImages();
bool useOldRewriteStructSamplers = contextVk->useOldRewriteStructSamplers();
std::unordered_map<std::string, uint32_t> mappedImageNameToArrayOffset;
angle::HashMap<std::string, uint32_t> mappedImageNameToArrayOffset;
// Write images.
for (uint32_t imageIndex = 0; imageIndex < imageBindings.size(); ++imageIndex)
......@@ -1440,7 +1440,7 @@ angle::Result ProgramExecutableVk::updateTexturesDescriptorSet(ContextVk *contex
for (const gl::ShaderType shaderType : executable->getLinkedShaderStages())
{
std::unordered_map<std::string, uint32_t> mappedSamplerNameToArrayOffset;
angle::HashMap<std::string, uint32_t> mappedSamplerNameToArrayOffset;
const gl::ProgramState *programState = programStates[shaderType];
ASSERT(programState);
for (uint32_t textureIndex = 0; textureIndex < programState->getSamplerBindings().size();
......
......@@ -1338,8 +1338,8 @@ class RenderPassCache final : angle::NonCopyable
// Use a two-layer caching scheme. The top level matches the "compatible" RenderPass elements.
// The second layer caches the attachment load/store ops and initial/final layout.
using InnerCache = std::unordered_map<vk::AttachmentOpsArray, vk::RenderPassHelper>;
using OuterCache = std::unordered_map<vk::RenderPassDesc, InnerCache>;
using InnerCache = angle::HashMap<vk::AttachmentOpsArray, vk::RenderPassHelper>;
using OuterCache = angle::HashMap<vk::RenderPassDesc, InnerCache>;
OuterCache mPayload;
};
......
......@@ -742,7 +742,7 @@ std::string GetConfigNameFromTestIdentifier(const TestIdentifier &id)
TestQueue BatchTests(const std::vector<TestIdentifier> &tests, int batchSize)
{
// First sort tests by configuration.
std::unordered_map<std::string, std::vector<TestIdentifier>> testsSortedByConfig;
angle::HashMap<std::string, std::vector<TestIdentifier>> testsSortedByConfig;
for (const TestIdentifier &id : tests)
{
std::string config = GetConfigNameFromTestIdentifier(id);
......
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