Skip to content

Rt pipeline asset conversion #911

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
38 changes: 27 additions & 11 deletions include/nbl/asset/ICPURayTracingPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ class ICPURayTracingPipeline final : public ICPUPipeline<IRayTracingPipeline<ICP
core::vector<SShaderSpecInfo> intersections;
};

static core::smart_refctd_ptr<ICPURayTracingPipeline> create(const ICPUPipelineLayout* layout)
static core::smart_refctd_ptr<ICPURayTracingPipeline> create(ICPUPipelineLayout* layout)
{
auto retval = new ICPURayTracingPipeline(layout);
return core::smart_refctd_ptr<ICPURayTracingPipeline>(retval,core::dont_grab);
}



constexpr static inline auto AssetType = ET_RAYTRACING_PIPELINE;
inline E_TYPE getAssetType() const override { return AssetType; }

Expand Down Expand Up @@ -83,12 +81,13 @@ class ICPURayTracingPipeline final : public ICPUPipeline<IRayTracingPipeline<ICP
return nullptr;
}


inline bool valid() const override final
{
if (!m_layout) return false;
if (!m_layout->valid()) return false;
if (m_raygen.valid() == SShaderSpecInfo::INVALID_SPEC_INFO) return false;
if (m_hitGroups.anyHits.size() != m_hitGroups.closestHits.size()) return false;
if (m_hitGroups.anyHits.size() != m_hitGroups.intersections.size()) return false;
return true;
}

Expand All @@ -102,7 +101,23 @@ class ICPURayTracingPipeline final : public ICPUPipeline<IRayTracingPipeline<ICP
return m_params;
}

inline uint32_t getMissGroupCount() const
{
return m_misses.size();
}

inline uint32_t getHitGroupCount() const
{
return m_hitGroups.anyHits.size();
}

inline uint32_t getCallableGroupCount() const
{
return m_callables.size();
}

protected:
using base_t::base_t;
virtual ~ICPURayTracingPipeline() = default;

private:
Expand All @@ -112,18 +127,19 @@ class ICPURayTracingPipeline final : public ICPUPipeline<IRayTracingPipeline<ICP
SHitGroupSpecInfos m_hitGroups;
core::vector<SShaderSpecInfo> m_callables;

explicit ICPURayTracingPipeline(const ICPUPipelineLayout* layout)
explicit ICPURayTracingPipeline(ICPUPipelineLayout* layout)
: base_t(layout, {})
{}

inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
{
if (!visit(m_raygen.shader.get()) return;
for (const auto& missInfo : self->m_misses) if (!visit(missInfo.shader.get())) return;
for (const auto& anyHitInfo : self->m_hitGroups.anyHits) if (!visit(anyHitInfo.shader.get())) return;
for (const auto& closestHitInfo : self->m_hitGroups.closestHits) if (!visit(closestHitInfo.shader.get())) return;
for (const auto& intersectionInfo : self->m_hitGroups.intersections) if (!visit(intersectionInfo.shader.get())) return;
for (const auto& callableInfo : self->m_callables) if(!visit(callableInfo.shader.get())) return;
if (!visit(m_layout.get())) return;
if (!visit(m_raygen.shader.get())) return;
for (const auto& missInfo : m_misses) if (!visit(missInfo.shader.get())) return;
for (const auto& anyHitInfo : m_hitGroups.anyHits) if (!visit(anyHitInfo.shader.get())) return;
for (const auto& closestHitInfo : m_hitGroups.closestHits) if (!visit(closestHitInfo.shader.get())) return;
for (const auto& intersectionInfo : m_hitGroups.intersections) if (!visit(intersectionInfo.shader.get())) return;
for (const auto& callableInfo : m_callables) if(!visit(callableInfo.shader.get())) return;
}

inline core::smart_refctd_ptr<base_t> clone_impl(core::smart_refctd_ptr<ICPUPipelineLayout>&& layout, uint32_t depth) const override final
Expand Down
26 changes: 13 additions & 13 deletions include/nbl/asset/IRayTracingPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ namespace nbl::asset
class IRayTracingPipelineBase : public virtual core::IReferenceCounted
{
public:
struct SCachedCreationParams final
{
uint32_t maxRecursionDepth : 6 = 0;
uint32_t dynamicStackSize : 1 = false;
};
};

template<typename PipelineLayoutType>
class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTracingPipelineBase
{
public:

#define base_flag(F) static_cast<uint64_t>(IPipelineBase::FLAGS::F)
enum class CreationFlags : uint64_t
{
Expand All @@ -43,7 +31,19 @@ class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTra
ALLOW_MOTION = 1<<20,
};
#undef base_flag
using FLAGS = CreationFlags;

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

template<typename PipelineLayoutType>
class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTracingPipelineBase
{
public:

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

Expand Down
4 changes: 4 additions & 0 deletions include/nbl/video/IGPUComputePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class IGPUComputePipeline : public IGPUPipeline<asset::IComputePipeline<const IG
return {};
}

inline core::bitflag<FLAGS>& getFlags() { return flags; }

inline core::bitflag<FLAGS> getFlags() const { return flags; }

const IGPUPipelineLayout* layout = nullptr;
// TODO: Could guess the required flags from SPIR-V introspection of declared caps
core::bitflag<FLAGS> flags = FLAGS::NONE;
Expand Down
4 changes: 4 additions & 0 deletions include/nbl/video/IGPUGraphicsPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class IGPUGraphicsPipeline : public IGPUPipeline<asset::IGraphicsPipeline<const
return stages;
}

inline core::bitflag<FLAGS>& getFlags() { return flags; }

inline core::bitflag<FLAGS> getFlags() const { return flags; }

const IGPUPipelineLayout* layout = nullptr;
SShaderSpecInfo vertexShader;
SShaderSpecInfo tesselationControlShader;
Expand Down
18 changes: 9 additions & 9 deletions include/nbl/video/IGPURayTracingPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c

struct SCreationParams : public SPipelineCreationParams<const IGPURayTracingPipeline>
{
using FLAGS = pipeline_t::FLAGS;
using FLAGS = IRayTracingPipelineBase::CreationFlags;

struct SShaderGroupsParams
{
Expand All @@ -45,8 +45,6 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c
SShaderGroupsParams shaderGroups;

SCachedCreationParams cached = {};
// TODO: Could guess the required flags from SPIR-V introspection of declared caps
core::bitflag<FLAGS> flags = FLAGS::NONE;

inline SSpecializationValidationResult valid() const
{
Expand Down Expand Up @@ -76,7 +74,7 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c
}

// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-flags-03470
if (flags.hasFlags(FLAGS::NO_NULL_ANY_HIT_SHADERS) && !shaderGroup.anyHit.shader)
if (cached.flags.hasFlags(FLAGS::NO_NULL_ANY_HIT_SHADERS) && !shaderGroup.anyHit.shader)
return {};

if (shaderGroup.anyHit.shader)
Expand All @@ -86,7 +84,7 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c
}

// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-flags-03471
if (flags.hasFlags(FLAGS::NO_NULL_CLOSEST_HIT_SHADERS) && !shaderGroup.intersection.shader)
if (cached.flags.hasFlags(FLAGS::NO_NULL_CLOSEST_HIT_SHADERS) && !shaderGroup.intersection.shader)
return {};
}

Expand Down Expand Up @@ -137,6 +135,10 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c
return stages;
}

inline core::bitflag<FLAGS>& getFlags() { return cached.flags; }

inline core::bitflag<FLAGS> getFlags() const { return cached.flags; }

};

struct SShaderGroupHandle
Expand All @@ -153,7 +155,7 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c
uint16_t intersection;
};

inline core::bitflag<SCreationParams::FLAGS> getCreationFlags() const { return m_flags; }
inline core::bitflag<SCreationParams::FLAGS> getCreationFlags() const { return getCachedCreationParams().flags; }

// Vulkan: const VkPipeline*
virtual const void* getNativeHandle() const = 0;
Expand All @@ -170,13 +172,11 @@ class IGPURayTracingPipeline : public IGPUPipeline<asset::IRayTracingPipeline<c
virtual uint16_t getDefaultStackSize() const = 0;

protected:
IGPURayTracingPipeline(const SCreationParams& params) : IGPUPipeline(core::smart_refctd_ptr<const ILogicalDevice>(params.layout->getOriginDevice()), params.layout, params.cached),
m_flags(params.flags)
IGPURayTracingPipeline(const SCreationParams& params) : IGPUPipeline(core::smart_refctd_ptr<const ILogicalDevice>(params.layout->getOriginDevice()), params.layout, params.cached)
{}

virtual ~IGPURayTracingPipeline() = default;

const core::bitflag<SCreationParams::FLAGS> m_flags;
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/video/ILogicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
}
}
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkComputePipelineCreateInfo.html#VUID-VkComputePipelineCreateInfo-flags-07985
else if (ci.basePipelineIndex < -1 || ci.basePipelineIndex >= i || ci.basePipelineIndex >= 0 && !params[ci.basePipelineIndex].flags.hasFlags(AllowDerivativesFlag))
else if (ci.basePipelineIndex < -1 || ci.basePipelineIndex >= i || ci.basePipelineIndex >= 0 && !params[ci.basePipelineIndex].getFlags().hasFlags(AllowDerivativesFlag))
{
NBL_LOG_ERROR("Invalid basePipeline was specified (params[%d])", i);
return {};
Expand Down
16 changes: 16 additions & 0 deletions include/nbl/video/asset_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "nbl/video/IGPUAccelerationStructure.h"
#include "nbl/asset/ICPUPolygonGeometry.h"
#include "nbl/video/IGPUPolygonGeometry.h"
#include "nbl/asset/ICPURayTracingPipeline.h"
#include "nbl/video/IGPURayTracingPipeline.h"


namespace nbl::video
Expand Down Expand Up @@ -244,6 +246,20 @@ struct asset_traits<asset::ICPUPolygonGeometry>
};


template<>
struct asset_traits<asset::ICPURayTracingPipeline>
{
// the asset type
using asset_t = asset::ICPURayTracingPipeline;
// Depends on shader and layout
constexpr static inline bool HasChildren = true;
// the video type
using video_t = IGPURayTracingPipeline;
// lookup type
using lookup_t = const video_t*;
};


/* TODO
template<>
struct asset_traits<asset::ICPUFramebuffer>;
Expand Down
2 changes: 2 additions & 0 deletions include/nbl/video/utilities/CAssetConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CAssetConverter : public core::IReferenceCounted
asset::ICPUPipelineLayout,
asset::ICPUPipelineCache,
asset::ICPUComputePipeline,
asset::ICPURayTracingPipeline,
asset::ICPURenderpass,
asset::ICPUGraphicsPipeline,
asset::ICPUDescriptorSet,
Expand Down Expand Up @@ -690,6 +691,7 @@ class CAssetConverter : public core::IReferenceCounted
bool operator()(lookup_t<asset::ICPUPipelineLayout>);
bool operator()(lookup_t<asset::ICPUPipelineCache>);
bool operator()(lookup_t<asset::ICPUComputePipeline>);
bool operator()(lookup_t<asset::ICPURayTracingPipeline>);
bool operator()(lookup_t<asset::ICPURenderpass>);
bool operator()(lookup_t<asset::ICPUGraphicsPipeline>);
bool operator()(lookup_t<asset::ICPUDescriptorSet>);
Expand Down
2 changes: 1 addition & 1 deletion src/nbl/video/CVulkanLogicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ template<typename VkPipelineCreateInfo_t, typename SCreationParams>
void initPipelineCreateInfo(VkPipelineCreateInfo_t* vk_info, const SCreationParams& info)
{
// the new flags type (64bit) is only available with maintenance5
vk_info->flags = static_cast<VkPipelineCreateFlags>(info.flags.value);
vk_info->flags = static_cast<VkPipelineCreateFlags>(info.getFlags().value);
vk_info->layout = static_cast<const CVulkanPipelineLayout*>(info.layout)->getInternalObject();
if (info.isDerivative())
{
Expand Down
4 changes: 2 additions & 2 deletions src/nbl/video/ILogicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,8 @@ bool ILogicalDevice::createRayTracingPipelines(IGPUPipelineCache* const pipeline

for (const auto& param : params)
{
const bool skipAABBs = bool(param.flags & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_AABBS);
const bool skipBuiltin = bool(param.flags & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_BUILT_IN_PRIMITIVES);
const bool skipAABBs = bool(param.getFlags() & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_AABBS);
const bool skipBuiltin = bool(param.getFlags() & IGPURayTracingPipeline::SCreationParams::FLAGS::SKIP_BUILT_IN_PRIMITIVES);

if (!features.rayTracingPipeline)
{
Expand Down
Loading
Loading