Commit 156da4c9 by jchen10 Committed by Commit Bot

ParallelCompile: Make resource tracking thread-safe

ResourceManger11 tracks the total resource count and memoery size. Such tracking can be concurrently updated from both main thread and background thread. It can be thread-safe by using std::atomic types instead. Also ShaderCache in d3d9 adds a std::mutex to be safe. Bug: angleproject:2771 Change-Id: Ia7cdcc7fd04579839a5d43e4a02adafb09e6078d Reviewed-on: https://chromium-review.googlesource.com/1175547Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
parent c1551dc2
......@@ -348,11 +348,16 @@ static_assert(kResourceTypeErrors[NumResourceTypes - 1] != nullptr,
} // anonymous namespace
// ResourceManager11 Implementation.
ResourceManager11::ResourceManager11()
: mInitializeAllocations(false),
mAllocatedResourceCounts({{}}),
mAllocatedResourceDeviceMemory({{}})
ResourceManager11::ResourceManager11() : mInitializeAllocations(false)
{
for (auto &count : mAllocatedResourceCounts)
{
count = 0;
}
for (auto &memorySize : mAllocatedResourceDeviceMemory)
{
memorySize = 0;
}
}
ResourceManager11::~ResourceManager11()
......
......@@ -10,6 +10,7 @@
#define LIBANGLE_RENDERER_D3D_D3D11_RESOURCEFACTORY11_H_
#include <array>
#include <atomic>
#include <memory>
#include "common/MemoryBuffer.h"
......@@ -337,8 +338,8 @@ class ResourceManager11 final : angle::NonCopyable
bool mInitializeAllocations;
std::array<size_t, NumResourceTypes> mAllocatedResourceCounts;
std::array<uint64_t, NumResourceTypes> mAllocatedResourceDeviceMemory;
std::array<std::atomic_size_t, NumResourceTypes> mAllocatedResourceCounts;
std::array<std::atomic_uint64_t, NumResourceTypes> mAllocatedResourceDeviceMemory;
angle::MemoryBuffer mZeroMemory;
std::vector<D3D11_SUBRESOURCE_DATA> mShadowInitData;
......
......@@ -16,8 +16,9 @@
#include "libANGLE/renderer/d3d/d3d9/Context9.h"
#include <cstddef>
#include <unordered_map>
#include <mutex>
#include <string>
#include <unordered_map>
namespace rx
{
......@@ -43,6 +44,8 @@ class ShaderCache : angle::NonCopyable
size_t length,
ShaderObject **outShaderObject)
{
std::lock_guard<std::mutex> lock(mMutex);
std::string key(reinterpret_cast<const char*>(function), length);
typename Map::iterator it = mMap.find(key);
if (it != mMap.end())
......@@ -72,6 +75,8 @@ class ShaderCache : angle::NonCopyable
void clear()
{
std::lock_guard<std::mutex> lock(mMutex);
for (typename Map::iterator it = mMap.begin(); it != mMap.end(); ++it)
{
SafeRelease(it->second);
......@@ -95,6 +100,7 @@ class ShaderCache : angle::NonCopyable
typedef std::unordered_map<std::string, ShaderObject*> Map;
Map mMap;
std::mutex mMutex;
IDirect3DDevice9 *mDevice;
};
......
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