Skip to content

Commit 66ccf38

Browse files
author
devsh
committed
bring back asset reloads
1 parent fbcc060 commit 66ccf38

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

include/nbl/asset/IDescriptor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class IDescriptor : public virtual core::IReferenceCounted
8080
virtual ~IDescriptor() = default;
8181
};
8282

83+
template<typename T>
84+
concept Descriptor = std::is_base_of_v<IDescriptor,T>;
8385
}
8486

8587
#endif

include/nbl/asset/interchange/IAssetLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class NBL_API2 IAssetLoader : public virtual core::IReferenceCounted
297297
// accessors for loaders
298298
SAssetBundle interm_getAssetInHierarchy(IAssetManager* _mgr, system::IFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override);
299299
SAssetBundle interm_getAssetInHierarchy(IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override);
300+
// only the overload we use for now
301+
SAssetBundle interm_getAssetInHierarchyWithAllContent(IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override);
300302

301303
void interm_setAssetMutability(const IAssetManager* _mgr, IAsset* _asset, const bool _val);
302304

src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,14 @@ CGraphicsPipelineLoaderMTL::image_views_set_t CGraphicsPipelineLoaderMTL::loadIm
556556
if (_mtl.maps[i].size() )
557557
{
558558
const uint32_t hierarchyLevel = _ctx.topHierarchyLevel + ICPURenderpassIndependentPipeline::IMAGE_HIERARCHYLEVELS_BELOW; // this is weird actually, we're not sure if we're loading image or image view
559-
SAssetBundle bundle = interm_getAssetInHierarchy(m_assetMgr, _mtl.maps[i], lp, hierarchyLevel, _ctx.loaderOverride);
559+
SAssetBundle bundle;
560+
if (i != CMTLMetadata::CRenderpassIndependentPipeline::EMP_BUMP)
561+
bundle = interm_getAssetInHierarchy(m_assetMgr, _mtl.maps[i], lp, hierarchyLevel, _ctx.loaderOverride);
562+
else // TODO: you should attempt to get derivative map FIRST, then restore and regenerate! (right now you're always restoring!)
563+
{
564+
// we need bumpmap restored to create derivative map from it
565+
bundle = interm_getAssetInHierarchyWithAllContent(m_assetMgr, _mtl.maps[i], lp, hierarchyLevel, _ctx.loaderOverride);
566+
}
560567
auto asset = _ctx.loaderOverride->chooseDefaultAsset(bundle,_ctx.inner);
561568
if (asset)
562569
switch (bundle.getAssetType())

src/nbl/asset/interchange/IAssetLoader.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ SAssetBundle IAssetLoader::interm_getAssetInHierarchy(IAssetManager* _mgr, const
4545
return _mgr->getAssetInHierarchy(_filename, _params, _hierarchyLevel, _override);
4646
}
4747

48+
SAssetBundle IAssetLoader::interm_getAssetInHierarchyWithAllContent(IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override)
49+
{
50+
auto firstLoad = interm_getAssetInHierarchy(_mgr,_filename,_params,_hierarchyLevel,_override);
51+
auto bundleHasAllContent = [](const SAssetBundle& retval)->bool
52+
{
53+
for (const auto& asset : retval.getContents())
54+
if (IPreHashed::anyDependantDiscardedContents(asset.get()))
55+
return false;
56+
return true;
57+
};
58+
if (bundleHasAllContent(firstLoad))
59+
return firstLoad;
60+
61+
IAssetLoader::SAssetLoadParams paramCopy = _params;
62+
paramCopy.cacheFlags = ECF_DUPLICATE_REFERENCES;
63+
auto secondLoad = interm_getAssetInHierarchy(_mgr,_filename,paramCopy,_hierarchyLevel,_override);
64+
if (bundleHasAllContent(secondLoad))
65+
{
66+
_mgr->removeAssetFromCache(firstLoad);
67+
return secondLoad;
68+
}
69+
else
70+
return {};
71+
}
72+
4873
void IAssetLoader::interm_setAssetMutability(const IAssetManager* _mgr, IAsset* _asset, const bool _val)
4974
{
5075
_mgr->setAssetMutability(_asset, _val);

0 commit comments

Comments
 (0)