Skip to content

Rework pipeline shader spec info #871

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 45 commits into
base: stagesless_shaders
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
dc41722
Implement mutable shader spec info
Apr 28, 2025
7fe3431
Rework IGPUGraphicsPipeline
Apr 28, 2025
8dbe9c7
Rework IGPUComputePipeline.h
Apr 28, 2025
436e6e1
Remove default value for mutable template parameter
Apr 29, 2025
2e367d1
Implement IGPUPipeline and refactor SCreationParams
May 5, 2025
a9d5aaf
Fix gpu graphics pipeline stage validation
May 5, 2025
51b69c1
Fix compute pipeline
May 5, 2025
fa759be
Implement cpu graphics pipeline validation
May 5, 2025
de8813f
Implement compute pipeline validation
May 5, 2025
37ab1ce
Add FLAGS alias
May 7, 2025
a0ecd50
Fix clone_impl to return smart pointer
May 7, 2025
7890981
Add final decoration to ICPUComputePipeline
May 7, 2025
9a14aa1
Make cpu pipeline constructor private
May 7, 2025
9bb9d14
Add layout validation to compute pipeline validation
May 7, 2025
bcb096f
Refactor getSpecInfo
May 7, 2025
278eb71
Move stageToIndex and indexToStage
May 7, 2025
68bbcff
Add constraint to template parameter of ICPUPipeline and IGPUPipeline
May 7, 2025
8ec0415
Rework IGPUPipeline SSpecConstantValue
May 7, 2025
57136e8
Rework SShaderSpecInfo for ICPUPIpeline
May 7, 2025
7983e62
Move cloneSpecInfo into SShaderSpecInfo
May 7, 2025
071f1eb
Remove valid virtual function from ICPUPipeline to IAsset
May 7, 2025
b8f8ba0
Remove getShaders from SShaderSpecInfo
May 7, 2025
f661366
Rename isValidStagePresence to hasRequiredStages
May 7, 2025
8c10cbd
Rework IGPUGraphicsPipeline to have individual shaderSpecInfo per stages
May 7, 2025
71056f2
Add IGPUPipelineLayout to IGPUPipeline
May 7, 2025
11255d4
Implement ICPURayTracingPipeline
May 8, 2025
8c549fb
Add computeDependants virtual function to IAsset
May 12, 2025
01c4ac6
Implement computeDependants for ICPUComputePipeline
May 12, 2025
d9efa1a
Implement compute pipeline base
May 12, 2025
0b791b5
Fix discardDependantsContents and anyDependantDiscardedContents to us…
May 13, 2025
e8e43b1
Add Ray Tracing Pipeline Asset to IAsset
May 13, 2025
b9db6aa
Remove unnecessary specInfo assignment in clone method
May 13, 2025
2ae6f78
Move subgroup argument to computePipelineBase
May 13, 2025
8de6d9a
Remove getDependantCount and getDependant and getDependant_impl from …
May 13, 2025
3f65992
Implement computeDependants for ICPUGraphicsPIpeline
May 13, 2025
89b8daa
Implement computeDependants for ICPURayTracingPIpeline
May 13, 2025
434d73e
Fix IGraphicsPIpeline constructor
May 13, 2025
1cd1771
Remove SUBGROUP_SIZE from IPIpeline
May 13, 2025
5823a84
Refactor IRayTracingPipeline to use new SShaderSpecInfo scheme
May 13, 2025
10ec458
Remove Subgroup related argument from IGPUPipeline
May 13, 2025
39904f7
Refactor IGPUComputePipeline to use IComputePipeline
May 13, 2025
2ce032f
Refactor IGPURayTracingPipeline to use new SShaderSpecInfo scheme
May 13, 2025
058657b
Restore deleted comments
May 13, 2025
a3905be
Merge branch 'stagesless_shaders' into rework_pipeline_shader_spec_info
May 14, 2025
59fcc93
Implement all computeDependants for IAssets
May 15, 2025
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
19 changes: 4 additions & 15 deletions include/nbl/asset/IAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class IAsset : virtual public core::IReferenceCounted
ET_COMPUTE_PIPELINE = 1ull<<20, //!< asset::ICPUComputePipeline
ET_PIPELINE_CACHE = 1ull<<21, //!< asset::ICPUPipelineCache
ET_SCENE = 1ull<<22, //!< reserved, to implement later
ET_RAYTRACING_PIPELINE = 1ull << 23, //!< asset::ICPURayTracingPipeline
ET_IMPLEMENTATION_SPECIFIC_METADATA = 1ull<<31u, //!< lights, etc.
//! Reserved special value used for things like terminating lists of this enum

Expand Down Expand Up @@ -155,27 +156,15 @@ class IAsset : virtual public core::IReferenceCounted
//!
inline bool isMutable() const {return m_mutable;}

//!
virtual size_t getDependantCount() const = 0;
inline IAsset* getDependant(const size_t ix)
{
if (ix<getDependantCount())
return getDependant_impl(ix);
return nullptr;
}
inline const IAsset* getDependant(const size_t ix) const
{
IAsset* const retval = const_cast<IAsset*>(this)->getDependant(ix);
return retval;
}
virtual core::unordered_set<const IAsset*> computeDependants() const = 0;

virtual bool valid() const = 0;

protected:
inline IAsset() = default;
//! Pure virtual destructor to ensure no instantiation
NBL_API2 virtual ~IAsset() = 0;

virtual IAsset* getDependant_impl(const size_t ix) = 0;

private:
friend IAssetManager;
bool m_mutable = true;
Expand Down
21 changes: 11 additions & 10 deletions include/nbl/asset/ICPUAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
}

// Do not report anything as a dependant, we'll simply drop the data instead of discarding its contents
inline size_t getDependantCount() const override {return 0;}
inline core::unordered_set<const IAsset*> computeDependants() const override
{
return {};
}

inline core::blake3_hash_t computeContentHash() const override
{
Expand Down Expand Up @@ -236,8 +239,6 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
protected:
virtual ~ICPUBottomLevelAccelerationStructure() = default;

inline IAsset* getDependant_impl(const size_t ix) override {return nullptr;}

inline void discardContent_impl() override
{
m_triangleGeoms = nullptr;
Expand All @@ -263,8 +264,13 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
//
ICPUTopLevelAccelerationStructure() = default;

//
inline size_t getDependantCount() const override {return m_instances->size();}
inline core::unordered_set<const IAsset*> computeDependants() const override
{
core::unordered_set<const IAsset*> dependants;
for (const auto& instance : m_instances)
dependants.insert(instance.getBase().blas.get());
return dependants;
}

//
inline auto& getBuildRangeInfo()
Expand Down Expand Up @@ -360,11 +366,6 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
protected:
virtual ~ICPUTopLevelAccelerationStructure() = default;

inline IAsset* getDependant_impl(const size_t ix) override
{
return m_instances->operator[](ix).getBase().blas.get();
}

private:
core::smart_refctd_dynamic_array<PolymorphicInstance> m_instances = nullptr;
hlsl::acceleration_structures::top_level::BuildRangeInfo m_buildRangeInfo;
Expand Down
16 changes: 2 additions & 14 deletions include/nbl/asset/ICPUAnimationLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,9 @@ class ICPUAnimationLibrary final : public IAnimationLibrary<ICPUBuffer>, public
constexpr static inline auto AssetType = ET_ANIMATION_LIBRARY;
inline E_TYPE getAssetType() const override { return AssetType; }

inline size_t getDependantCount() const override {return 3;}

protected:
inline IAsset* getDependant_impl(const size_t ix) override
inline core::unordered_set<const IAsset*> computeDependants() const override
{
switch (ix)
{
case 0:
return m_keyframeStorageBinding.buffer.get();
case 1:
return m_timestampStorageBinding.buffer.get();
default:
break;
}
return m_animationStorageRange.buffer.get();
return { m_keyframeStorageBinding.buffer.get(), m_timestampStorageBinding.buffer.get(), m_animationStorageRange.buffer.get() };
}
};

Expand Down
10 changes: 4 additions & 6 deletions include/nbl/asset/ICPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
constexpr static inline auto AssetType = ET_BUFFER;
inline IAsset::E_TYPE getAssetType() const override final { return AssetType; }

inline size_t getDependantCount() const override { return 0; }
inline core::unordered_set<const IAsset*> computeDependants() const override
{
return {};
}

inline core::blake3_hash_t computeContentHash() const override
{
Expand Down Expand Up @@ -113,11 +116,6 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
}

protected:
inline IAsset* getDependant_impl(const size_t ix) override
{
return nullptr;
}

inline void discardContent_impl() override
{
if (m_data)
Expand Down
9 changes: 4 additions & 5 deletions include/nbl/asset/ICPUBufferView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class ICPUBufferView : public IBufferView<ICPUBuffer>, public IAsset
constexpr static inline auto AssetType = ET_BUFFER_VIEW;
inline IAsset::E_TYPE getAssetType() const override { return AssetType; }

inline size_t getDependantCount() const override {return 1;}
inline core::unordered_set<const IAsset*> computeDependants() const override
{
return { m_buffer.get() };
}

ICPUBuffer* getUnderlyingBuffer()
{
Expand All @@ -51,10 +54,6 @@ class ICPUBufferView : public IBufferView<ICPUBuffer>, public IAsset
protected:
virtual ~ICPUBufferView() = default;

inline IAsset* getDependant_impl(const size_t ix) override
{
return m_buffer.get();
}
};

}
Expand Down
73 changes: 39 additions & 34 deletions include/nbl/asset/ICPUComputePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,68 @@


#include "nbl/asset/ICPUPipeline.h"
#include "nbl/asset/IComputePipeline.h"


namespace nbl::asset
{

//! CPU Version of Compute Pipeline
class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
class ICPUComputePipeline final : public ICPUPipeline<IComputePipeline<ICPUPipelineLayout>>
{
using base_t = ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>;
using base_t = ICPUPipeline<IComputePipeline<ICPUPipelineLayout>>;

public:
struct SCreationParams final : IPipeline<ICPUPipelineLayout>::SCreationParams
{
SShaderSpecInfo shader;
};
static core::smart_refctd_ptr<ICPUComputePipeline> create(const SCreationParams& params)

static core::smart_refctd_ptr<ICPUComputePipeline> create(const ICPUPipelineLayout* layout)
{
if (!params.layout)
return nullptr;
auto retval = new ICPUComputePipeline(core::smart_refctd_ptr<const ICPUPipelineLayout>(params.layout));
if (!retval->setSpecInfo(params.shader))
{
retval->drop();
return nullptr;
}
auto retval = new ICPUComputePipeline(layout);
return core::smart_refctd_ptr<ICPUComputePipeline>(retval,core::dont_grab);
}

inline core::smart_refctd_ptr<base_t> clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout, uint32_t depth) const override final
{
auto newPipeline = new ICPUComputePipeline(layout.get());
newPipeline->m_specInfo = m_specInfo.clone(depth);
return core::smart_refctd_ptr<base_t>(newPipeline, core::dont_grab);
}

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

//!
inline size_t getDependantCount() const override {return 2;}

// provide default arg
inline IPipelineBase::SShaderSpecInfo getSpecInfo() const {return base_t::getSpecInfo(hlsl::ShaderStage::ESS_COMPUTE);}

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

base_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const override
//!
virtual core::unordered_set<const IAsset*> computeDependants() const override
{
return new ICPUComputePipeline(std::move(layout));
return {m_layout.get(), m_specInfo.shader.get()};
}
inline IAsset* getDependant_impl(const size_t ix) override

inline virtual std::span<const SShaderSpecInfo> getSpecInfo(hlsl::ShaderStage stage) const override final
{
if (ix!=0)
return m_stages[0].shader.get();
return const_cast<ICPUPipelineLayout*>(m_layout.get());
if (stage==hlsl::ShaderStage::ESS_COMPUTE && isMutable())
return {&m_specInfo,1};
return {};
}

inline int8_t stageToIndex(const hlsl::ShaderStage stage) const override

inline virtual bool valid() const override final
{
return stage!=hlsl::ShaderStage::ESS_COMPUTE ? (-1):0;
if (!m_layout) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layout valid check?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (!m_layout->valid()) return false;
return m_specInfo.valid();
}

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


private:
SShaderSpecInfo m_specInfo;

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

};

}
Expand Down
5 changes: 2 additions & 3 deletions include/nbl/asset/ICPUDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSet
constexpr static inline auto AssetType = ET_DESCRIPTOR_SET;
inline E_TYPE getAssetType() const override {return AssetType;}

inline size_t getDependantCount() const override {return m_layout->getTotalBindingCount()+1;}

//
inline ICPUDescriptorSetLayout* getLayout()
{
Expand Down Expand Up @@ -79,10 +77,11 @@ class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSet

core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override;

core::unordered_set<const IAsset*> computeDependants() const override;

protected:
virtual ~ICPUDescriptorSet() = default;

IAsset* getDependant_impl(size_t ix) override;

private:

Expand Down
15 changes: 10 additions & 5 deletions include/nbl/asset/ICPUDescriptorSetLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ class ICPUDescriptorSetLayout : public IDescriptorSetLayout<ICPUSampler>, public
constexpr static inline auto AssetType = ET_DESCRIPTOR_SET_LAYOUT;
inline E_TYPE getAssetType() const override { return AssetType; }

inline size_t getDependantCount() const override {return m_immutableSamplers ? m_immutableSamplers->size():0;}
core::unordered_set<const IAsset*> computeDependants() const override
{
if (!m_immutableSamplers) return {};
core::unordered_set<const IAsset*> dependants;
for (const auto& sampler: m_immutableSamplers)
{
dependants.insert(sampler.get());
}
return dependants;
}

protected:
virtual ~ICPUDescriptorSetLayout() = default;

inline IAsset* getDependant_impl(const size_t ix) override
{
return m_immutableSamplers->operator[](ix).get();
}
};

}
Expand Down
Loading