Skip to content

Commit cbcc1c9

Browse files
committed
create INTERFACE_TO_BUILTINS, add NblExtExamplesAPIBuiltinsSPIRV target created with NBL_REGISTER_SPIRV_SHADERS utility, update CSimpleDebugRenderer.hpp, change location of unified.hlsl
1 parent bb68b7b commit cbcc1c9

File tree

8 files changed

+74
-82
lines changed

8 files changed

+74
-82
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ if(NBL_BUILD_EXAMPLES)
9797
target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}")
9898
LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource)
9999
LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude)
100+
LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSPIRV)
100101
endforeach()
101102

102103
NBL_ADJUST_FOLDERS(examples)

common/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ nbl_create_ext_library_project(ExamplesAPI "" "${CMAKE_CURRENT_SOURCE_DIR}/src/n
1313
set_target_properties(${LIB_NAME} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF)
1414
target_precompile_headers(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/nbl/examples/PCH.hpp")
1515

16+
set(COMMON_INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include")
17+
18+
function(INTERFACE_TO_BUILTINS TARGET)
19+
#[[
20+
even though builtin target is static library its still valid to reuse
21+
common PCH to boost its build speed to not preprocess entire Nabla again
22+
]]
23+
set_target_properties(${TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF)
24+
target_precompile_headers(${TARGET} REUSE_FROM "${LIB_NAME}")
25+
26+
target_include_directories(${TARGET} PUBLIC "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include")
27+
target_link_libraries(${TARGET} INTERFACE ${LIB_NAME})
28+
endfunction()
29+
1630
function(REGISTER_COMMON_BUILTINS)
1731
cmake_parse_arguments(EX "" "TARGET;ARCHIVE_ABS_ENTRY;ARCHIVE_NAMESPACE" "GLOB_RGX" ${ARGN})
1832

@@ -36,13 +50,7 @@ function(REGISTER_COMMON_BUILTINS)
3650
endforeach()
3751

3852
ADD_CUSTOM_BUILTIN_RESOURCES(${EX_TARGET} EXAMPLES_RESOURCES_TO_EMBED "${INPUT_DIRECTORY}" "${EX_ARCHIVE_ABS_ENTRY}" "${EX_ARCHIVE_NAMESPACE}" "${OUTPUT_INCLUDE}" "${OUTPUT_SRC}")
39-
40-
# 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
41-
set_target_properties(${EX_TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF)
42-
target_precompile_headers(${EX_TARGET} REUSE_FROM "${LIB_NAME}")
43-
44-
target_include_directories(${EX_TARGET} PUBLIC "${INPUT_DIRECTORY}/include")
45-
target_link_libraries(${EX_TARGET} INTERFACE ${LIB_NAME})
53+
INTERFACE_TO_BUILTINS(${EX_TARGET})
4654
endfunction()
4755

4856
#! common example API builtins as static library targets linked to each example

common/include/nbl/examples/common/BuiltinResourcesApplication.hpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44
#ifndef _NBL_EXAMPLES_BUILTIN_RESOURCE_APPLICATION_HPP_INCLUDED_
55
#define _NBL_EXAMPLES_BUILTIN_RESOURCE_APPLICATION_HPP_INCLUDED_
66

7-
87
// we need a system, logger and an asset manager
98
#include "nbl/application_templates/MonoAssetManagerApplication.hpp"
109

1110
#ifdef NBL_EMBED_BUILTIN_RESOURCES
1211
#include "nbl/builtin/examples/include/CArchive.h"
1312
#include "nbl/builtin/examples/src/CArchive.h"
14-
// TODO: the build `nbl/examples` archive
15-
#if __has_include("nbl/this_example/builtin/CArchive.h")
16-
#include "nbl/this_example/builtin/CArchive.h"
17-
#endif
13+
#include "nbl/builtin/examples/build/spirv/CArchive.h"
14+
#if __has_include("nbl/this_example/builtin/CArchive.h")
15+
#include "nbl/this_example/builtin/CArchive.h"
16+
#endif
17+
// TODO: (**) there should be also 5th arch "nbl/this_example/builtin/build/spirv/CArchive.h"
18+
/*
19+
#if __has_include("nbl/this_example/builtin/build/spirv/CArchive.h")
20+
#include "nbl/this_example/builtin/build/spirv/CArchive.h"
21+
#endif
22+
*/
23+
//! this ain't meant to be the same as this_example ordinary archive
1824
#endif
1925

20-
2126
namespace nbl::examples
2227
{
2328

@@ -40,32 +45,35 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs
4045

4146
using namespace core;
4247

43-
smart_refctd_ptr<system::IFileArchive> examplesHeaderArch,examplesSourceArch,examplesBuildArch,thisExampleArch;
44-
#ifdef NBL_EMBED_BUILTIN_RESOURCES
48+
smart_refctd_ptr<system::IFileArchive> examplesHeaderArch,examplesSourceArch,examplesBuildSpirvArch,thisExampleArch;
49+
#ifdef NBL_EMBED_BUILTIN_RESOURCES
4550
examplesHeaderArch = core::make_smart_refctd_ptr<nbl::builtin::examples::include::CArchive>(smart_refctd_ptr(m_logger));
4651
examplesSourceArch = core::make_smart_refctd_ptr<nbl::builtin::examples::src::CArchive>(smart_refctd_ptr(m_logger));
47-
// TODO: the build archive
52+
examplesBuildSpirvArch = core::make_smart_refctd_ptr<nbl::builtin::examples::build::spirv::CArchive>(smart_refctd_ptr(m_logger));
4853

4954
#ifdef _NBL_THIS_EXAMPLE_BUILTIN_C_ARCHIVE_H_
5055
thisExampleArch = make_smart_refctd_ptr<nbl::this_example::builtin::CArchive>(smart_refctd_ptr(m_logger));
5156
#endif
52-
#else
57+
// TODO: (**)
58+
#else
5359
examplesHeaderArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"../common/include/nbl/examples",smart_refctd_ptr(m_logger),m_system.get());
5460
examplesSourceArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"../common/src/nbl/examples",smart_refctd_ptr(m_logger),m_system.get());
55-
// TODO: examplesBuildArch =
61+
examplesBuildSpirvArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(NBL_EXAMPLES_BUILD_SPIRV_MOUNT_POINT, smart_refctd_ptr(m_logger), m_system.get());
5662
thisExampleArch = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"app_resources",smart_refctd_ptr(m_logger),m_system.get());
57-
#endif
63+
// TODO: (**)
64+
#endif
5865
// yes all 3 aliases are meant to be the same
5966
m_system->mount(std::move(examplesHeaderArch),"nbl/examples");
6067
m_system->mount(std::move(examplesSourceArch),"nbl/examples");
61-
// m_system->mount(std::move(examplesBuildArch),"nbl/examples");
68+
m_system->mount(std::move(examplesBuildSpirvArch),"nbl/examples");
6269
if (thisExampleArch)
6370
m_system->mount(std::move(thisExampleArch),"app_resources");
71+
// TODO: (**)
6472

6573
return true;
6674
}
6775
};
6876

6977
}
7078

71-
#endif // _CAMERA_IMPL_
79+
#endif // _NBL_EXAMPLES_BUILTIN_RESOURCE_APPLICATION_HPP_INCLUDED_

common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,26 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
9797
// load shader
9898
smart_refctd_ptr<IShader> shader;
9999
{
100-
const auto bundle = assMan->getAsset("nbl/examples/geometry/shaders/unified.hlsl",{});
101-
// TODO: Arek
102-
//const auto bundle = assMan->getAsset("nbl/examples/geometry/shaders/unified.spv",{});
100+
// TODO & NOTE: tmp, maybe I will turn it into CMake option
101+
#define NBL_USE_PRECOMPILED_SPIRV
102+
103+
#ifdef NBL_USE_PRECOMPILED_SPIRV
104+
constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl.spv";
105+
#else
106+
constexpr std::string_view key = "nbl/examples/shaders/geometry/unified.hlsl";
107+
#endif // NBL_USE_PRECOMPILED_SPIRV
108+
109+
const auto bundle = assMan->getAsset(key.data(), {});
110+
111+
//const auto bundle = assMan->getAsset("nbl/examples/shaders/geometry/unified.hlsl.spv",{});
103112
const auto contents = bundle.getContents();
104113
if (contents.empty() || bundle.getAssetType()!=IAsset::ET_SHADER)
105114
return nullptr;
106115
shader = IAsset::castDown<IShader>(contents[0]);
107-
shader = device->compileShader({.source=shader.get()});
116+
117+
#ifndef NBL_USE_PRECOMPILED_SPIRV
118+
shader = device->compileShader({ .source = shader.get() });
119+
#endif // NBL_USE_PRECOMPILED_SPIRV
108120
if (!shader)
109121
return nullptr;
110122
}
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
# TODO builtin SPIR-V shaders
2-
# add_subdirectory(geometry EXCLUDE_FROM_ALL)
1+
set(SPIRV_TARGET_V 6_8)
32

4-
# TODO: make docs once I get n4ce embed SPIRV tool to build system and then use the tool with Matts new shader
3+
set(COMMON_OPTIONS
4+
-I "${COMMON_INCLUDE_DIRECTORY}"
5+
)
6+
7+
NBL_REGISTER_SPIRV_SHADERS(
8+
MOUNT_POINT_DEFINE
9+
NBL_EXAMPLES_BUILD_SPIRV_MOUNT_POINT
10+
11+
ARCHIVE
12+
TARGET NblExtExamplesAPIBuiltinsSPIRV
13+
INPUT_DIRECTORY .
14+
NAMESPACE nbl::builtin::examples::build::spirv
15+
16+
INPUTS
17+
KEY shaders/geometry/unified.hlsl COMPILE_OPTIONS ${COMMON_OPTIONS} -T lib_${SPIRV_TARGET_V}
18+
# KEY <xyz> COMPILE_OPTIONS ${COMMON_OPTIONS} -T <target>_${SPIRV_TARGET_V}
19+
)
20+
21+
INTERFACE_TO_BUILTINS(NblExtExamplesAPIBuiltinsSPIRV)

common/src/nbl/examples/geometry/shaders/grid.vertex.hlsl

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

common/src/nbl/examples/geometry/shaders/template/grid.common.hlsl

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

0 commit comments

Comments
 (0)