Move xxhash to boo; cached shader components

This commit is contained in:
Jack Andersen
2017-03-04 21:54:58 -10:00
parent 8bcac27c10
commit 03f155fcf5
16 changed files with 1558 additions and 217 deletions

View File

@@ -50,6 +50,44 @@ public:
Token lock() const { return Token(this); }
};
template <class FactoryImpl, class ShaderImpl>
class IShareableShader
{
std::atomic_int m_refCount = {0};
FactoryImpl& m_factory;
uint64_t m_key;
public:
IShareableShader(FactoryImpl& factory, uint64_t key)
: m_factory(factory), m_key(key) {}
void increment() { m_refCount++; }
void decrement()
{
if (m_refCount.fetch_sub(1) == 1)
m_factory._unregisterShareableShader(m_key);
}
class Token
{
IShareableShader<FactoryImpl, ShaderImpl>* m_parent = nullptr;
public:
Token() = default;
Token(IShareableShader* p)
: m_parent(p)
{ m_parent->increment(); }
Token& operator=(const Token&) = delete;
Token(const Token&) = delete;
Token& operator=(Token&& other)
{ m_parent = other.m_parent; other.m_parent = nullptr; return *this; }
Token(Token&& other)
{ m_parent = other.m_parent; other.m_parent = nullptr; }
~Token() { if (m_parent) m_parent->decrement(); }
operator bool() const { return m_parent != nullptr; }
ShaderImpl& get() const { return static_cast<ShaderImpl&>(*m_parent); }
};
Token lock() { return Token(this); }
};
}
#endif // BOO_GRAPHICSDEV_COMMON_HPP