@@ -179,6 +179,8 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
179
179
180
180
class CCache final : public IReferenceCounted
181
181
{
182
+ friend class IShaderCompiler ;
183
+
182
184
public:
183
185
// Used to check compatibility of Caches before reading
184
186
constexpr static inline std::string_view VERSION = " 1.0.0" ;
@@ -399,7 +401,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
399
401
return retVal;
400
402
}
401
403
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 ;
403
405
404
406
inline CCache () {}
405
407
@@ -426,7 +428,11 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
426
428
}
427
429
428
430
};
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 ;
430
436
};
431
437
432
438
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
438
444
439
445
if (options.readCache )
440
446
{
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 ())
444
449
{
445
450
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 ;
448
456
}
449
457
}
450
458
0 commit comments