Skip to content

Commit a73014c

Browse files
committed
add static mount method to the UI's extension
1 parent 791ef1c commit a73014c

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

include/nbl/ext/ImGui/ImGui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class UI final : public core::IReferenceCounted
151151
//! creates default pipeline layout for the UI resources, "texturesCount" argument is textures descriptor binding's array size. Samplers are immutable and part of the created layout, SResourceParameters::DefaultSamplerIx::COUNT is the size of the samplers descriptor binding's array
152152
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createDefaultPipelineLayout(video::IUtilities* const utilities, const SResourceParameters::SBindingInfo texturesInfo, const SResourceParameters::SBindingInfo samplersInfo, uint32_t texturesCount = 0x45);
153153

154+
//! mounts the extension's archive to given system - useful if you want to create your own shaders with common header included
155+
static const core::smart_refctd_ptr<system::IFileArchive> mount(core::smart_refctd_ptr<system::ILogger> logger, system::ISystem* system, const std::string_view archiveAlias = "");
156+
154157
//! creation cached parametrs
155158
inline const SCachedCreationParams& getCreationParameters() const { return m_cachedCreationParams; }
156159

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ namespace nbl::ext::imgui
115115
return utilities->getLogicalDevice()->createPipelineLayout(PushConstantRanges, std::move(layouts[0u]), std::move(layouts[1u]), std::move(layouts[2u]), std::move(layouts[3u]));
116116
}
117117

118+
const core::smart_refctd_ptr<system::IFileArchive> UI::mount(core::smart_refctd_ptr<system::ILogger> logger, system::ISystem* system, const std::string_view archiveAlias)
119+
{
120+
assert(system);
121+
122+
if(!system)
123+
return nullptr;
124+
125+
auto archive = make_smart_refctd_ptr<nbl::ext::imgui::builtin::CArchive>(smart_refctd_ptr(logger));
126+
system->mount(smart_refctd_ptr(archive), archiveAlias.data());
127+
128+
return smart_refctd_ptr(archive);
129+
}
130+
118131
void UI::createPipeline(SCreationParameters& creationParams)
119132
{
120133
auto pipelineLayout = smart_refctd_ptr<IGPUPipelineLayout>(creationParams.pipelineLayout);
@@ -133,11 +146,11 @@ namespace nbl::ext::imgui
133146
{
134147
constexpr std::string_view NBL_ARCHIVE_ALIAS = "nbl/ext/imgui/shaders";
135148

136-
auto system = smart_refctd_ptr<system::ISystem>(creationParams.assetManager->getSystem()); //! proxy the system, we will touch it gently
137-
assert(system->areBuiltinsMounted()); //! we assume user has all Nabla builtins mounted, but we won't check it at release
149+
//! proxy the system, we will touch it gently
150+
auto system = smart_refctd_ptr<system::ISystem>(creationParams.assetManager->getSystem());
138151

139-
auto archive = make_smart_refctd_ptr<nbl::ext::imgui::builtin::CArchive>(smart_refctd_ptr<system::ILogger>(creationParams.utilities->getLogger())); //! we should never assume user will mount our internal archive since its the extension and not user's job to do it, hence we mount only to compile our extension sources then unmount the archive
140-
auto compiler = make_smart_refctd_ptr<CHLSLCompiler>(smart_refctd_ptr(system)); //! note we are out of default logical device's compiler set scope so also a few special steps are required to compile our extension shaders to SPIRV
152+
//! note we are out of default logical device's compiler set scope so also a few special steps are required to compile our extension shaders to SPIRV
153+
auto compiler = make_smart_refctd_ptr<CHLSLCompiler>(smart_refctd_ptr(system));
141154
auto includeFinder = make_smart_refctd_ptr<IShaderCompiler::CIncludeFinder>(smart_refctd_ptr(system));
142155
auto includeLoader = includeFinder->getDefaultFileSystemLoader();
143156
includeFinder->addSearchPath(NBL_ARCHIVE_ALIAS.data(), includeLoader);
@@ -219,7 +232,11 @@ namespace nbl::ext::imgui
219232
return gpu;
220233
};
221234

222-
system->mount(smart_refctd_ptr(archive), NBL_ARCHIVE_ALIAS.data());
235+
//! we assume user has all Nabla builtins mounted - we don't check it at release
236+
assert(system->areBuiltinsMounted());
237+
238+
//! but we should never assume user will mount our internal archive since its the extension and not user's job to do it, hence we mount ourselves temporary archive to compile our extension sources then unmount it
239+
auto archive = mount(smart_refctd_ptr<system::ILogger>(creationParams.utilities->getLogger()), system.get(), NBL_ARCHIVE_ALIAS.data());
223240
shaders.vertex = createShader.template operator() < NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("vertex.hlsl"), IShader::E_SHADER_STAGE::ESS_VERTEX > ();
224241
shaders.fragment = createShader.template operator() < NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("fragment.hlsl"), IShader::E_SHADER_STAGE::ESS_FRAGMENT > ();
225242
system->unmount(archive.get(), NBL_ARCHIVE_ALIAS.data());

0 commit comments

Comments
 (0)