Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builtin Resources CMake Refactor #477

Merged
merged 52 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bcc127f
add src/nbl/builtin/template/CAPKResourcesArchieve.cpp.in and src/nbl…
AnastaZIuk Feb 23, 2023
f4a8ab0
bugfix: address build issues with embedded assets for clang and gnu c…
pollend Feb 24, 2023
9cfedb9
address build problems with gnu compiler
pollend Feb 24, 2023
a4b32c6
list all created builtin libraries and link to Nabla, bring back pyth…
AnastaZIuk Feb 25, 2023
b6d5e30
move some code from common.h to autogenerated CArchive.h, update src/…
AnastaZIuk Feb 25, 2023
d667624
update examples_tests submodule with archive builtin resources test
AnastaZIuk Feb 25, 2023
0e5b7de
correct python script, fix and correct CArchive.h.in and update src/n…
AnastaZIuk Feb 28, 2023
46b2b71
correct nasty bug and make sure builtin resources works
AnastaZIuk Mar 10, 2023
51b95d5
Merge branch 'newBuiltinResources' into bugfix/address-build-problems…
AnastaZIuk Mar 10, 2023
56a524d
Merge pull request #465 from pollend/bugfix/address-build-problems-bu…
AnastaZIuk Mar 10, 2023
446e301
correct missing correspondingHeaderFile after merge and remove #inclu…
AnastaZIuk Mar 10, 2023
c110ce0
move builtin resources creation macro and function to src/nbl/builtin…
AnastaZIuk Mar 10, 2023
782b6ba
request only python interpreter and correct its variable name, add mo…
AnastaZIuk Mar 10, 2023
469483a
correct python3 variable
AnastaZIuk Mar 17, 2023
1f95857
make define.h generate again, it looks like policy of custom command …
AnastaZIuk Mar 26, 2023
e2e3adc
update scripts for generating define.h header - add `_DXC_DLL_NAME_`
AnastaZIuk Mar 28, 2023
5ab06c8
Cherry pick some of Erfan's work from master
Erfan-Ahmadi Apr 11, 2023
aef1445
resolve conflicts and merge
AnastaZIuk Apr 12, 2023
4ce34b4
bad merge - fix src/nbl/builtin/builtinDataGen.py
AnastaZIuk Apr 12, 2023
345e2e0
spot issues with ambiguity causing linker errors and lack of some spi…
AnastaZIuk Apr 12, 2023
8373b38
spot a bug thanks to my apple clang compiler - but I'm not surprised…
devshgraphicsprogrammingjenkins Apr 19, 2023
cb5450a
Mounting directories (#492)
Hazardu May 5, 2023
9daedfa
add some docs to src/nbl/builtin/utils.cmake, add new parameters for …
AnastaZIuk May 10, 2023
c847d6d
save work, don't add every builtin resource as Nabla dependency, hard…
AnastaZIuk May 12, 2023
b9435da
handle multiple builtin resource aliases with CMake
AnastaZIuk May 16, 2023
78f8bfa
patch python builtin generation scripts to handle multiple aliases. T…
AnastaZIuk May 18, 2023
3d753f5
correct all issues & compile errors regarding builtin resources targe…
AnastaZIuk May 19, 2023
0433827
add LINK_BUILTIN_RESOURCES_TO_TARGET and correct bug in macro, updat…
AnastaZIuk May 19, 2023
ba669f7
address all ISystem comments - nuke some stuff, make it compile but e…
AnastaZIuk May 19, 2023
7709a8c
Changing things in File Archive class
Hazardu May 19, 2023
38084b2
Changed type name to new entry type
Hazardu May 21, 2023
c97b67c
Update CFileArchive.h
Hazardu May 21, 2023
4767028
Updated more files to have correct archive entry type
Hazardu May 21, 2023
a7c99b6
introduce in ADD_CUSTOM_BUILTIN_RESOURCES function, correct builtin …
AnastaZIuk May 21, 2023
e8e5a4b
update docs
AnastaZIuk May 21, 2023
9cb464f
update a few lines regarding path prefix, use pathPrefix created given
AnastaZIuk May 21, 2023
763f9fb
remove getItemList() proxy function and keep resources as inline stat…
AnastaZIuk May 21, 2023
806a43e
Switched all vectors from std to core
Hazardu May 21, 2023
7a499f4
merge master and resolve conflicts
AnastaZIuk May 23, 2023
34c4cdf
correct a bug
AnastaZIuk May 23, 2023
1ecd112
include search directory of nbl builtin resources for targets created…
AnastaZIuk May 23, 2023
e73e0af
add handling DLL imports/exports for builtin resource targets, have o…
AnastaZIuk May 23, 2023
0fa3cf3
add more NBL_API2 for some classes and update builtin resource genera…
AnastaZIuk May 23, 2023
cf5fec1
reverted core to std on vector usages
Hazardu May 24, 2023
dffbed2
Split archive into header CArchive.h and source CArchive.cpp files, h…
AnastaZIuk May 26, 2023
9f6bcc2
Merge branch 'newBuiltinResources' into FileArchiveTweaks
Hazardu May 26, 2023
7f665bf
Changed back to core::vector, fixes to generated CArchives
Hazardu May 26, 2023
76d10b4
got rid of double shared ptr to a single object
Hazardu May 26, 2023
c18fc86
removed extra parenthesis
Hazardu May 26, 2023
e55b5a0
removed extra parentheses
Hazardu May 26, 2023
7bd08b7
Moved CMountDirectoryArchive.h to include, changed type to sharedptr
Hazardu May 26, 2023
d6b18e3
resolve conflicts, merge master
AnastaZIuk May 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 3rdparty/dxc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,11 @@ CACHE INTERNAL "")

set(DXC_DLL
$<IF:$<CONFIG:Debug>,${NBL_DXC_DEBUG_DLL},${NBL_DXC_RELEASE_DLL}>
CACHE INTERNAL "")

cmake_path(GET NBL_DXC_DEBUG_DLL FILENAME _NBL_DXC_DEBUG_DLL_NAME_)
cmake_path(GET NBL_DXC_RELEASE_DLL FILENAME _NBL_DXC_RELEASE_DLL_NAME_)

set(DXC_DLL_NAME
$<IF:$<CONFIG:Debug>,${_NBL_DXC_DEBUG_DLL_NAME_},${_NBL_DXC_RELEASE_DLL_NAME_}>
CACHE INTERNAL "")
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is part of the "Nabla Engine".
# For conditions of distribution and use, see copyright notice in nabla.h.in or nabla.h

cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.26)
#policies
cmake_policy(SET CMP0112 NEW)

Expand Down Expand Up @@ -56,6 +56,7 @@ endif()

get_filename_component(NBL_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(NBL_ROOT_PATH_BINARY "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE)
set(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH "${NBL_ROOT_PATH}/include")

# Configure CCache if available
find_program(CCACHE_FOUND ccache)
Expand Down
21 changes: 21 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUD
add_dependencies(${LIB_NAME} Nabla)

get_target_property(_NBL_NABLA_TARGET_BINARY_DIR_ Nabla BINARY_DIR)
get_target_property(_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_ nblBuiltinResourceData BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY)

target_include_directories(${LIB_NAME}
PUBLIC ${_NBL_NABLA_TARGET_BINARY_DIR_}/build/import
Expand All @@ -230,6 +231,7 @@ macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUD
PUBLIC ${CMAKE_SOURCE_DIR}/include
PUBLIC ${CMAKE_SOURCE_DIR}/src
PUBLIC ${CMAKE_SOURCE_DIR}/source/Nabla
PUBLIC ${_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_}
PRIVATE ${LIB_INCLUDES}
)
add_dependencies(${LIB_NAME} Nabla)
Expand Down Expand Up @@ -339,6 +341,13 @@ function(nbl_install_file _FILE _RELATIVE_DESTINATION)
install(FILES ${_FILE} DESTINATION relwithdebinfo/include/${_RELATIVE_DESTINATION} CONFIGURATIONS RelWithDebInfo)
endfunction()

function(nbl_install_builtin_resources _TARGET_)
get_target_property(_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_ ${_TARGET_} BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY)
get_target_property(_BUILTIN_RESOURCES_HEADERS_ ${_TARGET_} BUILTIN_RESOURCES_HEADERS)

nbl_install_headers("${_BUILTIN_RESOURCES_HEADERS_}" "${_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_}")
endfunction()

function(nbl_install_config_header _CONF_HDR_NAME)
nbl_get_conf_dir(dir_deb Debug)
nbl_get_conf_dir(dir_rel Release)
Expand All @@ -351,6 +360,18 @@ function(nbl_install_config_header _CONF_HDR_NAME)
install(FILES ${file_relWithDebInfo} DESTINATION relwithdebinfo/include CONFIGURATIONS RelWithDebInfo)
endfunction()

# links builtin resource target to a target
# @_TARGET_@ is target name builtin resource target will be linked to
# @_BS_TARGET_@ is a builtin resource target

function(LINK_BUILTIN_RESOURCES_TO_TARGET _TARGET_ _BS_TARGET_)
add_dependencies(${EXECUTABLE_NAME} ${_BS_TARGET_})
target_link_libraries(${EXECUTABLE_NAME} PUBLIC ${_BS_TARGET_})

get_target_property(_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_ ${_BS_TARGET_} BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY)
target_include_directories(${EXECUTABLE_NAME} PUBLIC "${_BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY_}")
endfunction()

macro(nbl_android_create_apk _TARGET)
get_target_property(TARGET_NAME ${_TARGET} NAME)
# TARGET_NAME_IDENTIFIER is identifier that can be used in code
Expand Down
1 change: 1 addition & 0 deletions cmake/install/nbl/sharedDefines.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
*/

#define _NABLA_DLL_NAME_ "@_NABLA_DLL_NAME_@"
#define _DXC_DLL_NAME_ "@_DXC_DLL_NAME_@"
#define _NABLA_INSTALL_DIR_ @_NABLA_INSTALL_DIR_@
4 changes: 4 additions & 0 deletions cmake/scripts/nbl/nablaDefines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ if(NOT DEFINED _NABLA_DLL_NAME_)
message(FATAL_ERROR "_NABLA_DLL_NAME_ variable must be specified for this script!")
endif()

if(NOT DEFINED _DXC_DLL_NAME_)
message(FATAL_ERROR "_DXC_DLL_NAME_ variable must be specified for this script!")
endif()

if(NOT DEFINED _NABLA_INSTALL_DIR_)
message(FATAL_ERROR "_NABLA_INSTALL_DIR_ variable must be specified for this script!")
endif()
Expand Down
37 changes: 0 additions & 37 deletions include/nbl/builtin/common.h

This file was deleted.

2 changes: 2 additions & 0 deletions include/nbl/config/BuildConfigOptions.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
#endif
#endif

#define NBL_BUILTIN_RESOURCES_DIRECTORY_PATH "@NBL_BUILTIN_RESOURCES_DIRECTORY_PATH@"

// DDL exports
#cmakedefine _NBL_SHARED_BUILD_
#ifdef _NBL_SHARED_BUILD_
Expand Down
12 changes: 11 additions & 1 deletion include/nbl/scene/ICullingLoDSelectionSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,17 @@ class ICullingLoDSelectionSystem : public virtual core::IReferenceCounted
auto getShader = [device]<core::StringLiteral Path>() -> shader_source_and_path
{
auto system = device->getPhysicalDevice()->getSystem();
auto glslFile = system->loadBuiltinData<Path>();

auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr<const nbl::system::IFile>
{
nbl::system::ISystem::future_t<core::smart_refctd_ptr<nbl::system::IFile>> future;
system->createFile(future, system::path(_path), core::bitflag(nbl::system::IFileBase::ECF_READ) | nbl::system::IFileBase::ECF_MAPPABLE);
if (future.wait())
return future.copy();
return nullptr;
};

auto glslFile = loadBuiltinData(Path.value);
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
{
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());
Expand Down
17 changes: 13 additions & 4 deletions include/nbl/scene/ISkinInstanceCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
auto system = device->getPhysicalDevice()->getSystem();
auto createShader = [&system,&device](auto uniqueString, asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr<video::IGPUSpecializedShader>
{
auto glslFile = system->loadBuiltinData<decltype(uniqueString)>();
auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr<const nbl::system::IFile>
{
nbl::system::ISystem::future_t<core::smart_refctd_ptr<nbl::system::IFile>> future;
system->createFile(future, system::path(_path), core::bitflag(nbl::system::IFileBase::ECF_READ) | nbl::system::IFileBase::ECF_MAPPABLE);
if (future.wait())
return future.copy();
return nullptr;
};

auto glslFile = loadBuiltinData(uniqueString);
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
{
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());
Expand All @@ -36,9 +45,9 @@ class ISkinInstanceCacheManager : public virtual core::IReferenceCounted
return device->createSpecializedShader(shader.get(),{nullptr,nullptr,"main"});
};

auto updateSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/skinning/cache_update.comp")());
auto debugDrawVertexSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/skinning/debug.vert")(),asset::IShader::ESS_VERTEX);
auto debugDrawFragmentSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag")(),asset::IShader::ESS_FRAGMENT);
auto updateSpec = createShader("nbl/builtin/glsl/skinning/cache_update.comp");
auto debugDrawVertexSpec = createShader("nbl/builtin/glsl/skinning/debug.vert",asset::IShader::ESS_VERTEX);
auto debugDrawFragmentSpec = createShader("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag",asset::IShader::ESS_FRAGMENT);
if (!updateSpec || !debugDrawVertexSpec || !debugDrawFragmentSpec)
return nullptr;

Expand Down
11 changes: 10 additions & 1 deletion include/nbl/scene/ITransformTreeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ class ITransformTreeManager : public virtual core::IReferenceCounted
auto system = device->getPhysicalDevice()->getSystem();
auto createShader = [&system,&device]<core::StringLiteral Path>(asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr<video::IGPUSpecializedShader>
{
auto glslFile = system->loadBuiltinData<Path>();
auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr<const nbl::system::IFile>
{
nbl::system::ISystem::future_t<core::smart_refctd_ptr<nbl::system::IFile>> future;
system->createFile(future, system::path(_path), core::bitflag(nbl::system::IFileBase::ECF_READ) | nbl::system::IFileBase::ECF_MAPPABLE);
if (future.wait())
return future.copy();
return nullptr;
};

auto glslFile = loadBuiltinData(Path.value);
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
{
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/system/CFileViewVirtualAllocatorWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace nbl::system
{
#ifdef _NBL_PLATFORM_WINDOWS_
class CFileViewVirtualAllocatorWin32 : public IFileViewAllocator
class NBL_API2 CFileViewVirtualAllocatorWin32 : public IFileViewAllocator
{
public:
using IFileViewAllocator::IFileViewAllocator;
Expand Down
10 changes: 5 additions & 5 deletions include/nbl/system/IFileArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace nbl::system
class IFile;

//! The FileArchive manages archives and provides access to files inside them.
class IFileArchive : public core::IReferenceCounted
class NBL_API2 IFileArchive : public core::IReferenceCounted
{
public:
enum E_ALLOCATOR_TYPE
Expand Down Expand Up @@ -64,10 +64,10 @@ class IFileArchive : public core::IReferenceCounted
};

devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
//
core::SRange<const SListEntry> listAssets() const {return {m_items.data(),m_items.data()+m_items.size()};}
virtual core::SRange<const SListEntry> listAssets() const {return {m_items.data(),m_items.data()+m_items.size()};}

// List all files and directories in a specific dir of the archive
core::SRange<const SListEntry> listAssets(const path& asset_path) const;
virtual core::SRange<const SListEntry> listAssets(const path& asset_path) const;

//
virtual core::smart_refctd_ptr<IFile> getFile(const path& pathRelativeToArchive, const std::string_view& password) = 0;
Expand All @@ -88,10 +88,10 @@ class IFileArchive : public core::IReferenceCounted
return &(*found);
}

std::mutex itemMutex; // TODO: update to readers writer lock
mutable std::mutex itemMutex; // TODO: update to readers writer lock
path m_defaultAbsolutePath;
// files and directories
core::vector<SListEntry> m_items;
mutable core::vector<SListEntry> m_items;
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
//
system::logger_opt_smart_ptr m_logger;
};
Expand Down
30 changes: 11 additions & 19 deletions include/nbl/system/ISystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "nbl/core/declarations.h"
#include "nbl/core/util/bitflag.h"

#include "nbl/builtin/common.h"

#include <variant>

#include "nbl/system/IFileArchive.h"
#include "nbl/system/IAsyncQueueDispatcher.h"
//#include "nbl/builtin/builtinResources.h"

#ifdef _NBL_EMBED_BUILTIN_RESOURCES_
#include "nbl/builtin/builtinResources.h"
#endif

namespace nbl::system
{
Expand All @@ -23,6 +24,7 @@ class NBL_API2 ISystem : public core::IReferenceCounted
{
public:
inline static constexpr uint32_t MAX_FILENAME_LENGTH = 4096;

//! We overrride the future a little bit, to allow to put a result in it right away without asynchronocity
template <typename T>
struct future_t final : public impl::IAsyncQueueDispatcherBase::cancellable_future_t<T>
Expand All @@ -49,21 +51,14 @@ class NBL_API2 ISystem : public core::IReferenceCounted
future.set_result(value);
}
};

//! Compile time resource ID
template<nbl::core::StringLiteral Path>
inline core::smart_refctd_ptr<const IFile> loadBuiltinData()

#ifndef _NBL_EMBED_BUILTIN_RESOURCES_
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
constexpr std::string_view getBuiltinResourcesDirectoryPath()
{
#ifdef _NBL_EMBED_BUILTIN_RESOURCES_
return impl_loadEmbeddedBuiltinData(Path.value,nbl::builtin::get_resource<Path>());
#else
future_t<core::smart_refctd_ptr<IFile>> future;
createFile(future,system::path(Path.value),core::bitflag(IFileBase::ECF_READ)|IFileBase::ECF_MAPPABLE);
if (future.wait())
return future.copy();
return nullptr;
#endif
std::string_view retval = NBL_BUILTIN_RESOURCES_DIRECTORY_PATH;
return retval;
}
#endif

//
inline void addArchiveLoader(core::smart_refctd_ptr<IArchiveLoader>&& loader)
Expand Down Expand Up @@ -198,9 +193,6 @@ class NBL_API2 ISystem : public core::IReferenceCounted
explicit ISystem(core::smart_refctd_ptr<ICaller>&& caller);
virtual ~ISystem() {}

//
core::smart_refctd_ptr<const IFile> impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair<const uint8_t*,size_t>& found) const;

// given an `absolutePath` find the archive it belongs to
struct FoundArchiveFile
{
Expand Down
Loading