Skip to content

Commit b23e2b8

Browse files
added a common pipeline loader class
1 parent 6abb8fb commit b23e2b8

18 files changed

+202
-169
lines changed

examples_tests/06.MeshLoaders/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int main()
6565

6666
asset::IAssetLoader::SAssetLoadParams lp;
6767
auto meshes_bundle = am->getAsset("sponza.obj", lp);
68-
assert(!meshes_bundle.isEmpty());
68+
assert(!meshes_bundle.getContents().empty());
6969

7070
metaOBJ = meshes_bundle.getMetadata()->selfCast<const asset::COBJMetadata>();
7171

include/nbl/asset/asset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
#include "nbl/asset/IAssetManager.h"
6666
// importexport
6767
#include "nbl/asset/interchange/IAssetLoader.h"
68+
#include "nbl/asset/interchange/IImageLoader.h"
69+
#include "nbl/asset/interchange/IRenderpassIndependentPipelineLoader.h"
6870
#include "nbl/asset/interchange/IAssetWriter.h"
71+
#include "nbl/asset/interchange/IImageWriter.h"
6972
#include "nbl/asset/metadata/COpenEXRMetadata.h"
7073
#include "nbl/asset/metadata/CMTLMetadata.h"
7174
#include "nbl/asset/metadata/COBJMetadata.h"

include/nbl/asset/interchange/IAssetLoader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ class IAssetLoader : public virtual core::IReferenceCounted
296296
bool insertBuiltinAssetIntoCache(IAssetManager* _mgr, SAssetBundle& _asset, const std::string _path);
297297
bool insertBuiltinAssetIntoCache(IAssetManager* _mgr, core::smart_refctd_ptr<IAsset>& _asset, core::smart_refctd_ptr<IAssetMetadata>&& metadata, const std::string _path);
298298
bool insertBuiltinAssetIntoCache(IAssetManager* _mgr, core::smart_refctd_ptr<IAsset>&& _asset, core::smart_refctd_ptr<IAssetMetadata>&& metadata, const std::string _path);
299+
300+
inline void setAssetInBundle(SAssetBundle& bundle, const uint32_t offset, core::smart_refctd_ptr<IAsset>&& _asset)
301+
{
302+
bundle.setAsset(offset,std::move(_asset));
303+
}
299304
};
300305

301306
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#ifndef __NBL_ASSET_I_RENDERPASS_INDEPENDENT_PIPELINE_LOADER_H_INCLUDED__
6+
#define __NBL_ASSET_I_RENDERPASS_INDEPENDENT_PIPELINE_LOADER_H_INCLUDED__
7+
8+
#include "nbl/core/core.h"
9+
10+
#include "nbl/asset/ICPURenderpassIndependentPipeline.h"
11+
#include "nbl/asset/interchange/IAssetLoader.h"
12+
13+
namespace nbl
14+
{
15+
namespace asset
16+
{
17+
18+
class IRenderpassIndependentPipelineLoader : public IAssetLoader
19+
{
20+
public:
21+
virtual void initialize() override;
22+
23+
protected:
24+
IAssetManager* m_assetMgr;
25+
core::smart_refctd_ptr<IRenderpassIndependentPipelineMetadata::semantics_container_t> m_basicViewParamsSemantics;
26+
27+
inline IRenderpassIndependentPipelineLoader(IAssetManager* _am) : m_assetMgr(_am) {}
28+
virtual ~IRenderpassIndependentPipelineLoader() = 0;
29+
30+
private:
31+
};
32+
33+
}
34+
}
35+
36+
#endif

include/nbl/asset/interchange/SAssetBundle.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class SAssetBundle
103103
inline void setNewCacheKey(std::string&& newKey) { m_cacheKey = std::move(newKey); }
104104
inline void setCached(bool val) { m_isCached = val; }
105105

106+
friend class IAssetLoader;
107+
inline void setAsset(const uint32_t offset, core::smart_refctd_ptr<IAsset>&& _asset)
108+
{
109+
m_contents->operator[](offset) = std::move(_asset);
110+
assert(allSameTypeAndNotNull());
111+
}
112+
106113

107114
core::smart_refctd_ptr<IAssetMetadata> m_metadata;
108115
contents_container_t m_contents;

include/nbl/asset/metadata/IAssetMetadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class IAssetMetadata : public core::IReferenceCounted
6565
using meta_container_t = core::smart_refctd_dynamic_array<Meta>;
6666

6767
template<class Meta>
68-
static inline meta_container_t<Meta> createContainer(uint32_t length)
68+
static inline meta_container_t<Meta> createContainer(const uint32_t length)
6969
{
7070
return core::make_refctd_dynamic_array<meta_container_t<Meta>>(length);
7171
}

include/nbl/ext/MitsubaLoader/CMitsubaSerializedMetadata.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef __NBL_C_MITSUBA_SERIALIZED_PIPELINE_METADATA_H_INCLUDED__
66
#define __NBL_C_MITSUBA_SERIALIZED_PIPELINE_METADATA_H_INCLUDED__
77

8+
#include "nbl/asset/ICPURenderpassIndependentPipeline.h"
9+
#include "nbl/asset/ICPUMesh.h"
810
#include "nbl/asset/metadata/IAssetMetadata.h"
911

1012
namespace nbl
@@ -22,19 +24,36 @@ class CMitsubaSerializedMetadata final : public asset::IAssetMetadata
2224
public:
2325
using IRenderpassIndependentPipelineMetadata::IRenderpassIndependentPipelineMetadata;
2426
};
27+
class CMesh : public asset::IMeshMetadata
28+
{
29+
public:
30+
inline CMesh() : IMeshMetadata() {}
31+
template<typename... Args>
32+
inline CMesh(std::string&& _name, const uint32_t _id, Args&&... args) : m_name(std::move(_name)), m_id(_id), IMeshMetadata(std::forward<Args>(args)...) {}
33+
34+
std::string m_name;
35+
uint32_t m_id;
36+
};
37+
38+
CMitsubaSerializedMetadata(const uint32_t meshBound) :
39+
m_pipelineStorage(IAssetMetadata::createContainer<CRenderpassIndependentPipeline>(meshBound)), m_meshStorage(IAssetMetadata::createContainer<CMesh>(meshBound))
40+
{
41+
}
2542

2643
_NBL_STATIC_INLINE_CONSTEXPR const char* LoaderName = "ext::MitsubaLoader::CSerializedLoader";
2744
const char* getLoaderName() const override { return LoaderName; }
2845

2946
private:
30-
meta_container_t<CRenderpassIndependentPipeline> m_metaStorage;
47+
meta_container_t<CRenderpassIndependentPipeline> m_pipelineStorage;
48+
meta_container_t<CMesh> m_meshStorage;
3149

3250
friend class CSerializedLoader;
33-
inline void placeMeta(uint32_t offset, const asset::ICPURenderpassIndependentPipeline* ppln)
51+
inline void placeMeta(uint32_t offset, const ICPURenderpassIndependentPipeline* ppln, CRenderpassIndependentPipeline&& pplnMeta, const ICPUMesh* mesh, CMesh&& meshMeta)
3452
{
35-
static_assert(false);
36-
//auto& meta = m_metaStorage->operator[](offset);
37-
//IAssetMetadata::insertAssetSpecificMetadata(ppln, &meta);
53+
auto& pplnMetaRef = m_pipelineStorage->operator[](offset) = std::move(pplnMeta);
54+
auto& meshMetaRef = m_meshStorage->operator[](offset) = std::move(meshMeta);
55+
IAssetMetadata::insertAssetSpecificMetadata(ppln,&pplnMetaRef);
56+
IAssetMetadata::insertAssetSpecificMetadata(mesh,&meshMetaRef);
3857
}
3958
};
4059

include/nbl/ext/MitsubaLoader/CSerializedLoader.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,17 @@ namespace ext
1313
{
1414
namespace MitsubaLoader
1515
{
16-
17-
class CSerializedMetadata : public asset::IAssetMetadata
18-
{
19-
public:
20-
CSerializedMetadata(std::string&& _name, uint32_t _id) : name(_name), id(_id) {}
21-
22-
_NBL_STATIC_INLINE_CONSTEXPR const char* LoaderName = "Mistuba Serialized";
23-
const char* getLoaderName() const override {return LoaderName;}
24-
25-
const std::string name;
26-
const uint32_t id;
27-
};
2816

2917
//! Meshloader capable of loading obj meshes.
30-
class CSerializedLoader final : public asset::IAssetLoader
18+
class CSerializedLoader final : public asset::IRenderpassIndependentPipelineLoader
3119
{
3220
protected:
33-
asset::IAssetManager* manager;
34-
3521
//! Destructor
3622
inline ~CSerializedLoader() {}
3723

3824
public:
3925
//! Constructor
40-
CSerializedLoader(asset::IAssetManager* _manager) : manager(_manager) {}
26+
CSerializedLoader(asset::IAssetManager* _manager) : IRenderpassIndependentPipelineLoader(_manager) {}
4127

4228
inline bool isALoadableFileFormat(io::IReadFile* _file) const override
4329
{
@@ -78,7 +64,7 @@ class CSerializedLoader final : public asset::IAssetLoader
7864

7965
struct SContext
8066
{
81-
io::IReadFile* file = nullptr;
67+
IAssetLoader::SAssetLoadContext inner;
8268
uint32_t meshCount;
8369
core::smart_refctd_dynamic_array<uint64_t> meshOffsets;
8470
};

src/nbl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ set(NBL_ASSET_SOURCES
139139
${NBL_ROOT_PATH}/src/nbl/asset/IAssetManager.cpp
140140
${NBL_ROOT_PATH}/src/nbl/asset/interchange/IAssetWriter.cpp
141141
${NBL_ROOT_PATH}/src/nbl/asset/interchange/IAssetLoader.cpp
142+
${NBL_ROOT_PATH}/src/nbl/asset/interchange/IRenderpassIndependentPipelineLoader.cpp
142143

143144
# Shaders
144145
${NBL_ROOT_PATH}/src/nbl/asset/utils/ISPIRVOptimizer.cpp

src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace asset;
2525
#define FRAG_SHADER_NO_UV_CACHE_KEY "nbl/builtin/shader/loader/mtl/fragment_no_uv.frag"
2626
#define FRAG_SHADER_UV_CACHE_KEY "nbl/builtin/shader/loader/mtl/fragment_uv.frag"
2727

28-
CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am) : m_assetMgr{_am}
28+
CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am) : IRenderpassIndependentPipelineLoader(_am)
2929
{
3030
//create vertex shaders and insert them into cache
3131
auto registerShader = [&](auto constexprStringType, ICPUSpecializedShader::E_SHADER_STAGE stage) -> void
@@ -50,13 +50,15 @@ CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am) : m_a
5050

5151
void CGraphicsPipelineLoaderMTL::initialize()
5252
{
53+
IRenderpassIndependentPipelineLoader::initialize();
54+
5355
auto dfltOver = IAssetLoaderOverride(m_assetMgr);
54-
// need to initialize this first
56+
// need to do this first
5557
{
56-
const IAssetLoader::SAssetLoadContext fakeCtx(IAssetLoader::SAssetLoadParams{},nullptr);
58+
const IAssetLoader::SAssetLoadContext fakeCtx(IAssetLoader::SAssetLoadParams{}, nullptr);
5759

5860
// find ds1 layout
59-
auto ds1layout = dfltOver.findDefaultAsset<ICPUDescriptorSetLayout>("nbl/builtin/descriptor_set_layout/basic_view_parameters",fakeCtx,0u).first;
61+
auto ds1layout = dfltOver.findDefaultAsset<ICPUDescriptorSetLayout>("nbl/builtin/descriptor_set_layout/basic_view_parameters", fakeCtx, 0u).first;
6062

6163
// precompute the no UV pipeline layout
6264
{
@@ -67,55 +69,20 @@ void CGraphicsPipelineLoaderMTL::initialize()
6769
//if intellisense shows error here, it's most likely intellisense's fault and it'll build fine anyway
6870
static_assert(sizeof(SMtl::params) <= ICPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE, "It must fit in push constants!");
6971

70-
auto pplnLayout = core::make_smart_refctd_ptr<ICPUPipelineLayout>(&pcRng, &pcRng+1, nullptr, core::smart_refctd_ptr(ds1layout), nullptr, nullptr);
71-
insertBuiltinAssetIntoCache(m_assetMgr, SAssetBundle(nullptr,{ core::smart_refctd_ptr_static_cast<IAsset>(std::move(pplnLayout)) }), "nbl/builtin/pipeline_layout/loader/mtl/no_uv");
72-
}
73-
74-
// create common metadata part
75-
{
76-
constexpr size_t DS1_METADATA_ENTRY_CNT = 3ull;
77-
m_inputSemantics = core::make_refctd_dynamic_array<decltype(m_inputSemantics)>(DS1_METADATA_ENTRY_CNT);
78-
79-
// TODO: this seems very common to many mesh loaders @Crisspl maybe an `IRenderpassIndependentPipelineLoaderBase` is in order?
80-
constexpr IRenderpassIndependentPipelineMetadata::E_COMMON_SHADER_INPUT types[DS1_METADATA_ENTRY_CNT] =
81-
{
82-
IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW_PROJ,
83-
IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW,
84-
IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE
85-
};
86-
constexpr uint32_t sizes[DS1_METADATA_ENTRY_CNT] =
87-
{
88-
sizeof(SBasicViewParameters::MVP),
89-
sizeof(SBasicViewParameters::MV),
90-
sizeof(SBasicViewParameters::NormalMat)
91-
};
92-
constexpr uint32_t relOffsets[DS1_METADATA_ENTRY_CNT] =
93-
{
94-
offsetof(SBasicViewParameters,MVP),
95-
offsetof(SBasicViewParameters,MV),
96-
offsetof(SBasicViewParameters,NormalMat)
97-
};
98-
for (uint32_t i=0u; i<DS1_METADATA_ENTRY_CNT; ++i)
99-
{
100-
auto& semantic = (m_inputSemantics->end()-i-1u)[0];
101-
semantic.type = types[i];
102-
semantic.descriptorSection.type = IRenderpassIndependentPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER;
103-
semantic.descriptorSection.uniformBufferObject.binding = ds1layout->getBindings().begin()[0].binding;
104-
semantic.descriptorSection.uniformBufferObject.set = 1u;
105-
semantic.descriptorSection.uniformBufferObject.relByteoffset = relOffsets[i];
106-
semantic.descriptorSection.uniformBufferObject.bytesize = sizes[i];
107-
semantic.descriptorSection.shaderAccessFlags = ICPUSpecializedShader::ESS_VERTEX;
108-
}
72+
auto pplnLayout = core::make_smart_refctd_ptr<ICPUPipelineLayout>(&pcRng, &pcRng + 1, nullptr, core::smart_refctd_ptr(ds1layout), nullptr, nullptr);
73+
insertBuiltinAssetIntoCache(m_assetMgr, SAssetBundle(nullptr, { core::smart_refctd_ptr_static_cast<IAsset>(std::move(pplnLayout)) }), "nbl/builtin/pipeline_layout/loader/mtl/no_uv");
10974
}
11075
}
11176

11277
// default pipelines
113-
SAssetLoadParams assetLoadParams;
114-
11578
auto default_mtl_file = m_assetMgr->getFileSystem()->createMemoryReadFile(DUMMY_MTL_CONTENT, strlen(DUMMY_MTL_CONTENT), "default IrrlichtBAW material");
79+
80+
SAssetLoadParams assetLoadParams;
11681
auto bundle = loadAsset(default_mtl_file, assetLoadParams, &dfltOver);
82+
11783
default_mtl_file->drop();
11884

85+
11986
insertBuiltinAssetIntoCache(m_assetMgr, std::move(bundle), "nbl/builtin/renderpass_independent_pipeline/loader/mtl/missing_material_pipeline");
12087
}
12188

@@ -186,7 +153,7 @@ SAssetBundle CGraphicsPipelineLoaderMTL::loadAsset(io::IReadFile* _file, const I
186153
}
187154
}
188155
}
189-
meta->placeMeta(offset,ppln.get(),std::move(ds3),material.params,std::string(material.name),hash,core::smart_refctd_ptr(m_inputSemantics));
156+
meta->placeMeta(offset,ppln.get(),std::move(ds3),material.params,std::string(material.name),hash,core::smart_refctd_ptr(m_basicViewParamsSemantics));
190157
retval->operator[](offset) = std::move(ppln);
191158
offset++;
192159
};

0 commit comments

Comments
 (0)