TextureConfig: Specialize std::hash for TextureConfig
This allows the hashing for TextureConfig instances to automatically be resolved instead of needing to directly specify it all the time.
This commit is contained in:
parent
1a4883ac5a
commit
c8af9e5f7b
|
@ -212,9 +212,9 @@ private:
|
||||||
int frameCount = FRAMECOUNT_INVALID;
|
int frameCount = FRAMECOUNT_INVALID;
|
||||||
TexPoolEntry(std::unique_ptr<AbstractTexture> tex) : texture(std::move(tex)) {}
|
TexPoolEntry(std::unique_ptr<AbstractTexture> tex) : texture(std::move(tex)) {}
|
||||||
};
|
};
|
||||||
typedef std::multimap<u32, TCacheEntry*> TexAddrCache;
|
using TexAddrCache = std::multimap<u32, TCacheEntry*>;
|
||||||
typedef std::multimap<u64, TCacheEntry*> TexHashCache;
|
using TexHashCache = std::multimap<u64, TCacheEntry*>;
|
||||||
typedef std::unordered_multimap<TextureConfig, TexPoolEntry, TextureConfig::Hasher> TexPool;
|
using TexPool = std::unordered_multimap<TextureConfig, TexPoolEntry>;
|
||||||
|
|
||||||
void SetBackupConfig(const VideoConfig& config);
|
void SetBackupConfig(const VideoConfig& config);
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,22 @@ struct TextureConfig
|
||||||
u32 layers = 1;
|
u32 layers = 1;
|
||||||
AbstractTextureFormat format = AbstractTextureFormat::RGBA8;
|
AbstractTextureFormat format = AbstractTextureFormat::RGBA8;
|
||||||
bool rendertarget = false;
|
bool rendertarget = false;
|
||||||
|
};
|
||||||
|
|
||||||
struct Hasher : std::hash<u64>
|
namespace std
|
||||||
{
|
{
|
||||||
size_t operator()(const TextureConfig& c) const
|
template <>
|
||||||
|
struct hash<TextureConfig>
|
||||||
{
|
{
|
||||||
u64 id = (u64)c.rendertarget << 63 | (u64)c.format << 50 | (u64)c.layers << 48 |
|
using argument_type = TextureConfig;
|
||||||
(u64)c.levels << 32 | (u64)c.height << 16 | (u64)c.width;
|
using result_type = size_t;
|
||||||
return std::hash<u64>::operator()(id);
|
|
||||||
|
result_type operator()(const argument_type& c) const noexcept
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue