From 40845e6b8f10d1fb0d4b6d02b1994b1ebe7f8552 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 25 Feb 2018 00:21:04 +1000 Subject: [PATCH] D3D: Make StateCache thread safe --- Source/Core/VideoBackends/D3D/D3DState.cpp | 4 ++++ Source/Core/VideoBackends/D3D/D3DState.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Source/Core/VideoBackends/D3D/D3DState.cpp b/Source/Core/VideoBackends/D3D/D3DState.cpp index b779683fb8..8a2862479b 100644 --- a/Source/Core/VideoBackends/D3D/D3DState.cpp +++ b/Source/Core/VideoBackends/D3D/D3DState.cpp @@ -212,6 +212,7 @@ StateCache::~StateCache() ID3D11SamplerState* StateCache::Get(SamplerState state) { + std::lock_guard guard(m_lock); auto it = m_sampler.find(state.hex); if (it != m_sampler.end()) return it->second; @@ -266,6 +267,7 @@ ID3D11SamplerState* StateCache::Get(SamplerState state) ID3D11BlendState* StateCache::Get(BlendingState state) { + std::lock_guard guard(m_lock); auto it = m_blend.find(state.hex); if (it != m_blend.end()) return it->second; @@ -348,6 +350,7 @@ ID3D11BlendState* StateCache::Get(BlendingState state) ID3D11RasterizerState* StateCache::Get(RasterizationState state) { + std::lock_guard guard(m_lock); auto it = m_raster.find(state.hex); if (it != m_raster.end()) return it->second; @@ -372,6 +375,7 @@ ID3D11RasterizerState* StateCache::Get(RasterizationState state) ID3D11DepthStencilState* StateCache::Get(DepthState state) { + std::lock_guard guard(m_lock); auto it = m_depth.find(state.hex); if (it != m_depth.end()) return it->second; diff --git a/Source/Core/VideoBackends/D3D/D3DState.h b/Source/Core/VideoBackends/D3D/D3DState.h index 805ed8996b..db48e7f18b 100644 --- a/Source/Core/VideoBackends/D3D/D3DState.h +++ b/Source/Core/VideoBackends/D3D/D3DState.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "Common/BitField.h" @@ -35,6 +36,7 @@ private: std::unordered_map m_raster; std::unordered_map m_blend; std::unordered_map m_sampler; + std::mutex m_lock; }; namespace D3D