metaforce/hecl/include/HECL/Runtime.hpp

137 lines
3.5 KiB
C++
Raw Normal View History

2015-05-15 22:39:43 +00:00
#ifndef HECLRUNTIME_HPP
#define HECLRUNTIME_HPP
2015-06-09 22:19:59 +00:00
#include "HECL.hpp"
2015-11-13 02:12:09 +00:00
#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
#include <Athena/DNA.hpp>
#include <Athena/FileReader.hpp>
#include <unordered_map>
2015-06-09 22:19:59 +00:00
2015-06-10 02:40:03 +00:00
namespace HECL
{
namespace Runtime
2015-06-09 22:19:59 +00:00
{
/**
2015-11-13 02:12:09 +00:00
* @brief Per-platform file store resolution
2015-06-09 22:19:59 +00:00
*/
2015-11-13 02:12:09 +00:00
class FileStoreManager
2015-06-09 22:19:59 +00:00
{
2015-11-13 02:12:09 +00:00
SystemString m_domain;
SystemString m_storeRoot;
2015-06-09 22:19:59 +00:00
public:
2015-11-13 02:12:09 +00:00
FileStoreManager(const SystemString& domain);
const SystemString& getDomain() const {return m_domain;}
const SystemString& getStoreRoot() const {return m_storeRoot;}
2015-06-09 22:19:59 +00:00
};
2015-08-21 00:06:18 +00:00
/**
2015-11-13 02:12:09 +00:00
* @brief Shader formats that may be identified within ShaderHash
2015-08-21 00:06:18 +00:00
*/
2015-11-13 02:12:09 +00:00
enum ShaderFormat : uint8_t
2015-08-21 00:06:18 +00:00
{
2015-11-13 02:12:09 +00:00
ShaderFormatNone,
ShaderFormatGLSL,
ShaderFormatHLSL,
ShaderFormatMetal,
ShaderFormatSpirV
2015-08-21 00:06:18 +00:00
};
/**
2015-11-13 02:12:09 +00:00
* @brief Hash subclass for identifying shaders and their metadata
2015-08-21 00:06:18 +00:00
*/
2015-11-13 02:12:09 +00:00
class ShaderTag : public Hash
2015-08-21 00:06:18 +00:00
{
2015-11-13 02:12:09 +00:00
union
{
uint64_t m_meta = 0;
struct
{
ShaderFormat m_fmt;
uint8_t m_colorCount;
uint8_t m_uvCount;
uint8_t m_weightCount;
};
};
public:
ShaderTag() = default;
ShaderTag(const void* buf, size_t len, ShaderFormat fmt, uint8_t c, uint8_t u, uint8_t w)
: Hash(buf, len), m_fmt(fmt), m_colorCount(c), m_uvCount(u), m_weightCount(w) {}
ShaderTag(unsigned long long hashin, uint64_t meta)
: Hash(hashin), m_meta(meta) {}
ShaderTag(const ShaderTag& other) : Hash(other) {}
ShaderFormat getShaderFormat() const {return m_fmt;}
uint8_t getColorCount() const {return m_colorCount;}
uint8_t getUvCount() const {return m_uvCount;}
uint8_t getWeightCount() const {return m_weightCount;}
uint64_t getMetaData() const {return m_meta;}
2015-08-21 00:06:18 +00:00
};
/**
2015-11-13 02:12:09 +00:00
* @brief Maintains index/data file pair containing platform-dependent cached shader data
2015-08-21 00:06:18 +00:00
*/
2015-11-13 02:12:09 +00:00
class ShaderCacheManager
2015-08-21 00:06:18 +00:00
{
2015-11-13 02:12:09 +00:00
const FileStoreManager& m_storeMgr;
Athena::io::FileReader m_idxFr;
Athena::io::FileReader m_datFr;
struct IndexEntry : Athena::io::DNA<Athena::BigEndian>
{
DECL_DNA
Value<atUint64> m_hash;
Value<atUint64> m_meta;
Value<atUint64> m_compOffset;
Value<atUint32> m_compSize;
Value<atUint32> m_decompSize;
};
std::vector<IndexEntry> m_entries;
std::unordered_map<Hash, size_t> m_entryLookup;
uint64_t m_loadedRand = 0;
void BootstrapIndex();
2015-08-21 00:06:18 +00:00
public:
2015-11-13 02:12:09 +00:00
ShaderCacheManager(const FileStoreManager& storeMgr)
: m_storeMgr(storeMgr),
m_idxFr(storeMgr.getStoreRoot() + _S("/shadercache.idx")),
m_datFr(storeMgr.getStoreRoot() + _S("/shadercache.dat"))
{reload();}
void reload();
class CachedData
{
friend class ShaderCacheManager;
CachedData() = default;
CachedData(unsigned long long hashin, uint64_t meta, size_t decompSz)
: m_tag(hashin, meta), m_data(new uint8_t[decompSz]), m_sz(decompSz) {}
public:
ShaderTag m_tag;
std::unique_ptr<uint8_t[]> m_data;
size_t m_sz;
operator bool() const {return m_tag.operator bool();}
};
CachedData lookupData(const Hash& hash);
bool addData(const ShaderTag& hash, const void* data, size_t sz);
2015-08-21 00:06:18 +00:00
};
2015-06-09 22:19:59 +00:00
/**
2015-11-13 02:12:09 +00:00
* @brief Integrated reader/constructor/container for HMDL data
2015-06-09 22:19:59 +00:00
*/
2015-11-13 02:12:09 +00:00
class HMDLData
2015-06-09 22:19:59 +00:00
{
public:
2015-11-13 02:12:09 +00:00
HMDLData(boo::IGraphicsDataFactory* factory, const void* data);
2015-06-09 22:19:59 +00:00
};
2015-06-10 02:40:03 +00:00
}
2015-06-09 22:19:59 +00:00
}
2015-11-13 02:12:09 +00:00
namespace std
{
template <> struct hash<HECL::Runtime::ShaderTag>
{
size_t operator()(const HECL::Runtime::ShaderTag& val) const NOEXCEPT
{return val.valSizeT();}
};
}
2015-05-15 22:39:43 +00:00
#endif // HECLRUNTIME_HPP