Skip to content
2 changes: 1 addition & 1 deletion examples_tests
Submodule examples_tests updated 47 files
+3 −1,125 22_RaytracedAO/Renderer.cpp
+1 −37 22_RaytracedAO/Renderer.h
+0 −150 22_RaytracedAO/SimpleJson.cpp
+0 −78 22_RaytracedAO/SimpleJson.h
+0 −36 22_RaytracedAO/common.h
+0 −28 22_RaytracedAO/config.json
+0 −28 22_RaytracedAO/config.json.template
+0 −74 22_RaytracedAO/cull.comp
+0 −40 22_RaytracedAO/extractCubemap.bat
+0 −36 22_RaytracedAO/fillVisBuffer.frag
+22 −665 22_RaytracedAO/main.cpp
+0 −32 22_RaytracedAO/mergeCubemap.bat
+0 −50 22_RaytracedAO/pipeline.groovy
+0 −74 22_RaytracedAO/raytraceCommon.h
+0 −46 22_RaytracedAO/test_scenes.txt
+0 −42 22_RaytracedAO/virtualGeometry.glsl
+79 −0 40_PathTracer/CMakeLists.txt
+26 −0 40_PathTracer/app_resources/pathtrace/beauty.hlsl
+26 −0 40_PathTracer/app_resources/pathtrace/debug.hlsl
+25 −0 40_PathTracer/app_resources/pathtrace/previs.hlsl
+40 −0 40_PathTracer/app_resources/present/default.hlsl
+28 −0 40_PathTracer/include/common.hpp
+278 −0 40_PathTracer/include/io/CSceneLoader.h
+197 −0 40_PathTracer/include/renderer/CRenderer.h
+97 −0 40_PathTracer/include/renderer/CScene.h
+158 −0 40_PathTracer/include/renderer/CSession.h
+1,046 −0 40_PathTracer/include/renderer/SAASequence.h
+94 −0 40_PathTracer/include/renderer/present/CWindowPresenter.h
+204 −0 40_PathTracer/include/renderer/present/IPresenter.h
+104 −0 40_PathTracer/include/renderer/resolve/CBasicRWMCResolver.h
+47 −0 40_PathTracer/include/renderer/resolve/IResolver.h
+9 −0 40_PathTracer/include/renderer/shaders/common.hlsl
+23 −0 40_PathTracer/include/renderer/shaders/pathtrace/common.hlsl
+48 −0 40_PathTracer/include/renderer/shaders/pathtrace/push_constants.hlsl
+60 −0 40_PathTracer/include/renderer/shaders/present/push_constants.hlsl
+35 −0 40_PathTracer/include/renderer/shaders/resolve/rwmc.hlsl
+68 −0 40_PathTracer/include/renderer/shaders/scene.hlsl
+111 −0 40_PathTracer/include/renderer/shaders/session.hlsl
+590 −0 40_PathTracer/main.cpp
+541 −0 40_PathTracer/src/io/CSceneLoader.cpp
+710 −0 40_PathTracer/src/renderer/CRenderer.cpp
+78 −0 40_PathTracer/src/renderer/CScene.cpp
+306 −0 40_PathTracer/src/renderer/CSession.cpp
+297 −0 40_PathTracer/src/renderer/present/CWindowPresenter.cpp
+76 −0 40_PathTracer/src/renderer/resolve/CBasicRWMCResolver.cpp
+37 −57 71_RayTracingPipeline/main.cpp
+8 −3 CMakeLists.txt
68 changes: 68 additions & 0 deletions include/nbl/asset/IAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,72 @@ concept Asset = std::is_base_of_v<IAsset,T>;

}

namespace nbl::system::impl
{
template<>
struct to_string_helper<asset::IAsset::E_TYPE>
{
private:
using enum_t = asset::IAsset::E_TYPE;

public:
static inline std::string __call(const enum_t value)
{
switch (value)
{
case enum_t::ET_BUFFER:
return "ICPUBuffer";
case enum_t::ET_BUFFER_VIEW:
return "ICPUBufferView";
case enum_t::ET_SAMPLER:
return "ICPUSampler";
case enum_t::ET_IMAGE:
return "ICPUImage";
case enum_t::ET_IMAGE_VIEW:
return "ICPUImageView";
case enum_t::ET_DESCRIPTOR_SET:
return "ICPUDescriptorSet";
case enum_t::ET_DESCRIPTOR_SET_LAYOUT:
return "ICPUDescriptorSetLayout";
case enum_t::ET_SKELETON:
return "ICPUSkeleton";
case enum_t::ET_ANIMATION_LIBRARY:
return "ICPUAnimationLibrary";
case enum_t::ET_PIPELINE_LAYOUT:
return "ICPUPipelineLayout";
case enum_t::ET_SHADER:
return "IShader";
case enum_t::ET_GEOMETRY:
return "IGeometry<ICPUBuffer>";
case enum_t::ET_RENDERPASS:
return "ICPURenderpass";
case enum_t::ET_FRAMEBUFFER:
return "ICPUFramebuffer";
case enum_t::ET_GRAPHICS_PIPELINE:
return "ICPUGraphicsPipeline";
case enum_t::ET_BOTOM_LEVEL_ACCELERATION_STRUCTURE:
return "ICPUBottomLevelAccelerationStructure";
case enum_t::ET_TOP_LEVEL_ACCELERATION_STRUCTURE:
return "ICPUTopLevelAccelerationStructure";
case enum_t::ET_GEOMETRY_COLLECTION:
return "ICPUGeometryCollection";
case enum_t::ET_MORPH_TARGETS:
return "ICPUMorphTargets";
case enum_t::ET_COMPUTE_PIPELINE:
return "ICPUComputePipeline";
case enum_t::ET_PIPELINE_CACHE:
return "ICPUPipelineCache";
case enum_t::ET_SCENE:
return "ICPUScene";
case enum_t::ET_RAYTRACING_PIPELINE:
return "ICPURayTracingPipeline";
case enum_t::ET_IMPLEMENTATION_SPECIFIC_METADATA:
return "";
default:
break;
}
return "";
}
};
}
#endif
9 changes: 9 additions & 0 deletions include/nbl/asset/IBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ struct SBufferRange
inline bool operator!=(const SBufferRange<const BufferType>& rhs) const { return !operator==(rhs); }
};

template<typename BufferType>
struct SStridedRange
{
inline operator bool() const {return range.isValid();}

SBufferRange<BufferType> range = {};
uint32_t stride = 0;
};

}

namespace std
Expand Down
50 changes: 26 additions & 24 deletions include/nbl/asset/ICPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,32 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
return (m_alignment > 0 && !(m_alignment & (m_alignment - 1)));
}

protected:
inline void discardContent_impl() override
{
if (m_data)
m_mem_resource->deallocate(m_data, m_creationParams.size, m_alignment);
m_data = nullptr;
m_mem_resource = nullptr;
m_creationParams.size = 0ull;
}

private:
ICPUBuffer(SCreationParams&& params) :
asset::IBuffer({ params.size, EUF_TRANSFER_DST_BIT }), m_data(params.data),
m_mem_resource(params.memoryResource), m_alignment(params.alignment) {}

~ICPUBuffer() override {
discardContent_impl();
}

inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override {}

void* m_data;
core::smart_refctd_ptr<core::refctd_memory_resource> m_mem_resource;
size_t m_alignment;
protected:
inline void discardContent_impl() override
{
if (m_data)
m_mem_resource->deallocate(m_data, m_creationParams.size, m_alignment);
m_data = nullptr;
m_mem_resource = nullptr;
m_creationParams.size = 0ull;
}

private:
// TODO: we should remove the addition of TRANSFER_DST_BIT because its the asset converter patcher that handles that
// But we need LLVM-pipe CI first so I don't have to test 70 examples by hand
inline ICPUBuffer(SCreationParams&& params) : asset::IBuffer({params.size,params.usage|EUF_TRANSFER_DST_BIT}),
m_data(params.data), m_mem_resource(params.memoryResource), m_alignment(params.alignment) {}

inline ~ICPUBuffer() override
{
discardContent_impl();
}

inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override {}

void* m_data;
core::smart_refctd_ptr<core::refctd_memory_resource> m_mem_resource;
size_t m_alignment;
};

} // end namespace nbl::asset
Expand Down
4 changes: 2 additions & 2 deletions include/nbl/asset/ICPURayTracingPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace nbl::asset
{

//! CPU Version of RayTracing Pipeline
class ICPURayTracingPipeline final : public ICPUPipeline<IRayTracingPipeline<ICPUPipelineLayout>>
class ICPURayTracingPipeline final : public ICPUPipeline<IRayTracingPipeline<ICPUPipelineLayout,ICPUBuffer>>
{
using pipeline_base_t = IRayTracingPipeline<ICPUPipelineLayout>;
using pipeline_base_t = IRayTracingPipeline<ICPUPipelineLayout,ICPUBuffer>;
using base_t = ICPUPipeline<pipeline_base_t>;

public:
Expand Down
1 change: 1 addition & 0 deletions include/nbl/asset/IPipelineLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ template<typename DescLayoutType>
class IPipelineLayout
{
public:
using desc_layout_t = DescLayoutType;
static inline constexpr uint32_t DESCRIPTOR_SET_COUNT = 4u;

std::span<const DescLayoutType* const,DESCRIPTOR_SET_COUNT> getDescriptorSetLayouts() const
Expand Down
125 changes: 89 additions & 36 deletions include/nbl/asset/IRayTracingPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,102 @@ namespace nbl::asset

class IRayTracingPipelineBase : public virtual core::IReferenceCounted
{
public:
#define base_flag(F) static_cast<uint64_t>(IPipelineBase::FLAGS::F)
enum class CreationFlags : uint64_t
{
NONE = base_flag(NONE),
// there's a bit of a problem, as the ICPUCompute and Graphics pipelines don't care about flags, because the following 4 flags
DISABLE_OPTIMIZATIONS = base_flag(DISABLE_OPTIMIZATIONS),
ALLOW_DERIVATIVES = base_flag(ALLOW_DERIVATIVES),
FAIL_ON_PIPELINE_COMPILE_REQUIRED = base_flag(FAIL_ON_PIPELINE_COMPILE_REQUIRED),
EARLY_RETURN_ON_FAILURE = base_flag(EARLY_RETURN_ON_FAILURE),
// don't matter for ICPU Pipelines, we'd really need to have these separate from `base_flag` and use the `IRayTracingPipelineBase::CreationFlags` for the ICPU creation params only
SKIP_BUILT_IN_PRIMITIVES = 1<<12,
SKIP_AABBS = 1<<13,
NO_NULL_ANY_HIT_SHADERS = 1<<14,
NO_NULL_CLOSEST_HIT_SHADERS = 1<<15,
NO_NULL_MISS_SHADERS = 1<<16,
NO_NULL_INTERSECTION_SHADERS = 1<<17,
ALLOW_MOTION = 1<<20,
};
#undef base_flag

struct SCachedCreationParams final
{
core::bitflag<CreationFlags> flags = CreationFlags::NONE;
uint32_t maxRecursionDepth : 6 = 0;
uint32_t dynamicStackSize : 1 = false;
};
public:
#define base_flag(F) static_cast<uint64_t>(IPipelineBase::FLAGS::F)
enum class CreationFlags : uint64_t
{
NONE = base_flag(NONE),
// there's a bit of a problem, as the ICPUCompute and Graphics pipelines don't care about flags, because the following 4 flags
DISABLE_OPTIMIZATIONS = base_flag(DISABLE_OPTIMIZATIONS),
ALLOW_DERIVATIVES = base_flag(ALLOW_DERIVATIVES),
FAIL_ON_PIPELINE_COMPILE_REQUIRED = base_flag(FAIL_ON_PIPELINE_COMPILE_REQUIRED),
EARLY_RETURN_ON_FAILURE = base_flag(EARLY_RETURN_ON_FAILURE),
// don't matter for ICPU Pipelines, we'd really need to have these separate from `base_flag` and use the `IRayTracingPipelineBase::CreationFlags` for the ICPU creation params only
SKIP_BUILT_IN_PRIMITIVES = 1<<12,
SKIP_AABBS = 1<<13,
NO_NULL_ANY_HIT_SHADERS = 1<<14,
NO_NULL_CLOSEST_HIT_SHADERS = 1<<15,
NO_NULL_MISS_SHADERS = 1<<16,
NO_NULL_INTERSECTION_SHADERS = 1<<17,
ALLOW_MOTION = 1<<20,
};
#undef base_flag

struct SCachedCreationParams final
{
core::bitflag<CreationFlags> flags = CreationFlags::NONE;
uint32_t maxRecursionDepth : 6 = 0;
uint32_t dynamicStackSize : 1 = false;
};
};

template<typename PipelineLayoutType>
template<typename PipelineLayoutType, typename BufferType>
class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTracingPipelineBase
{
public:
public:
struct SShaderBindingTable
{
inline bool valid(const core::bitflag<IRayTracingPipelineBase::CreationFlags> flags) const
{
return valid(flags,[](const std::string_view, auto... args)->void{});
}
template<typename Callback>
inline bool valid(const core::bitflag<IRayTracingPipelineBase::CreationFlags> flags, Callback&& cb) const
{
using create_flag_e = IRayTracingPipelineBase::CreationFlags;
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkCmdTraceRaysKHR.html#VUID-vkCmdTraceRaysKHR-flags-03696
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkCmdTraceRaysKHR.html#VUID-vkCmdTraceRaysKHR-flags-03697
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkCmdTraceRaysKHR.html#VUID-vkCmdTraceRaysKHR-flags-03512
const auto shouldHaveHitGroup = flags & (core::bitflag(create_flag_e::NO_NULL_ANY_HIT_SHADERS) | create_flag_e::NO_NULL_CLOSEST_HIT_SHADERS | create_flag_e::NO_NULL_INTERSECTION_SHADERS);
if (shouldHaveHitGroup && !hit.range.buffer)
{
cb("bound pipeline indicates that traceRays command should have hit group, but SRayTracingSBT::hit::range::buffer is null!");
return false;
}

// https://registry.khronos.org/vulkan/specs/latest/man/html/vkCmdTraceRaysKHR.html#VUID-vkCmdTraceRaysKHR-flags-03511
const auto shouldHaveMissGroup = flags & create_flag_e::NO_NULL_MISS_SHADERS;
if (shouldHaveMissGroup && !miss.range.buffer)
{
cb("bound pipeline indicates that traceRays command should have miss group, but SRayTracingSBT::hit::range::buffer is null!");
return false;
}

auto invalidBufferRegion = [&cb](const SStridedRange<const BufferType>& stRange, const char* groupName) -> bool
{
const auto& range = stRange.range;
const auto* const buffer = range.buffer.get();
if (!buffer)
return false;

if (!range.isValid())
{
cb("%s buffer range is not valid!",groupName);
return false;
}

return false;
};

if (invalidBufferRegion({.range=raygen},"Raygen Group")) return false;
if (invalidBufferRegion(miss,"Miss groups")) return false;
if (invalidBufferRegion(hit,"Hit groups")) return false;
if (invalidBufferRegion(callable,"Callable groups")) return false;

return true;
}

asset::SBufferRange<BufferType> raygen = {};
asset::SStridedRange<BufferType> miss = {}, hit = {}, callable = {};
};

inline const SCachedCreationParams& getCachedCreationParams() const { return m_params; }
inline const SCachedCreationParams& getCachedCreationParams() const { return m_params; }

protected:
explicit IRayTracingPipeline(PipelineLayoutType* layout, const SCachedCreationParams& cachedParams) :
IPipeline<PipelineLayoutType>(core::smart_refctd_ptr<PipelineLayoutType>(layout)),
m_params(cachedParams)
{}
protected:
explicit inline IRayTracingPipeline(PipelineLayoutType* layout, const SCachedCreationParams& cachedParams) :
IPipeline<PipelineLayoutType>(core::smart_refctd_ptr<PipelineLayoutType>(layout)), m_params(cachedParams) {}

SCachedCreationParams m_params;
SCachedCreationParams m_params;

};

Expand Down
6 changes: 3 additions & 3 deletions include/nbl/builtin/hlsl/indirect_commands.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct TraceRaysIndirectCommand_t
uint64_t callableShaderBindingTableAddress;
uint64_t callableShaderBindingTableSize;
uint64_t callableShaderBindingTableStride;
uint32_t width;
uint32_t height;
uint32_t depth;
uint32_t width;
uint32_t height;
uint32_t depth;
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/rwmc/ResolveParameters.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ResolveParameters
float NOverKappa;
};

ResolveParameters computeResolveParameters(float base, uint32_t sampleCount, float minReliableLuma, float kappa, uint32_t cascadeSize)
inline ResolveParameters computeResolveParameters(float base, uint32_t sampleCount, float minReliableLuma, float kappa, uint32_t cascadeSize)
{
ResolveParameters retval;
retval.lastCascadeIndex = cascadeSize - 1u;
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/ext/FullScreenTriangle/FullScreenTriangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct ProtoPipeline final
inline core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createPipeline(
const video::IGPUPipelineBase::SShaderSpecInfo& fragShader,
video::IGPUPipelineLayout* layout,
video::IGPURenderpass* renderpass,
const video::IGPURenderpass* renderpass,
const uint32_t subpassIx=0,
asset::SBlendParams blendParams = {},
const hlsl::SurfaceTransform::FLAG_BITS swapchainTransform=hlsl::SurfaceTransform::FLAG_BITS::IDENTITY_BIT
Expand Down
2 changes: 0 additions & 2 deletions include/nbl/ext/MitsubaLoader/CElementSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace nbl::ext::MitsubaLoader
{
class CGlobalMitsubaMetadata;

class CElementSampler : public IElement
{
public:
Expand Down
1 change: 1 addition & 0 deletions include/nbl/ext/MitsubaLoader/CElementSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class CElementSensor final : public IElement
};*/
union
{
CameraBase base;
PerspectivePinhole perspective;
PerspectiveThinLens thinlens;
Orthographic orthographic;
Expand Down
3 changes: 3 additions & 0 deletions include/nbl/system/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "nbl/system/DynamicFunctionCaller.h"
#include "nbl/system/SReadWriteSpinLock.h"

// printing and serialization
#include "nbl/system/to_string.h"

// files
#include "nbl/system/IFile.h"

Expand Down
7 changes: 4 additions & 3 deletions include/nbl/video/CVulkanCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,15 @@ inline VkPipelineBindPoint getVkPipelineBindPointFrom(asset::E_PIPELINE_BIND_POI
}
}

inline VkStridedDeviceAddressRegionKHR getVkStridedDeviceAddressRegion(const asset::SBufferRange<const IGPUBuffer>& range, uint32_t stride)
inline VkStridedDeviceAddressRegionKHR getVkStridedDeviceAddressRegion(const asset::SStridedRange<const IGPUBuffer>& stRange)
{
if (range.buffer.get() == nullptr)
const auto& range = stRange.range;
if (range.buffer.get()==nullptr)
return {};

return {
.deviceAddress = range.buffer->getDeviceAddress() + range.offset,
.stride = stride,
.stride = stRange.stride,
.size = range.size,
};
}
Expand Down
Loading
Loading