Skip to content

IShader, no more conversions, stage is now part of spec info. #839

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 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6fd47aa
first commit that turns IGPUShader and ICPUShader into one IShader an…
Feb 21, 2025
92a58ea
Asset Converter should work after this change
Feb 21, 2025
7e3d71c
correct the eggregious typos, add TODOs
Feb 21, 2025
2370636
touch up the Vulkan Pipelines to not hold onto shaders
Feb 21, 2025
38dd6e5
fix more typos, and add one more TODO
Feb 21, 2025
499f57b
Create pipeline now use spir-v directly
Mar 27, 2025
40d744e
Remove constructor. this overload conflict with another constructor.
Mar 27, 2025
e7beb7e
FIx spirv introspector
Mar 27, 2025
782bf4c
Fix CComputeBlit to use IShader
Mar 27, 2025
a2f7d91
Merge branch 'master' into stagesless_shaders
Mar 27, 2025
82dc575
Fix asset converter to support the new IShader
Mar 27, 2025
19b0c21
Fix NSC to use AssetMetadata to get shader stage
Mar 28, 2025
7be8def
use std::string_view for shader entry points
Apr 1, 2025
1a8ea98
remove getObjectDebugName from IShader
Apr 1, 2025
a428d4d
disable IShader patching
Apr 1, 2025
8028703
Disable IShader patching
Apr 1, 2025
36e6f33
Fix by adding static to getLoogingLabel
Apr 1, 2025
7c548b7
Enable HLSLMetadata to support multiple shader stages
Apr 1, 2025
64875ac
Expose more option in ISPIRVOptimizer
Apr 2, 2025
94cc246
Implement ISPIRVDebloater
Apr 2, 2025
565fd4a
expose dead constant elim optimization in ISPIRVOptimizer
Apr 2, 2025
08d4e70
Expose more options in ISPIRVOptimizer
Apr 2, 2025
0bf0601
make the noun plural in optimization pass
Apr 2, 2025
6ddea53
add more optimization pass to spirv debloater
Apr 2, 2025
31724ef
improve optimization name for trim capabilities. plural instead of si…
Apr 2, 2025
d5c6081
Add missing comma
Apr 7, 2025
cfb4bd1
Rework ISPIRVDebloater algorithm
Apr 7, 2025
48055b6
Move SPIRV_VERSION as constant
Apr 7, 2025
690cbb5
Validate entry points parameter
Apr 7, 2025
52c03a8
Handle unsupported execution model failure case
Apr 7, 2025
550dc3f
Fix wrong error log message placement
Apr 7, 2025
24d7f33
Refactor ISPIRVDebloater::Result naming and add operator bool
Apr 7, 2025
80297ed
Set default value for logger
Apr 7, 2025
247c7c3
Add comparison operator to EntryPoint so it can be inserterd to set
Apr 7, 2025
488d383
Implement more ergonomic overload
Apr 7, 2025
b1068a5
Move spirv debloater to ILogicalDevice
Apr 8, 2025
3e1b375
More fixes on moving ISPIRVDebloater to ILogicalDevice
Apr 8, 2025
c5b252b
Add agressive dce to optimization pass
Apr 8, 2025
9c9a742
Initialize m_spirvDebloater
Apr 8, 2025
78d20c2
Add dead member removal to the optimization pass.
Apr 8, 2025
5b119de
Add more optimization pass
Apr 9, 2025
a508eb1
Use core::set for entryPoints in debloat
Apr 11, 2025
f0eef49
improve naming from shaderStage to stage
Apr 11, 2025
d226301
Improve spirv optimizer passes mapping logic
Apr 11, 2025
7c43412
Remove spirv override argument
Apr 11, 2025
419016b
Add comment about spirv layout
Apr 11, 2025
7258912
Fix debloat by adding const to return type
Apr 11, 2025
2b85156
Pass reserved vector instead of pointer to shader when debloating
Apr 11, 2025
1670efa
Merge branch 'master' into stagesless_shaders
Apr 11, 2025
da73442
Some fixes to make nabla compile after merging with ray tracing pipel…
Apr 14, 2025
0ec9cf1
run debloat shaders on each module instead of each entry point
Apr 14, 2025
d18de3b
Refactor ray tracing to use SPIRVDebloater
Apr 14, 2025
597516f
Remove unfoundEntryPoint and use a counter to make it more efficient
Apr 14, 2025
9f3f823
print debug information in spirv debloater in debug mode
Apr 14, 2025
2e89fa2
Fix spirvdebloater when debloat is not needed
Apr 15, 2025
4d5af4e
Fix optimizer to remove array maps.
Apr 16, 2025
977c92e
Add inline modifier
Apr 16, 2025
7675c23
Validate that shader is spirv
Apr 16, 2025
716330c
Return null shader when spirv is null instead of shader that contain …
Apr 16, 2025
44a09a9
Fix some logic regarding entry point collection when debloating
Apr 16, 2025
4295b84
Fix SPIRVIntrospector use IShader
Apr 16, 2025
eda3310
Add assert that reserve is working for outShaders
Apr 16, 2025
4e8f41c
Remove IShader as template parameter for IRayTracingPipeline
Apr 16, 2025
2560e3e
Merge branch 'master' into stagesless_shaders
Apr 20, 2025
2b90640
Ray Tracing Pipeline interface does not need ShaderType
Apr 21, 2025
659ac5a
Add validate option to skip block layout validation
Apr 23, 2025
def49f7
Set pipeline name from shader
Apr 23, 2025
8d608bd
Merge branch 'master' into stagesless_shaders
May 13, 2025
7d6ede4
Fix outputReverseMap so it can hold IShader
May 13, 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
2 changes: 1 addition & 1 deletion include/nbl/asset/IAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class IAsset : virtual public core::IReferenceCounted
ET_SKELETON = 1ull<<7, //!< asset::ICPUSkeleton
ET_ANIMATION_LIBRARY = 1ull<<8, //!< asset::ICPUAnimationLibrary
ET_PIPELINE_LAYOUT = 1ull<<9, //!< asset::ICPUPipelineLayout
ET_SHADER = 1ull<<10, //!< asset::ICPUShader
ET_SHADER = 1ull<<10, //!< asset::IShader
ET_RENDERPASS_INDEPENDENT_PIPELINE = 1ull<<12, //!< asset::ICPURenderpassIndependentPipeline
ET_RENDERPASS = 1ull<<13, //!< asset::ICPURenderpass
ET_FRAMEBUFFER = 1ull<<14, //!< asset::ICPUFramebuffer
Expand Down
9 changes: 4 additions & 5 deletions include/nbl/asset/ICPUComputePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
public:
struct SCreationParams final : IPipeline<ICPUPipelineLayout>::SCreationParams
{
ICPUShader::SSpecInfo shader;
SShaderSpecInfo shader;
};
static core::smart_refctd_ptr<ICPUComputePipeline> create(const SCreationParams& params)
{
Expand All @@ -41,8 +41,7 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
inline size_t getDependantCount() const override {return 2;}

// provide default arg
inline IShader::SSpecInfo<ICPUShader> getSpecInfo() {return base_t::getSpecInfo(ICPUShader::E_SHADER_STAGE::ESS_COMPUTE);}
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo() const {return base_t::getSpecInfo(ICPUShader::E_SHADER_STAGE::ESS_COMPUTE);}
inline IPipelineBase::SShaderSpecInfo getSpecInfo() const {return base_t::getSpecInfo(hlsl::ShaderStage::ESS_COMPUTE);}

protected:
using base_t::base_t;
Expand All @@ -60,9 +59,9 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
return const_cast<ICPUPipelineLayout*>(m_layout.get());
}

inline int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const override
inline int8_t stageToIndex(const hlsl::ShaderStage stage) const override
{
return stage!=ICPUShader::E_SHADER_STAGE::ESS_COMPUTE ? (-1):0;
return stage!=hlsl::ShaderStage::ESS_COMPUTE ? (-1):0;
}
};

Expand Down
10 changes: 5 additions & 5 deletions include/nbl/asset/ICPUGraphicsPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
namespace nbl::asset
{

class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPipelineLayout,ICPUShader,ICPURenderpass>,5u>
class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPipelineLayout,ICPURenderpass>,5u>
{
using pipeline_base_t = IGraphicsPipeline<ICPUPipelineLayout,ICPUShader,ICPURenderpass>;
using pipeline_base_t = IGraphicsPipeline<ICPUPipelineLayout,ICPURenderpass>;
using base_t = ICPUPipeline<pipeline_base_t,5u>;

public:
Expand All @@ -32,7 +32,7 @@ class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPip
static core::smart_refctd_ptr<ICPUGraphicsPipeline> create(const SCreationParams& params)
{
// we'll validate the specialization info later when attempting to set it
if (!params.impl_valid([](const ICPUShader::SSpecInfo& info)->bool{return true;}))
if (!params.impl_valid([](const IPipelineBase::SShaderSpecInfo& info)->bool{return true;}))
return nullptr;
auto retval = new ICPUGraphicsPipeline(params);
for (const auto spec : params.shaders)
Expand Down Expand Up @@ -67,7 +67,7 @@ class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPip

base_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const override
{
std::array<ICPUShader::SSpecInfo,GRAPHICS_SHADER_STAGE_COUNT> _shaders;
std::array<IPipelineBase::SShaderSpecInfo,GRAPHICS_SHADER_STAGE_COUNT> _shaders;
for (auto i=0; i<GRAPHICS_SHADER_STAGE_COUNT; i++)
_shaders[i] = m_stages[i].info;
const SCreationParams params = {{
Expand All @@ -91,7 +91,7 @@ class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPip
return nullptr;
}

inline int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const override
inline int8_t stageToIndex(const hlsl::ShaderStage stage) const override
{
const auto stageIx = hlsl::findLSB(stage);
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
Expand Down
49 changes: 30 additions & 19 deletions include/nbl/asset/ICPUPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "nbl/asset/IAsset.h"
#include "nbl/asset/IPipeline.h"
#include "nbl/asset/ICPUPipelineLayout.h"
#include "nbl/asset/ICPUShader.h"


namespace nbl::asset
Expand All @@ -34,10 +33,10 @@ class ICPUPipeline : public IAsset, public PipelineNonAssetBase
if (shader)
{
auto stageInfo = m_stages[i].info;
core::smart_refctd_ptr<ICPUShader> newShader;
core::smart_refctd_ptr<IShader> newShader;
if (_depth>0u)
{
newShader = core::smart_refctd_ptr_static_cast<ICPUShader>(shader->clone(_depth-1u));
newShader = core::smart_refctd_ptr_static_cast<IShader>(shader->clone(_depth-1u));
stageInfo.shader = newShader.get();
}
cp->setSpecInfo(stageInfo);
Expand All @@ -61,40 +60,50 @@ class ICPUPipeline : public IAsset, public PipelineNonAssetBase
PipelineNonAssetBase::m_layout = std::move(_layout);
}

// The getters are weird because the shader pointer needs patching
inline IShader::SSpecInfo<ICPUShader> getSpecInfo(const ICPUShader::E_SHADER_STAGE stage)
// The getters are weird because the shader pointer, spec constant map and entry point needs patching
inline IShader* getShader(const hlsl::ShaderStage stage)
{
assert(isMutable());
return const_cast<IShader*>(getSpecInfo(stage).shader);
}
inline std::string* getEntryPoint(const hlsl::ShaderStage stage)
{
assert(isMutable());
const auto stageIx = stageToIndex(stage);
if (stageIx<0)
return {};
return m_stages[stageIx].info;
return &m_stages[stageIx].entryPoint;
}
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo(const ICPUShader::E_SHADER_STAGE stage) const
inline IPipelineBase::SShaderSpecInfo::spec_constant_map_t* getSpecConstantMap(const hlsl::ShaderStage stage)
{
assert(isMutable());
return const_cast<IPipelineBase::SShaderSpecInfo::spec_constant_map_t*>(getSpecInfo(stage).entries);
}
//
inline IPipelineBase::SShaderSpecInfo getSpecInfo(const hlsl::ShaderStage stage) const
{
const auto stageIx = stageToIndex(stage);
if (stageIx<0)
return {};
return m_stages[stageIx].info;
}
inline bool setSpecInfo(const IShader::SSpecInfo<ICPUShader>& info)
inline bool setSpecInfo(const IPipelineBase::SShaderSpecInfo& info)
{
assert(isMutable());
const int64_t specSize = info.valid();
if (specSize<0)
return false;
const auto stage = info.shader->getStage();
const auto stageIx = stageToIndex(stage);
const auto stageIx = stageToIndex(info.stage);
if (stageIx<0)
return false;
auto& outStage = m_stages[stageIx];
outStage.info = info;
outStage.shader = core::smart_refctd_ptr<ICPUShader>(info.shader);
outStage.entryPoint = info.entryPoint;
outStage.shader = core::smart_refctd_ptr<IShader>(const_cast<IShader*>(info.shader));
outStage.info.shader = outStage.shader.get();
auto& outEntries = outStage.entries;
if (specSize>0)
{
outEntries = std::make_unique<ICPUShader::SSpecInfo::spec_constant_map_t>();
outEntries = std::make_unique<IPipelineBase::SShaderSpecInfo::spec_constant_map_t>();
outEntries->reserve(info.entries->size());
std::copy(info.entries->begin(),info.entries->end(),std::insert_iterator(*outEntries,outEntries->begin()));
}
Expand All @@ -103,7 +112,7 @@ class ICPUPipeline : public IAsset, public PipelineNonAssetBase
outStage.info.entries = outEntries.get();
return true;
}
inline bool clearStage(const ICPUShader::E_SHADER_STAGE stage)
inline bool clearStage(const hlsl::ShaderStage stage)
{
assert(isMutable());
const auto stageIx = stageToIndex(stage);
Expand All @@ -118,12 +127,14 @@ class ICPUPipeline : public IAsset, public PipelineNonAssetBase
virtual ~ICPUPipeline() = default;

virtual this_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const = 0;
virtual int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const = 0;
virtual int8_t stageToIndex(const hlsl::ShaderStage stage) const = 0;

struct ShaderStage {
core::smart_refctd_ptr<ICPUShader> shader = {};
std::unique_ptr<ICPUShader::SSpecInfo::spec_constant_map_t> entries = {};
ICPUShader::SSpecInfo info = {};
struct ShaderStage
{
std::string entryPoint = {};
core::smart_refctd_ptr<IShader> shader = {};
std::unique_ptr<IPipelineBase::SShaderSpecInfo::spec_constant_map_t> entries = {};
IPipelineBase::SShaderSpecInfo info = {};
} m_stages[MaxShaderStageCount] = {};
};

Expand Down
30 changes: 18 additions & 12 deletions include/nbl/asset/ICPURenderpassIndependentPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "nbl/asset/IRenderpassIndependentPipeline.h"
#include "nbl/asset/ICPUPipelineLayout.h"
#include "nbl/asset/ICPUShader.h"
#include "nbl/asset/IShader.h"

namespace nbl::asset
{
Expand All @@ -16,10 +16,8 @@ namespace nbl::asset
@see IRenderpassIndependentPipeline
*/

class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<ICPUShader>, public IAsset
class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline, public IAsset
{
using base_t = IRenderpassIndependentPipeline<ICPUShader>;

public:
//(TODO) it is true however it causes DSs to not be cached when ECF_DONT_CACHE_TOP_LEVEL is set which isnt really intuitive
constexpr static inline uint32_t DESC_SET_HIERARCHYLEVELS_BELOW = 0u;
Expand All @@ -38,9 +36,11 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
if (!_layout || params.shaders.empty())
return nullptr;
auto retval = new ICPURenderpassIndependentPipeline(std::move(_layout),params.cached);
#if 0
for (const auto spec : params.shaders)
if (spec.shader)
retval->setSpecInfo(spec);
#endif
return core::smart_refctd_ptr<ICPURenderpassIndependentPipeline>(retval,core::dont_grab);
}

Expand All @@ -54,9 +54,11 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
layout = m_layout;

auto cp = new ICPURenderpassIndependentPipeline(std::move(layout),m_cachedParams);
#if 0
for (const auto spec : m_infos)
if (spec.shader)
cp->setSpecInfo(spec);
#endif

return core::smart_refctd_ptr<ICPURenderpassIndependentPipeline>(cp,core::dont_grab);
}
Expand All @@ -67,7 +69,7 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
inline size_t getDependantCount() const override {return 0;}

//
inline const SCachedCreationParams& getCachedCreationParams() const {return base_t::getCachedCreationParams();}
inline const SCachedCreationParams& getCachedCreationParams() const {return IRenderpassIndependentPipeline::getCachedCreationParams();}
inline SCachedCreationParams& getCachedCreationParams()
{
assert(isMutable());
Expand All @@ -87,16 +89,17 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
m_layout = std::move(_layout);
}

#if 0
// The getters are weird because the shader pointer needs patching
inline IShader::SSpecInfo<ICPUShader> getSpecInfo(const ICPUShader::E_SHADER_STAGE stage)
inline IShader::SSpecInfo<ICPUShader> getSpecInfo(const hlsl::ShaderStage stage)
{
assert(isMutable());
const auto stageIx = hlsl::findLSB(stage);
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
return {};
return m_infos[stageIx];
}
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo(const ICPUShader::E_SHADER_STAGE stage) const
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo(const hlsl::ShaderStage stage) const
{
const auto stageIx = hlsl::findLSB(stage);
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
Expand Down Expand Up @@ -127,18 +130,21 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
m_infos[stageIx].entries = m_entries[stageIx].get();
return true;
}
#endif

protected:
ICPURenderpassIndependentPipeline(core::smart_refctd_ptr<ICPUPipelineLayout>&& _layout, const base_t::SCachedCreationParams& params)
: base_t(params), m_layout(std::move(_layout)) {}
ICPURenderpassIndependentPipeline(core::smart_refctd_ptr<ICPUPipelineLayout>&& _layout, const IRenderpassIndependentPipeline::SCachedCreationParams& params)
: IRenderpassIndependentPipeline(params), m_layout(std::move(_layout)) {}
virtual ~ICPURenderpassIndependentPipeline() = default;

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

core::smart_refctd_ptr<ICPUPipelineLayout> m_layout;
std::array<core::smart_refctd_ptr<ICPUShader>,GRAPHICS_SHADER_STAGE_COUNT> m_shaders = {};
std::array<std::unique_ptr<ICPUShader::SSpecInfo::spec_constant_map_t>,GRAPHICS_SHADER_STAGE_COUNT> m_entries = {};
std::array<ICPUShader::SSpecInfo,GRAPHICS_SHADER_STAGE_COUNT> m_infos = {};
#if 0
std::array<core::smart_refctd_ptr<IShader>,GRAPHICS_SHADER_STAGE_COUNT> m_shaders = {};
std::array<std::unique_ptr<IPipelineBase::SShaderSpecInfo::spec_constant_map_t>,GRAPHICS_SHADER_STAGE_COUNT> m_entries = {};
std::array<IPipelineBase::SShaderSpecInfo,GRAPHICS_SHADER_STAGE_COUNT> m_infos = {};
#endif
};

}
Expand Down
87 changes: 0 additions & 87 deletions include/nbl/asset/ICPUShader.h

This file was deleted.

Loading