Skip to content

Commit c211346

Browse files
committed
move UI extension headers into appropriate place, allow to go with mounted directory
1 parent a8a7c7d commit c211346

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

src/nbl/ext/ImGui/CMakeLists.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@ nbl_create_ext_library_project(
2323

2424
target_link_libraries(${LIB_NAME} PUBLIC imtestengine)
2525

26-
# (*) -> I wish we could just take NSC, offline-precompile to SPIRV, embed into builtin resource library (as we did!) but then be smart & adjust at runtime OpDecorate of our resources according to wishes - unfortunately no linker yet we have and we are not going to make one ourselves so we compile imgui shaders at runtime
27-
set(_BR_TARGET_ extImguibuiltinResourceData)
28-
set(_RESOURCE_DIR_ "shaders")
29-
30-
get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
26+
# this should be standard for all extensions
27+
get_filename_component(_ARCHIVE_ABSOLUTE_ENTRY_PATH_ "${NBL_EXT_INTERNAL_INCLUDE_DIR}/nbl/ext" ABSOLUTE)
3128
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
3229
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)
30+
set(_ARCHIVE_ENTRY_KEY_ "ImGui/builtin/hlsl") # then each one has unique archive key
31+
32+
target_compile_definitions(${LIB_NAME} PRIVATE _ARCHIVE_ABSOLUTE_ENTRY_PATH_="${_ARCHIVE_ABSOLUTE_ENTRY_PATH_}")
33+
34+
if(NBL_EMBED_BUILTIN_RESOURCES)
35+
# (*) -> I wish we could just take NSC, offline-precompile to SPIRV, embed into builtin resource library (as we did!) but then be smart & adjust at runtime OpDecorate of our resources according to wishes - unfortunately no linker yet we have and we are not going to make one ourselves so we compile imgui shaders at runtime
36+
set(_BR_TARGET_ extImguibuiltinResourceData)
3337

34-
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "common.hlsl")
35-
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "psinput.hlsl")
36-
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "vertex.hlsl") # (*) -> this we could precompile [no resources for which set/binding Ixs could be adjusted] but I'm not going to mix stuff
37-
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "fragment.hlsl") # (*) -> but this we could not since we let users to provide external descriptor set layout + ImGUI textures & sampler state set/binding Ixs (for pipeline layout) at runtime
38+
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "common.hlsl")
39+
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "psinput.hlsl")
40+
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "vertex.hlsl") # (*) -> this we could precompile [no resources for which set/binding Ixs could be adjusted] but I'm not going to mix stuff
41+
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "fragment.hlsl") # (*) -> but this we could not since we let users to provide external descriptor set layout + ImGUI textures & sampler state set/binding Ixs (for pipeline layout) at runtime
3842

39-
ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${_RESOURCE_DIR_}" "nbl::ext::imgui::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")
40-
LINK_BUILTIN_RESOURCES_TO_TARGET(${LIB_NAME} ${_BR_TARGET_})
43+
ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_ARCHIVE_ABSOLUTE_ENTRY_PATH_}" "${_ARCHIVE_ENTRY_KEY_}" "nbl::ext::imgui::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")
44+
LINK_BUILTIN_RESOURCES_TO_TARGET(${LIB_NAME} ${_BR_TARGET_})
45+
endif()

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "nbl/system/CStdoutLogger.h"
1010
#include "nbl/ext/ImGui/ImGui.h"
11-
#include "shaders/common.hlsl"
11+
#include "nbl/ext/ImGui/builtin/hlsl/common.hlsl"
1212
#include "nbl/ext/ImGui/builtin/builtinResources.h"
1313
#include "nbl/ext/ImGui/builtin/CArchive.h"
1414
#include "imgui/imgui.h"
@@ -112,15 +112,27 @@ smart_refctd_ptr<IGPUPipelineLayout> UI::createDefaultPipelineLayout(ILogicalDev
112112
return device->createPipelineLayout(PushConstantRanges, std::move(layouts[0u]), std::move(layouts[1u]), std::move(layouts[2u]), std::move(layouts[3u]));
113113
}
114114

115+
// note we use archive entry explicitly for temporary compiler include search path & asset cwd to use keys directly
116+
constexpr std::string_view NBL_ARCHIVE_ENTRY = nbl::ext::imgui::builtin::pathPrefix;
117+
115118
const smart_refctd_ptr<IFileArchive> UI::mount(smart_refctd_ptr<ILogger> logger, ISystem* system, const std::string_view archiveAlias)
116119
{
117120
assert(system);
118121

119122
if(!system)
120123
return nullptr;
121124

125+
// extension should mount everything for you, regardless if content goes from virtual filesystem
126+
// or disk directly - and you should never rely on application framework to expose extension data
127+
128+
#ifdef NBL_EMBED_BUILTIN_RESOURCES
122129
auto archive = make_smart_refctd_ptr<builtin::CArchive>(smart_refctd_ptr(logger));
123130
system->mount(smart_refctd_ptr(archive), archiveAlias.data());
131+
#else
132+
auto NBL_EXTENSION_MOUNT_DIRECTORY_ENTRY = (path(_ARCHIVE_ABSOLUTE_ENTRY_PATH_) / NBL_ARCHIVE_ENTRY).make_preferred();
133+
auto archive = make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(std::move(NBL_EXTENSION_MOUNT_DIRECTORY_ENTRY), smart_refctd_ptr(logger), system);
134+
system->mount(smart_refctd_ptr(archive), NBL_ARCHIVE_ENTRY);
135+
#endif
124136

125137
return smart_refctd_ptr(archive);
126138
}
@@ -140,23 +152,21 @@ core::smart_refctd_ptr<video::IGPUGraphicsPipeline> UI::createPipeline(SCreation
140152
smart_refctd_ptr<IGPUShader> vertex, fragment;
141153
} shaders;
142154

143-
{
144-
constexpr std::string_view NBL_ARCHIVE_ALIAS = "nbl/ext/imgui/shaders";
145-
155+
{
146156
//! proxy the system, we will touch it gently
147157
auto system = smart_refctd_ptr<ISystem>(creationParams.assetManager->getSystem());
148158

149159
auto* set = creationParams.assetManager->getCompilerSet();
150160
auto compiler = set->getShaderCompiler(IShader::E_CONTENT_TYPE::ECT_HLSL);
151161
auto includeFinder = make_smart_refctd_ptr<IShaderCompiler::CIncludeFinder>(smart_refctd_ptr(system));
152162
auto includeLoader = includeFinder->getDefaultFileSystemLoader();
153-
includeFinder->addSearchPath(NBL_ARCHIVE_ALIAS.data(), includeLoader);
163+
includeFinder->addSearchPath(NBL_ARCHIVE_ENTRY.data(), includeLoader);
154164

155165
auto createShader = [&]<StringLiteral key, IShader::E_SHADER_STAGE stage>() -> smart_refctd_ptr<IGPUShader>
156166
{
157167
IAssetLoader::SAssetLoadParams params = {};
158168
params.logger = creationParams.utilities->getLogger();
159-
params.workingDirectory = NBL_ARCHIVE_ALIAS.data();
169+
params.workingDirectory = NBL_ARCHIVE_ENTRY.data();
160170

161171
auto bundle = creationParams.assetManager->getAsset(key.value, params);
162172
const auto assets = bundle.getContents();
@@ -250,11 +260,12 @@ core::smart_refctd_ptr<video::IGPUGraphicsPipeline> UI::createPipeline(SCreation
250260
return nullptr;
251261
}
252262

253-
//! 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
254-
auto archive = mount(smart_refctd_ptr<ILogger>(creationParams.utilities->getLogger()), system.get(), NBL_ARCHIVE_ALIAS.data());
263+
//! but we should never assume user will mount our internal data since its the extension and not user's job to do it so we do to compile our extension sources
264+
if(!system->isDirectory(path(NBL_ARCHIVE_ENTRY.data())))
265+
mount(smart_refctd_ptr<ILogger>(creationParams.utilities->getLogger()), system.get());
266+
255267
shaders.vertex = createShader.template operator() < NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("vertex.hlsl"), IShader::E_SHADER_STAGE::ESS_VERTEX > ();
256268
shaders.fragment = createShader.template operator() < NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("fragment.hlsl"), IShader::E_SHADER_STAGE::ESS_FRAGMENT > ();
257-
system->unmount(archive.get(), NBL_ARCHIVE_ALIAS.data());
258269

259270
if (!shaders.vertex)
260271
{

0 commit comments

Comments
 (0)