Skip to content

Commit 547586e

Browse files
authored
Merge pull request #477 from Devsh-Graphics-Programming/newBuiltinResources
Builtin Resources CMake Refactor
2 parents a85d00e + d6b18e3 commit 547586e

38 files changed

+922
-566
lines changed

3rdparty/dxc/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,11 @@ CACHE INTERNAL "")
135135

136136
set(DXC_DLL
137137
$<IF:$<CONFIG:Debug>,${NBL_DXC_DEBUG_DLL},${NBL_DXC_RELEASE_DLL}>
138+
CACHE INTERNAL "")
139+
140+
cmake_path(GET NBL_DXC_DEBUG_DLL FILENAME _NBL_DXC_DEBUG_DLL_NAME_)
141+
cmake_path(GET NBL_DXC_RELEASE_DLL FILENAME _NBL_DXC_RELEASE_DLL_NAME_)
142+
143+
set(DXC_DLL_NAME
144+
$<IF:$<CONFIG:Debug>,${_NBL_DXC_DEBUG_DLL_NAME_},${_NBL_DXC_RELEASE_DLL_NAME_}>
138145
CACHE INTERNAL "")

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
22
# This file is part of the "Nabla Engine".
33
# For conditions of distribution and use, see copyright notice in nabla.h.in or nabla.h
4-
#
5-
cmake_minimum_required(VERSION 3.25)
4+
cmake_minimum_required(VERSION 3.26)
65
#policies
76
cmake_policy(SET CMP0112 NEW)
87

@@ -56,6 +55,7 @@ endif()
5655

5756
get_filename_component(NBL_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
5857
get_filename_component(NBL_ROOT_PATH_BINARY "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE)
58+
set(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH "${NBL_ROOT_PATH}/include")
5959

6060
# Configure CCache if available
6161
find_program(CCACHE_FOUND ccache)

cmake/common.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUD
221221
add_dependencies(${LIB_NAME} Nabla)
222222

223223
get_target_property(_NBL_NABLA_TARGET_BINARY_DIR_ Nabla BINARY_DIR)
224+
get_target_property(_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_ nblBuiltinResourceData BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY)
224225

225226
target_include_directories(${LIB_NAME}
226227
PUBLIC ${_NBL_NABLA_TARGET_BINARY_DIR_}/build/import
@@ -230,6 +231,7 @@ macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUD
230231
PUBLIC ${CMAKE_SOURCE_DIR}/include
231232
PUBLIC ${CMAKE_SOURCE_DIR}/src
232233
PUBLIC ${CMAKE_SOURCE_DIR}/source/Nabla
234+
PUBLIC ${_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_}
233235
PRIVATE ${LIB_INCLUDES}
234236
)
235237
add_dependencies(${LIB_NAME} Nabla)
@@ -339,6 +341,13 @@ function(nbl_install_file _FILE _RELATIVE_DESTINATION)
339341
install(FILES ${_FILE} DESTINATION relwithdebinfo/include/${_RELATIVE_DESTINATION} CONFIGURATIONS RelWithDebInfo)
340342
endfunction()
341343

344+
function(nbl_install_builtin_resources _TARGET_)
345+
get_target_property(_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_ ${_TARGET_} BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY)
346+
get_target_property(_BUILTIN_RESOURCES_HEADERS_ ${_TARGET_} BUILTIN_RESOURCES_HEADERS)
347+
348+
nbl_install_headers("${_BUILTIN_RESOURCES_HEADERS_}" "${_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_}")
349+
endfunction()
350+
342351
function(nbl_install_config_header _CONF_HDR_NAME)
343352
nbl_get_conf_dir(dir_deb Debug)
344353
nbl_get_conf_dir(dir_rel Release)
@@ -351,6 +360,18 @@ function(nbl_install_config_header _CONF_HDR_NAME)
351360
install(FILES ${file_relWithDebInfo} DESTINATION relwithdebinfo/include CONFIGURATIONS RelWithDebInfo)
352361
endfunction()
353362

363+
# links builtin resource target to a target
364+
# @_TARGET_@ is target name builtin resource target will be linked to
365+
# @_BS_TARGET_@ is a builtin resource target
366+
367+
function(LINK_BUILTIN_RESOURCES_TO_TARGET _TARGET_ _BS_TARGET_)
368+
add_dependencies(${EXECUTABLE_NAME} ${_BS_TARGET_})
369+
target_link_libraries(${EXECUTABLE_NAME} PUBLIC ${_BS_TARGET_})
370+
371+
get_target_property(_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_ ${_BS_TARGET_} BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY)
372+
target_include_directories(${EXECUTABLE_NAME} PUBLIC "${_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_}")
373+
endfunction()
374+
354375
macro(nbl_android_create_apk _TARGET)
355376
get_target_property(TARGET_NAME ${_TARGET} NAME)
356377
# TARGET_NAME_IDENTIFIER is identifier that can be used in code

cmake/install/nbl/sharedDefines.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
*/
55

66
#define _NABLA_DLL_NAME_ "@_NABLA_DLL_NAME_@"
7+
#define _DXC_DLL_NAME_ "@_DXC_DLL_NAME_@"
78
#define _NABLA_INSTALL_DIR_ @_NABLA_INSTALL_DIR_@

cmake/scripts/nbl/nablaDefines.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ if(NOT DEFINED _NABLA_DLL_NAME_)
4242
message(FATAL_ERROR "_NABLA_DLL_NAME_ variable must be specified for this script!")
4343
endif()
4444

45+
if(NOT DEFINED _DXC_DLL_NAME_)
46+
message(FATAL_ERROR "_DXC_DLL_NAME_ variable must be specified for this script!")
47+
endif()
48+
4549
if(NOT DEFINED _NABLA_INSTALL_DIR_)
4650
message(FATAL_ERROR "_NABLA_INSTALL_DIR_ variable must be specified for this script!")
4751
endif()

include/nbl/builtin/common.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

include/nbl/config/BuildConfigOptions.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
#endif
8080
#endif
8181

82+
#define NBL_BUILTIN_RESOURCES_DIRECTORY_PATH "@NBL_BUILTIN_RESOURCES_DIRECTORY_PATH@"
83+
8284
// DDL exports
8385
#cmakedefine _NBL_SHARED_BUILD_
8486
#ifdef _NBL_SHARED_BUILD_

include/nbl/scene/ICullingLoDSelectionSystem.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,17 @@ class ICullingLoDSelectionSystem : public virtual core::IReferenceCounted
490490
auto getShader = [device]<core::StringLiteral Path>() -> shader_source_and_path
491491
{
492492
auto system = device->getPhysicalDevice()->getSystem();
493-
auto glslFile = system->loadBuiltinData<Path>();
493+
494+
auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr<const nbl::system::IFile>
495+
{
496+
nbl::system::ISystem::future_t<core::smart_refctd_ptr<nbl::system::IFile>> future;
497+
system->createFile(future, system::path(_path), core::bitflag(nbl::system::IFileBase::ECF_READ) | nbl::system::IFileBase::ECF_MAPPABLE);
498+
if (future.wait())
499+
return future.copy();
500+
return nullptr;
501+
};
502+
503+
auto glslFile = loadBuiltinData(Path.value);
494504
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
495505
{
496506
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());

include/nbl/scene/ISkinInstanceCacheManager.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
2626
auto system = device->getPhysicalDevice()->getSystem();
2727
auto createShader = [&system,&device](auto uniqueString, asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr<video::IGPUSpecializedShader>
2828
{
29-
auto glslFile = system->loadBuiltinData<decltype(uniqueString)>();
29+
auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr<const nbl::system::IFile>
30+
{
31+
nbl::system::ISystem::future_t<core::smart_refctd_ptr<nbl::system::IFile>> future;
32+
system->createFile(future, system::path(_path), core::bitflag(nbl::system::IFileBase::ECF_READ) | nbl::system::IFileBase::ECF_MAPPABLE);
33+
if (future.wait())
34+
return future.copy();
35+
return nullptr;
36+
};
37+
38+
auto glslFile = loadBuiltinData(uniqueString);
3039
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
3140
{
3241
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());
@@ -36,9 +45,9 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
3645
return device->createSpecializedShader(shader.get(),{nullptr,nullptr,"main"});
3746
};
3847

39-
auto updateSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/skinning/cache_update.comp")());
40-
auto debugDrawVertexSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/skinning/debug.vert")(),asset::IShader::ESS_VERTEX);
41-
auto debugDrawFragmentSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag")(),asset::IShader::ESS_FRAGMENT);
48+
auto updateSpec = createShader("nbl/builtin/glsl/skinning/cache_update.comp");
49+
auto debugDrawVertexSpec = createShader("nbl/builtin/glsl/skinning/debug.vert",asset::IShader::ESS_VERTEX);
50+
auto debugDrawFragmentSpec = createShader("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag",asset::IShader::ESS_FRAGMENT);
4251
if (!updateSpec || !debugDrawVertexSpec || !debugDrawFragmentSpec)
4352
return nullptr;
4453

include/nbl/scene/ITransformTreeManager.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,16 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
108108
auto system = device->getPhysicalDevice()->getSystem();
109109
auto createShader = [&system,&device]<core::StringLiteral Path>(asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr<video::IGPUSpecializedShader>
110110
{
111-
auto glslFile = system->loadBuiltinData<Path>();
111+
auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr<const nbl::system::IFile>
112+
{
113+
nbl::system::ISystem::future_t<core::smart_refctd_ptr<nbl::system::IFile>> future;
114+
system->createFile(future, system::path(_path), core::bitflag(nbl::system::IFileBase::ECF_READ) | nbl::system::IFileBase::ECF_MAPPABLE);
115+
if (future.wait())
116+
return future.copy();
117+
return nullptr;
118+
};
119+
120+
auto glslFile = loadBuiltinData(Path.value);
112121
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
113122
{
114123
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());

include/nbl/system/CFileArchive.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class CFileArchive : public IFileArchive
7676
public:
7777
inline core::smart_refctd_ptr<IFile> getFile(const path& pathRelativeToArchive, const std::string_view& password) override
7878
{
79-
std::unique_lock lock(itemMutex);
80-
8179
const auto* item = getItemFromPath(pathRelativeToArchive);
8280
if (!item)
8381
return nullptr;
@@ -107,13 +105,13 @@ class CFileArchive : public IFileArchive
107105
}
108106

109107
protected:
110-
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, core::vector<SListEntry> _items) :
108+
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, std::shared_ptr<core::vector<SFileList::SEntry>> _items) :
111109
IFileArchive(std::move(_defaultAbsolutePath),std::move(logger))
112110
{
113-
m_items = std::move(_items);
114-
std::sort(m_items.begin(),m_items.end());
111+
std::sort(_items->begin(), _items->end());
112+
m_items.store(_items);
115113

116-
const auto fileCount = m_items.size();
114+
const auto fileCount = _items->size();
117115
m_filesBuffer = (std::byte*)_NBL_ALIGNED_MALLOC(fileCount*SIZEOF_INNER_ARCHIVE_FILE, ALIGNOF_INNER_ARCHIVE_FILE);
118116
m_fileFlags = (std::atomic_flag*)_NBL_ALIGNED_MALLOC(fileCount*sizeof(std::atomic_flag), alignof(std::atomic_flag));
119117
for (size_t i=0u; i<fileCount; i++)
@@ -127,7 +125,7 @@ class CFileArchive : public IFileArchive
127125
}
128126

129127
template<class Allocator>
130-
inline core::smart_refctd_ptr<CInnerArchiveFile<Allocator>> getFile_impl(const IFileArchive::SListEntry* item)
128+
inline core::smart_refctd_ptr<CInnerArchiveFile<Allocator>> getFile_impl(const IFileArchive::SFileList::SEntry* item)
131129
{
132130
auto* file = reinterpret_cast<CInnerArchiveFile<Allocator>*>(m_filesBuffer+item->ID*SIZEOF_INNER_ARCHIVE_FILE);
133131
// NOTE: Intentionally calling grab() on maybe-not-existing object!
@@ -160,7 +158,7 @@ class CFileArchive : public IFileArchive
160158
size_t size;
161159
void* allocatorState;
162160
};
163-
virtual file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) = 0;
161+
virtual file_buffer_t getFileBuffer(const IFileArchive::SFileList::SEntry* item) = 0;
164162

165163
std::atomic_flag* m_fileFlags = nullptr;
166164
std::byte* m_filesBuffer = nullptr;

include/nbl/system/CFileViewVirtualAllocatorWin32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace nbl::system
55
{
66
#ifdef _NBL_PLATFORM_WINDOWS_
7-
class CFileViewVirtualAllocatorWin32 : public IFileViewAllocator
7+
class NBL_API2 CFileViewVirtualAllocatorWin32 : public IFileViewAllocator
88
{
99
public:
1010
using IFileViewAllocator::IFileViewAllocator;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#ifndef _NBL_SYSTEM_C_MOUNT_DIRECTORY_ARCHIVE_H_INCLUDED_
2+
#define _NBL_SYSTEM_C_MOUNT_DIRECTORY_ARCHIVE_H_INCLUDED_
3+
4+
#include "nbl/system/IFileArchive.h"
5+
6+
#include "nbl/system/IFile.h"
7+
8+
namespace nbl::system {
9+
10+
11+
12+
class CMountDirectoryArchive : public IFileArchive
13+
{
14+
ISystem* m_system;
15+
16+
public:
17+
inline CMountDirectoryArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, ISystem* system) :
18+
IFileArchive(std::move(_defaultAbsolutePath), std::move(logger))
19+
{
20+
m_system = system;
21+
}
22+
23+
core::smart_refctd_ptr<IFile> getFile(const path& pathRelativeToArchive, const std::string_view& password) override
24+
{
25+
{
26+
//std::unique_lock(itemMutex); already inside `getItemFromPath`
27+
if (!getItemFromPath(pathRelativeToArchive))
28+
return nullptr;
29+
}
30+
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
31+
m_system->createFile(future, m_defaultAbsolutePath / pathRelativeToArchive, system::IFile::ECF_READ);
32+
if (auto file = future.acquire())
33+
return *file;
34+
}
35+
36+
SFileList listAssets(const path& asset_path) const override
37+
{
38+
populateItemList(asset_path);
39+
return IFileArchive::listAssets(asset_path);
40+
}
41+
SFileList listAssets() const override {
42+
populateItemList(path());
43+
return IFileArchive::listAssets();
44+
}
45+
46+
void populateItemList(const path& p) const {
47+
auto items = m_system->listItemsInDirectory(m_defaultAbsolutePath/p);
48+
auto new_entries = std::make_shared<core::vector<SFileList::SEntry>>();
49+
for (auto item : items)
50+
{
51+
if (item.has_extension())
52+
{
53+
auto relpath = item.lexically_relative(m_defaultAbsolutePath);
54+
auto entry = SFileList::SEntry{ relpath, 0xdeadbeefu, 0xdeadbeefu, 0xdeadbeefu, EAT_NONE };
55+
new_entries->push_back(entry);
56+
}
57+
}
58+
m_items.store({new_entries});
59+
}
60+
};
61+
62+
} //namespace nbl::system
63+
#endif

0 commit comments

Comments
 (0)