Commit 63d8c266 by Jamie Madill Committed by Commit Bot

Re-use std::hash in RenderStateCache.

This will allow us to more easily take advantage of Chromium's MRUCache class. BUG=angleproject:2044 Change-Id: I3fad82fc825861dc1c2095f25da83159da76e76b Reviewed-on: https://chromium-review.googlesource.com/517359Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent aa0a5446
......@@ -23,6 +23,21 @@ namespace rx
{
using namespace gl_d3d11;
template <typename T>
std::size_t ComputeGenericHash(const T &key)
{
static const unsigned int seed = 0xABCDEF98;
std::size_t hash = 0;
MurmurHash3_x86_32(&key, sizeof(key), seed, &hash);
return hash;
}
template std::size_t ComputeGenericHash(const rx::d3d11::BlendStateKey &);
template std::size_t ComputeGenericHash(const rx::d3d11::RasterizerStateKey &);
template std::size_t ComputeGenericHash(const gl::DepthStencilState &);
template std::size_t ComputeGenericHash(const gl::SamplerState &);
// 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
......@@ -36,10 +51,10 @@ const unsigned int RenderStateCache::kMaxSamplerStates = 2048;
RenderStateCache::RenderStateCache(Renderer11 *renderer)
: mRenderer(renderer),
mCounter(0),
mBlendStateCache(kMaxBlendStates, HashBlendState),
mRasterizerStateCache(kMaxRasterizerStates, HashRasterizerState),
mDepthStencilStateCache(kMaxDepthStencilStates, HashDepthStencilState),
mSamplerStateCache(kMaxSamplerStates, HashSamplerState)
mBlendStateCache(kMaxBlendStates),
mRasterizerStateCache(kMaxRasterizerStates),
mDepthStencilStateCache(kMaxDepthStencilStates),
mSamplerStateCache(kMaxSamplerStates)
{
}
......@@ -56,16 +71,6 @@ void RenderStateCache::clear()
}
// static
std::size_t RenderStateCache::HashBlendState(const d3d11::BlendStateKey &blendState)
{
static const unsigned int seed = 0xABCDEF98;
std::size_t hash = 0;
MurmurHash3_x86_32(&blendState, sizeof(d3d11::BlendStateKey), seed, &hash);
return hash;
}
// static
d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState)
{
......@@ -174,16 +179,6 @@ gl::Error RenderStateCache::getBlendState(const d3d11::BlendStateKey &key,
}
}
// static
std::size_t RenderStateCache::HashRasterizerState(const d3d11::RasterizerStateKey &rasterState)
{
static const unsigned int seed = 0xABCDEF98;
std::size_t hash = 0;
MurmurHash3_x86_32(&rasterState, sizeof(d3d11::RasterizerStateKey), seed, &hash);
return hash;
}
gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState)
{
......@@ -256,16 +251,6 @@ gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &raster
}
}
// static
std::size_t RenderStateCache::HashDepthStencilState(const gl::DepthStencilState &dsState)
{
static const unsigned int seed = 0xABCDEF98;
std::size_t hash = 0;
MurmurHash3_x86_32(&dsState, sizeof(gl::DepthStencilState), seed, &hash);
return hash;
}
gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &glState,
ID3D11DepthStencilState **outDSState)
{
......@@ -319,16 +304,6 @@ gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &gl
return gl::NoError();
}
// static
std::size_t RenderStateCache::HashSamplerState(const gl::SamplerState &samplerState)
{
static const unsigned int seed = 0xABCDEF98;
std::size_t hash = 0;
MurmurHash3_x86_32(&samplerState, sizeof(gl::SamplerState), seed, &hash);
return hash;
}
gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState)
{
SamplerStateMap::iterator keyIter = mSamplerStateCache.find(samplerState);
......
......@@ -24,6 +24,48 @@ class Framebuffer;
namespace rx
{
template <typename T>
std::size_t ComputeGenericHash(const T &key);
} // namespace rx
namespace std
{
template <>
struct hash<rx::d3d11::BlendStateKey>
{
size_t operator()(const rx::d3d11::BlendStateKey &key) const
{
return rx::ComputeGenericHash(key);
}
};
template <>
struct hash<rx::d3d11::RasterizerStateKey>
{
size_t operator()(const rx::d3d11::RasterizerStateKey &key) const
{
return rx::ComputeGenericHash(key);
}
};
template <>
struct hash<gl::DepthStencilState>
{
size_t operator()(const gl::DepthStencilState &key) const
{
return rx::ComputeGenericHash(key);
}
};
template <>
struct hash<gl::SamplerState>
{
size_t operator()(const gl::SamplerState &key) const { return rx::ComputeGenericHash(key); }
};
} // namespace std
namespace rx
{
class Renderer11;
class RenderStateCache : angle::NonCopyable
......@@ -47,47 +89,33 @@ class RenderStateCache : angle::NonCopyable
unsigned long long mCounter;
// Blend state cache
static std::size_t HashBlendState(const d3d11::BlendStateKey &blendState);
static const unsigned int kMaxBlendStates;
typedef std::size_t (*BlendStateHashFunction)(const d3d11::BlendStateKey &);
typedef std::pair<d3d11::BlendState, unsigned long long> BlendStateCounterPair;
typedef std::unordered_map<d3d11::BlendStateKey, BlendStateCounterPair, BlendStateHashFunction>
BlendStateMap;
typedef std::unordered_map<d3d11::BlendStateKey, BlendStateCounterPair> BlendStateMap;
BlendStateMap mBlendStateCache;
// Rasterizer state cache
static std::size_t HashRasterizerState(const d3d11::RasterizerStateKey &rasterState);
static const unsigned int kMaxRasterizerStates;
typedef std::size_t (*RasterizerStateHashFunction)(const d3d11::RasterizerStateKey &);
typedef std::pair<d3d11::RasterizerState, unsigned long long> RasterizerStateCounterPair;
typedef std::unordered_map<d3d11::RasterizerStateKey,
RasterizerStateCounterPair,
RasterizerStateHashFunction>
typedef std::unordered_map<d3d11::RasterizerStateKey, RasterizerStateCounterPair>
RasterizerStateMap;
RasterizerStateMap mRasterizerStateCache;
// Depth stencil state cache
static std::size_t HashDepthStencilState(const gl::DepthStencilState &dsState);
static const unsigned int kMaxDepthStencilStates;
typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
typedef std::pair<d3d11::DepthStencilState, unsigned long long> DepthStencilStateCounterPair;
typedef std::unordered_map<gl::DepthStencilState,
DepthStencilStateCounterPair,
DepthStencilStateHashFunction>
typedef std::unordered_map<gl::DepthStencilState, DepthStencilStateCounterPair>
DepthStencilStateMap;
DepthStencilStateMap mDepthStencilStateCache;
// Sample state cache
static std::size_t HashSamplerState(const gl::SamplerState &samplerState);
static const unsigned int kMaxSamplerStates;
typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
typedef std::pair<d3d11::SamplerState, unsigned long long> SamplerStateCounterPair;
typedef std::unordered_map<gl::SamplerState, SamplerStateCounterPair, SamplerStateHashFunction>
SamplerStateMap;
typedef std::unordered_map<gl::SamplerState, SamplerStateCounterPair> SamplerStateMap;
SamplerStateMap mSamplerStateCache;
};
......
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