Skip to content

Commit cab3b5b

Browse files
committed
Merge branch 'cad_large_texture_streaming' into shader_caching_fixes
2 parents e84bd60 + a9f3989 commit cab3b5b

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/nbl/asset/utils/IShaderCompiler.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ auto IShaderCompiler::CIncludeFinder::tryIncludeGenerators(const std::string& in
216216
return {};
217217
}
218218

219-
SEntry IShaderCompiler::CCache::find(const SEntry& mainFile, const IShaderCompiler::CIncludeFinder* finder) const
219+
core::smart_refctd_ptr<asset::ICPUShader> IShaderCompiler::CCache::find(const SEntry& mainFile, const IShaderCompiler::CIncludeFinder* finder) const
220+
{
221+
return find_impl(mainFile, finder)->cpuShader;
222+
}
223+
224+
IShaderCompiler::CCache::EntrySet::const_iterator IShaderCompiler::CCache::find_impl(const SEntry& mainFile, const IShaderCompiler::CIncludeFinder* finder) const
220225
{
221226
auto foundRange = m_container.equal_range(mainFile);
222227
for (auto& found = foundRange.first; found != foundRange.second; found++)
@@ -239,11 +244,10 @@ SEntry IShaderCompiler::CCache::find(const SEntry& mainFile, const IShaderCompil
239244
break;
240245
}
241246
}
242-
if (allDependenciesMatch) {
243-
return *found;
244-
}
247+
if (allDependenciesMatch)
248+
return found;
245249
}
246-
return SEntry();
250+
return m_container.end();
247251
}
248252

249253
core::smart_refctd_ptr<ICPUBuffer> IShaderCompiler::CCache::serialize() const

0 commit comments

Comments
 (0)