Skip to content
Permalink
Browse files
Merge pull request #6110 from lioncash/texture-config-hash
TextureConfig: Specialize std::hash for TextureConfig
  • Loading branch information
leoetlino committed Oct 11, 2017
2 parents 6230860 + c8af9e5 commit 0eafb2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
@@ -212,9 +212,9 @@ class TextureCacheBase
int frameCount = FRAMECOUNT_INVALID;
TexPoolEntry(std::unique_ptr<AbstractTexture> tex) : texture(std::move(tex)) {}
};
typedef std::multimap<u32, TCacheEntry*> TexAddrCache;
typedef std::multimap<u64, TCacheEntry*> TexHashCache;
typedef std::unordered_multimap<TextureConfig, TexPoolEntry, TextureConfig::Hasher> TexPool;
using TexAddrCache = std::multimap<u32, TCacheEntry*>;
using TexHashCache = std::multimap<u64, TCacheEntry*>;
using TexPool = std::unordered_multimap<TextureConfig, TexPoolEntry>;

void SetBackupConfig(const VideoConfig& config);

@@ -31,14 +31,22 @@ struct TextureConfig
u32 layers = 1;
AbstractTextureFormat format = AbstractTextureFormat::RGBA8;
bool rendertarget = false;
};

namespace std
{
template <>
struct hash<TextureConfig>
{
using argument_type = TextureConfig;
using result_type = size_t;

struct Hasher : std::hash<u64>
result_type operator()(const argument_type& c) const noexcept
{
size_t operator()(const TextureConfig& c) const
{
u64 id = (u64)c.rendertarget << 63 | (u64)c.format << 50 | (u64)c.layers << 48 |
(u64)c.levels << 32 | (u64)c.height << 16 | (u64)c.width;
return std::hash<u64>::operator()(id);
}
};
const u64 id = static_cast<u64>(c.rendertarget) << 63 | static_cast<u64>(c.format) << 50 |
static_cast<u64>(c.layers) << 48 | static_cast<u64>(c.levels) << 32 |
static_cast<u64>(c.height) << 16 | static_cast<u64>(c.width);
return std::hash<u64>{}(id);
}
};
} // namespace std

0 comments on commit 0eafb2f

Please sign in to comment.