Skip to content

Refactor how Shader Stage is provided #887

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

Merged
merged 233 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
233 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
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
8d608bd
Merge branch 'master' into stagesless_shaders
May 13, 2025
7d6ede4
Fix outputReverseMap so it can hold IShader
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
2eea2b0
Fix layout constness on IComputePipeline
May 26, 2025
969bcb8
Fix ICPUAcclerationStructure to use computeDependantsImpl
May 26, 2025
3e96339
Fix ICPUAnimationLibrary to use computeDependantsImpl
May 26, 2025
6de189d
Remove layout constness from ICPUComputePipeline
May 26, 2025
b0fe090
Move ICPUDescriptorSet computeDependantsImpl to header
May 26, 2025
1d764ec
Remove layout constness from cpu graphics pipeline
May 26, 2025
377f25d
Remove layout constness from cpu pipeline
May 26, 2025
8809bda
Use computeDependantsImpl in cpu pipeline layout
May 26, 2025
3c0b3ba
Fix argument pack passing on IGPUPipeline
May 26, 2025
53b45ec
Remove layout constness from cpu ray tracing pipeline
May 26, 2025
e249931
Add cached parameter to SCreationParams for gpu compute pipeline
May 26, 2025
006dd7d
Remove layout constness on IPipeline
May 26, 2025
389c358
Fix IGPURayTracingPipeline construction
May 26, 2025
81df19b
Fix debloatedHitSpecData error in ILogicalDevice
May 26, 2025
2d97ce8
Fix CComputeBlit
May 26, 2025
68095da
Fix error in ILogicalDevice.cpp due to removed getShaders method
May 27, 2025
98e1759
Fix all errors in CVulkanLogicalDevice
May 27, 2025
59ccb22
Add get shader count for creationParams
May 27, 2025
bc9befb
Move shader stage validation out of commonCreatePipelines
May 27, 2025
b8d53cc
Fix vulkan ray tracing creation
May 28, 2025
f26201e
Another fix to CCOmputeBlit
May 28, 2025
edac59f
Fix AssetConvert to use the current SpecInfo
May 29, 2025
a31cc66
Small fixes to asset and video
May 29, 2025
08ece5d
Fix CComputeBlit
May 29, 2025
0784b45
Merge branch 'master' into stagesless_shaders
Jun 4, 2025
1fc684d
Fix AssetConverter after merge
Jun 6, 2025
0112f0f
Merge branch 'stagesless_shaders' into rework_pipeline_shader_spec_info
Jun 6, 2025
5c2f55b
Fix pipeline creation in full screen triangle pass
Jun 9, 2025
03f7bc7
Fix descriptor set casting for const counterpart
Jun 9, 2025
aeebe36
Fix entries traversal in gpu pipeline
Jun 9, 2025
b65f14f
move SHitGroup to outside SCreationParams
Jun 9, 2025
c5f9479
Fix ray tracing pipeline creation
Jun 9, 2025
edefa67
Fix imgui pass
Jun 9, 2025
67c4d8d
Add assert shader stage
Jun 9, 2025
bc9aed6
use core::bitflag::hasFlags instead of &
Jun 9, 2025
294a399
Add whether shader is null when cloning SShaderSpecInfo
Jun 9, 2025
35815d2
Small improvement on ILogicalDevice
Jun 9, 2025
66c87a0
Small improvement on SShaderSpecInfo::create
Jun 9, 2025
01dced9
Skip null node
Jun 9, 2025
2440dec
Add renderpass to constructor parameter of cpu graphics pipeline
Jun 11, 2025
ccecd47
Fix overload error
Jun 11, 2025
99f2d49
Optimize SpirvDebloaterTask to use only one map
Jun 11, 2025
efecb7e
Add inline to method in IGPUPipeline
Jun 11, 2025
1707b84
Move required subgroups size stages checking to commonCreatePipelines
Jun 11, 2025
165eebc
Implement visitDependents
Jun 11, 2025
d0a0245
Check shader availability in getRequiredSubgroupStages
Jun 11, 2025
2ad3e73
Use visitDependents for discardDependantContents and anyDependantDisc…
Jun 11, 2025
542bd06
Fix debloat task
Jun 11, 2025
c9597ff
Initialize stages to zero.
Jun 11, 2025
046a334
More descriptive error
Jun 11, 2025
50281c6
Remove computeDependants interface
Jun 14, 2025
6a84bd7
Rename visitDependentsImpl to visitDependents_impl
Jun 14, 2025
d58554e
Fix visitDependents_impl on some asset
Jun 14, 2025
4fcd6e2
Implement ICPUBuffer valid()
Jun 14, 2025
c3c50b4
Implement ICPUBufferView::valid()
Jun 14, 2025
51e408b
Implement ICPUDescriptorSet::valid()
Jun 14, 2025
345dbd8
Implement ICPUDescriptorSetLayout::valid()
Jun 14, 2025
4a4b51d
Implement ICPUImage::valid()
Jun 14, 2025
c5d1d85
Implement ICPUImageView::valid()
Jun 14, 2025
7087099
Implement ICPUPipelineCache::valid()
Jun 14, 2025
73a17a0
Implement ICPUSampler::valid()
Jun 14, 2025
c7cff1d
Remove valid implementation on IAsset and implement valid for all der…
Jun 16, 2025
ae3946e
Add comment to some valid logic of top acceleration structure
Jun 16, 2025
ef2ed3a
Rename getSpecInfoVec to getSpecInfoVector
Jun 16, 2025
9c87925
Fix indentation
Jun 16, 2025
697589c
Remove virtual from final classes
Jun 16, 2025
469bf04
Fix indentation
Jun 16, 2025
6e23e6e
Fix indentation
Jun 16, 2025
9c138b7
Fix indentation
Jun 16, 2025
026d494
Fix indentation
Jun 16, 2025
2578abe
Check raygen shader existence for raytracing pipeline
Jun 16, 2025
0608e9d
Check vertex shader existence for graphics pipeline
Jun 16, 2025
6080475
Remove comment on IShader::valid()
Jun 16, 2025
e2f7b8f
Remove virtual on IShader::valid and IShader::visitDependents_impl
Jun 16, 2025
47900b1
Add final to IShader
Jun 16, 2025
5d990a3
Rename ISPIRVDebloater to ISPIRVEntryPointTrimmer
Jun 17, 2025
6505cde
Fix indentation to use tabs
Jun 17, 2025
11df7a6
Initial refinement for IDescriptorSet::valid()
Jun 17, 2025
033c7cf
Remove unnecessary final specifier
Jun 17, 2025
3cf4554
Add const to hlsl::ShaderStage
Jun 17, 2025
9eab2f8
Remove unnecessary final specifier
Jun 17, 2025
74241f3
Add comment on why we need multiple dead branch elimination and multi…
Jun 17, 2025
04bcf0d
Remove unused variable
Jun 17, 2025
fc1983f
Small fixes on SpirvTrimTask
Jun 17, 2025
3767ede
Fix shader indexing logic in ray tracing pipeline creation
Jun 17, 2025
061d49c
Fix maxShaderStages calculation when creating ray tracing pipeline
Jun 17, 2025
e6d8727
update submodule pointer
AnastaZIuk Jun 17, 2025
4a374b0
Merge branch 'master' into rework_pipeline_shader_spec_info
Jun 17, 2025
6fea3e5
Add agrressive dce pass to remove type and remove multiple round of b…
Jun 17, 2025
0aa03c7
Remove comment
Jun 17, 2025
f74d78b
Merge branch 'rework_pipeline_shader_spec_info' of github.com:Devsh-G…
Jun 17, 2025
cdab2dc
Reorder agressive dce to last to remove unused type
Jun 17, 2025
6ec73f7
Add some comment to spirv optimizer passes
Jun 17, 2025
2716eca
More comment on passes
Jun 18, 2025
8226fbb
Add comment to the doc for ray tracing pipeline requiring raygen shader
Jun 18, 2025
e74a1f3
Add validation whether compute shader exist when creating compute pip…
Jun 18, 2025
d02f474
Merge branch 'master' into rework_pipeline_shader_spec_info
Jun 18, 2025
5ac389d
Add const to layout parameter in creation params
Jun 18, 2025
01997cc
Merge branch 'master' into rework_pipeline_shader_spec_info
Jun 18, 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
40 changes: 24 additions & 16 deletions 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 All @@ -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,30 +156,37 @@ 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;
}
inline void visitDependents(std::function<bool(const IAsset*)> visit) const
{
visitDependents_impl([&visit](const IAsset* dep)->bool
{
if (dep)
return visit(dep);
return true;
});
}

inline void visitDependents(std::function<bool(IAsset*)> visit)
{
assert(isMutable());
visitDependents([&](const IAsset* dependent) -> bool
{
return visit(const_cast<IAsset*>(dependent));
});
}

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;

virtual void visitDependents_impl(std::function<bool(const IAsset*)> visit) const = 0;
};

template<typename T>
Expand Down
60 changes: 48 additions & 12 deletions include/nbl/asset/ICPUAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
return cp;
}

// 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::blake3_hash_t computeContentHash() const override
{
Expand Down Expand Up @@ -233,11 +231,36 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
return !m_geometryPrimitiveCount || !m_triangleGeoms && !m_AABBGeoms;
}

inline bool valid() const override
{
if (!validBuildFlags(m_buildFlags)) return false;

size_t geometryCount = 0;
if (m_buildFlags.hasFlags(BUILD_FLAGS::GEOMETRY_TYPE_IS_AABB_BIT))
{
if (!m_AABBGeoms || m_triangleGeoms) return false;
geometryCount = m_AABBGeoms->size();
}
else
{
if (!m_triangleGeoms || m_AABBGeoms) return false;
geometryCount = m_triangleGeoms->size();
}

// https://registry.khronos.org/vulkan/specs/latest/man/html/vkGetAccelerationStructureBuildSizesKHR.html#VUID-vkGetAccelerationStructureBuildSizesKHR-pBuildInfo-03619
if (geometryCount == 0) {
if (m_geometryPrimitiveCount && m_geometryPrimitiveCount->size() > 0) return false;
}
else
{
if (!m_geometryPrimitiveCount || m_geometryPrimitiveCount->size() != geometryCount) return false;
}
return true;
}

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 @@ -251,6 +274,8 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
core::smart_refctd_dynamic_array<AABBs<ICPUBuffer>> m_AABBGeoms = nullptr;
core::smart_refctd_dynamic_array<uint32_t> m_geometryPrimitiveCount = nullptr;
core::bitflag<BUILD_FLAGS> m_buildFlags = BUILD_FLAGS::PREFER_FAST_TRACE_BIT;

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

class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelAccelerationStructure
Expand All @@ -263,9 +288,6 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
//
ICPUTopLevelAccelerationStructure() = default;

//
inline size_t getDependantCount() const override {return m_instances->size();}

//
inline auto& getBuildRangeInfo()
{
Expand Down Expand Up @@ -357,18 +379,32 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
return cp;
}

protected:
virtual ~ICPUTopLevelAccelerationStructure() = default;

inline IAsset* getDependant_impl(const size_t ix) override
inline bool valid() const override
{
return m_instances->operator[](ix).getBase().blas.get();
if (!validBuildFlags(m_buildFlags)) return false;
if (!m_instances) return false;
for (const auto& instance : *m_instances)
if (!instance.getBase().blas->valid()) return false;
if (m_buildRangeInfo.instanceCount != m_instances->size()) return false;
// https://registry.khronos.org/vulkan/specs/latest/man/html/VkAccelerationStructureBuildRangeInfoKHR.html#VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03660
if (m_buildRangeInfo.instanceByteOffset % 16 != 0) return false;
return true;
}

protected:
virtual ~ICPUTopLevelAccelerationStructure() = default;

private:
core::smart_refctd_dynamic_array<PolymorphicInstance> m_instances = nullptr;
hlsl::acceleration_structures::top_level::BuildRangeInfo m_buildRangeInfo;
core::bitflag<BUILD_FLAGS> m_buildFlags = BUILD_FLAGS::PREFER_FAST_BUILD_BIT;

inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
{
if (!m_instances) return;
for (const auto& instance : *m_instances)
if (!visit(instance.getBase().blas.get())) return;
}
};

}
Expand Down
23 changes: 8 additions & 15 deletions include/nbl/asset/ICPUAnimationLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,16 @@ class ICPUAnimationLibrary final : public IAnimationLibrary<ICPUBuffer>, public

constexpr static inline auto AssetType = ET_ANIMATION_LIBRARY;
inline E_TYPE getAssetType() const override { return AssetType; }
inline bool valid() const override { return true; }

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

protected:
inline IAsset* getDependant_impl(const size_t ix) override
{
switch (ix)
{
case 0:
return m_keyframeStorageBinding.buffer.get();
case 1:
return m_timestampStorageBinding.buffer.get();
default:
break;
}
return m_animationStorageRange.buffer.get();
}
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
{
if (!visit(m_keyframeStorageBinding.buffer.get())) return;
if (!visit(m_timestampStorageBinding.buffer.get())) return;
if (!visit(m_animationStorageRange.buffer.get())) return;
}
};

}
Expand Down
17 changes: 10 additions & 7 deletions include/nbl/asset/ICPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ 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::blake3_hash_t computeContentHash() const override
{
core::blake3_hasher hasher;
Expand Down Expand Up @@ -112,12 +110,15 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
return true;
}

protected:
inline IAsset* getDependant_impl(const size_t ix) override
{
return nullptr;
}
inline bool valid() const override
{
if (!m_data) return false;
if (!m_mem_resource) return false;
// check if alignment is power of two
return (m_alignment > 0 && !(m_alignment & (m_alignment - 1)));
}

protected:
inline void discardContent_impl() override
{
if (m_data)
Expand All @@ -136,6 +137,8 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
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;
Expand Down
18 changes: 14 additions & 4 deletions include/nbl/asset/ICPUBufferView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ 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;}

ICPUBuffer* getUnderlyingBuffer()
{
assert(isMutable());
Expand All @@ -48,12 +46,24 @@ class ICPUBufferView : public IBufferView<ICPUBuffer>, public IAsset
m_size = _size;
}

inline bool valid() const override
{
if (!m_buffer->valid()) return false;
if (m_offset >= m_buffer->getSize()) return false;
if (m_size <= 0) return false;
if (m_offset >= m_buffer->getSize()) return false;
if (m_size > m_buffer->getSize() - m_offset) return false;
return true;
}

protected:
virtual ~ICPUBufferView() = default;

inline IAsset* getDependant_impl(const size_t ix) override
private:

inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
{
return m_buffer.get();
if (!visit(m_buffer.get())) return;
}
};

Expand Down
Loading
Loading