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 all 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 "")
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
# 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 +55,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
14 changes: 6 additions & 8 deletions include/nbl/system/CFileArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class CFileArchive : public IFileArchive
public:
inline core::smart_refctd_ptr<IFile> getFile(const path& pathRelativeToArchive, const std::string_view& password) override
{
std::unique_lock lock(itemMutex);

const auto* item = getItemFromPath(pathRelativeToArchive);
if (!item)
return nullptr;
Expand Down Expand Up @@ -107,13 +105,13 @@ class CFileArchive : public IFileArchive
}

protected:
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, core::vector<SListEntry> _items) :
CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, std::shared_ptr<core::vector<SFileList::SEntry>> _items) :
IFileArchive(std::move(_defaultAbsolutePath),std::move(logger))
{
m_items = std::move(_items);
std::sort(m_items.begin(),m_items.end());
std::sort(_items->begin(), _items->end());
m_items.store(_items);

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

template<class Allocator>
inline core::smart_refctd_ptr<CInnerArchiveFile<Allocator>> getFile_impl(const IFileArchive::SListEntry* item)
inline core::smart_refctd_ptr<CInnerArchiveFile<Allocator>> getFile_impl(const IFileArchive::SFileList::SEntry* item)
{
auto* file = reinterpret_cast<CInnerArchiveFile<Allocator>*>(m_filesBuffer+item->ID*SIZEOF_INNER_ARCHIVE_FILE);
// NOTE: Intentionally calling grab() on maybe-not-existing object!
Expand Down Expand Up @@ -160,7 +158,7 @@ class CFileArchive : public IFileArchive
size_t size;
void* allocatorState;
};
virtual file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) = 0;
virtual file_buffer_t getFileBuffer(const IFileArchive::SFileList::SEntry* item) = 0;

std::atomic_flag* m_fileFlags = nullptr;
std::byte* m_filesBuffer = nullptr;
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
63 changes: 63 additions & 0 deletions include/nbl/system/CMountDirectoryArchive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef _NBL_SYSTEM_C_MOUNT_DIRECTORY_ARCHIVE_H_INCLUDED_
#define _NBL_SYSTEM_C_MOUNT_DIRECTORY_ARCHIVE_H_INCLUDED_

#include "nbl/system/IFileArchive.h"

#include "nbl/system/IFile.h"

namespace nbl::system {



class CMountDirectoryArchive : public IFileArchive
{
ISystem* m_system;

public:
inline CMountDirectoryArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, ISystem* system) :
IFileArchive(std::move(_defaultAbsolutePath), std::move(logger))
{
m_system = system;
}

core::smart_refctd_ptr<IFile> getFile(const path& pathRelativeToArchive, const std::string_view& password) override
{
{
//std::unique_lock(itemMutex); already inside `getItemFromPath`
if (!getItemFromPath(pathRelativeToArchive))
return nullptr;
}
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
m_system->createFile(future, m_defaultAbsolutePath / pathRelativeToArchive, system::IFile::ECF_READ);
if (auto file = future.acquire())
return *file;
}

SFileList listAssets(const path& asset_path) const override
{
populateItemList(asset_path);
return IFileArchive::listAssets(asset_path);
}
SFileList listAssets() const override {
populateItemList(path());
return IFileArchive::listAssets();
}

void populateItemList(const path& p) const {
auto items = m_system->listItemsInDirectory(m_defaultAbsolutePath/p);
auto new_entries = std::make_shared<core::vector<SFileList::SEntry>>();
for (auto item : items)
{
if (item.has_extension())
{
auto relpath = item.lexically_relative(m_defaultAbsolutePath);
auto entry = SFileList::SEntry{ relpath, 0xdeadbeefu, 0xdeadbeefu, 0xdeadbeefu, EAT_NONE };
new_entries->push_back(entry);
}
}
m_items.store({new_entries});
}
};

} //namespace nbl::system
#endif
Loading