Implemented KRSamplerManager
This commit is contained in:
@@ -30,8 +30,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "KRSampler.h"
|
#include "KRSampler.h"
|
||||||
|
#include "KRSamplerManager.h"
|
||||||
|
|
||||||
KRSampler::KRSampler(KRContext& context, KRSurface& surface, const SamplerInfo& info)
|
KRSampler::KRSampler(KRContext& context, const SamplerInfo& info)
|
||||||
: KRContextObject(context)
|
: KRContextObject(context)
|
||||||
{
|
{
|
||||||
// TODO - Implement stub function
|
// TODO - Implement stub function
|
||||||
|
|||||||
@@ -34,19 +34,14 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRSurface.h"
|
|
||||||
|
|
||||||
class SamplerInfo
|
class SamplerInfo;
|
||||||
{
|
|
||||||
public:
|
|
||||||
VkSamplerCreateInfo createInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
class KRSampler : public KRContextObject
|
class KRSampler : public KRContextObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
KRSampler(KRContext& context, KRSurface& surface, const SamplerInfo& info);
|
KRSampler(KRContext& context, const SamplerInfo& info);
|
||||||
virtual ~KRSampler();
|
virtual ~KRSampler();
|
||||||
|
|
||||||
VkSampler& getSampler();
|
VkSampler& getSampler();
|
||||||
|
|||||||
@@ -33,19 +33,32 @@
|
|||||||
|
|
||||||
#include "KRSamplerManager.h"
|
#include "KRSamplerManager.h"
|
||||||
|
|
||||||
|
// TODO - Purge samplers that are not used for several frames
|
||||||
|
|
||||||
|
bool SamplerInfo::operator==(const SamplerInfo& rhs) const
|
||||||
|
{
|
||||||
|
assert(rhs.createInfo.pNext == nullptr);
|
||||||
|
assert(createInfo.pNext == nullptr);
|
||||||
|
// Compare the contents of the SamplerInfo struct, ignoring the first two members (sType, pNext)
|
||||||
|
return memcmp(&rhs.createInfo.flags, &createInfo.flags, sizeof(createInfo) - size_t(&createInfo.flags) - size_t(&createInfo));
|
||||||
|
}
|
||||||
|
|
||||||
KRSamplerManager::KRSamplerManager(KRContext& context)
|
KRSamplerManager::KRSamplerManager(KRContext& context)
|
||||||
: KRContextObject(context)
|
: KRContextObject(context)
|
||||||
{
|
{
|
||||||
// TODO - Implement stub function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRSamplerManager::~KRSamplerManager()
|
KRSamplerManager::~KRSamplerManager()
|
||||||
{
|
{
|
||||||
// TODO - Implement stub function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRSampler* KRSamplerManager::getSampler(KRSurface& surface, const SamplerInfo& info)
|
KRSampler* KRSamplerManager::getSampler(const SamplerInfo& info)
|
||||||
{
|
{
|
||||||
// TODO - Implement stub function
|
SamplerMap::iterator itr = m_samplers.find(info);
|
||||||
return nullptr;
|
if (itr != m_samplers.end()) {
|
||||||
|
return itr->second;
|
||||||
|
}
|
||||||
|
KRSampler* sampler = new KRSampler(getContext(), info);
|
||||||
|
m_samplers.emplace(info, sampler);
|
||||||
|
return sampler;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,19 +40,32 @@ using std::vector;
|
|||||||
|
|
||||||
#include "KRSampler.h"
|
#include "KRSampler.h"
|
||||||
|
|
||||||
class KRSampler;
|
class SamplerInfo
|
||||||
class SamplerInfo;
|
{
|
||||||
|
public:
|
||||||
|
VkSamplerCreateInfo createInfo;
|
||||||
|
bool operator==(const SamplerInfo& rhs) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SamplerInfoHasher
|
||||||
|
{
|
||||||
|
std::size_t operator()(const SamplerInfo& s) const
|
||||||
|
{
|
||||||
|
// Compute a hash using the most commonly used sampler fields
|
||||||
|
// Collisions are okay, but we need to balance cost of creating
|
||||||
|
// hashes with cost of resolving collisions.
|
||||||
|
return std::hash<uint32_t>{}(static_cast<uint32_t>((s.createInfo.flags)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class KRSamplerManager : public KRContextObject
|
class KRSamplerManager : public KRContextObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
KRSamplerManager(KRContext& context);
|
KRSamplerManager(KRContext& context);
|
||||||
virtual ~KRSamplerManager();
|
virtual ~KRSamplerManager();
|
||||||
|
|
||||||
KRSampler* getSampler(KRSurface& surface, const SamplerInfo& info);
|
KRSampler* getSampler(const SamplerInfo& info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::pair<std::string, std::vector<int> >, KRSampler*> SamplerMap;
|
typedef std::unordered_map<SamplerInfo, KRSampler*, SamplerInfoHasher> SamplerMap;
|
||||||
SamplerMap m_samplers;
|
SamplerMap m_samplers;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user