@@ -179,6 +179,8 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
179179
180180 class CCache final : public IReferenceCounted
181181 {
182+ friend class IShaderCompiler ;
183+
182184 public:
183185 // Used to check compatibility of Caches before reading
184186 constexpr static inline std::string_view VERSION = " 1.0.0" ;
@@ -399,7 +401,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
399401 return retVal;
400402 }
401403
402- NBL_API2 SEntry find (const SEntry& mainFile, const CIncludeFinder* finder) const ;
404+ NBL_API2 core::smart_refctd_ptr<asset::ICPUShader> find (const SEntry& mainFile, const CIncludeFinder* finder) const ;
403405
404406 inline CCache () {}
405407
@@ -426,7 +428,11 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
426428 }
427429
428430 };
429- core::unordered_multiset<SEntry,Hash,KeyEqual> m_container;
431+
432+ using EntrySet = core::unordered_multiset<SEntry, Hash, KeyEqual>;
433+ EntrySet m_container;
434+
435+ NBL_API2 EntrySet::const_iterator find_impl (const SEntry& mainFile, const CIncludeFinder* finder) const ;
430436 };
431437
432438 inline core::smart_refctd_ptr<ICPUShader> compileToSPIRV (const std::string_view code, const SCompilerOptions& options) const
@@ -438,13 +444,15 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
438444
439445 if (options.readCache )
440446 {
441- auto found = options.readCache ->find (entry, options.preprocessorOptions .includeFinder );
442- auto cpuShader = found.cpuShader ;
443- if (cpuShader)
447+ auto found = options.readCache ->find_impl (entry, options.preprocessorOptions .includeFinder );
448+ if (found != options.readCache ->m_container .end ())
444449 {
445450 if (options.writeCache )
446- options.writeCache ->insert (std::move (found));
447- return cpuShader;
451+ {
452+ CCache::SEntry writeEntry = *found;
453+ options.writeCache ->insert (std::move (writeEntry));
454+ }
455+ return found->cpuShader ;
448456 }
449457 }
450458
0 commit comments