From bb68b7bc660b3631c2ca0d124fcf197b321cc2d0 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Mon, 23 Jun 2025 16:26:41 +0200 Subject: [PATCH 01/10] create REGISTER_COMMON_BUILTINS, register example API source & include archives, update common/include/nbl/examples/common/BuiltinResourcesApplication.hpp and test on 09 example --- CMakeLists.txt | 2 + common/CMakeLists.txt | 56 ++++++++++++++++++- .../common/BuiltinResourcesApplication.hpp | 11 ++-- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa3880762..56c0ee60c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,8 @@ if(NBL_BUILD_EXAMPLES) target_link_libraries(${T} PUBLIC ${NBL_EXAMPLES_API_TARGET}) target_include_directories(${T} PUBLIC $) target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}") + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource) + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude) endforeach() NBL_ADJUST_FOLDERS(examples) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3a55e7a26..b32e1a394 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -13,6 +13,53 @@ nbl_create_ext_library_project(ExamplesAPI "" "${CMAKE_CURRENT_SOURCE_DIR}/src/n set_target_properties(${LIB_NAME} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF) target_precompile_headers(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/nbl/examples/PCH.hpp") +function(REGISTER_COMMON_BUILTINS) + cmake_parse_arguments(EX "" "TARGET;ARCHIVE_ABS_ENTRY;ARCHIVE_NAMESPACE" "GLOB_RGX" ${ARGN}) + + get_filename_component(INPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) + get_filename_component(OUTPUT_SRC "${CMAKE_CURRENT_BINARY_DIR}/builtin/${EX_TARGET}/src" ABSOLUTE) + get_filename_component(OUTPUT_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/builtin/${EX_TARGET}/include" ABSOLUTE) + + set(KEYS_ENTRY "${INPUT_DIRECTORY}/${EX_ARCHIVE_ABS_ENTRY}") + list(TRANSFORM EX_GLOB_RGX PREPEND "${KEYS_ENTRY}/") + file(GLOB_RECURSE KEYS RELATIVE "${KEYS_ENTRY}" CONFIGURE_DEPENDS ${EX_GLOB_RGX}) + + #[[ + note we do force you to specify full globbing expressions relative to keys entry which we do not filter + because if runtime outputs .spv compilation artifacts/shader cache preprocessed.hlsl(s) to source you will hit CMake + reconfiguration each time the file content or timestampts change and it could lead to embeding intermediate trash + ]] + + unset(EXAMPLES_RESOURCES_TO_EMBED) + foreach(KEY IN LISTS KEYS) + LIST_BUILTIN_RESOURCE(EXAMPLES_RESOURCES_TO_EMBED "${KEY}") + endforeach() + + ADD_CUSTOM_BUILTIN_RESOURCES(${EX_TARGET} EXAMPLES_RESOURCES_TO_EMBED "${INPUT_DIRECTORY}" "${EX_ARCHIVE_ABS_ENTRY}" "${EX_ARCHIVE_NAMESPACE}" "${OUTPUT_INCLUDE}" "${OUTPUT_SRC}") + + # even though builtin target is static library its still valid to reuse common PCH to boost its build speed to not preprocess entire Nabla again + set_target_properties(${EX_TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF) + target_precompile_headers(${EX_TARGET} REUSE_FROM "${LIB_NAME}") + + target_include_directories(${EX_TARGET} PUBLIC "${INPUT_DIRECTORY}/include") + target_link_libraries(${EX_TARGET} INTERFACE ${LIB_NAME}) +endfunction() + +#! common example API builtins as static library targets linked to each example +if(NBL_EMBED_BUILTIN_RESOURCES) + REGISTER_COMMON_BUILTINS(TARGET NblExtExamplesAPIBuiltinsSource + ARCHIVE_ABS_ENTRY src/nbl/examples + ARCHIVE_NAMESPACE nbl::builtin::examples::src + GLOB_RGX *.hlsl *.txt + ) + + REGISTER_COMMON_BUILTINS(TARGET NblExtExamplesAPIBuiltinsInclude + ARCHIVE_ABS_ENTRY include/nbl/examples + ARCHIVE_NAMESPACE nbl::builtin::examples::include + GLOB_RGX *.hpp *.h *.hlsl *.txt + ) +endif() + #! Examples API common libraries #[[ The rule is to avoid creating additional libraries as part of the examples' common @@ -24,7 +71,8 @@ target_precompile_headers(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/includ but If you have a good reason to create library because you cannot make it header only AND you *can REUSE* the examples' PCH then go ahead anyway and put it under `src/nbl/examples`, otherwise keep it header only - a good example would be to use our embedded-whatever-you-want tool - which does create library but can reuse example's PCH + which does create library but can reuse example's PCH (see NblExtExamplesAPIBuiltinsSource + and NblExtExamplesAPIBuiltinsInclude targets) ]] #! NOTE: as I write it we don't have any targets there yet @@ -35,7 +83,7 @@ list(REMOVE_ITEM TARGETS ${LIB_NAME}) # the Examples API proxy library CMake target name #[[ - this one gets linked to each executable automatically + this one gets linked to each executable automatically with its interface libraries ]] set(NBL_EXAMPLES_API_TARGET ${LIB_NAME} PARENT_SCOPE) @@ -45,4 +93,6 @@ set(NBL_EXAMPLES_API_TARGET ${LIB_NAME} PARENT_SCOPE) then you must target_link_libraries() the lib you want as we don't link all those libraries to each executable automatically ]] -set(NBL_EXAMPLES_API_LIBRARIES ${TARGETS} PARENT_SCOPE) \ No newline at end of file +set(NBL_EXAMPLES_API_LIBRARIES ${TARGETS} PARENT_SCOPE) + +NBL_ADJUST_FOLDERS(common) \ No newline at end of file diff --git a/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp b/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp index aa1949ecd..c32bbc3ea 100644 --- a/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp +++ b/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp @@ -9,9 +9,9 @@ #include "nbl/application_templates/MonoAssetManagerApplication.hpp" #ifdef NBL_EMBED_BUILTIN_RESOURCES -// TODO: the include/header `nbl/examples` archive -// TODO: the source `nbl/examples` archive -// TODO: the build `nbl/examples` archive + #include "nbl/builtin/examples/include/CArchive.h" + #include "nbl/builtin/examples/src/CArchive.h" + // TODO: the build `nbl/examples` archive #if __has_include("nbl/this_example/builtin/CArchive.h") #include "nbl/this_example/builtin/CArchive.h" #endif @@ -42,7 +42,10 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs smart_refctd_ptr examplesHeaderArch,examplesSourceArch,examplesBuildArch,thisExampleArch; #ifdef NBL_EMBED_BUILTIN_RESOURCES -// TODO: the 3 examples archives + examplesHeaderArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); + examplesSourceArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); + // TODO: the build archive + #ifdef _NBL_THIS_EXAMPLE_BUILTIN_C_ARCHIVE_H_ thisExampleArch = make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); #endif From cbcc1c90a399820939ea0dc080bea52734f39a8a Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Wed, 25 Jun 2025 15:26:34 +0200 Subject: [PATCH 02/10] create INTERFACE_TO_BUILTINS, add NblExtExamplesAPIBuiltinsSPIRV target created with NBL_REGISTER_SPIRV_SHADERS utility, update CSimpleDebugRenderer.hpp, change location of unified.hlsl --- CMakeLists.txt | 1 + common/CMakeLists.txt | 22 +++++++--- .../common/BuiltinResourcesApplication.hpp | 36 ++++++++++------ .../geometry/CSimpleDebugRenderer.hpp | 20 +++++++-- common/src/nbl/examples/CMakeLists.txt | 23 ++++++++-- .../geometry/shaders/grid.vertex.hlsl | 11 ----- .../shaders/template/grid.common.hlsl | 43 ------------------- .../shaders => shaders/geometry}/unified.hlsl | 0 8 files changed, 74 insertions(+), 82 deletions(-) delete mode 100644 common/src/nbl/examples/geometry/shaders/grid.vertex.hlsl delete mode 100644 common/src/nbl/examples/geometry/shaders/template/grid.common.hlsl rename common/src/nbl/examples/{geometry/shaders => shaders/geometry}/unified.hlsl (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56c0ee60c..bf18c445d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,7 @@ if(NBL_BUILD_EXAMPLES) target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}") LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource) LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude) + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSPIRV) endforeach() NBL_ADJUST_FOLDERS(examples) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b32e1a394..66f7e6ea7 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -13,6 +13,20 @@ nbl_create_ext_library_project(ExamplesAPI "" "${CMAKE_CURRENT_SOURCE_DIR}/src/n set_target_properties(${LIB_NAME} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF) target_precompile_headers(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/nbl/examples/PCH.hpp") +set(COMMON_INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include") + +function(INTERFACE_TO_BUILTINS TARGET) + #[[ + even though builtin target is static library its still valid to reuse + common PCH to boost its build speed to not preprocess entire Nabla again + ]] + set_target_properties(${TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF) + target_precompile_headers(${TARGET} REUSE_FROM "${LIB_NAME}") + + target_include_directories(${TARGET} PUBLIC "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include") + target_link_libraries(${TARGET} INTERFACE ${LIB_NAME}) +endfunction() + function(REGISTER_COMMON_BUILTINS) cmake_parse_arguments(EX "" "TARGET;ARCHIVE_ABS_ENTRY;ARCHIVE_NAMESPACE" "GLOB_RGX" ${ARGN}) @@ -36,13 +50,7 @@ function(REGISTER_COMMON_BUILTINS) endforeach() ADD_CUSTOM_BUILTIN_RESOURCES(${EX_TARGET} EXAMPLES_RESOURCES_TO_EMBED "${INPUT_DIRECTORY}" "${EX_ARCHIVE_ABS_ENTRY}" "${EX_ARCHIVE_NAMESPACE}" "${OUTPUT_INCLUDE}" "${OUTPUT_SRC}") - - # even though builtin target is static library its still valid to reuse common PCH to boost its build speed to not preprocess entire Nabla again - set_target_properties(${EX_TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF) - target_precompile_headers(${EX_TARGET} REUSE_FROM "${LIB_NAME}") - - target_include_directories(${EX_TARGET} PUBLIC "${INPUT_DIRECTORY}/include") - target_link_libraries(${EX_TARGET} INTERFACE ${LIB_NAME}) + INTERFACE_TO_BUILTINS(${EX_TARGET}) endfunction() #! common example API builtins as static library targets linked to each example diff --git a/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp b/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp index c32bbc3ea..02509ca6a 100644 --- a/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp +++ b/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp @@ -4,20 +4,25 @@ #ifndef _NBL_EXAMPLES_BUILTIN_RESOURCE_APPLICATION_HPP_INCLUDED_ #define _NBL_EXAMPLES_BUILTIN_RESOURCE_APPLICATION_HPP_INCLUDED_ - // we need a system, logger and an asset manager #include "nbl/application_templates/MonoAssetManagerApplication.hpp" #ifdef NBL_EMBED_BUILTIN_RESOURCES #include "nbl/builtin/examples/include/CArchive.h" #include "nbl/builtin/examples/src/CArchive.h" - // TODO: the build `nbl/examples` archive -#if __has_include("nbl/this_example/builtin/CArchive.h") - #include "nbl/this_example/builtin/CArchive.h" -#endif + #include "nbl/builtin/examples/build/spirv/CArchive.h" + #if __has_include("nbl/this_example/builtin/CArchive.h") + #include "nbl/this_example/builtin/CArchive.h" + #endif + // TODO: (**) there should be also 5th arch "nbl/this_example/builtin/build/spirv/CArchive.h" + /* + #if __has_include("nbl/this_example/builtin/build/spirv/CArchive.h") + #include "nbl/this_example/builtin/build/spirv/CArchive.h" + #endif + */ + //! this ain't meant to be the same as this_example ordinary archive #endif - namespace nbl::examples { @@ -40,27 +45,30 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs using namespace core; - smart_refctd_ptr examplesHeaderArch,examplesSourceArch,examplesBuildArch,thisExampleArch; - #ifdef NBL_EMBED_BUILTIN_RESOURCES + smart_refctd_ptr examplesHeaderArch,examplesSourceArch,examplesBuildSpirvArch,thisExampleArch; + #ifdef NBL_EMBED_BUILTIN_RESOURCES examplesHeaderArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); examplesSourceArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); - // TODO: the build archive + examplesBuildSpirvArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); #ifdef _NBL_THIS_EXAMPLE_BUILTIN_C_ARCHIVE_H_ thisExampleArch = make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); #endif - #else + // TODO: (**) + #else examplesHeaderArch = make_smart_refctd_ptr(localInputCWD/"../common/include/nbl/examples",smart_refctd_ptr(m_logger),m_system.get()); examplesSourceArch = make_smart_refctd_ptr(localInputCWD/"../common/src/nbl/examples",smart_refctd_ptr(m_logger),m_system.get()); -// TODO: examplesBuildArch = + examplesBuildSpirvArch = make_smart_refctd_ptr(NBL_EXAMPLES_BUILD_SPIRV_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get()); thisExampleArch = make_smart_refctd_ptr(localInputCWD/"app_resources",smart_refctd_ptr(m_logger),m_system.get()); - #endif + // TODO: (**) + #endif // yes all 3 aliases are meant to be the same m_system->mount(std::move(examplesHeaderArch),"nbl/examples"); m_system->mount(std::move(examplesSourceArch),"nbl/examples"); -// m_system->mount(std::move(examplesBuildArch),"nbl/examples"); + m_system->mount(std::move(examplesBuildSpirvArch),"nbl/examples"); if (thisExampleArch) m_system->mount(std::move(thisExampleArch),"app_resources"); + // TODO: (**) return true; } @@ -68,4 +76,4 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs } -#endif // _CAMERA_IMPL_ \ No newline at end of file +#endif // _NBL_EXAMPLES_BUILTIN_RESOURCE_APPLICATION_HPP_INCLUDED_ \ No newline at end of file diff --git a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp index 474f1d350..7b849e3b6 100644 --- a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp +++ b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp @@ -97,14 +97,26 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted // load shader smart_refctd_ptr shader; { - const auto bundle = assMan->getAsset("nbl/examples/geometry/shaders/unified.hlsl",{}); -// TODO: Arek - //const auto bundle = assMan->getAsset("nbl/examples/geometry/shaders/unified.spv",{}); + // TODO & NOTE: tmp, maybe I will turn it into CMake option + #define NBL_USE_PRECOMPILED_SPIRV + + #ifdef NBL_USE_PRECOMPILED_SPIRV + constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl.spv"; + #else + constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl"; + #endif // NBL_USE_PRECOMPILED_SPIRV + + const auto bundle = assMan->getAsset(key.data(), {}); + + //const auto bundle = assMan->getAsset("nbl/examples/shaders/geometry/unified.hlsl.spv",{}); const auto contents = bundle.getContents(); if (contents.empty() || bundle.getAssetType()!=IAsset::ET_SHADER) return nullptr; shader = IAsset::castDown(contents[0]); - shader = device->compileShader({.source=shader.get()}); + + #ifndef NBL_USE_PRECOMPILED_SPIRV + shader = device->compileShader({ .source = shader.get() }); + #endif // NBL_USE_PRECOMPILED_SPIRV if (!shader) return nullptr; } diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index a95372eea..3f4008541 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -1,4 +1,21 @@ -# TODO builtin SPIR-V shaders -# add_subdirectory(geometry EXCLUDE_FROM_ALL) +set(SPIRV_TARGET_V 6_8) -# TODO: make docs once I get n4ce embed SPIRV tool to build system and then use the tool with Matts new shader \ No newline at end of file +set(COMMON_OPTIONS + -I "${COMMON_INCLUDE_DIRECTORY}" +) + +NBL_REGISTER_SPIRV_SHADERS( + MOUNT_POINT_DEFINE + NBL_EXAMPLES_BUILD_SPIRV_MOUNT_POINT + + ARCHIVE + TARGET NblExtExamplesAPIBuiltinsSPIRV + INPUT_DIRECTORY . + NAMESPACE nbl::builtin::examples::build::spirv + + INPUTS + KEY shaders/geometry/unified.hlsl COMPILE_OPTIONS ${COMMON_OPTIONS} -T lib_${SPIRV_TARGET_V} + # KEY COMPILE_OPTIONS ${COMMON_OPTIONS} -T _${SPIRV_TARGET_V} +) + +INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsSPIRV) \ No newline at end of file diff --git a/common/src/nbl/examples/geometry/shaders/grid.vertex.hlsl b/common/src/nbl/examples/geometry/shaders/grid.vertex.hlsl deleted file mode 100644 index 389c37bf2..000000000 --- a/common/src/nbl/examples/geometry/shaders/grid.vertex.hlsl +++ /dev/null @@ -1,11 +0,0 @@ -#include "template/grid.common.hlsl" - - -PSInput VSMain(VSInput input) -{ - PSInput output; - output.position = mul(params.MVP, float4(input.position, 1.0)); - output.uv = (input.uv - float2(0.5, 0.5)) * abs(input.position.xy); - - return output; -} \ No newline at end of file diff --git a/common/src/nbl/examples/geometry/shaders/template/grid.common.hlsl b/common/src/nbl/examples/geometry/shaders/template/grid.common.hlsl deleted file mode 100644 index 7ec9017e9..000000000 --- a/common/src/nbl/examples/geometry/shaders/template/grid.common.hlsl +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _NBL_EXAMPLES_GRID_COMMON_HLSL_ -#define _NBL_EXAMPLES_GRID_COMMON_HLSL_ - -#include "common/SBasicViewParameters.hlsl" - -#ifdef __HLSL_VERSION -// TODO: why is there even a mesh with HW vertices for this? -struct VSInput -{ - [[vk::location(0)]] float3 position : POSITION; - [[vk::location(1)]] float4 color : COLOR; - [[vk::location(2)]] float2 uv : TEXCOORD; - [[vk::location(3)]] float3 normal : NORMAL; -}; - -struct PSInput -{ - float4 position : SV_Position; - float2 uv : TEXCOORD0; -}; - -[[vk::push_constant]] SBasicViewParameters params; -#endif // __HLSL_VERSION - - -float gridTextureGradBox(float2 p, float2 ddx, float2 ddy) -{ - float N = 30.0; // grid ratio - float2 w = max(abs(ddx), abs(ddy)) + 0.01; // filter kernel - - // analytic (box) filtering - float2 a = p + 0.5 * w; - float2 b = p - 0.5 * w; - float2 i = (floor(a) + min(frac(a) * N, 1.0) - floor(b) - min(frac(b) * N, 1.0)) / (N * w); - - // pattern - return (1.0 - i.x) * (1.0 - i.y); -} - -#endif // _NBL_EXAMPLES_GRID_COMMON_HLSL_ -/* - do not remove this text, WAVE is so bad that you can get errors if no proper ending xD -*/ \ No newline at end of file diff --git a/common/src/nbl/examples/geometry/shaders/unified.hlsl b/common/src/nbl/examples/shaders/geometry/unified.hlsl similarity index 100% rename from common/src/nbl/examples/geometry/shaders/unified.hlsl rename to common/src/nbl/examples/shaders/geometry/unified.hlsl From c71e38692e5be4a73012e937043fd9fb3f69ace2 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Wed, 25 Jun 2025 16:52:58 +0200 Subject: [PATCH 03/10] update CMake to support (NOT NBL_EMBED_BUILTIN_RESOURCES) mode but it seems NSC cannot find boost headers (like something is off with mounting the boost directory) --- CMakeLists.txt | 12 +++++++++--- common/CMakeLists.txt | 2 +- common/src/nbl/examples/CMakeLists.txt | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf18c445d..044cf6049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,9 +95,15 @@ if(NBL_BUILD_EXAMPLES) target_link_libraries(${T} PUBLIC ${NBL_EXAMPLES_API_TARGET}) target_include_directories(${T} PUBLIC $) target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}") - LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource) - LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude) - LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSPIRV) + + # TODO: make them all INTERFACE if not NBL_EMBED_BUILTIN_RESOURCES and link in loop + if(NBL_EMBED_BUILTIN_RESOURCES) + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource) + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude) + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSPIRV) + else() + target_link_libraries(${T} PUBLIC NblExtExamplesAPIBuiltinsSPIRV) + endif() endforeach() NBL_ADJUST_FOLDERS(examples) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 66f7e6ea7..1cbdefea7 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -23,7 +23,7 @@ function(INTERFACE_TO_BUILTINS TARGET) set_target_properties(${TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF) target_precompile_headers(${TARGET} REUSE_FROM "${LIB_NAME}") - target_include_directories(${TARGET} PUBLIC "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include") + target_include_directories(${TARGET} PUBLIC "${COMMON_INCLUDE_DIRECTORY}") target_link_libraries(${TARGET} INTERFACE ${LIB_NAME}) endfunction() diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index 3f4008541..cfebab2b4 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -18,4 +18,6 @@ NBL_REGISTER_SPIRV_SHADERS( # KEY COMPILE_OPTIONS ${COMMON_OPTIONS} -T _${SPIRV_TARGET_V} ) -INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsSPIRV) \ No newline at end of file +if(NBL_EMBED_BUILTIN_RESOURCES) + INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsSPIRV) +endif() \ No newline at end of file From 229b5211effb676218829073cd6e1d535094efc8 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Fri, 27 Jun 2025 11:22:34 +0200 Subject: [PATCH 04/10] remove my tests and assume pre-compiled SPIRV for CSimpleDebugRenderer.hpp --- common/CMakeLists.txt | 1 - .../nbl/examples/geometry/CSimpleDebugRenderer.hpp | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 1cbdefea7..2c4037e2d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -83,7 +83,6 @@ endif() and NblExtExamplesAPIBuiltinsInclude targets) ]] -#! NOTE: as I write it we don't have any targets there yet add_subdirectory("src/nbl/examples" EXCLUDE_FROM_ALL) NBL_GET_ALL_TARGETS(TARGETS) diff --git a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp index 7b849e3b6..f5fd2bac6 100644 --- a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp +++ b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp @@ -97,26 +97,14 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted // load shader smart_refctd_ptr shader; { - // TODO & NOTE: tmp, maybe I will turn it into CMake option - #define NBL_USE_PRECOMPILED_SPIRV - - #ifdef NBL_USE_PRECOMPILED_SPIRV constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl.spv"; - #else - constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl"; - #endif // NBL_USE_PRECOMPILED_SPIRV - const auto bundle = assMan->getAsset(key.data(), {}); - //const auto bundle = assMan->getAsset("nbl/examples/shaders/geometry/unified.hlsl.spv",{}); const auto contents = bundle.getContents(); if (contents.empty() || bundle.getAssetType()!=IAsset::ET_SHADER) return nullptr; shader = IAsset::castDown(contents[0]); - #ifndef NBL_USE_PRECOMPILED_SPIRV - shader = device->compileShader({ .source = shader.get() }); - #endif // NBL_USE_PRECOMPILED_SPIRV if (!shader) return nullptr; } From 60bdf1bb1e37465fac44c8f865e63189f497cfb1 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Thu, 3 Jul 2025 20:37:21 +0200 Subject: [PATCH 05/10] use NBL_REGISTER_BUILD_MOUNT_POINT, update BuiltinResourcesApplication and common/src/nbl/examples/CMakeLists.txt --- .../common/BuiltinResourcesApplication.hpp | 12 ++++++------ common/src/nbl/examples/CMakeLists.txt | 16 +++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp b/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp index 02509ca6a..b0a21fb05 100644 --- a/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp +++ b/common/include/nbl/examples/common/BuiltinResourcesApplication.hpp @@ -10,14 +10,14 @@ #ifdef NBL_EMBED_BUILTIN_RESOURCES #include "nbl/builtin/examples/include/CArchive.h" #include "nbl/builtin/examples/src/CArchive.h" - #include "nbl/builtin/examples/build/spirv/CArchive.h" + #include "nbl/builtin/examples/build/CArchive.h" #if __has_include("nbl/this_example/builtin/CArchive.h") #include "nbl/this_example/builtin/CArchive.h" #endif - // TODO: (**) there should be also 5th arch "nbl/this_example/builtin/build/spirv/CArchive.h" + // TODO: (**) there should be also 5th arch "nbl/this_example/builtin/build/CArchive.h" /* - #if __has_include("nbl/this_example/builtin/build/spirv/CArchive.h") - #include "nbl/this_example/builtin/build/spirv/CArchive.h" + #if __has_include("nbl/this_example/builtin/build/CArchive.h") + #include "nbl/this_example/builtin/build/CArchive.h" #endif */ //! this ain't meant to be the same as this_example ordinary archive @@ -49,7 +49,7 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs #ifdef NBL_EMBED_BUILTIN_RESOURCES examplesHeaderArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); examplesSourceArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); - examplesBuildSpirvArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); + examplesBuildSpirvArch = core::make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); #ifdef _NBL_THIS_EXAMPLE_BUILTIN_C_ARCHIVE_H_ thisExampleArch = make_smart_refctd_ptr(smart_refctd_ptr(m_logger)); @@ -58,7 +58,7 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs #else examplesHeaderArch = make_smart_refctd_ptr(localInputCWD/"../common/include/nbl/examples",smart_refctd_ptr(m_logger),m_system.get()); examplesSourceArch = make_smart_refctd_ptr(localInputCWD/"../common/src/nbl/examples",smart_refctd_ptr(m_logger),m_system.get()); - examplesBuildSpirvArch = make_smart_refctd_ptr(NBL_EXAMPLES_BUILD_SPIRV_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get()); + examplesBuildSpirvArch = make_smart_refctd_ptr(NBL_EXAMPLES_BUILD_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get()); thisExampleArch = make_smart_refctd_ptr(localInputCWD/"app_resources",smart_refctd_ptr(m_logger),m_system.get()); // TODO: (**) #endif diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index cfebab2b4..7cc198ebe 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -4,16 +4,22 @@ set(COMMON_OPTIONS -I "${COMMON_INCLUDE_DIRECTORY}" ) -NBL_REGISTER_SPIRV_SHADERS( - MOUNT_POINT_DEFINE - NBL_EXAMPLES_BUILD_SPIRV_MOUNT_POINT +set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen" ) +file(WRITE "${OUTPUT_DIRECTORY}/dummy.txt" "dummy, test") +NBL_REGISTER_BUILD_MOUNT_POINT( ARCHIVE TARGET NblExtExamplesAPIBuiltinsSPIRV INPUT_DIRECTORY . - NAMESPACE nbl::builtin::examples::build::spirv + OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}" + NAMESPACE nbl::builtin::examples::build + MOUNT_POINT_DEFINE NBL_EXAMPLES_BUILD_MOUNT_POINT + + # relative to ARCHIVE.OUTPUT_DIRECTORY + BUILTINS + dummy.txt - INPUTS + SHADERS KEY shaders/geometry/unified.hlsl COMPILE_OPTIONS ${COMMON_OPTIONS} -T lib_${SPIRV_TARGET_V} # KEY COMPILE_OPTIONS ${COMMON_OPTIONS} -T _${SPIRV_TARGET_V} ) From 767e6c4e46e1e5c5ab4ec827f94f8886f705eb33 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Thu, 3 Jul 2025 21:10:07 +0200 Subject: [PATCH 06/10] update common/src/nbl/examples/CMakeLists.txt --- common/src/nbl/examples/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index 7cc198ebe..fce1f48ac 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -15,13 +15,17 @@ NBL_REGISTER_BUILD_MOUNT_POINT( NAMESPACE nbl::builtin::examples::build MOUNT_POINT_DEFINE NBL_EXAMPLES_BUILD_MOUNT_POINT - # relative to ARCHIVE.OUTPUT_DIRECTORY BUILTINS - dummy.txt + dummy.txt # relative to ARCHIVE.OUTPUT_DIRECTORY SHADERS - KEY shaders/geometry/unified.hlsl COMPILE_OPTIONS ${COMMON_OPTIONS} -T lib_${SPIRV_TARGET_V} - # KEY COMPILE_OPTIONS ${COMMON_OPTIONS} -T _${SPIRV_TARGET_V} + KEY shaders/geometry/unified.hlsl + COMPILE_OPTIONS ${COMMON_OPTIONS} -T lib_${SPIRV_TARGET_V} + # DEPENDS <> + + # KEY + # COMPILE_OPTIONS ${COMMON_OPTIONS} -T _${SPIRV_TARGET_V} + # DEPENDS <> ) if(NBL_EMBED_BUILTIN_RESOURCES) From c573951ec38a3aa187b6ac8724cff1c9d293631c Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Thu, 3 Jul 2025 21:57:17 +0200 Subject: [PATCH 07/10] update some examples after moving spirv target field --- 03_DeviceSelectionAndSharedSources/Testers.h | 2 +- 03_DeviceSelectionAndSharedSources/main.cpp | 2 +- 23_Arithmetic2UnitTest/main.cpp | 2 +- 29_Arithmetic2Bench/main.cpp | 2 +- 64_EmulatedFloatTest/main.cpp | 4 ++-- 70_FLIPFluids/main.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/03_DeviceSelectionAndSharedSources/Testers.h b/03_DeviceSelectionAndSharedSources/Testers.h index f957e50a0..fcd5c5ee4 100644 --- a/03_DeviceSelectionAndSharedSources/Testers.h +++ b/03_DeviceSelectionAndSharedSources/Testers.h @@ -56,7 +56,7 @@ class IntrospectionTesterBase // if the extension is generic (.glsl or .hlsl) the stage is unknown. // But it can still be overriden from within the source with a `#pragma shader_stage` options.stage = shaderStage == IShader::E_SHADER_STAGE::ESS_COMPUTE ? shaderStage : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it - options.targetSpirvVersion = device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = device->getPhysicalDevice()->getLimits().spirvVersion; // we need to perform an unoptimized compilation with source debug info or we'll lose names of variable sin the introspection options.spirvOptimizer = nullptr; options.debugInfoFlags |= IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT; diff --git a/03_DeviceSelectionAndSharedSources/main.cpp b/03_DeviceSelectionAndSharedSources/main.cpp index c09228ce5..b8fd3d18b 100644 --- a/03_DeviceSelectionAndSharedSources/main.cpp +++ b/03_DeviceSelectionAndSharedSources/main.cpp @@ -275,7 +275,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M // if the extension is generic (.glsl or .hlsl) the stage is unknown. // But it can still be overriden from within the source with a `#pragma shader_stage` options.stage = shaderStage == IShader::E_SHADER_STAGE::ESS_COMPUTE ? shaderStage : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it - options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; // we need to perform an unoptimized compilation with source debug info or we'll lose names of variable sin the introspection options.spirvOptimizer = nullptr; options.debugInfoFlags |= IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT; diff --git a/23_Arithmetic2UnitTest/main.cpp b/23_Arithmetic2UnitTest/main.cpp index 3939fd443..8d70547bc 100644 --- a/23_Arithmetic2UnitTest/main.cpp +++ b/23_Arithmetic2UnitTest/main.cpp @@ -294,7 +294,7 @@ class Workgroup2ScanTestApp final : public application_templates::BasicMultiQueu auto compiler = make_smart_refctd_ptr(smart_refctd_ptr(m_system)); CHLSLCompiler::SOptions options = {}; options.stage = IShader::E_SHADER_STAGE::ESS_COMPUTE; - options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; options.spirvOptimizer = nullptr; #ifndef _NBL_DEBUG ISPIRVOptimizer::E_OPTIMIZER_PASS optPasses = ISPIRVOptimizer::EOP_STRIP_DEBUG_INFO; diff --git a/29_Arithmetic2Bench/main.cpp b/29_Arithmetic2Bench/main.cpp index 75f483db0..5809c4a9a 100644 --- a/29_Arithmetic2Bench/main.cpp +++ b/29_Arithmetic2Bench/main.cpp @@ -527,7 +527,7 @@ class ArithmeticBenchApp final : public examples::SimpleWindowedApplication, pub auto compiler = make_smart_refctd_ptr(smart_refctd_ptr(m_system)); CHLSLCompiler::SOptions options = {}; options.stage = IShader::E_SHADER_STAGE::ESS_COMPUTE; - options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; options.spirvOptimizer = nullptr; #ifndef _NBL_DEBUG ISPIRVOptimizer::E_OPTIMIZER_PASS optPasses = ISPIRVOptimizer::EOP_STRIP_DEBUG_INFO; diff --git a/64_EmulatedFloatTest/main.cpp b/64_EmulatedFloatTest/main.cpp index fd3e465e7..3fc635e87 100644 --- a/64_EmulatedFloatTest/main.cpp +++ b/64_EmulatedFloatTest/main.cpp @@ -280,7 +280,7 @@ class CompatibilityTest final : public MonoDeviceApplication, public BuiltinReso nbl::asset::IShaderCompiler::SCompilerOptions options = {}; options.stage = ESS_COMPUTE; - options.targetSpirvVersion = base.m_device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = base.m_device->getPhysicalDevice()->getLimits().spirvVersion; options.spirvOptimizer = nullptr; options.debugInfoFlags |= IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT; options.preprocessorOptions.sourceIdentifier = source->getFilepathHint(); @@ -946,7 +946,7 @@ class CompatibilityTest final : public MonoDeviceApplication, public BuiltinReso IShaderCompiler::SCompilerOptions options = {}; options.stage = ESS_COMPUTE; - options.targetSpirvVersion = base.m_device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = base.m_device->getPhysicalDevice()->getLimits().spirvVersion; options.spirvOptimizer = nullptr; options.debugInfoFlags |= IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT; options.preprocessorOptions.sourceIdentifier = source->getFilepathHint(); diff --git a/70_FLIPFluids/main.cpp b/70_FLIPFluids/main.cpp index 66596c526..899d00ba4 100644 --- a/70_FLIPFluids/main.cpp +++ b/70_FLIPFluids/main.cpp @@ -1426,7 +1426,7 @@ class FLIPFluidsApp final : public SimpleWindowedApplication, public BuiltinReso options.stage = shaderStage; if (!(options.stage == IShader::E_SHADER_STAGE::ESS_COMPUTE || options.stage == IShader::E_SHADER_STAGE::ESS_FRAGMENT)) options.stage = IShader::E_SHADER_STAGE::ESS_VERTEX; - options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; + options.preprocessorOptions.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion; options.spirvOptimizer = nullptr; #ifndef _NBL_DEBUG ISPIRVOptimizer::E_OPTIMIZER_PASS optPasses = ISPIRVOptimizer::EOP_STRIP_DEBUG_INFO; From 89ab539f1fe0d98d50b42f1a3f190cc66ec90073 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Sun, 6 Jul 2025 20:27:02 +0200 Subject: [PATCH 08/10] update CMakeLists.txt files after changes, remove .hlsl ext part from SPIRV key in CSimpleDebugRenderer --- CMakeLists.txt | 6 +- .../geometry/CSimpleDebugRenderer.hpp | 2 +- common/src/nbl/examples/CMakeLists.txt | 88 +++++++++++++------ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b238942e..6891691f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,13 +98,13 @@ if(NBL_BUILD_EXAMPLES) target_include_directories(${T} PUBLIC $) target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}") - # TODO: make them all INTERFACE if not NBL_EMBED_BUILTIN_RESOURCES and link in loop + # TODO: make them all INTERFACE if not NBL_EMBED_BUILTIN_RESOURCES and link in loop without checking the var if(NBL_EMBED_BUILTIN_RESOURCES) LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource) LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude) - LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSPIRV) + LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsBuild) else() - target_link_libraries(${T} PUBLIC NblExtExamplesAPIBuiltinsSPIRV) + target_link_libraries(${T} PUBLIC NblExtExamplesAPIBuiltinsBuild) endif() endforeach() diff --git a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp index 53ca1be5d..d5b48de0e 100644 --- a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp +++ b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp @@ -108,7 +108,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted // load shader smart_refctd_ptr shader; { - constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl.spv"; + constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.spv"; const auto bundle = assMan->getAsset(key.data(), {}); const auto contents = bundle.getContents(); diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index fce1f48ac..f79b23d9b 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -1,33 +1,65 @@ -set(SPIRV_TARGET_V 6_8) - -set(COMMON_OPTIONS - -I "${COMMON_INCLUDE_DIRECTORY}" +set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen") +set(ARGS + TARGET NblExtExamplesAPISPIRV + BINARY_DIR ${OUTPUT_DIRECTORY} + COMMON_OPTIONS -I "${COMMON_INCLUDE_DIRECTORY}" + OUTPUT_VAR KEYS ) -set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen" ) -file(WRITE "${OUTPUT_DIRECTORY}/dummy.txt" "dummy, test") - -NBL_REGISTER_BUILD_MOUNT_POINT( - ARCHIVE - TARGET NblExtExamplesAPIBuiltinsSPIRV - INPUT_DIRECTORY . - OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}" - NAMESPACE nbl::builtin::examples::build - MOUNT_POINT_DEFINE NBL_EXAMPLES_BUILD_MOUNT_POINT - - BUILTINS - dummy.txt # relative to ARCHIVE.OUTPUT_DIRECTORY - - SHADERS - KEY shaders/geometry/unified.hlsl - COMPILE_OPTIONS ${COMMON_OPTIONS} -T lib_${SPIRV_TARGET_V} - # DEPENDS <> - - # KEY - # COMPILE_OPTIONS ${COMMON_OPTIONS} -T _${SPIRV_TARGET_V} - # DEPENDS <> +# note json is array of objects, you can register all rules at once +set(JSON [=[ +[ + { + "INPUT": "shaders/geometry/unified.hlsl", + "COMPILE_OPTIONS": ["-T", "lib_6_6"], + "DEPENDS": [], + "CAPS": [] + } +] +]=]) + +NBL_CREATE_NSC_COMPILE_RULES(${ARGS} INPUTS ${JSON}) + +set(JSON [=[ +[ + { + "INPUT": "shaders/geometry/unified.hlsl", + "COMPILE_OPTIONS": ["-T", "lib_6_6"], + "DEPENDS": [], + "CAPS": [ + { + "name": "shaderFloat64", + "type": "bool", + "values": ["true", "false"] + }, + { + "name": "subgroupSize", + "type": "uint16_t", + "values": ["32", "64"] + } + ] + } +] +]=]) + +# but it also supports incremental rule updates, uncomment to add rules with permutation caps +# NBL_CREATE_NSC_COMPILE_RULES(${ARGS} INPUTS ${JSON}) + +# note we can add more inputs from build dir which keys can be part of the same archive/mount point, +# ex. one could auto generate bc texture or whatever and add here like +# file(WRITE "${OUTPUT_DIRECTORY}/dummy.txt" "dummy, test") +# list(APPEND KEYS dummy.txt) + +NBL_CREATE_RESOURCE_ARCHIVE( + TARGET NblExtExamplesAPIBuiltinsBuild + BIND "${OUTPUT_DIRECTORY}" + NAMESPACE nbl::builtin::examples::build + MOUNT_POINT_DEFINE NBL_EXAMPLES_BUILD_MOUNT_POINT + BUILTINS ${KEYS} ) if(NBL_EMBED_BUILTIN_RESOURCES) - INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsSPIRV) -endif() \ No newline at end of file + INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsBuild) +endif() + +target_link_libraries(NblExtExamplesAPIBuiltinsBuild PUBLIC NblExtExamplesAPISPIRV) From e074ad32c23569bf5baa0cf8af4c65de2ef92c17 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Mon, 7 Jul 2025 11:00:13 +0200 Subject: [PATCH 09/10] use json canonical KEY field, update common/src/nbl/examples/CMakeLists.txt --- common/src/nbl/examples/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index f79b23d9b..b55b699dd 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -11,6 +11,7 @@ set(JSON [=[ [ { "INPUT": "shaders/geometry/unified.hlsl", + "KEY": "shaders/geometry/unified.spv", "COMPILE_OPTIONS": ["-T", "lib_6_6"], "DEPENDS": [], "CAPS": [] @@ -24,6 +25,7 @@ set(JSON [=[ [ { "INPUT": "shaders/geometry/unified.hlsl", + "KEY": "shaders/geometry/unified.spv", "COMPILE_OPTIONS": ["-T", "lib_6_6"], "DEPENDS": [], "CAPS": [ From a6271a4ca05eb0fe8bb7316f5bd857e64fdc3734 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz Date: Thu, 10 Jul 2025 03:12:49 +0200 Subject: [PATCH 10/10] adjust to new API changes --- 09_GeometryCreator/main.cpp | 1 - common/CMakeLists.txt | 1 + common/include/nbl/examples/PCH.hpp | 1 + common/include/nbl/examples/examples.hpp | 3 +- .../geometry/CSimpleDebugRenderer.hpp | 8 +--- common/src/nbl/examples/CMakeLists.txt | 41 +++++++++++++++---- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/09_GeometryCreator/main.cpp b/09_GeometryCreator/main.cpp index 900d827b7..cb3c21f4d 100644 --- a/09_GeometryCreator/main.cpp +++ b/09_GeometryCreator/main.cpp @@ -5,7 +5,6 @@ #include "common.hpp" - class GeometryCreatorApp final : public MonoWindowApplication, public BuiltinResourcesApplication { using device_base_t = MonoWindowApplication; diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 2c4037e2d..f388c4cbf 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -84,6 +84,7 @@ endif() ]] add_subdirectory("src/nbl/examples" EXCLUDE_FROM_ALL) +target_link_libraries(${LIB_NAME} PUBLIC NblExtExamplesAPISPIRV) NBL_GET_ALL_TARGETS(TARGETS) list(REMOVE_ITEM TARGETS ${LIB_NAME}) diff --git a/common/include/nbl/examples/PCH.hpp b/common/include/nbl/examples/PCH.hpp index 0905465c2..a20984464 100644 --- a/common/include/nbl/examples/PCH.hpp +++ b/common/include/nbl/examples/PCH.hpp @@ -14,6 +14,7 @@ #include "nabla.h" //! Common example interface headers +#include "nbl/examples/common/build/spirv/keys.hpp" #include "nbl/examples/common/SimpleWindowedApplication.hpp" #include "nbl/examples/common/MonoWindowApplication.hpp" #include "nbl/examples/common/InputSystem.hpp" diff --git a/common/include/nbl/examples/examples.hpp b/common/include/nbl/examples/examples.hpp index d82303514..1450abc2a 100644 --- a/common/include/nbl/examples/examples.hpp +++ b/common/include/nbl/examples/examples.hpp @@ -17,8 +17,7 @@ // #include "..." -// Cannot be in PCH because depens on definition of `this_example` for Example's builtins +// cannot be in PCH because depens on definition of `this_example` for Example's builtins #include "nbl/examples/common/BuiltinResourcesApplication.hpp" - #endif // _NBL_EXAMPLES_HPP_ \ No newline at end of file diff --git a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp index d5b48de0e..9a9e5c966 100644 --- a/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp +++ b/common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp @@ -1,15 +1,9 @@ #ifndef _NBL_EXAMPLES_C_SIMPLE_DEBUG_RENDERER_H_INCLUDED_ #define _NBL_EXAMPLES_C_SIMPLE_DEBUG_RENDERER_H_INCLUDED_ - #include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl" #include "nbl/examples/geometry/SPushConstants.hlsl" -// TODO: Arek bring back -//#include "nbl/examples/geometry/spirv/builtin/CArchive.h" -//#include "nbl/examples/geometry/spirv/builtin/builtinResources.h" - - namespace nbl::examples { @@ -108,7 +102,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted // load shader smart_refctd_ptr shader; { - constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.spv"; + auto key = "nbl/examples/" + nbl::builtin::examples::build::get_spirv_key<"shaders/geometry/unified">(device); const auto bundle = assMan->getAsset(key.data(), {}); const auto contents = bundle.getContents(); diff --git a/common/src/nbl/examples/CMakeLists.txt b/common/src/nbl/examples/CMakeLists.txt index b55b699dd..3fa63c839 100644 --- a/common/src/nbl/examples/CMakeLists.txt +++ b/common/src/nbl/examples/CMakeLists.txt @@ -1,9 +1,22 @@ set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen") -set(ARGS +set(ARGS + # meta INTERFACE target with NSC compilation rules TARGET NblExtExamplesAPISPIRV + + # build directory for its SPIRV outputs BINARY_DIR ${OUTPUT_DIRECTORY} + + # extra NSC compile options COMMON_OPTIONS -I "${COMMON_INCLUDE_DIRECTORY}" + + # fallback variable to which SPIRV access keys are appended to (including permutations), relative to BINARY_DIR OUTPUT_VAR KEYS + + # include file with key getters, use with #include directive on downstream targets + INCLUDE nbl/examples/common/build/spirv/keys.hpp + + # namespace for key getters in include file + NAMESPACE nbl::builtin::examples::build ) # note json is array of objects, you can register all rules at once @@ -11,7 +24,7 @@ set(JSON [=[ [ { "INPUT": "shaders/geometry/unified.hlsl", - "KEY": "shaders/geometry/unified.spv", + "KEY": "shaders/geometry/unified", "COMPILE_OPTIONS": ["-T", "lib_6_6"], "DEPENDS": [], "CAPS": [] @@ -25,26 +38,39 @@ set(JSON [=[ [ { "INPUT": "shaders/geometry/unified.hlsl", - "KEY": "shaders/geometry/unified.spv", + "KEY": "shaders/geometry/unified-caps", "COMPILE_OPTIONS": ["-T", "lib_6_6"], "DEPENDS": [], "CAPS": [ { "name": "shaderFloat64", "type": "bool", - "values": ["true", "false"] + "values": [1, 0] }, { "name": "subgroupSize", "type": "uint16_t", - "values": ["32", "64"] + "values": [32, 64] + } + ] + }, + { + "INPUT": "shaders/geometry/unified.hlsl", + "KEY": "shaders/geometry/unified-caps-2", + "COMPILE_OPTIONS": ["-T", "lib_6_6"], + "DEPENDS": [], + "CAPS": [ + { + "name": "shaderFloat64", + "type": "bool", + "values": [1, 0] } ] } ] ]=]) -# but it also supports incremental rule updates, uncomment to add rules with permutation caps +# it also supports incremental rule updates, uncomment to add rules with permutation caps (testing purposes, remove after review) # NBL_CREATE_NSC_COMPILE_RULES(${ARGS} INPUTS ${JSON}) # note we can add more inputs from build dir which keys can be part of the same archive/mount point, @@ -62,6 +88,5 @@ NBL_CREATE_RESOURCE_ARCHIVE( if(NBL_EMBED_BUILTIN_RESOURCES) INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsBuild) + target_link_libraries(NblExtExamplesAPIBuiltinsBuild PUBLIC NblExtExamplesAPISPIRV) endif() - -target_link_libraries(NblExtExamplesAPIBuiltinsBuild PUBLIC NblExtExamplesAPISPIRV)