Skip to content

Commit ba53410

Browse files
committed
hash_combine + usage in caching IntrospectionData
1 parent 8f1a30f commit ba53410

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

include/nbl/asset/utils/CSPIRVIntrospector.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,18 @@ class NBL_API2 CSPIRVIntrospector : public core::Uncopyable
174174

175175
struct KeyHasher
176176
{
177-
std::size_t operator()(const SIntrospectionParams& t) const { return 0; /*TODO*/ }
177+
size_t operator()(const SIntrospectionParams& param) const
178+
{
179+
auto stringViewHasher = std::hash<std::string_view>();
180+
181+
auto code = std::string_view(reinterpret_cast<const char*>(param.cpuShader->getContent()->getPointer()), param.cpuShader->getContent()->getSize());
182+
size_t hash = stringViewHasher(code);
183+
184+
core::hash_combine<std::string_view>(hash, std::string_view(param.entryPoint));
185+
core::hash_combine<uint32_t>(hash, static_cast<uint32_t>(param.cpuShader->getStage()));
186+
187+
return hash;
188+
}
178189
};
179190

180191
using ParamsToDataMap = core::unordered_map<SIntrospectionParams,core::smart_refctd_ptr<const CIntrospectionData>, KeyHasher>;

include/nbl/core/algorithm/utility.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ inline void for_each_in_tuple(std::tuple<Ts...> const& t, F f)
2222
impl::for_each(t, f, std::make_index_sequence<N>());
2323
}
2424

25+
template <class T>
26+
inline void hash_combine(std::size_t& seed, const T& v)
27+
{
28+
std::hash<T> hasher;
29+
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
30+
}
31+
2532
}
2633
}
2734

0 commit comments

Comments
 (0)