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 65 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
65 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
6884d45
Add non const computeDependants to IAsset and its child classes
May 16, 2025
2ac65f6
Refactor anyDependantDiscardedContents and discardDependantsContents
May 16, 2025
5c13a93
Remove impl_valid and rework SSpecializatioNValidationResult
May 20, 2025
9f43c02
Return Subgroup size to IPipelineBase
May 22, 2025
bae94c5
Fix missing bracket for getLayout
May 22, 2025
0d8fe94
Return Subgroup Size to every SShaderSpecInfo
May 22, 2025
4ed04c8
Fix stagePresence typo
May 22, 2025
7e2fd2c
Move clone_impl to private
May 22, 2025
c01392c
Implement getSpecInfoVec for ICPURayTracingPipeline
May 22, 2025
7b3c0ed
Fix getSpecInfoVec
May 22, 2025
96db32b
Implement ICPURayTracingPIpeline valid
May 22, 2025
98f3153
Fix ICPUSkeleton.h computeDependants
May 23, 2025
30f35af
Small fixes
May 23, 2025
2983ff0
Remove redundant final specifier
May 23, 2025
e218e77
Remove const so it can be cast to IAsset*
May 23, 2025
b58e486
Fix RenderpassIndependentPipeline
May 23, 2025
1f3a477
Fix SpirvIntrospector
May 23, 2025
d042f42
Add some utility function to IGPURayTracingPipeline SShaderGroup
May 23, 2025
c4de7c2
Fix debloat logic in logical device
May 23, 2025
f1fe089
Remove unused funciton in ILogicalDevice.cpp
May 23, 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
25 changes: 10 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,21 @@ 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 core::unordered_set<IAsset*> computeDependants() = 0;

virtual bool valid() const
{
//TODO(kevinyu): Temporary set this to true to make changes compile. Will revisit this later for each asset
return true;
}

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
26 changes: 16 additions & 10 deletions include/nbl/asset/ICPUAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,15 @@ 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::unordered_set<IAsset*> computeDependants() override
{
return {};
}

inline core::blake3_hash_t computeContentHash() const override
{
Expand Down Expand Up @@ -236,8 +244,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 +269,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 +371,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
25 changes: 11 additions & 14 deletions include/nbl/asset/ICPUAnimationLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,19 @@ 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() };
}

private:

template <typename Self>
requires(std::same_as<std::remove_cv_t<Self>, ICPUAnimationLibrary>)
static auto computeDependantsImpl(Self* self) {
using asset_ptr_t = std::conditional_t<std::is_const_v<Self>, const IAsset*, IAsset*>;
return core::unordered_set<asset_ptr_t>{ self->m_keyframeStorageBinding.buffer.get(), self->m_timestampStorageBinding.buffer.get(), self->m_animationStorageRange.buffer.get() };
}
};

}
Expand Down
15 changes: 9 additions & 6 deletions include/nbl/asset/ICPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ 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::unordered_set<IAsset*> computeDependants() override
{
return {};
}

inline core::blake3_hash_t computeContentHash() const override
{
Expand Down Expand Up @@ -113,11 +121,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
21 changes: 16 additions & 5 deletions include/nbl/asset/ICPUBufferView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ 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 computeDependantsImpl(this);
}

inline core::unordered_set<IAsset*> computeDependants() override
{
return computeDependantsImpl(this);
}

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

inline IAsset* getDependant_impl(const size_t ix) override
{
return m_buffer.get();
}
private:
template <typename Self>
requires(std::same_as<std::remove_cv_t<Self>, ICPUBufferView>)
static auto computeDependantsImpl(Self* self) {
using asset_ptr_t = std::conditional_t<std::is_const_v<Self>, const IAsset*, IAsset*>;
return core::unordered_set<asset_ptr_t>{ self->m_buffer.get() };
}
};

}
Expand Down
77 changes: 46 additions & 31 deletions include/nbl/asset/ICPUComputePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,77 @@


#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);
}

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

//!
inline size_t getDependantCount() const override {return 2;}
//!
inline core::unordered_set<const IAsset*> computeDependants() const override
{
return computeDependantsImpl(this);
}

inline core::unordered_set<IAsset*> computeDependants() override
{
return computeDependantsImpl(this);
}

// provide default arg
inline IPipelineBase::SShaderSpecInfo getSpecInfo() const {return base_t::getSpecInfo(hlsl::ShaderStage::ESS_COMPUTE);}
inline std::span<const SShaderSpecInfo> getSpecInfo(hlsl::ShaderStage stage) const override
{
if (stage==hlsl::ShaderStage::ESS_COMPUTE)
return {&m_specInfo,1};
return {};
}

inline bool valid() const override
{
if (!m_layout) return false;
Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming May 13, 2025

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;

base_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const override
{
return new ICPUComputePipeline(std::move(layout));
}

inline IAsset* getDependant_impl(const size_t ix) override

private:
SShaderSpecInfo m_specInfo;

inline core::smart_refctd_ptr<base_t> clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout, uint32_t depth) const override final
{
if (ix!=0)
return m_stages[0].shader.get();
return const_cast<ICPUPipelineLayout*>(m_layout.get());
auto newPipeline = new ICPUComputePipeline(layout.get());
newPipeline->m_specInfo = m_specInfo.clone(depth);
return core::smart_refctd_ptr<base_t>(newPipeline, core::dont_grab);
}

inline int8_t stageToIndex(const hlsl::ShaderStage stage) const override
{
return stage!=hlsl::ShaderStage::ESS_COMPUTE ? (-1):0;
explicit ICPUComputePipeline(const ICPUPipelineLayout* layout):
base_t(layout, {})
{}

template <typename Self>
requires(std::same_as<std::remove_cv_t<Self>, ICPUComputePipeline>)
static auto computeDependantsImpl(Self* self) {
using asset_ptr_t = std::conditional_t<std::is_const_v<Self>, const IAsset*, IAsset*>;
return core::unordered_set<asset_ptr_t>{ self->m_layout.get(), self->m_specInfo.shader.get() };
}
};

Expand Down
6 changes: 3 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,12 @@ 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;
core::unordered_set<IAsset*> computeDependants() override;

protected:
virtual ~ICPUDescriptorSet() = default;

IAsset* getDependant_impl(size_t ix) override;

private:

Expand Down
29 changes: 24 additions & 5 deletions include/nbl/asset/ICPUDescriptorSetLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,34 @@ 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
{
return computeDependantsImpl(this);
}

core::unordered_set<IAsset*> computeDependants() override
{
return computeDependantsImpl(this);
}

protected:
virtual ~ICPUDescriptorSetLayout() = default;

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

private:
template <typename Self>
requires(std::same_as<std::remove_cv_t<Self>, ICPUDescriptorSetLayout>)
static auto computeDependantsImpl(Self* self) {
using asset_ptr_t = std::conditional_t<std::is_const_v<Self>, const IAsset*, IAsset*>;
core::unordered_set<asset_ptr_t> dependants;
if (!self->m_immutableSamplers) return dependants;
for (const auto& sampler: *self->m_immutableSamplers)
{
dependants.insert(sampler.get());
}
return dependants;
}

};

}
Expand Down
Loading