Skip to content
Open
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
2 changes: 1 addition & 1 deletion 03_DeviceSelectionAndSharedSources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
}

const auto* metadata = assetBundle.getMetadata();
const auto hlslMetadata = static_cast<const CHLSLMetadata*>(metadata);
const auto hlslMetadata = static_cast<const CHLSLMetadata*>(metadata);
const auto shaderStage = hlslMetadata->shaderStages->front();

// It would be super weird if loading a shader from a file produced more than 1 asset
Expand Down
48 changes: 47 additions & 1 deletion 05_StreamingAndBufferDeviceAddressApp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,50 @@ if(NBL_EMBED_BUILTIN_RESOURCES)
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()
endif()

set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen")
set(DEPENDS
app_resources/common.hlsl
app_resources/shader.comp.hlsl
)
target_sources(${EXECUTABLE_NAME} PRIVATE ${DEPENDS})
set_source_files_properties(${DEPENDS} PROPERTIES HEADER_FILE_ONLY ON)

set(SM 6_8)
set(JSON [=[
[
{
"INPUT": "app_resources/shader.comp.hlsl",
"KEY": "shader",
}
]
]=])
string(CONFIGURE "${JSON}" JSON)

set(COMPILE_OPTIONS
-I "${CMAKE_CURRENT_SOURCE_DIR}"
-O3
-T lib_${SM}
)

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 ${COMPILE_OPTIONS}
OUTPUT_VAR KEYS
INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp
NAMESPACE nbl::this_example::builtin::build
INPUTS ${JSON}
)

NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin::build
TARGET ${EXECUTABLE_NAME}_builtinsBuild
LINK_TO ${EXECUTABLE_NAME}
BIND ${OUTPUT_DIRECTORY}
BUILTINS ${KEYS}
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include "common.hlsl"

// just a small test
#include "nbl/builtin/hlsl/jit/device_capabilities.hlsl"

[[vk::push_constant]] PushConstantData pushConstants;

// does absolutely nothing, a later example will show how it gets used
template<typename capability_traits=nbl::hlsl::jit::device_capabilities_traits>
template<typename capability_traits=DeviceConfigCaps>
void dummyTraitTest() {}

[numthreads(WorkgroupSize,1,1)]
Expand Down
11 changes: 6 additions & 5 deletions 05_StreamingAndBufferDeviceAddressApp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// I've moved out a tiny part of this example into a shared header for reuse, please open and read it.
#include "nbl/application_templates/MonoDeviceApplication.hpp"
#include "nbl/examples/common/BuiltinResourcesApplication.hpp"
#include "nbl/this_example/builtin/build/spirv/keys.hpp"


using namespace nbl;
Expand Down Expand Up @@ -95,15 +96,15 @@ class StreamingAndBufferDeviceAddressApp final : public application_templates::M
{
IAssetLoader::SAssetLoadParams lp = {};
lp.logger = m_logger.get();
lp.workingDirectory = ""; // virtual root
auto assetBundle = m_assetMgr->getAsset("app_resources/shader.comp.hlsl",lp);
lp.workingDirectory = "app_resources"; // virtual root

auto key = nbl::this_example::builtin::build::get_spirv_key<"shader">(m_device.get());
auto assetBundle = m_assetMgr->getAsset(key.data(), lp);
const auto assets = assetBundle.getContents();
if (assets.empty())
return logFail("Could not load shader!");

// lets go straight from ICPUSpecializedShader to IGPUSpecializedShader
const auto shaderSource = IAsset::castDown<IShader>(assets[0]);
shader = m_device->compileShader({shaderSource.get()});
shader = IAsset::castDown<IShader>(assets[0]);
// The down-cast should not fail!
assert(shader);
}
Expand Down
48 changes: 47 additions & 1 deletion 07_StagingAndMultipleQueues/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,50 @@ if(NBL_EMBED_BUILTIN_RESOURCES)
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()
endif()

set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen")
set(DEPENDS
app_resources/common.hlsl
app_resources/comp_shader.hlsl
)
target_sources(${EXECUTABLE_NAME} PRIVATE ${DEPENDS})
set_source_files_properties(${DEPENDS} PROPERTIES HEADER_FILE_ONLY ON)

set(SM 6_8)
set(JSON [=[
[
{
"INPUT": "app_resources/comp_shader.hlsl",
"KEY": "comp_shader",
}
]
]=])
string(CONFIGURE "${JSON}" JSON)

set(COMPILE_OPTIONS
-I "${CMAKE_CURRENT_SOURCE_DIR}"
-O3
-T lib_${SM}
)

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 ${COMPILE_OPTIONS}
OUTPUT_VAR KEYS
INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp
NAMESPACE nbl::this_example::builtin::build
INPUTS ${JSON}
)

NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin::build
TARGET ${EXECUTABLE_NAME}_builtinsBuild
LINK_TO ${EXECUTABLE_NAME}
BIND ${OUTPUT_DIRECTORY}
BUILTINS ${KEYS}
)
44 changes: 28 additions & 16 deletions 07_StagingAndMultipleQueues/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// I've moved out a tiny part of this example into a shared header for reuse, please open and read it.
#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 @@ -189,7 +190,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
for (uint32_t imageIdx = 0; imageIdx < IMAGE_CNT; ++imageIdx)
{
const auto imagePathToLoad = imagesToLoad[imageIdx];
auto cpuImage = loadFistAssetInBundle<ICPUImage>(imagePathToLoad);
auto cpuImage = loadImageAsset(imagePathToLoad);
if (!cpuImage)
logFailAndTerminate("Failed to load image from path %s",ILogger::ELL_ERROR,imagePathToLoad);

Expand Down Expand Up @@ -279,17 +280,10 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
}

// LOAD SHADER FROM FILE
smart_refctd_ptr<IShader> source;
{
source = loadFistAssetInBundle<IShader>("../app_resources/comp_shader.hlsl");
}
smart_refctd_ptr<IShader> shader = loadPreCompiledShader<"comp_shader">(); // "../app_resources/comp_shader.hlsl"

if (!source)
logFailAndTerminate("Could not create a CPU shader!");

core::smart_refctd_ptr<IShader> shader = m_device->compileShader({ source.get() });
if(!shader)
logFailAndTerminate("Could not compile shader to spirv!");
if (!shader)
logFailAndTerminate("Could not load the precompiled shader!");

// CREATE COMPUTE PIPELINE
SPushConstantRange pc[1];
Expand Down Expand Up @@ -534,21 +528,39 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul

return false;
}

template<typename AssetType>
core::smart_refctd_ptr<AssetType> loadFistAssetInBundle(const std::string& path)

core::smart_refctd_ptr<ICPUImage> loadImageAsset(const std::string& path)
{
IAssetLoader::SAssetLoadParams lp;
SAssetBundle bundle = m_assetMgr->getAsset(path, lp);
if (bundle.getContents().empty())
logFailAndTerminate("Couldn't load an asset.",ILogger::ELL_ERROR);
logFailAndTerminate("Couldn't load an image.",ILogger::ELL_ERROR);

auto asset = IAsset::castDown<AssetType>(bundle.getContents()[0]);
auto asset = IAsset::castDown<ICPUImage>(bundle.getContents()[0]);
if (!asset)
logFailAndTerminate("Incorrect asset loaded.",ILogger::ELL_ERROR);

return asset;
}

template<core::StringLiteral ShaderKey>
core::smart_refctd_ptr<IShader> loadPreCompiledShader()
{
IAssetLoader::SAssetLoadParams lp;
lp.logger = m_logger.get();
lp.workingDirectory = "app_resources";

auto key = nbl::this_example::builtin::build::get_spirv_key<ShaderKey>(m_device.get());
SAssetBundle bundle = m_assetMgr->getAsset(key.data(), lp);
if (bundle.getContents().empty())
logFailAndTerminate("Couldn't load a shader.", ILogger::ELL_ERROR);

auto asset = IAsset::castDown<IShader>(bundle.getContents()[0]);
if (!asset)
logFailAndTerminate("Incorrect asset loaded.", ILogger::ELL_ERROR);

return asset;
}
};

NBL_MAIN_FUNC(StagingAndMultipleQueuesApp)
68 changes: 68 additions & 0 deletions 10_CountingSort/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,71 @@ if(NBL_EMBED_BUILTIN_RESOURCES)

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

set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen")
set(DEPENDS
app_resources/common.hlsl
app_resources/prefix_sum_shader.comp.hlsl
app_resources/scatter_shader.comp.hlsl
)
target_sources(${EXECUTABLE_NAME} PRIVATE ${DEPENDS})
set_source_files_properties(${DEPENDS} PROPERTIES HEADER_FILE_ONLY ON)

set(SM 6_8)
set(REQUIRED_CAPS [=[
{
"kind": "limits",
"name": "maxComputeWorkGroupInvocations",
"type": "uint32_t",
"values": [256,512,1024]
},
{
"kind": "limits",
"name": "maxComputeSharedMemorySize",
"type": "uint32_t",
"values": [16384, 32768, 65536]
}
]=])

set(JSON [=[
[
{
"INPUT": "app_resources/prefix_sum_shader.comp.hlsl",
"KEY": "prefix_sum_shader",
"CAPS": [${REQUIRED_CAPS}]
},
{
"INPUT": "app_resources/scatter_shader.comp.hlsl",
"KEY": "scatter_shader",
"CAPS": [${REQUIRED_CAPS}]
}
]
]=])
string(CONFIGURE "${JSON}" JSON)

set(COMPILE_OPTIONS
-I "${CMAKE_CURRENT_SOURCE_DIR}"
-O3
-T lib_${SM}
)

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 ${COMPILE_OPTIONS}
OUTPUT_VAR KEYS
INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp
NAMESPACE nbl::this_example::builtin::build
INPUTS ${JSON}
)

NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin::build
TARGET ${EXECUTABLE_NAME}_builtinsBuild
LINK_TO ${EXECUTABLE_NAME}
BIND ${OUTPUT_DIRECTORY}
BUILTINS ${KEYS}
)
6 changes: 6 additions & 0 deletions 10_CountingSort/app_resources/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ using namespace nbl::hlsl;
#ifdef __HLSL_VERSION
#include "nbl/builtin/hlsl/bda/bda_accessor.hlsl"

static const uint32_t WorkgroupSize = DeviceConfigCaps::maxComputeWorkGroupInvocations;
static const uint32_t MaxBucketCount = (DeviceConfigCaps::maxComputeSharedMemorySize / sizeof(uint32_t)) / 2;
static const uint32_t BucketCount = (MaxBucketCount > 3000) ? 3000 : MaxBucketCount;

using Ptr = bda::__ptr<uint32_t>;
using PtrAccessor = BdaAccessor<uint32_t>;

Expand Down Expand Up @@ -54,6 +58,8 @@ uint32_t3 glsl::gl_WorkGroupSize()
{
return uint32_t3(WorkgroupSize, 1, 1);
}


#endif

#endif
Loading