Skip to content

Commit 547586e

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

38 files changed

+922
-566
lines changed

3rdparty/dxc/CMakeLists.txt

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

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

CMakeLists.txt

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

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

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

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

cmake/common.cmake

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

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

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

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

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

cmake/install/nbl/sharedDefines.h.in

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

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

cmake/scripts/nbl/nablaDefines.cmake

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

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

include/nbl/builtin/common.h

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

include/nbl/config/BuildConfigOptions.h.in

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

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

include/nbl/scene/ICullingLoDSelectionSystem.h

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

include/nbl/scene/ISkinInstanceCacheManager.h

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

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

0 commit comments

Comments
 (0)