Skip to content

Ex updates #204

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions 23_Arithmetic2UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@

include(common RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
endif()

nbl_create_executable_project("" "" "" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")

if(NBL_EMBED_BUILTIN_RESOURCES)
set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData)
set(RESOURCE_DIR "app_resources")

get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)

file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")
foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
endforeach()

ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")

LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
endif()
include(common)

nbl_create_executable_project("" "" "" "")

NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin
TARGET ${EXECUTABLE_NAME}_builtins
LINK_TO ${EXECUTABLE_NAME}
BIND app_resources
BUILTINS
common.hlsl
shaderCommon.hlsl
testSubgroup.comp.hlsl
testWorkgroup.comp.hlsl
)
2 changes: 1 addition & 1 deletion 23_Arithmetic2UnitTest/app_resources/shaderCommon.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hlsl"
#include "app_resources/common.hlsl"

using namespace nbl;
using namespace hlsl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "nbl/builtin/hlsl/subgroup2/arithmetic_portability.hlsl"
#include "nbl/builtin/hlsl/subgroup2/arithmetic_params.hlsl"

#include "shaderCommon.hlsl"
#include "app_resources/shaderCommon.hlsl"
#include "nbl/builtin/hlsl/workgroup2/basic.hlsl"

template<class Binop, class device_capabilities>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using config_t = WORKGROUP_CONFIG_T;

#include "shaderCommon.hlsl"
#include "app_resources/shaderCommon.hlsl"

typedef vector<uint32_t, config_t::ItemsPerInvocation_0> type_t;

Expand Down
60 changes: 41 additions & 19 deletions 27_MPMCScheduler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
include(common RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
endif()
include(common)

nbl_create_executable_project("" "" "" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")
nbl_create_executable_project("" "" "" "")

if(NBL_EMBED_BUILTIN_RESOURCES)
set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData)
set(RESOURCE_DIR "app_resources")
set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen")
set(DEPENDS
app_resources/common.hlsl
app_resources/mpmc_queue.hlsl
app_resources/schedulers/mpmc.hlsl
app_resources/shader.comp.hlsl
app_resources/workgroup/pool_allocator.hlsl
app_resources/workgroup/stack.hlsl
)

get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)
set(JSON [=[
[
{
"INPUT": "app_resources/shader.comp.hlsl",
"KEY": "shader",
"COMPILE_OPTIONS": ["-T", "cs_6_8"],
"DEPENDS": [],
"CAPS": []
}
]
]=])

file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")
foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
endforeach()
NBL_CREATE_NSC_COMPILE_RULES(
TARGET ${EXECUTABLE_NAME}SPIRV
LINK_TO ${EXECUTABLE_NAME}
DEPENDS ${DEPENDS}
BINARY_DIR ${OUTPUT_DIRECTORY}
MOUNT_POINT_DEFINE NBL_THIS_EXAMPLE_BUILD_MOUNT_POINT
COMMON_OPTIONS -I ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VAR KEYS
INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp
NAMESPACE nbl::this_example::builtin::build
INPUTS ${JSON}
)

ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")

LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
endif()
NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin::build
TARGET ${EXECUTABLE_NAME}_builtinsBuild
LINK_TO ${EXECUTABLE_NAME}
BIND ${OUTPUT_DIRECTORY}
BUILTINS ${KEYS}
)
4 changes: 2 additions & 2 deletions 27_MPMCScheduler/app_resources/schedulers/mpmc.hlsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _NBL_HLSL_SCHEDULERS_MPMC_HLSL_
#define _NBL_HLSL_SCHEDULERS_MPMC_HLSL_

//#include "../workgroup/stack.hlsl"
//#include "mpmc_queue.hlsl"
//#include "app_resources/workgroup/stack.hlsl"
//#include "app_resources/mpmc_queue.hlsl"

#include "nbl/builtin/hlsl/workgroup/scratch_size.hlsl"
#include "nbl/builtin/hlsl/workgroup/arithmetic.hlsl"
Expand Down
4 changes: 2 additions & 2 deletions 27_MPMCScheduler/app_resources/shader.comp.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//#include "nbl/builtin/hlsl/memory_accessor.hlsl"

#include "common.hlsl"
#include "app_resources/common.hlsl"

#include "nbl/builtin/hlsl/limits.hlsl"
#include "nbl/builtin/hlsl/numbers.hlsl"
Expand Down Expand Up @@ -156,7 +156,7 @@ struct SharedAccessor
};

//
#include "schedulers/mpmc.hlsl"
#include "app_resources/schedulers/mpmc.hlsl"
struct SubgroupCaps
{
NBL_CONSTEXPR_STATIC_INLINE bool shaderSubgroupArithmetic = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _NBL_HLSL_WORKGROUP_POOL_ALLOCATOR_HLSL_
#define _NBL_HLSL_WORKGROUP_POOL_ALLOCATOR_HLSL_

#include "workgroup/stack.hlsl"
#include "app_resources/workgroup/stack.hlsl"

namespace nbl
{
Expand Down
40 changes: 24 additions & 16 deletions 27_MPMCScheduler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


#include "nbl/examples/examples.hpp"
#include "nbl/this_example/builtin/build/spirv/keys.hpp"

using namespace nbl;
using namespace nbl::core;
Expand Down Expand Up @@ -73,22 +74,29 @@ class MPMCSchedulerApp final : public SimpleWindowedApplication, public BuiltinR

smart_refctd_ptr<IShader> shader;
{
IAssetLoader::SAssetLoadParams lp = {};
lp.logger = m_logger.get();
lp.workingDirectory = ""; // virtual root
auto assetBundle = m_assetMgr->getAsset("app_resources/shader.comp.hlsl", lp);
const auto assets = assetBundle.getContents();
if (assets.empty())
return logFail("Failed to load shader from disk");

// lets go straight from ICPUSpecializedShader to IGPUSpecializedShader
auto source = IAsset::castDown<IShader>(assets[0]);
if (!source)
return logFail("Failed to load shader from disk");

shader = m_device->compileShader({ source.get() });
if (!shader)
return false;
// load shader
{
IAssetLoader::SAssetLoadParams lp = {};
lp.logger = m_logger.get();
lp.workingDirectory = "";

auto key = "app_resources/" + nbl::this_example::builtin::build::get_spirv_key<"shader">(m_device.get());
const auto bundle = m_assetMgr->getAsset(key.data(), lp);

const auto contents = bundle.getContents();

if (contents.empty())
return logFail("Failed to load shader from disk");

if (bundle.getAssetType() != IAsset::ET_SHADER)
return logFail("Loaded asset has wrong type!");

shader = IAsset::castDown<IShader>(contents[0]);

if (!shader)
false;
}

}

smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout;
Expand Down
40 changes: 15 additions & 25 deletions 29_Arithmetic2Bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@

include(common RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
endif()

nbl_create_executable_project("" "" "" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")

if(NBL_EMBED_BUILTIN_RESOURCES)
set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData)
set(RESOURCE_DIR "app_resources")

get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)

file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")
foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
endforeach()

ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")

LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
endif()
include(common)

nbl_create_executable_project("" "" "" "")

NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin
TARGET ${EXECUTABLE_NAME}_builtins
LINK_TO ${EXECUTABLE_NAME}
BIND app_resources
BUILTINS
benchmarkSubgroup.comp.hlsl
benchmarkWorkgroup.comp.hlsl
common.hlsl
shaderCommon.hlsl
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "nbl/builtin/hlsl/subgroup2/arithmetic_portability.hlsl"
#include "nbl/builtin/hlsl/random/xoroshiro.hlsl"

#include "shaderCommon.hlsl"
#include "app_resources/shaderCommon.hlsl"
#include "nbl/builtin/hlsl/workgroup2/basic.hlsl"

template<class Binop, class device_capabilities>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using config_t = WORKGROUP_CONFIG_T;

#include "shaderCommon.hlsl"
#include "app_resources/shaderCommon.hlsl"

typedef vector<uint32_t, config_t::ItemsPerInvocation_0> type_t;

Expand Down
2 changes: 1 addition & 1 deletion 29_Arithmetic2Bench/app_resources/shaderCommon.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hlsl"
#include "app_resources/common.hlsl"

using namespace nbl;
using namespace hlsl;
Expand Down
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ if(NBL_BUILD_EXAMPLES)

# we link common example api library and force examples to reuse its PCH
foreach(T IN LISTS TARGETS)
target_link_libraries(${T} PUBLIC ${NBL_EXAMPLES_API_TARGET})
target_include_directories(${T} PUBLIC $<TARGET_PROPERTY:${NBL_EXAMPLES_API_TARGET},INCLUDE_DIRECTORIES>)
target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}")

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} NblExtExamplesAPIBuiltinsBuild)
get_target_property(TYPE ${T} TYPE)
if(NOT ${TYPE} MATCHES INTERFACE)
target_link_libraries(${T} PUBLIC ${NBL_EXAMPLES_API_TARGET})
target_include_directories(${T} PUBLIC $<TARGET_PROPERTY:${NBL_EXAMPLES_API_TARGET},INCLUDE_DIRECTORIES>)
set_target_properties(${T} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF)
target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}")

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} NblExtExamplesAPIBuiltinsBuild)
endif()
endif()
endforeach()

Expand Down
32 changes: 18 additions & 14 deletions common/include/nbl/examples/common/BuiltinResourcesApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
#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/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
#if __has_include("nbl/this_example/builtin/build/CArchive.h")
#include "nbl/this_example/builtin/build/CArchive.h"
#endif
#endif

namespace nbl::examples
Expand All @@ -45,30 +41,38 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs

using namespace core;

smart_refctd_ptr<system::IFileArchive> examplesHeaderArch,examplesSourceArch,examplesBuildSpirvArch,thisExampleArch;
smart_refctd_ptr<system::IFileArchive> examplesHeaderArch,examplesSourceArch,examplesBuildArch,thisExampleArch, thisExampleBuildArch;
#ifdef NBL_EMBED_BUILTIN_RESOURCES
examplesHeaderArch = core::make_smart_refctd_ptr<nbl::builtin::examples::include::CArchive>(smart_refctd_ptr(m_logger));
examplesSourceArch = core::make_smart_refctd_ptr<nbl::builtin::examples::src::CArchive>(smart_refctd_ptr(m_logger));
examplesBuildSpirvArch = core::make_smart_refctd_ptr<nbl::builtin::examples::build::CArchive>(smart_refctd_ptr(m_logger));
examplesBuildArch = core::make_smart_refctd_ptr<nbl::builtin::examples::build::CArchive>(smart_refctd_ptr(m_logger));

#ifdef _NBL_THIS_EXAMPLE_BUILTIN_C_ARCHIVE_H_
thisExampleArch = make_smart_refctd_ptr<nbl::this_example::builtin::CArchive>(smart_refctd_ptr(m_logger));
#endif
// TODO: (**)

#ifdef _NBL_THIS_EXAMPLE_BUILTIN_BUILD_C_ARCHIVE_H_
thisExampleBuildArch = make_smart_refctd_ptr<nbl::this_example::builtin::build::CArchive>(smart_refctd_ptr(m_logger));
#endif

#else
examplesHeaderArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"../common/include/nbl/examples",smart_refctd_ptr(m_logger),m_system.get());
examplesSourceArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"../common/src/nbl/examples",smart_refctd_ptr(m_logger),m_system.get());
examplesBuildSpirvArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(NBL_EXAMPLES_BUILD_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get());
examplesBuildArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(NBL_EXAMPLES_BUILD_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get());
thisExampleArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"app_resources",smart_refctd_ptr(m_logger),m_system.get());
// TODO: (**)
#ifdef NBL_THIS_EXAMPLE_BUILD_MOUNT_POINT
thisExampleBuildArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(NBL_THIS_EXAMPLE_BUILD_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get());
#endif
#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(examplesBuildSpirvArch),"nbl/examples");
m_system->mount(std::move(examplesBuildArch),"nbl/examples");
if (thisExampleArch)
m_system->mount(std::move(thisExampleArch),"app_resources");
// TODO: (**)

if(thisExampleBuildArch)
m_system->mount(std::move(thisExampleBuildArch), "app_resources");

return true;
}
Expand Down