summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h')
-rw-r--r--src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h137
1 files changed, 73 insertions, 64 deletions
diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h
index 82cb13903c..7501e83fc4 100644
--- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h
+++ b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.h
@@ -10,9 +10,11 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_
#define LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_
-#include "libANGLE/angletypes.h"
-#include "libANGLE/Error.h"
#include "common/angleutils.h"
+#include "libANGLE/Error.h"
+#include "libANGLE/SizedMRUCache.h"
+#include "libANGLE/angletypes.h"
+#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include <unordered_map>
@@ -21,6 +23,42 @@ namespace gl
class Framebuffer;
}
+namespace std
+{
+template <>
+struct hash<rx::d3d11::BlendStateKey>
+{
+ size_t operator()(const rx::d3d11::BlendStateKey &key) const
+ {
+ return angle::ComputeGenericHash(key);
+ }
+};
+
+template <>
+struct hash<rx::d3d11::RasterizerStateKey>
+{
+ size_t operator()(const rx::d3d11::RasterizerStateKey &key) const
+ {
+ return angle::ComputeGenericHash(key);
+ }
+};
+
+template <>
+struct hash<gl::DepthStencilState>
+{
+ size_t operator()(const gl::DepthStencilState &key) const
+ {
+ return angle::ComputeGenericHash(key);
+ }
+};
+
+template <>
+struct hash<gl::SamplerState>
+{
+ size_t operator()(const gl::SamplerState &key) const { return angle::ComputeGenericHash(key); }
+};
+} // namespace std
+
namespace rx
{
class Renderer11;
@@ -28,87 +66,58 @@ class Renderer11;
class RenderStateCache : angle::NonCopyable
{
public:
- RenderStateCache(Renderer11 *renderer);
+ RenderStateCache();
virtual ~RenderStateCache();
- void initialize(ID3D11Device *device);
void clear();
- gl::Error getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, ID3D11BlendState **outBlendState);
- gl::Error getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, ID3D11RasterizerState **outRasterizerState);
- gl::Error getDepthStencilState(const gl::DepthStencilState &dsState,
- bool disableDepth,
- bool disableStencil,
- ID3D11DepthStencilState **outDSState);
- gl::Error getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState);
+ static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context,
+ const gl::Framebuffer *framebuffer,
+ const gl::BlendState &blendState);
+ gl::Error getBlendState(Renderer11 *renderer,
+ const d3d11::BlendStateKey &key,
+ const d3d11::BlendState **outBlendState);
+ gl::Error getRasterizerState(Renderer11 *renderer,
+ const gl::RasterizerState &rasterState,
+ bool scissorEnabled,
+ ID3D11RasterizerState **outRasterizerState);
+ gl::Error getDepthStencilState(Renderer11 *renderer,
+ const gl::DepthStencilState &dsState,
+ const d3d11::DepthStencilState **outDSState);
+ gl::Error getSamplerState(Renderer11 *renderer,
+ const gl::SamplerState &samplerState,
+ ID3D11SamplerState **outSamplerState);
private:
- Renderer11 *mRenderer;
- unsigned long long mCounter;
+ // MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState,
+ // ID3D11Device::CreateDepthStencilState and ID3D11Device::CreateSamplerState claims the maximum
+ // number of unique states of each type an application can create is 4096
+ // TODO(ShahmeerEsmail): Revisit the cache sizes to make sure they are appropriate for most
+ // scenarios.
+ static constexpr unsigned int kMaxStates = 4096;
+
+ // The cache tries to clean up this many states at once.
+ static constexpr unsigned int kGCLimit = 128;
// Blend state cache
- struct BlendStateKey
- {
- gl::BlendState blendState;
- bool rtChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
- };
- static std::size_t hashBlendState(const BlendStateKey &blendState);
- static bool compareBlendStates(const BlendStateKey &a, const BlendStateKey &b);
- static const unsigned int kMaxBlendStates;
-
- typedef std::size_t (*BlendStateHashFunction)(const BlendStateKey &);
- typedef bool (*BlendStateEqualityFunction)(const BlendStateKey &, const BlendStateKey &);
- typedef std::pair<ID3D11BlendState*, unsigned long long> BlendStateCounterPair;
- typedef std::unordered_map<BlendStateKey, BlendStateCounterPair, BlendStateHashFunction, BlendStateEqualityFunction> BlendStateMap;
+ using BlendStateMap = angle::base::HashingMRUCache<d3d11::BlendStateKey, d3d11::BlendState>;
BlendStateMap mBlendStateCache;
// Rasterizer state cache
- struct RasterizerStateKey
- {
- gl::RasterizerState rasterizerState;
- bool scissorEnabled;
- };
- static std::size_t hashRasterizerState(const RasterizerStateKey &rasterState);
- static bool compareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b);
- static const unsigned int kMaxRasterizerStates;
-
- typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &);
- typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &);
- typedef std::pair<ID3D11RasterizerState*, unsigned long long> RasterizerStateCounterPair;
- typedef std::unordered_map<RasterizerStateKey, RasterizerStateCounterPair, RasterizerStateHashFunction, RasterizerStateEqualityFunction> RasterizerStateMap;
+ using RasterizerStateMap =
+ angle::base::HashingMRUCache<d3d11::RasterizerStateKey, d3d11::RasterizerState>;
RasterizerStateMap mRasterizerStateCache;
// Depth stencil state cache
- static std::size_t hashDepthStencilState(const gl::DepthStencilState &dsState);
- static bool compareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b);
- static const unsigned int kMaxDepthStencilStates;
-
- typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
- typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &);
- typedef std::pair<ID3D11DepthStencilState*, unsigned long long> DepthStencilStateCounterPair;
- typedef std::unordered_map<gl::DepthStencilState,
- DepthStencilStateCounterPair,
- DepthStencilStateHashFunction,
- DepthStencilStateEqualityFunction> DepthStencilStateMap;
+ using DepthStencilStateMap =
+ angle::base::HashingMRUCache<gl::DepthStencilState, d3d11::DepthStencilState>;
DepthStencilStateMap mDepthStencilStateCache;
// Sample state cache
- static std::size_t hashSamplerState(const gl::SamplerState &samplerState);
- static bool compareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b);
- static const unsigned int kMaxSamplerStates;
-
- typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
- typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &);
- typedef std::pair<ID3D11SamplerState*, unsigned long long> SamplerStateCounterPair;
- typedef std::unordered_map<gl::SamplerState,
- SamplerStateCounterPair,
- SamplerStateHashFunction,
- SamplerStateEqualityFunction> SamplerStateMap;
+ using SamplerStateMap = angle::base::HashingMRUCache<gl::SamplerState, d3d11::SamplerState>;
SamplerStateMap mSamplerStateCache;
-
- ID3D11Device *mDevice;
};
-}
+} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_