diff --git a/3rdparty/dxc/CMakeLists.txt b/3rdparty/dxc/CMakeLists.txt index 0844306d92..77a7dddeb2 100644 --- a/3rdparty/dxc/CMakeLists.txt +++ b/3rdparty/dxc/CMakeLists.txt @@ -135,4 +135,11 @@ CACHE INTERNAL "") set(DXC_DLL $,${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 + $,${_NBL_DXC_DEBUG_DLL_NAME_},${_NBL_DXC_RELEASE_DLL_NAME_}> CACHE INTERNAL "") \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eb5684cfb..62abf1242b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/cmake/common.cmake b/cmake/common.cmake index 6b5548c907..47220dcad9 100755 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -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 @@ -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) @@ -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) @@ -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 diff --git a/cmake/install/nbl/sharedDefines.h.in b/cmake/install/nbl/sharedDefines.h.in index 1413dc1286..d904c8a0b6 100644 --- a/cmake/install/nbl/sharedDefines.h.in +++ b/cmake/install/nbl/sharedDefines.h.in @@ -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_@ \ No newline at end of file diff --git a/cmake/scripts/nbl/nablaDefines.cmake b/cmake/scripts/nbl/nablaDefines.cmake index ee5317ade6..615e041aa4 100644 --- a/cmake/scripts/nbl/nablaDefines.cmake +++ b/cmake/scripts/nbl/nablaDefines.cmake @@ -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() diff --git a/examples_tests b/examples_tests index 7ad86d334a..a0935fadd1 160000 --- a/examples_tests +++ b/examples_tests @@ -1 +1 @@ -Subproject commit 7ad86d334a65bb67822aa771a41fa413d2b9d2f6 +Subproject commit a0935fadd1b0500fa7d46f0bdcfe0edaf077f17a diff --git a/include/nbl/builtin/common.h b/include/nbl/builtin/common.h deleted file mode 100644 index 80bd79769d..0000000000 --- a/include/nbl/builtin/common.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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 - - - -#ifndef _NBL_BUILTIN_COMMON_H_INCLUDED_ -#define _NBL_BUILTIN_COMMON_H_INCLUDED_ - -#include "BuildConfigOptions.h" - -#include -#include - -#include "nbl/builtin/builtinResources.h" - -namespace nbl::builtin -{ - -constexpr std::string_view PathPrefix = "nbl/builtin/"; -constexpr bool hasPathPrefix(std::string_view str) { return str.find(PathPrefix) == 0ull; } - -// if you attempt to use this without `NBL_EMBED_BUILTIN_RESOURCES_` CMake option, this will always return `{nullptr,0ull}` -std::pair get_resource_runtime(const std::string&); - -#ifndef _NBL_EMBED_BUILTIN_RESOURCES_ -#define _NBL_BUILTIN_PATH_AVAILABLE -constexpr std::string_view getBuiltinResourcesDirectoryPath() -{ - std::string_view retval = __FILE__; - retval.remove_suffix(PathPrefix.size()+std::string_view("common.h").size()); - return retval; -} -#endif - -} -#endif diff --git a/include/nbl/config/BuildConfigOptions.h.in b/include/nbl/config/BuildConfigOptions.h.in index 78e7441627..031d324552 100644 --- a/include/nbl/config/BuildConfigOptions.h.in +++ b/include/nbl/config/BuildConfigOptions.h.in @@ -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_ diff --git a/include/nbl/scene/ICullingLoDSelectionSystem.h b/include/nbl/scene/ICullingLoDSelectionSystem.h index 411e9f7637..5ce6df591d 100644 --- a/include/nbl/scene/ICullingLoDSelectionSystem.h +++ b/include/nbl/scene/ICullingLoDSelectionSystem.h @@ -490,7 +490,17 @@ class ICullingLoDSelectionSystem : public virtual core::IReferenceCounted auto getShader = [device]() -> shader_source_and_path { auto system = device->getPhysicalDevice()->getSystem(); - auto glslFile = system->loadBuiltinData(); + + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> 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 glsl; { glsl = core::make_smart_refctd_ptr(glslFile->getSize()); diff --git a/include/nbl/scene/ISkinInstanceCacheManager.h b/include/nbl/scene/ISkinInstanceCacheManager.h index 88debdbd1b..496272d916 100644 --- a/include/nbl/scene/ISkinInstanceCacheManager.h +++ b/include/nbl/scene/ISkinInstanceCacheManager.h @@ -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 { - auto glslFile = system->loadBuiltinData(); + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> 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 glsl; { glsl = core::make_smart_refctd_ptr(glslFile->getSize()); @@ -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; diff --git a/include/nbl/scene/ITransformTreeManager.h b/include/nbl/scene/ITransformTreeManager.h index 838e37245d..141bb38566 100644 --- a/include/nbl/scene/ITransformTreeManager.h +++ b/include/nbl/scene/ITransformTreeManager.h @@ -108,7 +108,16 @@ class ITransformTreeManager : public virtual core::IReferenceCounted auto system = device->getPhysicalDevice()->getSystem(); auto createShader = [&system,&device](asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr { - auto glslFile = system->loadBuiltinData(); + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> 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 glsl; { glsl = core::make_smart_refctd_ptr(glslFile->getSize()); diff --git a/include/nbl/system/CFileArchive.h b/include/nbl/system/CFileArchive.h index fd19198c09..e344959a56 100644 --- a/include/nbl/system/CFileArchive.h +++ b/include/nbl/system/CFileArchive.h @@ -76,8 +76,6 @@ class CFileArchive : public IFileArchive public: inline core::smart_refctd_ptr getFile(const path& pathRelativeToArchive, const std::string_view& password) override { - std::unique_lock lock(itemMutex); - const auto* item = getItemFromPath(pathRelativeToArchive); if (!item) return nullptr; @@ -107,13 +105,13 @@ class CFileArchive : public IFileArchive } protected: - CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, core::vector _items) : + CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, std::shared_ptr> _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 - inline core::smart_refctd_ptr> getFile_impl(const IFileArchive::SListEntry* item) + inline core::smart_refctd_ptr> getFile_impl(const IFileArchive::SFileList::SEntry* item) { auto* file = reinterpret_cast*>(m_filesBuffer+item->ID*SIZEOF_INNER_ARCHIVE_FILE); // NOTE: Intentionally calling grab() on maybe-not-existing object! @@ -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; diff --git a/include/nbl/system/CFileViewVirtualAllocatorWin32.h b/include/nbl/system/CFileViewVirtualAllocatorWin32.h index 36b2366b82..ff53dc74e5 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorWin32.h +++ b/include/nbl/system/CFileViewVirtualAllocatorWin32.h @@ -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; diff --git a/include/nbl/system/CMountDirectoryArchive.h b/include/nbl/system/CMountDirectoryArchive.h new file mode 100644 index 0000000000..8450c8e60c --- /dev/null +++ b/include/nbl/system/CMountDirectoryArchive.h @@ -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 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> 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>(); + 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 \ No newline at end of file diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index e62c6a8176..c913557c25 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -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 @@ -33,41 +33,64 @@ class IFileArchive : public core::IReferenceCounted EAT_MALLOC // decompress to RAM }; //! An entry in a list of items, can be a folder or a file. - struct SListEntry + struct SFileList { - //! The name of the file including the path relative to archive root - system::path pathRelativeToArchive; - - //! The size of the file in bytes - size_t size; - - //! FileOffset inside an archive - size_t offset; - - //! The ID of the file in an archive, it maps it to a memory pool entry for CFileView - uint32_t ID; - - // `EAT_NONE` for directories - E_ALLOCATOR_TYPE allocatorType; - - //! The == operator is provided so that CFileList can slowly search the list! - inline bool operator==(const struct SListEntry& other) const - { - return pathRelativeToArchive.string()==other.pathRelativeToArchive.string(); - } - - //! The < operator is provided so that CFileList can sort and quickly search the list. - inline bool operator<(const struct SListEntry& other) const + struct SEntry { - return pathRelativeToArchive>; + using range_t = core::SRange; + + inline operator range_t() const { return m_range; } + + SFileList(const SFileList&) = default; + SFileList(SFileList&&) = default; + SFileList& operator=(const SFileList&) = default; + SFileList& operator=(SFileList&&) = default; + + private: + // default ctor full range + SFileList(refctd_storage_t _data) : m_data(_data), m_range({ _data->data(),_data->data() + _data->size() }) {} + + friend class IFileArchive; + refctd_storage_t m_data; + range_t m_range; }; // - core::SRange listAssets() const {return {m_items.data(),m_items.data()+m_items.size()};} + virtual inline SFileList listAssets() const { + return { m_items.load() }; + } // List all files and directories in a specific dir of the archive - core::SRange listAssets(const path& asset_path) const; + virtual SFileList listAssets(const path& pathRelativeToArchive) const; // virtual core::smart_refctd_ptr getFile(const path& pathRelativeToArchive, const std::string_view& password) = 0; @@ -79,19 +102,19 @@ class IFileArchive : public core::IReferenceCounted IFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger) : m_defaultAbsolutePath(std::move(_defaultAbsolutePath)), m_logger(std::move(logger)) {} - inline const SListEntry* getItemFromPath(const system::path& pathRelativeToArchive) const + inline const SFileList::SEntry* getItemFromPath(const system::path& pathRelativeToArchive) const { - const IFileArchive::SListEntry itemToFind = { pathRelativeToArchive }; - const auto found = std::lower_bound(m_items.begin(),m_items.end(),itemToFind); - if (found==m_items.end() || found->pathRelativeToArchive!=pathRelativeToArchive) + const SFileList::SEntry itemToFind = { pathRelativeToArchive }; + auto items = m_items.load(); + const auto found = std::lower_bound(items->begin(), items->end(),itemToFind); + if (found== items->end() || found->pathRelativeToArchive != pathRelativeToArchive) return nullptr; return &(*found); } - std::mutex itemMutex; // TODO: update to readers writer lock path m_defaultAbsolutePath; // files and directories - core::vector m_items; + mutable std::atomic m_items; // system::logger_opt_smart_ptr m_logger; }; diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 268b381aa2..ea78dbff89 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -5,13 +5,14 @@ #include "nbl/core/declarations.h" #include "nbl/core/util/bitflag.h" -#include "nbl/builtin/common.h" - #include #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 { @@ -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 struct future_t final : public impl::IAsyncQueueDispatcherBase::cancellable_future_t @@ -49,21 +51,14 @@ class NBL_API2 ISystem : public core::IReferenceCounted future.set_result(value); } }; - - //! Compile time resource ID - template - inline core::smart_refctd_ptr loadBuiltinData() + + #ifndef _NBL_EMBED_BUILTIN_RESOURCES_ + constexpr std::string_view getBuiltinResourcesDirectoryPath() { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - return impl_loadEmbeddedBuiltinData(Path.value,nbl::builtin::get_resource()); - #else - future_t> 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&& loader) @@ -198,9 +193,6 @@ class NBL_API2 ISystem : public core::IReferenceCounted explicit ISystem(core::smart_refctd_ptr&& caller); virtual ~ISystem() {} - // - core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const; - // given an `absolutePath` find the archive it belongs to struct FoundArchiveFile { diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index ad96d5bf89..878d658ae3 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -114,10 +114,6 @@ endif() nbl_get_conf_dir(NABLA_CONF_DIR_DEBUG Debug) nbl_get_conf_dir(NABLA_CONF_DIR_RELEASE Release) -if(NBL_EMBED_BUILTIN_RESOURCES) - add_subdirectory(builtin) - NBL_ADD_BUILTIN_RESOURCES() -endif() nbl_get_conf_dir(NABLA_CONF_DIR_RELWITHDEBINFO RelWithDebInfo) if (NBL_COMPILE_WITH_CUDA) @@ -360,15 +356,6 @@ set(COMMON_INCLUDE_DIRS file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") -#always install builtins (some may be included in cpp regardless if embedded or not) -foreach(X IN LISTS NBL_RESOURCES_TO_EMBED) - list(APPEND NABLA_RESOURCES_TO_EMBED_PUBLIC "${NBL_ROOT_PATH}/include/${X}") -endforeach() -list(APPEND NABLA_HEADERS_PUBLIC ${NABLA_RESOURCES_TO_EMBED_PUBLIC}) -source_group("Resources to embed" FILES ${NABLA_RESOURCES_TO_EMBED_PUBLIC}) -set_source_files_properties(${NABLA_RESOURCES_TO_EMBED_PUBLIC} - PROPERTIES HEADER_FILE_ONLY TRUE) - set(NABLA_HEADERS "${NBL_ROOT_PATH}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) set(NBL_LIBRARY_CREATION_SOURCES @@ -485,7 +472,7 @@ if(NBL_STATIC_BUILD) else() target_link_libraries(Nabla PRIVATE SPIRV SPIRV-Tools SPIRV-Tools-opt) endif() -target_include_directories(Nabla PUBLIC BEFORE ${THIRD_PARTY_SOURCE_DIR}/SPIRV-Tools/include) +target_include_directories(Nabla PUBLIC BEFORE "${THIRD_PARTY_SOURCE_DIR}/dxc/dxc/external/SPIRV-Tools/include") # simdjson add_dependencies(Nabla simdjson) if(NBL_STATIC_BUILD) @@ -607,6 +594,36 @@ target_compile_definitions(Nabla INTERFACE _NBL_PCH_IGNORE_PRIVATE_HEADERS ) +if(NBL_EMBED_BUILTIN_RESOURCES) + add_subdirectory(builtin) + NBL_ADD_BUILTIN_RESOURCES(nblBuiltinResourceData) # internal, must be added with the macro to properly propagate scope + add_dependencies(Nabla nblBuiltinResourceData) + + if(NBL_STATIC_BUILD) + target_link_libraries(Nabla INTERFACE + nblBuiltinResourceData + ) + else() + target_link_libraries(Nabla PRIVATE + nblBuiltinResourceData + ) + endif() + + # always install builtins (some may be included in cpp regardless if embedded or not) + get_target_property(_BUILTIN_RESOURCES_BUNDLE_ARCHIVE_ABSOLUTE_PATH_ nblBuiltinResourceData BUILTIN_RESOURCES_BUNDLE_ARCHIVE_ABSOLUTE_PATH) + foreach(X IN LISTS NBL_RESOURCES_TO_EMBED) + list(APPEND NABLA_RESOURCES_TO_EMBED_PUBLIC "${NBL_ROOT_PATH}/include/${_BUILTIN_RESOURCES_BUNDLE_ARCHIVE_ABSOLUTE_PATH_}/${X}") + endforeach() + + target_sources(Nabla PRIVATE + ${NABLA_RESOURCES_TO_EMBED_PUBLIC} + ) + + list(APPEND NABLA_HEADERS_PUBLIC ${NABLA_RESOURCES_TO_EMBED_PUBLIC}) + source_group("Resources to embed" FILES ${NABLA_RESOURCES_TO_EMBED_PUBLIC}) + set_source_files_properties(${NABLA_RESOURCES_TO_EMBED_PUBLIC} PROPERTIES HEADER_FILE_ONLY TRUE) +endif() + # generate Nabla definitions to a header glue_source_definitions(Nabla _NBL_SOURCE_DEFINITIONS_) set(_NBL_DEFINE_FILE_WRAPPER_ ${CMAKE_CURRENT_BINARY_DIR}/include/define.h) @@ -622,12 +639,6 @@ if(NBL_PCH) target_precompile_headers(Nabla PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pch.h") endif() -if(NBL_EMBED_BUILTIN_RESOURCES) - add_dependencies(Nabla nblBuiltinResourceData) - target_link_libraries(Nabla PUBLIC nblBuiltinResourceData) - target_include_directories(Nabla PUBLIC "${NBL_BUILTIN_RESOURCES_HEADER}") -endif() - # extensions start_tracking_variables_for_propagation_to_parent() add_subdirectory(ext) @@ -635,10 +646,17 @@ propagate_changed_variables_to_parent_scope() if(NOT NBL_STATIC_BUILD) add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$/generated/define.h" - COMMAND "${CMAKE_COMMAND}" -DNBL_ROOT_PATH:PATH=${NBL_ROOT_PATH} -DNBL_WRAPPER_FILE:FILEPATH=${_NBL_DEFINE_FILE_WRAPPER_} -DNBL_GEN_DIRECTORY:PATH=${CMAKE_CURRENT_BINARY_DIR}/$/generated -D_NABLA_DLL_NAME_:STRING=$ -D_NABLA_INSTALL_DIR_:PATH="${CMAKE_INSTALL_PREFIX}" -P ${NBL_ROOT_PATH}/cmake/scripts/nbl/nablaDefines.cmake + COMMAND "${CMAKE_COMMAND}" -DNBL_ROOT_PATH:PATH=${NBL_ROOT_PATH} -DNBL_WRAPPER_FILE:FILEPATH=${_NBL_DEFINE_FILE_WRAPPER_} -DNBL_GEN_DIRECTORY:PATH=${CMAKE_CURRENT_BINARY_DIR}/$/generated -D_NABLA_DLL_NAME_:STRING=$ -D_DXC_DLL_NAME_:STRING=${DXC_DLL_NAME} -D_NABLA_INSTALL_DIR_:PATH="${CMAKE_INSTALL_PREFIX}" -P ${NBL_ROOT_PATH}/cmake/scripts/nbl/nablaDefines.cmake COMMENT "Launching defines.h generation script!" VERBATIM ) + + add_custom_target(generate_nabla_defines ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/$/generated/define.h" + VERBATIM + ) + + add_dependencies(Nabla generate_nabla_defines) endif() nbl_install_headers("${NABLA_HEADERS_PUBLIC}" "${NBL_ROOT_PATH}/include") @@ -648,6 +666,10 @@ endif() nbl_install_file("${NBL_ROOT_PATH_BINARY}/include/nbl/builtin/builtinResources.h" "nbl/builtin") nbl_install_config_header(BuildConfigOptions.h) +if(NBL_EMBED_BUILTIN_RESOURCES) + nbl_install_builtin_resources(nblBuiltinResourceData) +endif() + # TODO: @AnastazIuk change macros to functions! https://github.com/buildaworldnet/IrrlichtBAW/issues/311 macro(nbl_install_program _TRGT) install(PROGRAMS $ DESTINATION lib CONFIGURATIONS Release) diff --git a/src/nbl/asset/IAssetManager.cpp b/src/nbl/asset/IAssetManager.cpp index 0a6ade8741..19614addd5 100644 --- a/src/nbl/asset/IAssetManager.cpp +++ b/src/nbl/asset/IAssetManager.cpp @@ -242,38 +242,47 @@ void IAssetManager::insertBuiltinAssets() }; auto fileSystem = getSystem(); - buildInGLSLShader(fileSystem->loadBuiltinData(), + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> future; + fileSystem->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; + }; + + buildInGLSLShader(loadBuiltinData("nbl/builtin/specialized_shader/fullscreentriangle.vert"), asset::IShader::ESS_VERTEX, { "nbl/builtin/specialized_shader/fullscreentriangle.vert" }); - buildInGLSLShader(fileSystem->loadBuiltinData(), + buildInGLSLShader(loadBuiltinData("nbl/builtin/material/lambertian/singletexture/specialized_shader.vert"), asset::IShader::ESS_VERTEX, { "nbl/builtin/material/lambertian/singletexture/specialized_shader.vert", "nbl/builtin/material/debug/vertex_uv/specialized_shader.vert" }); - buildInGLSLShader(fileSystem->loadBuiltinData(), // it somehow adds an extra "tt" raw string to the end of the returned value, beware + buildInGLSLShader(loadBuiltinData("nbl/builtin/material/lambertian/singletexture/specialized_shader.frag"), // it somehow adds an extra "tt" raw string to the end of the returned value, beware asset::IShader::ESS_FRAGMENT, { "nbl/builtin/material/lambertian/singletexture/specialized_shader.frag" }); - buildInGLSLShader(fileSystem->loadBuiltinData(), + buildInGLSLShader(loadBuiltinData("nbl/builtin/material/debug/vertex_normal/specialized_shader.vert"), asset::IShader::ESS_VERTEX, { "nbl/builtin/material/debug/vertex_normal/specialized_shader.vert"}); - buildInGLSLShader(fileSystem->loadBuiltinData(), + buildInGLSLShader(loadBuiltinData("nbl/builtin/material/debug/vertex_color/specialized_shader.vert"), asset::IShader::ESS_VERTEX, { "nbl/builtin/material/debug/vertex_color/specialized_shader.vert" }); - buildInGLSLShader(fileSystem->loadBuiltinData(), + buildInGLSLShader(loadBuiltinData("nbl/builtin/material/debug/vertex_uv/specialized_shader.frag"), asset::IShader::ESS_FRAGMENT, { "nbl/builtin/material/debug/vertex_uv/specialized_shader.frag" }); - buildInGLSLShader(fileSystem->loadBuiltinData(), + buildInGLSLShader(loadBuiltinData("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag"), asset::IShader::ESS_FRAGMENT, { "nbl/builtin/material/debug/vertex_normal/specialized_shader.frag", diff --git a/src/nbl/asset/interchange/CGLTFLoader.cpp b/src/nbl/asset/interchange/CGLTFLoader.cpp index abc0b364fc..1f8d788aa0 100644 --- a/src/nbl/asset/interchange/CGLTFLoader.cpp +++ b/src/nbl/asset/interchange/CGLTFLoader.cpp @@ -47,7 +47,18 @@ using namespace nbl::asset; { auto registerShader = [&](auto constexprStringType, IShader::E_SHADER_STAGE stage, const char* extraDefine=nullptr) -> void { - core::smart_refctd_ptr glslFile = assetManager->getSystem()->loadBuiltinData(); + auto fileSystem = assetManager->getSystem(); + + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> future; + fileSystem->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; + }; + + core::smart_refctd_ptr glslFile = loadBuiltinData(decltype(constexprStringType)::value); auto glsl = core::make_smart_refctd_ptr(glslFile->getSize()); memcpy(glsl->getPointer(),glslFile->getMappedPointer(),glsl->getSize()); diff --git a/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp b/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp index 1cf5c5b56d..be47d53c11 100644 --- a/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp +++ b/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp @@ -30,7 +30,18 @@ CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am, core: //create vertex shaders and insert them into cache auto registerShader = [&](ICPUShader::E_SHADER_STAGE stage) -> void { - core::smart_refctd_ptr data = m_assetMgr->getSystem()->loadBuiltinData(); + auto fileSystem = m_assetMgr->getSystem(); + + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> future; + fileSystem->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; + }; + + core::smart_refctd_ptr data = loadBuiltinData(Path.value); auto buffer = core::make_smart_refctd_ptr(data->getSize()+1u); char* bufferPtr = reinterpret_cast(buffer->getPointer()); memcpy(bufferPtr, data->getMappedPointer(), data->getSize()); diff --git a/src/nbl/asset/utils/CGLSLCompiler.cpp b/src/nbl/asset/utils/CGLSLCompiler.cpp index b99a7b77ac..f3f8377660 100644 --- a/src/nbl/asset/utils/CGLSLCompiler.cpp +++ b/src/nbl/asset/utils/CGLSLCompiler.cpp @@ -3,12 +3,12 @@ // For conditions of distribution and use, see copyright notice in nabla.h #include "nbl/asset/utils/CGLSLCompiler.h" #include "nbl/asset/utils/shadercUtils.h" +#include "nbl/builtin/CArchive.h" #include #include #include - using namespace nbl; using namespace nbl::asset; diff --git a/src/nbl/asset/utils/CHLSLCompiler.cpp b/src/nbl/asset/utils/CHLSLCompiler.cpp index 5ac83cc94e..59046b336b 100644 --- a/src/nbl/asset/utils/CHLSLCompiler.cpp +++ b/src/nbl/asset/utils/CHLSLCompiler.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in nabla.h #include "nbl/asset/utils/CHLSLCompiler.h" #include "nbl/asset/utils/shadercUtils.h" +#include "nbl/builtin/CArchive.h" #ifdef _NBL_PLATFORM_WINDOWS_ diff --git a/src/nbl/builtin/CMakeLists.txt b/src/nbl/builtin/CMakeLists.txt index 65d7705df7..327cb5bed0 100644 --- a/src/nbl/builtin/CMakeLists.txt +++ b/src/nbl/builtin/CMakeLists.txt @@ -1,294 +1,245 @@ -find_package(Python3 REQUIRED) +find_package (Python3 COMPONENTS Interpreter REQUIRED) -set(NBL_RESOURCES_TO_EMBED - "nbl/builtin/glsl/utils/acceleration_structures.glsl" - "nbl/builtin/shader/loader/mtl/vertex_impl.glsl" - "nbl/builtin/shader/loader/mtl/vertex_no_uv.vert" # TODO: remove naming tautology - "nbl/builtin/shader/loader/mtl/vertex_uv.vert" # TODO: remove naming tautology - "nbl/builtin/shader/loader/mtl/fragment_impl.glsl" - "nbl/builtin/shader/loader/mtl/fragment_no_uv.frag" # TODO: remove naming tautology - "nbl/builtin/shader/loader/mtl/fragment_uv.frag" # TODO: remove naming tautology - "nbl/builtin/shader/loader/gltf/common.glsl" - "nbl/builtin/shader/loader/gltf/vertex_impl.glsl" - "nbl/builtin/shader/loader/gltf/uv.vert" - "nbl/builtin/shader/loader/gltf/color.vert" - "nbl/builtin/shader/loader/gltf/no_uv_color.vert" - "nbl/builtin/shader/loader/gltf/fragment_impl.glsl" - "nbl/builtin/shader/loader/gltf/uv.frag" - "nbl/builtin/shader/loader/gltf/color.frag" - "nbl/builtin/shader/loader/gltf/no_uv_color.frag" - "nbl/builtin/specialized_shader/fullscreentriangle.vert" - "nbl/builtin/material/lambertian/singletexture/specialized_shader.vert" - "nbl/builtin/material/lambertian/singletexture/specialized_shader.frag" - "nbl/builtin/material/debug/vertex_color/specialized_shader.vert" - "nbl/builtin/material/debug/vertex_normal/specialized_shader.vert" - "nbl/builtin/material/debug/vertex_normal/specialized_shader.frag" - "nbl/builtin/material/debug/vertex_uv/specialized_shader.frag" - # generic GLSL headers after this line - "nbl/builtin/glsl/macros.glsl" - "nbl/builtin/glsl/algorithm.glsl" - "nbl/builtin/glsl/ieee754.glsl" - # barycentric - "nbl/builtin/glsl/barycentric/extensions.glsl" - "nbl/builtin/glsl/barycentric/frag.glsl" - "nbl/builtin/glsl/barycentric/vert.glsl" - "nbl/builtin/glsl/barycentric/utils.glsl" - # bump mapping - "nbl/builtin/glsl/bump_mapping/fragment.glsl" # TODO: rename to `frag.glsl` - "nbl/builtin/glsl/bump_mapping/utils.glsl" - # bxdf - "nbl/builtin/glsl/bxdf/common.glsl" - "nbl/builtin/glsl/bxdf/common_samples.glsl" - "nbl/builtin/glsl/bxdf/fresnel.glsl" - "nbl/builtin/glsl/bxdf/ndf/common.glsl" - "nbl/builtin/glsl/bxdf/ndf/blinn_phong.glsl" - "nbl/builtin/glsl/bxdf/ndf/beckmann.glsl" - "nbl/builtin/glsl/bxdf/ndf/ggx.glsl" - "nbl/builtin/glsl/bxdf/geom/smith/common.glsl" - "nbl/builtin/glsl/bxdf/geom/smith/beckmann.glsl" - "nbl/builtin/glsl/bxdf/geom/smith/ggx.glsl" - # brdf - "nbl/builtin/glsl/bxdf/brdf/diffuse/lambert.glsl" - "nbl/builtin/glsl/bxdf/brdf/diffuse/oren_nayar.glsl" - "nbl/builtin/glsl/bxdf/brdf/specular/blinn_phong.glsl" - "nbl/builtin/glsl/bxdf/brdf/specular/beckmann.glsl" - "nbl/builtin/glsl/bxdf/brdf/specular/ggx.glsl" - "nbl/builtin/glsl/bxdf/brdf/diffuse/fresnel_correction.glsl" - # bsdf - "nbl/builtin/glsl/bxdf/bsdf/diffuse/lambert.glsl" - "nbl/builtin/glsl/bxdf/bsdf/specular/common.glsl" - "nbl/builtin/glsl/bxdf/bsdf/specular/dielectric.glsl" - "nbl/builtin/glsl/bxdf/bsdf/specular/beckmann.glsl" - "nbl/builtin/glsl/bxdf/bsdf/specular/ggx.glsl" - # colorspace - "nbl/builtin/glsl/colorspace/EOTF.glsl" - "nbl/builtin/glsl/colorspace/OETF.glsl" - "nbl/builtin/glsl/colorspace/decodeCIEXYZ.glsl" - "nbl/builtin/glsl/colorspace/encodeCIEXYZ.glsl" - # Culling and LoD System - "nbl/builtin/glsl/culling_lod_selection/dispatch_indirect_params.glsl" - "nbl/builtin/glsl/culling_lod_selection/draw_instance_count_scan_override.glsl" - "nbl/builtin/glsl/culling_lod_selection/input_descriptor_set.glsl" - "nbl/builtin/glsl/culling_lod_selection/instance_cull_and_lod_select.comp" - "nbl/builtin/glsl/culling_lod_selection/instance_draw_count_scan_override.glsl" - "nbl/builtin/glsl/culling_lod_selection/instance_draw_cull.comp" - "nbl/builtin/glsl/culling_lod_selection/instance_ref_counting_sort_scatter.comp" - "nbl/builtin/glsl/culling_lod_selection/potentially_visible_instance_draw_struct.glsl" - "nbl/builtin/glsl/culling_lod_selection/output_descriptor_modifiers.glsl" - "nbl/builtin/glsl/culling_lod_selection/output_descriptor_set.glsl" - # VK_FORMAT support - "nbl/builtin/glsl/format/decode.glsl" - "nbl/builtin/glsl/format/encode.glsl" - "nbl/builtin/glsl/format/constants.glsl" - # asset loaders (mostly for pipelines) - "nbl/builtin/glsl/loader/mtl/common.glsl" - # LoD Library - "nbl/builtin/glsl/lod_library/structs.glsl" - "nbl/builtin/glsl/lod_library/descriptor_set.glsl" - # math and limits - "nbl/builtin/glsl/math/constants.glsl" - "nbl/builtin/glsl/math/complex.glsl" - "nbl/builtin/glsl/math/functions.glsl" - "nbl/builtin/glsl/math/quaternions.glsl" - "nbl/builtin/glsl/math/typeless_arithmetic.glsl" - "nbl/builtin/glsl/limits/numeric.glsl" - # material_compiler - "nbl/builtin/glsl/material_compiler/common.glsl" - "nbl/builtin/glsl/material_compiler/common_declarations.glsl" - "nbl/builtin/glsl/material_compiler/common_invariant_declarations.glsl" - "nbl/builtin/glsl/material_compiler/rasterization/impl.glsl" - # property pool - "nbl/builtin/glsl/property_pool/transfer.glsl" - "nbl/builtin/glsl/property_pool/copy.comp" - # random numbers - "nbl/builtin/glsl/random/xoroshiro.glsl" - # sampling - "nbl/builtin/glsl/sampling/bilinear.glsl" - "nbl/builtin/glsl/sampling/box_muller_transform.glsl" - "nbl/builtin/glsl/sampling/concentric_mapping.glsl" - "nbl/builtin/glsl/sampling/cos_weighted.glsl" - "nbl/builtin/glsl/sampling/linear.glsl" - "nbl/builtin/glsl/sampling/projected_spherical_triangle.glsl" - "nbl/builtin/glsl/sampling/spherical_rectangle.glsl" - "nbl/builtin/glsl/sampling/spherical_triangle.glsl" - "nbl/builtin/glsl/sampling/quantized_sequence.glsl" - # global exclusive scan - "nbl/builtin/glsl/scan/direct.comp" - "nbl/builtin/glsl/scan/declarations.glsl" - "nbl/builtin/glsl/scan/descriptors.glsl" - "nbl/builtin/glsl/scan/default_scheduler.glsl" - "nbl/builtin/glsl/scan/indirect.comp" - "nbl/builtin/glsl/scan/parameters_struct.glsl" - "nbl/builtin/glsl/scan/virtual_workgroup.glsl" - # faster and easier scan - "nbl/builtin/glsl/scanning_append/scanning_append.glsl" - # scene - "nbl/builtin/glsl/scene/animation.glsl" - "nbl/builtin/glsl/scene/keyframe.glsl" - "nbl/builtin/glsl/scene/node.glsl" - # shapes - "nbl/builtin/glsl/shapes/aabb.glsl" - "nbl/builtin/glsl/shapes/frustum.glsl" - "nbl/builtin/glsl/shapes/rectangle.glsl" - "nbl/builtin/glsl/shapes/triangle.glsl" - # skinning - "nbl/builtin/glsl/skinning/cache_descriptor_set.glsl" - "nbl/builtin/glsl/skinning/cache_update.comp" - "nbl/builtin/glsl/skinning/debug.vert" - "nbl/builtin/glsl/skinning/linear.glsl" - "nbl/builtin/glsl/skinning/render_descriptor_set.glsl" - "nbl/builtin/glsl/skinning/update_descriptor_set.glsl" - # subgroup emulation - "nbl/builtin/glsl/subgroup/shared_arithmetic_portability.glsl" - "nbl/builtin/glsl/subgroup/basic_portability.glsl" - "nbl/builtin/glsl/subgroup/arithmetic_portability.glsl" - "nbl/builtin/glsl/subgroup/arithmetic_portability_impl.glsl" - ##"nbl/builtin/glsl/subgroup/fft.glsl" - # utilities - "nbl/builtin/glsl/utils/indirect_commands.glsl" - "nbl/builtin/glsl/utils/common.glsl" - "nbl/builtin/glsl/utils/culling.glsl" - "nbl/builtin/glsl/utils/compressed_normal_matrix_t.glsl" - "nbl/builtin/glsl/utils/normal_decode.glsl" - "nbl/builtin/glsl/utils/normal_encode.glsl" - "nbl/builtin/glsl/utils/transform.glsl" - "nbl/builtin/glsl/utils/morton.glsl" - "nbl/builtin/glsl/utils/surface_transform_transformedDerivatives.glsl" - "nbl/builtin/glsl/utils/surface_transform.glsl" - "nbl/builtin/glsl/utils/surface_transform_e.h" - # virtual texturing - "nbl/builtin/glsl/virtual_texturing/descriptors.glsl" - "nbl/builtin/glsl/virtual_texturing/extensions.glsl" - "nbl/builtin/glsl/virtual_texturing/impl_functions.glsl" - # workgroup "intrinsics" - "nbl/builtin/glsl/workgroup/shared_arithmetic.glsl" - "nbl/builtin/glsl/workgroup/shared_ballot.glsl" - "nbl/builtin/glsl/workgroup/shared_clustered.glsl" - "nbl/builtin/glsl/workgroup/shared_fft.glsl" - "nbl/builtin/glsl/workgroup/shared_shuffle.glsl" - "nbl/builtin/glsl/workgroup/shared_shuffle_relative.glsl" - "nbl/builtin/glsl/workgroup/shared_vote.glsl" - "nbl/builtin/glsl/workgroup/arithmetic.glsl" - "nbl/builtin/glsl/workgroup/ballot.glsl" - "nbl/builtin/glsl/workgroup/basic.glsl" - "nbl/builtin/glsl/workgroup/clustered.glsl" - "nbl/builtin/glsl/workgroup/fft.glsl" - "nbl/builtin/glsl/workgroup/shuffle.glsl" - "nbl/builtin/glsl/workgroup/shuffle_relative.glsl" - "nbl/builtin/glsl/workgroup/vote.glsl" - #transform_tree - "nbl/builtin/glsl/transform_tree/global_transform_update.comp" - "nbl/builtin/glsl/transform_tree/global_transform_and_normal_matrix_update.comp" - "nbl/builtin/glsl/transform_tree/global_transform_update_common.glsl" - "nbl/builtin/glsl/transform_tree/global_transform_update_descriptor_set.glsl" - "nbl/builtin/glsl/transform_tree/modification_request_range.glsl" - "nbl/builtin/glsl/transform_tree/pool_descriptor_set.glsl" - "nbl/builtin/glsl/transform_tree/render_descriptor_set.glsl" - "nbl/builtin/glsl/transform_tree/relative_transform_modification.glsl" - "nbl/builtin/glsl/transform_tree/relative_transform_update.comp" - "nbl/builtin/glsl/transform_tree/relative_transform_update_common.glsl" - "nbl/builtin/glsl/transform_tree/relative_transform_update_descriptor_set.glsl" - "nbl/builtin/glsl/transform_tree/debug.vert" - # ext shouldn't be built into the engine, but there's no harm including some non-dynamic GLSL source to make life easier - #"nbl/builtin/glsl/ext/.glsl" - # radix sort - "nbl/builtin/glsl/ext/FFT/default_compute_fft.comp" - "nbl/builtin/glsl/ext/FFT/fft.glsl" - "nbl/builtin/glsl/ext/FFT/parameters_struct.glsl" - "nbl/builtin/glsl/ext/FFT/parameters.glsl" - "nbl/builtin/glsl/ext/FFT/types.glsl" - "nbl/builtin/glsl/ext/LumaMeter/common.glsl" - "nbl/builtin/glsl/ext/LumaMeter/impl.glsl" - "nbl/builtin/glsl/ext/ToneMapper/operators.glsl" - "nbl/builtin/glsl/ext/RadeonRays/intersection.glsl" - "nbl/builtin/glsl/ext/RadeonRays/ray.glsl" - "nbl/builtin/glsl/ext/MitsubaLoader/instance_data_struct.glsl" - "nbl/builtin/glsl/ext/MitsubaLoader/instance_data_descriptor.glsl" - "nbl/builtin/glsl/ext/MitsubaLoader/material_compiler_compatibility_impl.glsl" - # OIT - "nbl/builtin/glsl/ext/OIT/oit.glsl" - "nbl/builtin/glsl/ext/OIT/insert_node.glsl" - "nbl/builtin/glsl/ext/OIT/resolve.frag" - # virtual geometry - "nbl/builtin/glsl/virtual_geometry/descriptors.glsl" - "nbl/builtin/glsl/virtual_geometry/virtual_attribute.glsl" - "nbl/builtin/glsl/virtual_geometry/virtual_attribute_fetch.glsl" - # depth pyramid generator - "nbl/builtin/glsl/ext/DepthPyramidGenerator/common.glsl" - "nbl/builtin/glsl/ext/DepthPyramidGenerator/push_constants_struct_common.h" - "nbl/builtin/glsl/ext/DepthPyramidGenerator/depth_pyramid_generator_impl.glsl" - "nbl/builtin/glsl/ext/DepthPyramidGenerator/virtual_work_group.glsl" - # blit - "nbl/builtin/glsl/blit/formats_encode.glsl" - "nbl/builtin/glsl/blit/parameters.glsl" - "nbl/builtin/glsl/blit/multi_dimensional_array_addressing.glsl" - "nbl/builtin/glsl/blit/default_compute_common.comp" +include("${CMAKE_CURRENT_SOURCE_DIR}/utils.cmake") - "nbl/builtin/glsl/blit/default_compute_blit.comp" - "nbl/builtin/glsl/blit/blit/blit.glsl" - "nbl/builtin/glsl/blit/blit/descriptors.glsl" +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/acceleration_structures.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/mtl/vertex_impl.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/mtl/vertex_no_uv.vert") # TODO: remove naming tautology +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/mtl/vertex_uv.vert") # TODO: remove naming tautology +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/mtl/fragment_impl.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/mtl/fragment_no_uv.frag") # TODO: remove naming tautology +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/mtl/fragment_uv.frag") # TODO: remove naming tautology +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/vertex_impl.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/uv.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/color.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/no_uv_color.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/fragment_impl.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/uv.frag") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/color.frag") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "shader/loader/gltf/no_uv_color.frag") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "specialized_shader/fullscreentriangle.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "material/lambertian/singletexture/specialized_shader.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "material/lambertian/singletexture/specialized_shader.frag") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "material/debug/vertex_color/specialized_shader.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "material/debug/vertex_normal/specialized_shader.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "material/debug/vertex_normal/specialized_shader.frag") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "material/debug/vertex_uv/specialized_shader.frag") +# generic GLSL headers after this line +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/macros.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/algorithm.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ieee754.glsl") +# barycentric +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/barycentric/extensions.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/barycentric/frag.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/barycentric/vert.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/barycentric/utils.glsl") +# bump mapping +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bump_mapping/fragment.glsl") # TODO: rename to `frag.glsl` +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bump_mapping/utils.glsl") +# bxdf +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/common_samples.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/fresnel.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/ndf/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/ndf/blinn_phong.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/ndf/beckmann.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/ndf/ggx.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/geom/smith/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/geom/smith/beckmann.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/geom/smith/ggx.glsl") +# brdf +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/brdf/diffuse/lambert.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/brdf/diffuse/oren_nayar.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/brdf/specular/blinn_phong.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/brdf/specular/beckmann.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/brdf/specular/ggx.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/brdf/diffuse/fresnel_correction.glsl") +# bsdf +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/bsdf/diffuse/lambert.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/bsdf/specular/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/bsdf/specular/dielectric.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/bsdf/specular/beckmann.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bxdf/bsdf/specular/ggx.glsl") +# colorspace +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/colorspace/EOTF.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/colorspace/OETF.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/colorspace/decodeCIEXYZ.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/colorspace/encodeCIEXYZ.glsl") +# Culling and LoD System +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/dispatch_indirect_params.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/draw_instance_count_scan_override.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/input_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/instance_cull_and_lod_select.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/instance_draw_count_scan_override.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/instance_draw_cull.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/instance_ref_counting_sort_scatter.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/potentially_visible_instance_draw_struct.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/output_descriptor_modifiers.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/culling_lod_selection/output_descriptor_set.glsl") +# VK_FORMAT support +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/format/decode.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/format/encode.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/format/constants.glsl") +# asset loaders (mostly for pipelines) +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/loader/mtl/common.glsl") +# LoD Library +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/lod_library/structs.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/lod_library/descriptor_set.glsl") +# math and limits +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/math/constants.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/math/complex.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/math/functions.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/math/quaternions.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/math/typeless_arithmetic.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/limits/numeric.glsl") +# material_compiler +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/material_compiler/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/material_compiler/common_declarations.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/material_compiler/common_invariant_declarations.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/material_compiler/rasterization/impl.glsl") +# property pool +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/property_pool/transfer.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/property_pool/copy.comp") +# random numbers +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/random/xoroshiro.glsl") +# sampling +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/bilinear.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/box_muller_transform.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/concentric_mapping.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/cos_weighted.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/linear.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/projected_spherical_triangle.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/spherical_rectangle.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/spherical_triangle.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/sampling/quantized_sequence.glsl") +# global exclusive scan +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/direct.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/declarations.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/descriptors.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/default_scheduler.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/indirect.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/parameters_struct.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scan/virtual_workgroup.glsl") +# faster and easier scan +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scanning_append/scanning_append.glsl") +# scene +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scene/animation.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scene/keyframe.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/scene/node.glsl") +# shapes +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/shapes/aabb.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/shapes/frustum.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/shapes/rectangle.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/shapes/triangle.glsl") +# skinning +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/skinning/cache_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/skinning/cache_update.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/skinning/debug.vert") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/skinning/linear.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/skinning/render_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/skinning/update_descriptor_set.glsl") +# subgroup emulation +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/subgroup/shared_arithmetic_portability.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/subgroup/basic_portability.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/subgroup/arithmetic_portability.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/subgroup/arithmetic_portability_impl.glsl") +##LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/subgroup/fft.glsl") +# utilities +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/indirect_commands.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/culling.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/compressed_normal_matrix_t.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/normal_decode.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/normal_encode.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/transform.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/morton.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/surface_transform_transformedDerivatives.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/surface_transform.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/utils/surface_transform_e.h") +# virtual texturing +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/virtual_texturing/descriptors.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/virtual_texturing/extensions.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/virtual_texturing/impl_functions.glsl") +# workgroup "intrinsics" +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_arithmetic.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_ballot.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_clustered.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_fft.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_shuffle.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_shuffle_relative.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shared_vote.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/arithmetic.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/ballot.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/basic.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/clustered.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/fft.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shuffle.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/shuffle_relative.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/workgroup/vote.glsl") +#transform_tree +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/global_transform_update.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/global_transform_and_normal_matrix_update.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/global_transform_update_common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/global_transform_update_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/modification_request_range.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/pool_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/render_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/relative_transform_modification.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/relative_transform_update.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/relative_transform_update_common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/relative_transform_update_descriptor_set.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/transform_tree/debug.vert") +# ext shouldn't be built into the engine, but there's no harm including some non-dynamic GLSL source to make life easier +#LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/.glsl") +# radix sort +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/FFT/default_compute_fft.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/FFT/fft.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/FFT/parameters_struct.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/FFT/parameters.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/FFT/types.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/LumaMeter/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/LumaMeter/impl.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/ToneMapper/operators.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/RadeonRays/intersection.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/RadeonRays/ray.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/MitsubaLoader/instance_data_struct.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/MitsubaLoader/instance_data_descriptor.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/MitsubaLoader/material_compiler_compatibility_impl.glsl") +# OIT +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/OIT/oit.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/OIT/insert_node.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/OIT/resolve.frag") +# virtual geometry +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/virtual_geometry/descriptors.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/virtual_geometry/virtual_attribute.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/virtual_geometry/virtual_attribute_fetch.glsl") +# depth pyramid generator +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/DepthPyramidGenerator/common.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/DepthPyramidGenerator/push_constants_struct_common.h") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/DepthPyramidGenerator/depth_pyramid_generator_impl.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/ext/DepthPyramidGenerator/virtual_work_group.glsl") +# blit +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/formats_encode.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/parameters.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/multi_dimensional_array_addressing.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/default_compute_common.comp") - "nbl/builtin/glsl/blit/default_compute_alpha_test.comp" - "nbl/builtin/glsl/blit/alpha_test/alpha_test.glsl" - "nbl/builtin/glsl/blit/alpha_test/descriptors.glsl" +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/default_compute_blit.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/blit/blit.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/blit/descriptors.glsl") - "nbl/builtin/glsl/blit/default_compute_normalization.comp" - "nbl/builtin/glsl/blit/normalization/normalization.glsl" - "nbl/builtin/glsl/blit/normalization/descriptors.glsl" - "nbl/builtin/glsl/blit/normalization/shared_normalization.glsl" - "nbl/builtin/hlsl/shapes/line.hlsl" -PARENT_SCOPE) +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/default_compute_alpha_test.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/alpha_test/alpha_test.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/alpha_test/descriptors.glsl") -function(ADD_CUSTOM_BUILTIN_RESOURCES _TARGET_NAME_ _NAMESPACE_ _CUSTOM_RESOURCES_TO_EMBED_ _OUTPUT_DIRECTORY_) - set(NBL_BUILTIN_HEADER_GEN_PY "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/builtinHeaderGen.py") - set(NBL_BUILTIN_DATA_GEN_PY "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/builtinDataGen.py") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/default_compute_normalization.comp") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/normalization/normalization.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/normalization/descriptors.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/blit/normalization/shared_normalization.glsl") +LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/line.hlsl") - foreach(X IN LISTS _CUSTOM_RESOURCES_TO_EMBED_) - list(APPEND NBL_DEPENDENCY_FILES "${NBL_ROOT_PATH}/include/${X}") - endforeach() - - list(APPEND NBL_DEPENDENCY_FILES "${NBL_BUILTIN_HEADER_GEN_PY}") - list(APPEND NBL_DEPENDENCY_FILES "${NBL_BUILTIN_DATA_GEN_PY}") - - set(NBL_RESOURCES_LIST_FILE "${NBL_ROOT_PATH_BINARY}/include/nbl/builtin/resources.txt") - - string(REPLACE ";" "," RESOURCES_ARGS "${_CUSTOM_RESOURCES_TO_EMBED_}") - file(MAKE_DIRECTORY "${NBL_ROOT_PATH_BINARY}/include/nbl/builtin") - file(WRITE "${NBL_RESOURCES_LIST_FILE}" "${RESOURCES_ARGS}") - - set(NBL_BS_HEADER_FILENAME "builtinResources.h") - set(NBL_BS_DATA_SOURCE_FILENAME "builtinResourceData.cpp") - set(NBL_BUILTIN_RESOURCES_HEADER "${_OUTPUT_DIRECTORY_}/${NBL_BS_HEADER_FILENAME}") - set(NBL_BUILTIN_RESOURCE_DATA_SOURCE "${_OUTPUT_DIRECTORY_}/${NBL_BS_DATA_SOURCE_FILENAME}") - - set(_NBL_SOURCES_ - "${NBL_BUILTIN_RESOURCES_HEADER}" - "${NBL_BUILTIN_RESOURCE_DATA_SOURCE}" - ) - - add_custom_command( - OUTPUT "${NBL_BUILTIN_RESOURCES_HEADER}" "${NBL_BUILTIN_RESOURCE_DATA_SOURCE}" - COMMAND "${PYTHON_EXECUTABLE}" "${NBL_BUILTIN_HEADER_GEN_PY}" "${NBL_BUILTIN_RESOURCES_HEADER}" "${NBL_ROOT_PATH}/include" "${NBL_RESOURCES_LIST_FILE}" "${_NAMESPACE_}" - COMMAND "${PYTHON_EXECUTABLE}" "${NBL_BUILTIN_DATA_GEN_PY}" "${NBL_BUILTIN_RESOURCE_DATA_SOURCE}" "${NBL_ROOT_PATH}/include" "${NBL_RESOURCES_LIST_FILE}" "${_NAMESPACE_}" - COMMENT "Generating built-in resources" - DEPENDS ${NBL_DEPENDENCY_FILES} - VERBATIM - ) - - add_library(${_TARGET_NAME_} STATIC - ${_NBL_SOURCES_} - ) - - target_include_directories(${_TARGET_NAME_} PUBLIC "${NBL_ROOT_PATH}/include") - - if(NBL_DYNAMIC_MSVC_RUNTIME) - set_property(TARGET ${_TARGET_NAME_} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - else() - set_property(TARGET ${_TARGET_NAME_} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - endif() -endfunction() - -function(NBL_ADD_BUILTIN_RESOURCES) - ADD_CUSTOM_BUILTIN_RESOURCES(nblBuiltinResourceData "nbl::builtin" "${NBL_RESOURCES_TO_EMBED}" "${NBL_ROOT_PATH_BINARY}/include/nbl/builtin") -endfunction() +macro(NBL_ADD_BUILTIN_RESOURCES _TARGET_) # internal & Nabla only, must be added with the macro to properly propagate scope + ADD_CUSTOM_BUILTIN_RESOURCES("${_TARGET_}" NBL_RESOURCES_TO_EMBED "${NBL_ROOT_PATH}/include" "nbl/builtin" "nbl::builtin" "${NBL_ROOT_PATH_BINARY}/include" "${NBL_ROOT_PATH_BINARY}/src") +endmacro() diff --git a/src/nbl/builtin/builtinDataGen.py b/src/nbl/builtin/builtinDataGen.py index a8abaddd4f..d125e123f3 100644 --- a/src/nbl/builtin/builtinDataGen.py +++ b/src/nbl/builtin/builtinDataGen.py @@ -17,25 +17,25 @@ cmakeSourceDir = sys.argv[2] resourcesFile = sys.argv[3] resourcesNamespace = sys.argv[4] + correspondingHeaderFile = sys.argv[5] - with open(resourcesFile, "r") as f: - resourcePaths = f.read().rstrip().split(',') + file = open(resourcesFile, 'r') + resourcePaths = file.readlines() #opening a file outp = open(outputFilename,"w+") - - - outp.write("#include \"nbl/core/string/StringLiteral.h\"\n") - outp.write("#include \n") - outp.write("#include \n"); - outp.write("#include \n"); + + outp.write("#include \"" + correspondingHeaderFile + "\"\n") outp.write("\tnamespace " + resourcesNamespace + " {\n") outp.write("template") outp.write("const std::pair get_resource();") # writing binary data of all files in a loop - for x in resourcePaths: + for z in resourcePaths: + itemData = z.split(',') + x = itemData[0].rstrip() + outp.write('\n\ttemplate<> const std::pair get_resource()' % x) outp.write('\n\t{') outp.write('\n\t\tstatic const uint8_t data[] = {\n\t\t\t') @@ -58,21 +58,41 @@ outp.write('\n\t\t};') outp.write('\n\t\treturn { data, sizeof(data) };') - outp.write('\n\t}') - - + outp.write('\n\t}\n') + + if len(itemData) > 1: + for i in range(1, len(itemData)): + outp.write('\n\ttemplate<> const std::pair get_resource()' % itemData[i].rstrip()) + outp.write('\n\t{') + outp.write('\n\t\treturn get_resource();' % x) + outp.write('\n\t}\n') + outp.write("\tstd::pair get_resource_runtime(const std::string& filename) {\n") outp.write("\t\tstatic std::unordered_map resourcesByFilename( {\n") counter = 1 - for x in resourcePaths: + + for z in resourcePaths: + itemData = z.split(',') + x = itemData[0].rstrip() + outp.write("\t\t\t{\"%s\", %d},\n" % (x,counter)) + + if len(itemData) > 1: + for i in range(1, len(itemData)): + outp.write("\t\t\t{\"%s\", %d},\n" % (itemData[i].rstrip(),counter)) + counter+= 1 + outp.write("\t\t});\n\n") outp.write("\t\tauto resource = resourcesByFilename.find(filename);\n") outp.write("\t\tif(resource == resourcesByFilename.end()) return { nullptr,0ull };\n") outp.write("\t\tswitch (resource->second) \n\t\t\t{\n") counter = 1 - for x in resourcePaths: + + for z in resourcePaths: + itemData = z.split(',') + x = itemData[0].rstrip() + outp.write("\t\t\tcase %d:\n\t\t\t\t\treturn get_resource();\n" % (counter,x)) counter+= 1 diff --git a/src/nbl/builtin/builtinHeaderGen.py b/src/nbl/builtin/builtinHeaderGen.py index e1da040f83..f8e6d9e989 100644 --- a/src/nbl/builtin/builtinHeaderGen.py +++ b/src/nbl/builtin/builtinHeaderGen.py @@ -17,29 +17,66 @@ cmakeSourceDir = sys.argv[2] resourcesFile = sys.argv[3] resourcesNamespace = sys.argv[4] + guardSuffix = sys.argv[5] + isSharedLibrary = True if sys.argv[6] == "True" else False - with open(resourcesFile, "r") as f: - resourcePaths = f.read().rstrip().split(',') + file = open(resourcesFile, 'r') + resourcePaths = file.readlines() #opening a file outp = open(outputFilename,"w+") - outp.write("#ifndef BUILTINRESOURCEDATA_H\n") - outp.write("#define BUILTINRESOURCEDATA_H\n") + outp.write("#ifndef _" + guardSuffix + "_BUILTINRESOURCEDATA_H_\n") + outp.write("#define _" + guardSuffix + "_BUILTINRESOURCEDATA_H_\n") outp.write("#include \n") outp.write("#include \n") outp.write("#include \n") outp.write("#include \n") outp.write("#include \n#include \n\n") + + if isSharedLibrary: + outp.write("#if defined(__NBL_BUILDING_TARGET__) // currently compiling the target, this define is passed through the commandline\n") + outp.write("#if defined(_MSC_VER)\n") + outp.write("#define NBL_BR_API __declspec(dllexport)\n") + outp.write("#elif defined(__GNUC__)\n") + outp.write('#define NBL_BR_API __attribute__ ((visibility ("default")))' + "\n") + outp.write("#endif\n") + outp.write("#else\n") + outp.write("#if defined(_MSC_VER)\n") + outp.write("#define NBL_BR_API __declspec(dllimport)\n") + outp.write("#else\n") + outp.write("#define NBL_BR_API\n") + outp.write("#endif\n") + outp.write("#endif\n\n") + outp.write("namespace " + resourcesNamespace + " { \n") + + if isSharedLibrary: + outp.write("\t\tNBL_BR_API std::pair get_resource_runtime(const std::string& filename);\n\n") + else: + outp.write("\t\tstd::pair get_resource_runtime(const std::string& filename);\n\n") + outp.write("\t\ttemplate\n") outp.write("\t\tconst std::pair get_resource();\n") #Iterating through input list - for x in resourcePaths: - outp.write('\n\t\textern template const std::pair get_resource();' % x) + for z in resourcePaths: + itemData = z.split(',') + x = itemData[0].rstrip() + + if isSharedLibrary: + outp.write('\n\t\ttemplate<> NBL_BR_API const std::pair get_resource();' % x) + else: + outp.write('\n\t\ttemplate<> const std::pair get_resource();' % x) + + if len(itemData) > 1: + for i in range(1, len(itemData)): + if isSharedLibrary: + outp.write('\n\t\ttemplate<> NBL_BR_API const std::pair get_resource();' % itemData[i].rstrip()) + else: + outp.write('\n\t\ttemplate<> const std::pair get_resource();' % itemData[i].rstrip()) outp.write("\n\t}") - outp.write("\n#endif") + outp.write("\n#endif // _" + guardSuffix + "_BUILTINRESOURCEDATA_H_") outp.close() diff --git a/src/nbl/builtin/template/CArchive.cpp.in b/src/nbl/builtin/template/CArchive.cpp.in new file mode 100644 index 0000000000..f4b350be50 --- /dev/null +++ b/src/nbl/builtin/template/CArchive.cpp.in @@ -0,0 +1,16 @@ +#include "CArchive.h" +#include + +using namespace @_NAMESPACE_@; + +static const std::shared_ptr> k_builtinArchiveFileList = std::make_shared>( + nbl::core::vector{ +@_RESOURCES_INIT_LIST_@ +}); + +CArchive::CArchive(nbl::system::logger_opt_smart_ptr&& logger) + : nbl::system::CFileArchive(nbl::system::path(pathPrefix.data()),std::move(logger), k_builtinArchiveFileList) +{ + +} + diff --git a/src/nbl/builtin/template/CArchive.h.in b/src/nbl/builtin/template/CArchive.h.in new file mode 100644 index 0000000000..8e15b843df --- /dev/null +++ b/src/nbl/builtin/template/CArchive.h.in @@ -0,0 +1,28 @@ +#ifndef _@_GUARD_SUFFIX_@_C_ARCHIVE_H_ +#define _@_GUARD_SUFFIX_@_C_ARCHIVE_H_ + +#include "nbl/system/CFileArchive.h" +#include "@NBL_BS_HEADER_FILENAME@" + +namespace @_NAMESPACE_@ +{ + constexpr std::string_view pathPrefix = "@_BUNDLE_ARCHIVE_ABSOLUTE_PATH_@"; + constexpr bool hasPathPrefix(std::string_view str) { return str.find(pathPrefix) == 0ull; } + + class @_NBL_BR_API_@ CArchive final : public nbl::system::CFileArchive + { + public: + CArchive(nbl::system::logger_opt_smart_ptr&& logger); + + protected: + file_buffer_t getFileBuffer(const nbl::system::IFileArchive::SFileList::SEntry* item) override + { + auto found = get_resource_runtime(item->pathRelativeToArchive.string()); + return { const_cast(found.first), found.second, nullptr }; + } + }; +} + +#endif // _@_GUARD_SUFFIX_@_C_ARCHIVE_H_ + + diff --git a/src/nbl/builtin/utils.cmake b/src/nbl/builtin/utils.cmake new file mode 100644 index 0000000000..260cbb9bcb --- /dev/null +++ b/src/nbl/builtin/utils.cmake @@ -0,0 +1,202 @@ +# Assigns builtin resources to a bundle a target library will be created with +# _BUNDLE_NAME_ is a bundle name, must be a valid CMake list variable +# _LBR_PATH_ is a path to builtin resource + +macro(LIST_BUILTIN_RESOURCE _BUNDLE_NAME_ _LBR_PATH_) + math(EXPR _ALIAS_C_ "${ARGC} - 2" OUTPUT_FORMAT DECIMAL) + set(_ALIAS_ARGS_ ${ARGV}) + + if("${_ALIAS_C_}" GREATER "0") + list(SUBLIST _ALIAS_ARGS_ "2" "${_ALIAS_C_}" _ALIAS_ARGS_) + + foreach(_ALIAS_ IN LISTS _ALIAS_ARGS_) + string(APPEND _OPTIONAL_ALIASES_ ",${_ALIAS_}") + endforeach() + endif() + + list(APPEND ${_BUNDLE_NAME_} "${_LBR_PATH_}") + set(${_BUNDLE_NAME_} ${${_BUNDLE_NAME_}} PARENT_SCOPE) # override + + list(APPEND _LBR_${_BUNDLE_NAME_}_ "${_LBR_PATH_}${_OPTIONAL_ALIASES_}") + set(_LBR_${_BUNDLE_NAME_}_ ${_LBR_${_BUNDLE_NAME_}_} PARENT_SCOPE) # override + + unset(_OPTIONAL_ALIASES_) + unset(_ALIAS_ARGS_) +endmacro() + +# Creates a library with builtin resources for given bundle +# _TARGET_NAME_ is name of a target library that will be created +# _BUNDLE_NAME_ a list variable populated using LIST_BUILTIN_RESOURCE +# _BUNDLE_SEARCH_DIRECTORY_ is an absolute search directory path for builtin resorces for given bundle +# _BUNDLE_ARCHIVE_ABSOLUTE_PATH_ is a "absolute path" for an archive which will store a given bundle of builtin resources, must be relative _BUNDLE_SEARCH_DIRECTORY_ +# _NAMESPACE_ is a C++ namespace builtin resources will be wrapped into +# _OUTPUT_INCLUDE_SEARCH_DIRECTORY_ is an absolute path to output directory for builtin resources header files which will be a search directory for generated headers outputed to ${_OUTPUT_HEADER_DIRECTORY_}/${_NAMESPACE_PREFIX_} where namespace prefix is the namespace turned into a path +# _OUTPUT_SOURCE_DIRECTORY_ is an absolute path to output directory for builtin resources source files +# _STATIC_ optional last argument is a bool, if true then add_library will use STATIC, SHARED otherwise. Pay attention that MSVC runtime is controlled by NBL_DYNAMIC_MSVC_RUNTIME which is not an argument of this function +# +# As an example one could list a resource as following +# LIST_BUILTIN_RESOURCE(SOME_RESOURCES_TO_EMBED "glsl/blit/default_compute_normalization.comp") +# and then create builtin resource target with the resource above using +# ADD_CUSTOM_BUILTIN_RESOURCES("aTarget" SOME_RESOURCES_TO_EMBED "${NBL_ROOT_PATH}/include" "nbl/builtin" "myns::builtin" "${NBL_ROOT_PATH_BINARY}/include" "${NBL_ROOT_PATH_BINARY}/src") +# a real absolute path to the resource on the disk would be ${NBL_ROOT_PATH}/include/nbl/builtin/glsl/blit/default_compute_normalization.comp +# the builtin resource path seen in Nabla filesystem would be "nbl/builtin/builtin/glsl/blit/default_compute_normalization.comp" where "nbl/builtin" would be an absolute path for an archive + +function(ADD_CUSTOM_BUILTIN_RESOURCES _TARGET_NAME_ _BUNDLE_NAME_ _BUNDLE_SEARCH_DIRECTORY_ _BUNDLE_ARCHIVE_ABSOLUTE_PATH_ _NAMESPACE_ _OUTPUT_INCLUDE_SEARCH_DIRECTORY_ _OUTPUT_SOURCE_DIRECTORY_) + if(NOT DEFINED _Python3_EXECUTABLE) + message(FATAL_ERROR "_Python3_EXECUTABLE must be defined - call find_package(Python3 COMPONENTS Interpreter REQUIRED)") + endif() + + if("${ARGV7}" STREQUAL "SHARED") + set(_LIB_TYPE_ SHARED) + set(_SHARED_ True) + set(NBL_BR_API "NBL_BR_API") + else() + set(_LIB_TYPE_ STATIC) + set(_SHARED_ False) + unset(NBL_BR_API) + endif() + + set(NBL_TEMPLATE_RESOURCES_ARCHIVE_HEADER "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/CArchive.h.in") + set(NBL_TEMPLATE_RESOURCES_ARCHIVE_SOURCE "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/CArchive.cpp.in") + set(NBL_BUILTIN_HEADER_GEN_PY "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/builtinHeaderGen.py") + set(NBL_BUILTIN_DATA_GEN_PY "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/builtinDataGen.py") + set(NBL_BS_HEADER_FILENAME "builtinResources.h") + set(NBL_BS_DATA_SOURCE_FILENAME "builtinResourceData.cpp") + + string(REPLACE "::" "/" _NAMESPACE_PREFIX_ "${_NAMESPACE_}") + string(REPLACE "::" "_" _GUARD_SUFFIX_ "${_NAMESPACE_}") + string(REGEX REPLACE "^[0-9]+\." "" _GUARD_SUFFIX_ ${_GUARD_SUFFIX_}) + string(TOUPPER ${_GUARD_SUFFIX_} _GUARD_SUFFIX_) + string(MAKE_C_IDENTIFIER ${_GUARD_SUFFIX_} _GUARD_SUFFIX_) + + set(_OUTPUT_INCLUDE_SEARCH_DIRECTORY_ "${_OUTPUT_INCLUDE_SEARCH_DIRECTORY_}") + set(_OUTPUT_HEADER_DIRECTORY_ "${_OUTPUT_INCLUDE_SEARCH_DIRECTORY_}/${_NAMESPACE_PREFIX_}") + + file(MAKE_DIRECTORY "${_OUTPUT_HEADER_DIRECTORY_}") + file(MAKE_DIRECTORY "${_OUTPUT_SOURCE_DIRECTORY_}") + + set(_ITR_ 0) + foreach(X IN LISTS _LBR_${_BUNDLE_NAME_}_) # iterate over builtin resources bundle list given bundle name + set(_CURRENT_ITEM_ "${X}") + string(FIND "${_CURRENT_ITEM_}" "," _FOUND_ REVERSE) + + string(REPLACE "," ";" _ITEM_DATA_ "${_CURRENT_ITEM_}") + list(LENGTH _ITEM_DATA_ _ITEM_D_SIZE_) + list(GET _ITEM_DATA_ 0 _CURRENT_PATH_) # _LBR_PATH_ path for given bundle + + if(_ITEM_D_SIZE_ GREATER 1) + list(SUBLIST _ITEM_DATA_ "1" "${_ITEM_D_SIZE_}" _ITEM_ALIASES_) # optional aliases for given builtin resource + else() + unset(_ITEM_ALIASES_) + endif() + + set(_BUNDLE_ARCHIVE_ABSOLUTE_PATH_ "${_BUNDLE_ARCHIVE_ABSOLUTE_PATH_}") + set(NBL_BUILTIN_RESOURCE_ABS_PATH "${_BUNDLE_SEARCH_DIRECTORY_}/${_BUNDLE_ARCHIVE_ABSOLUTE_PATH_}/${_CURRENT_PATH_}") # an absolute path to a resource a builtin resource will be created as + list(APPEND NBL_BUILTIN_RESOURCES "${NBL_BUILTIN_RESOURCE_ABS_PATH}") + + if(EXISTS "${NBL_BUILTIN_RESOURCE_ABS_PATH}") + list(APPEND NBL_DEPENDENCY_FILES "${NBL_BUILTIN_RESOURCE_ABS_PATH}") + file(SIZE "${NBL_BUILTIN_RESOURCE_ABS_PATH}" _FILE_SIZE_) # determine size of builtin resource in bytes + + macro(LIST_RESOURCE_FOR_ARCHIVER _LBR_PATH_ _LBR_FILE_SIZE_ _LBR_ID_) + string(APPEND _RESOURCES_INIT_LIST_ "\t\t\t\t\t{\"${_LBR_PATH_}\", ${_LBR_FILE_SIZE_}, 0xdeadbeefu, ${_LBR_ID_}, nbl::system::IFileArchive::E_ALLOCATOR_TYPE::EAT_NULL},\n") # initializer list + endmacro() + + LIST_RESOURCE_FOR_ARCHIVER("${_CURRENT_PATH_}" "${_FILE_SIZE_}" "${_ITR_}") # pass builtin resource path to an archive without _BUNDLE_ARCHIVE_ABSOLUTE_PATH_ + + foreach(_CURRENT_ALIAS_ IN LISTS _ITEM_ALIASES_) + LIST_RESOURCE_FOR_ARCHIVER("${_CURRENT_ALIAS_}" "${_FILE_SIZE_}" "${_ITR_}") + endforeach() + else() + message(FATAL_ERROR "!") # TODO: set GENERATED property, therefore we could turn some input into output and list it as builtin resource + endif() + + math(EXPR _ITR_ "${_ITR_} + 1") + endforeach() + + configure_file("${NBL_TEMPLATE_RESOURCES_ARCHIVE_HEADER}" "${_OUTPUT_HEADER_DIRECTORY_}/CArchive.h") + configure_file("${NBL_TEMPLATE_RESOURCES_ARCHIVE_SOURCE}" "${_OUTPUT_SOURCE_DIRECTORY_}/CArchive.cpp") + + list(APPEND NBL_DEPENDENCY_FILES "${NBL_BUILTIN_HEADER_GEN_PY}") + list(APPEND NBL_DEPENDENCY_FILES "${NBL_BUILTIN_DATA_GEN_PY}") + + set(NBL_RESOURCES_LIST_FILE "${_OUTPUT_SOURCE_DIRECTORY_}/resources.txt") + + string(REPLACE ";" "\n" RESOURCES_ARGS "${_LBR_${_BUNDLE_NAME_}_}") + file(WRITE "${NBL_RESOURCES_LIST_FILE}" "${RESOURCES_ARGS}") + + set(NBL_BUILTIN_RESOURCES_HEADER "${_OUTPUT_HEADER_DIRECTORY_}/${NBL_BS_HEADER_FILENAME}") + set(NBL_BUILTIN_RESOURCE_DATA_SOURCE "${_OUTPUT_SOURCE_DIRECTORY_}/${NBL_BS_DATA_SOURCE_FILENAME}") + + add_custom_command( + OUTPUT "${NBL_BUILTIN_RESOURCES_HEADER}" "${NBL_BUILTIN_RESOURCE_DATA_SOURCE}" + COMMAND "${_Python3_EXECUTABLE}" "${NBL_BUILTIN_HEADER_GEN_PY}" "${NBL_BUILTIN_RESOURCES_HEADER}" "${_BUNDLE_SEARCH_DIRECTORY_}/${_BUNDLE_ARCHIVE_ABSOLUTE_PATH_}" "${NBL_RESOURCES_LIST_FILE}" "${_NAMESPACE_}" "${_GUARD_SUFFIX_}" "${_SHARED_}" + COMMAND "${_Python3_EXECUTABLE}" "${NBL_BUILTIN_DATA_GEN_PY}" "${NBL_BUILTIN_RESOURCE_DATA_SOURCE}" "${_BUNDLE_SEARCH_DIRECTORY_}/${_BUNDLE_ARCHIVE_ABSOLUTE_PATH_}" "${NBL_RESOURCES_LIST_FILE}" "${_NAMESPACE_}" "${NBL_BS_HEADER_FILENAME}" + COMMENT "Generating built-in resources" + DEPENDS ${NBL_DEPENDENCY_FILES} + VERBATIM + ) + + add_library(${_TARGET_NAME_} ${_LIB_TYPE_} + "${NBL_BUILTIN_RESOURCES_HEADER}" + "${NBL_BUILTIN_RESOURCE_DATA_SOURCE}" + "${_OUTPUT_SOURCE_DIRECTORY_}/CArchive.cpp" + "${_OUTPUT_HEADER_DIRECTORY_}/CArchive.h" + ) + + if(_LIB_TYPE_ STREQUAL SHARED) + target_compile_definitions(${_TARGET_NAME_} + PRIVATE __NBL_BUILDING_TARGET__ + ) + endif() + + get_target_property(_NABLA_INCLUDE_DIRECTORIES_ Nabla INCLUDE_DIRECTORIES) + + if(NOT DEFINED _NABLA_INCLUDE_DIRECTORIES_) # TODO, validate by populating generator expressions if any and checking whether a path to the BuildConfigOptions.h exists per config + message(ERROR "_NABLA_INCLUDE_DIRECTORIES_ has been not found. You are required to define _NABLA_INCLUDE_DIRECTORIES_ containing at least include search directory path to BuildConfigOptions.h") + endif() + + target_include_directories(${_TARGET_NAME_} PUBLIC + "${_NABLA_INCLUDE_DIRECTORIES_}" + "${_OUTPUT_HEADER_DIRECTORY_}" + ) + set_target_properties(${_TARGET_NAME_} PROPERTIES CXX_STANDARD 20) + + if(NBL_DYNAMIC_MSVC_RUNTIME) + set_property(TARGET ${_TARGET_NAME_} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + else() + set_property(TARGET ${_TARGET_NAME_} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() + + set(NBL_BUILTIN_RESOURCES ${NBL_BUILTIN_RESOURCES}) # turn builtin resources paths list into variable + set(NBL_BUILTIN_RESOURCES_HEADERS + "${NBL_BUILTIN_RESOURCES_HEADER}" + "${_OUTPUT_HEADER_DIRECTORY_}/CArchive.h" + ) + + macro(_ADD_PROPERTY_ _BR_PROPERTY_ _BR_PROXY_VAR_) + get_property(_BR_PROPERTY_DEFINED_ + TARGET ${_TARGET_NAME_} + PROPERTY ${_BR_PROPERTY_} + DEFINED + ) + + if(NOT _BR_PROPERTY_DEFINED_) + define_property(TARGET PROPERTY ${_BR_PROPERTY_}) + endif() + + set_target_properties(${_TARGET_NAME_} PROPERTIES ${_BR_PROPERTY_} "${${_BR_PROXY_VAR_}}") + + unset(_BR_PROPERTY_DEFINED_) + endmacro() + + _ADD_PROPERTY_(BUILTIN_RESOURCES NBL_BUILTIN_RESOURCES) + _ADD_PROPERTY_(BUILTIN_RESOURCES_BUNDLE_NAME _BUNDLE_NAME_) + _ADD_PROPERTY_(BUILTIN_RESOURCES_BUNDLE_SEARCH_DIRECTORY _BUNDLE_SEARCH_DIRECTORY_) + _ADD_PROPERTY_(BUILTIN_RESOURCES_BUNDLE_ARCHIVE_ABSOLUTE_PATH _BUNDLE_ARCHIVE_ABSOLUTE_PATH_) + _ADD_PROPERTY_(BUILTIN_RESOURCES_NAMESPACE _NAMESPACE_) + _ADD_PROPERTY_(BUILTIN_RESOURCES_HEADER_DIRECTORY _OUTPUT_HEADER_DIRECTORY_) + _ADD_PROPERTY_(BUILTIN_RESOURCES_SOURCE_DIRECTORY _OUTPUT_SOURCE_DIRECTORY_) + _ADD_PROPERTY_(BUILTIN_RESOURCES_HEADERS NBL_BUILTIN_RESOURCES_HEADERS) + _ADD_PROPERTY_(BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY _OUTPUT_INCLUDE_SEARCH_DIRECTORY_) +endfunction() \ No newline at end of file diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 011a9ff85f..f6e41858d6 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -12,7 +12,7 @@ CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt { } -core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path, ANativeActivity* activity, JNIEnv* jniEnv) +core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path, ANativeActivity* activity, JNIEnv* jniEnv) { auto context_object = activity->clazz; auto getAssets_method = jniEnv->GetMethodID(jniEnv->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); @@ -27,7 +27,7 @@ core::vector CAPKResourcesArchive::computeItems(const auto length = jniEnv->GetArrayLength(files_object); - core::vector result; + core::vector result; for (decltype(length) i=0; iGetObjectArrayElement(files_object,i); @@ -54,7 +54,7 @@ core::vector CAPKResourcesArchive::computeItems(const return result; } -CFileArchive::file_buffer_t CAPKResourcesArchive::getFileBuffer(const IFileArchive::SListEntry* item) +CFileArchive::file_buffer_t CAPKResourcesArchive::getFileBuffer(const IFileArchive::SFileList::SEntry* item) { AAsset* asset = AAssetManager_open(m_mgr,item->pathRelativeToArchive.string().c_str(),AASSET_MODE_BUFFER); return {const_cast(AAsset_getBuffer(asset)),static_cast(AAsset_getLength(asset)),asset}; diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h index 3ea1c9b757..e2a6fd2ac8 100644 --- a/src/nbl/system/CAPKResourcesArchive.h +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -22,7 +22,7 @@ class CAPKResourcesArchive final : public CFileArchive protected: static core::vector computeItems(const std::string& asset_path, ANativeActivity* activity, JNIEnv* jniEnv); - file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; + file_buffer_t getFileBuffer(const IFileArchive::SFileList::SEntry* item) override; AAssetManager* m_mgr; diff --git a/src/nbl/system/CArchiveLoaderTar.cpp b/src/nbl/system/CArchiveLoaderTar.cpp index 917a3bd543..aa5abe4b58 100644 --- a/src/nbl/system/CArchiveLoaderTar.cpp +++ b/src/nbl/system/CArchiveLoaderTar.cpp @@ -41,7 +41,7 @@ struct STarHeader using namespace nbl; using namespace nbl::system; -CFileArchive::file_buffer_t CArchiveLoaderTar::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) +CFileArchive::file_buffer_t CArchiveLoaderTar::CArchive::getFileBuffer(const IFileArchive::SFileList::SEntry* item) { assert(item->allocatorType==EAT_NULL); return {reinterpret_cast(m_file->getMappedPointer())+item->offset,item->size,nullptr}; @@ -98,7 +98,8 @@ core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core: if (!file || !(file->getFlags()&IFileBase::ECF_MAPPABLE)) return nullptr; - core::vector items; + std::shared_ptr> items = std::make_shared>(); + for (size_t pos=0ull; true; ) { STarHeader fHead; @@ -158,11 +159,11 @@ core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core: pos = offset + core::roundUp(size,BlockSize); // add file to list - auto& item = items.emplace_back(); + auto& item = items->emplace_back(); item.pathRelativeToArchive = fullPath; item.size = size; item.offset = offset; - item.ID = items.size()-1u; + item.ID = items->size()-1u; item.allocatorType = IFileArchive::EAT_NULL; break; } @@ -173,8 +174,8 @@ core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core: break; } } - if (items.empty()) + if (items->empty()) return nullptr; - return core::make_smart_refctd_ptr(std::move(file),core::smart_refctd_ptr(m_logger.get()),std::move(items)); + return core::make_smart_refctd_ptr(std::move(file),core::smart_refctd_ptr(m_logger.get()),items); } \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderTar.h b/src/nbl/system/CArchiveLoaderTar.h index c6b70829c9..89241af7b9 100644 --- a/src/nbl/system/CArchiveLoaderTar.h +++ b/src/nbl/system/CArchiveLoaderTar.h @@ -14,11 +14,11 @@ class CArchiveLoaderTar final : public IArchiveLoader class CArchive final : public CFileArchive { public: - CArchive(core::smart_refctd_ptr&& _file, system::logger_opt_smart_ptr&& logger, core::vector&& _items) : - CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), m_file(std::move(_file)) {} + CArchive(core::smart_refctd_ptr&& _file, system::logger_opt_smart_ptr&& logger, std::shared_ptr> _items) : + CFileArchive(path(_file->getFileName()),std::move(logger),_items), m_file(std::move(_file)) {} protected: - file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; + file_buffer_t getFileBuffer(const IFileArchive::SFileList::SEntry* item) override; core::smart_refctd_ptr m_file; }; diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 60f072cb69..bd6c5ad557 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -106,7 +106,7 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: return nullptr; } - core::vector items; + std::shared_ptr> items = std::make_shared>(); core::vector itemsMetadata; // load file entries { @@ -119,7 +119,7 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: if (_path.empty()) return; - auto& item = items.emplace_back(); + auto& item = items->emplace_back(); item.pathRelativeToArchive = _path; item.size = meta.DataDescriptor.UncompressedSize; item.offset = offset; @@ -316,7 +316,7 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: if (!success) return nullptr; } - items.reserve(dirEnd.TotalEntries); + items->reserve(dirEnd.TotalEntries); itemsMetadata.reserve(dirEnd.TotalEntries); offset = dirEnd.Offset; #if 0 @@ -333,11 +333,11 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: } } - assert(items.size()==itemsMetadata.size()); - if (items.empty()) + assert(items->size()==itemsMetadata.size()); + if (items->empty()) return nullptr; - return core::make_smart_refctd_ptr(std::move(file),core::smart_refctd_ptr(m_logger.get()),std::move(items),std::move(itemsMetadata)); + return core::make_smart_refctd_ptr(std::move(file),core::smart_refctd_ptr(m_logger.get()), items, std::move(itemsMetadata)); } #if 0 @@ -367,7 +367,7 @@ bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) } #endif -CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) +CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFileArchive::SFileList::SEntry* item) { const auto& header = m_itemsMetadata[item->ID]; // Nabla supports 0, 8, 12, 14, 99 diff --git a/src/nbl/system/CArchiveLoaderZip.h b/src/nbl/system/CArchiveLoaderZip.h index 1baecf300e..b5d2666516 100644 --- a/src/nbl/system/CArchiveLoaderZip.h +++ b/src/nbl/system/CArchiveLoaderZip.h @@ -39,14 +39,14 @@ class CArchiveLoaderZip final : public IArchiveLoader CArchive( core::smart_refctd_ptr&& _file, system::logger_opt_smart_ptr&& logger, - core::vector&& _items, + std::shared_ptr> _items, core::vector&& _itemsMetadata - ) : CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), + ) : CFileArchive(path(_file->getFileName()),std::move(logger),_items), m_file(std::move(_file)), m_itemsMetadata(std::move(_itemsMetadata)), m_password("") {} private: - file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; + file_buffer_t getFileBuffer(const IFileArchive::SFileList::SEntry* item) override; core::smart_refctd_ptr m_file; core::vector m_itemsMetadata; diff --git a/src/nbl/system/IFileArchive.cpp b/src/nbl/system/IFileArchive.cpp index 0993e8988f..6cc29e4756 100644 --- a/src/nbl/system/IFileArchive.cpp +++ b/src/nbl/system/IFileArchive.cpp @@ -6,35 +6,17 @@ using namespace nbl; using namespace nbl::system; -core::SRange IFileArchive::listAssets(const path& asset_path) const +IFileArchive::SFileList IFileArchive::listAssets(const path& pathRelativeToArchive) const { - // TODO: use something from ISystem for this? - constexpr auto isSubDir = [](path p, path root) -> bool - { - while (p != path()) + auto trimmedList = listAssets(); { - if (p==root) - return true; - p = p.parent_path(); + auto begin = trimmedList.m_data->begin(); + auto end = trimmedList.m_data->end(); + const SFileList::SEntry itemToFind = { pathRelativeToArchive }; + trimmedList.m_range = { &(*std::lower_bound(begin,end,itemToFind)),&(*std::upper_bound(begin,end,itemToFind)) }; } - return false; - }; + return trimmedList; - const IFileArchive::SListEntry* begin = nullptr; - const IFileArchive::SListEntry* end = nullptr; - for (auto& entry : m_items) - { - if (isSubDir(entry.pathRelativeToArchive, asset_path)) - { - if (begin) - end = &entry; - else - begin = &entry; - } - else if (end) - break; - } - return {begin,end}; /* // future, cause lower/upper bound don't work like that diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 01eb3f427c..5275e78562 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -1,52 +1,31 @@ #include "nbl/system/ISystem.h" #include "nbl/system/ISystemFile.h" #include "nbl/system/CFileView.h" +#include "nbl/builtin/CArchive.h" #include "nbl/system/CArchiveLoaderZip.h" #include "nbl/system/CArchiveLoaderTar.h" - +#include "nbl/system/CMountDirectoryArchive.h" using namespace nbl; using namespace nbl::system; - ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(std::move(caller)) { addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); -} - -core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const -{ -#ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - if (found.first && found.second) - { - auto fileView = core::make_smart_refctd_ptr>( - builtinPath, - IFile::ECF_READ, - const_cast(found.first), - found.second - ); - return fileView; - } -#endif - return nullptr; + + #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + mount(core::make_smart_refctd_ptr(nullptr)); + #else + mount(core::make_smart_refctd_ptr(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr), "nbl/builtin"); + #endif } bool ISystem::exists(const system::path& filename, const core::bitflag flags) const { const bool writeUsage = flags.value&IFile::ECF_WRITE; - if (!writeUsage && builtin::hasPathPrefix(filename.string())) - { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - std::pair found = nbl::builtin::get_resource_runtime(filename.string()); - if (found.first && found.second) - return true; - #else - if (exists(builtin::getBuiltinResourcesDirectoryPath()/filename,flags)) - return true; - #endif - } + // filename too long if (filename.string().size() >= sizeof(SRequestParams_CREATE_FILE::filename)) return false; @@ -59,10 +38,6 @@ bool ISystem::exists(const system::path& filename, const core::bitflag ISystem::listItemsInDirectory(const system::path& p) const auto archives = m_cachedArchiveFiles.findRange(archPath); for (auto& arch : archives) { - const auto assets = arch.second->listAssets(std::filesystem::relative(dirPath,archPath)); + const auto assets = static_cast(arch.second->listAssets(std::filesystem::relative(dirPath,archPath))); for (auto& item : assets) res.push_back(archPath/item.pathRelativeToArchive); } @@ -105,21 +80,6 @@ core::vector ISystem::listItemsInDirectory(const system::path& p) } else { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - // TODO: Change the python generator and make builtinResourceData.cpp's `resourcesByFilename` a nicely named `extern` variable - // then in ISystem precompute a [unordered] multimap with keys being builtin subpaths and values being full paths they contain - // find all the values here and iterate over them, adding to `res - #else - err.clear(); - // check root path is prefixed with "nbl/builtin/" - if (builtin::hasPathPrefix(p.string())) - { - const auto subdirs = std::filesystem::recursive_directory_iterator(builtin::getBuiltinResourcesDirectoryPath()/p,err); - if (!err) - for (auto entry : subdirs) // there are never any archives inside builtins - res.push_back(entry.path()); - } - #endif // check for part of subpath being an archive auto path = std::filesystem::exists(p) ? std::filesystem::canonical(p):p; // going up the directory tree @@ -216,21 +176,6 @@ void ISystem::createFile(future_t>& future, std::f if (std::filesystem::exists(filename)) filename = std::filesystem::canonical(filename); - // try builtins - if (!(flags.value&IFile::ECF_WRITE) && builtin::hasPathPrefix(filename.string())) - { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - auto file = impl_loadEmbeddedBuiltinData(filename.string(),nbl::builtin::get_resource_runtime(filename.string())); - if (file) - { - future.set_result(const_cast(file.get())); - return; - } - #else - createFile(future,builtin::getBuiltinResourcesDirectoryPath()/filename,flags); - return; - #endif - } // try archives (readonly, for now) if (!(flags.value&IFile::ECF_WRITE)) { @@ -299,9 +244,9 @@ ISystem::FoundArchiveFile ISystem::findFileInArchive(const system::path& absolut for (auto& archive : archives) { const auto relative = std::filesystem::relative(absolutePath,path); - const auto items = archive.second->listAssets(); + const auto items = static_cast(archive.second->listAssets()); - const IFileArchive::SListEntry itemToFind = { relative }; + const IFileArchive::SFileList::SEntry itemToFind = { relative }; auto found = std::lower_bound(items.begin(), items.end(), itemToFind); if (found!=items.end() && found->pathRelativeToArchive==relative) return {archive.second.get(),relative}; diff --git a/src/nbl/video/utilities/CPropertyPoolHandler.cpp b/src/nbl/video/utilities/CPropertyPoolHandler.cpp index 07baa3ad2e..6fcb5b30dd 100644 --- a/src/nbl/video/utilities/CPropertyPoolHandler.cpp +++ b/src/nbl/video/utilities/CPropertyPoolHandler.cpp @@ -15,7 +15,16 @@ CPropertyPoolHandler::CPropertyPoolHandler(core::smart_refctd_ptrgetPhysicalDevice()->getSystem(); core::smart_refctd_ptr glsl; { - auto glslFile = system->loadBuiltinData(); + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> 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("nbl/builtin/glsl/property_pool/copy.comp"); glsl = core::make_smart_refctd_ptr(glslFile->getSize()); memcpy(glsl->getPointer(), glslFile->getMappedPointer(), glsl->getSize()); } diff --git a/src/nbl/video/utilities/CScanner.cpp b/src/nbl/video/utilities/CScanner.cpp index 9daf17801d..a9c2f25c92 100644 --- a/src/nbl/video/utilities/CScanner.cpp +++ b/src/nbl/video/utilities/CScanner.cpp @@ -8,10 +8,19 @@ core::smart_refctd_ptr CScanner::createShader(const bool indi auto system = m_device->getPhysicalDevice()->getSystem(); core::smart_refctd_ptr glsl; { + auto loadBuiltinData = [&](const std::string _path) -> core::smart_refctd_ptr + { + nbl::system::ISystem::future_t> 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; + }; + if(indirect) - glsl = system->loadBuiltinData(); + glsl = loadBuiltinData("nbl/builtin/glsl/scan/indirect.comp"); else - glsl = system->loadBuiltinData(); + glsl = loadBuiltinData("nbl/builtin/glsl/scan/direct.comp"); } auto buffer = core::make_smart_refctd_ptr(glsl->getSize()); memcpy(buffer->getPointer(), glsl->getMappedPointer(), glsl->getSize());