Skip to content

Commit c42afec

Browse files
committed
pull Matt and resolve conflicts
2 parents 4dedfd6 + 3fa43e2 commit c42afec

File tree

121 files changed

+4725
-2906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4725
-2906
lines changed

examples_tests

Submodule examples_tests updated 98 files

include/nbl/asset/ECommonEnums.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ inline core::bitflag<ACCESS_FLAGS> allAccessesFromStages(core::bitflag<PIPELINE_
257257
};
258258
constexpr PerStageAccesses bitToAccess = {};
259259

260+
// TODO: add logically later or previous stages to make sure all other accesses remain valid
261+
// or ideally expand the stages before calling `allAccessesFromStages` (TODO: add a `allLaterStages` and `allPreviouStages` basically)
262+
260263
core::bitflag<ACCESS_FLAGS> retval = ACCESS_FLAGS::NONE;
261264
while (bool(stages.value))
262265
{

include/nbl/asset/IAsset.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class IAsset : virtual public core::IReferenceCounted
8282
ET_SKELETON = 1ull<<7, //!< asset::ICPUSkeleton
8383
ET_ANIMATION_LIBRARY = 1ull<<8, //!< asset::ICPUAnimationLibrary
8484
ET_PIPELINE_LAYOUT = 1ull<<9, //!< asset::ICPUPipelineLayout
85-
ET_SHADER = 1ull<<10, //!< asset::ICPUShader
86-
ET_GEOMETRY = 1ull<<12, //!< anything inheriting from asset::IGeometry<ICPUBuffer>
85+
ET_SHADER = 1ull<<10, //!< asset::IShader
86+
ET_GEOMETRY = 1ull<<12, //!< anything inheriting from asset::IGeometry<ICPUBuffer>
8787
ET_RENDERPASS = 1ull<<13, //!< asset::ICPURenderpass
8888
ET_FRAMEBUFFER = 1ull<<14, //!< asset::ICPUFramebuffer
8989
ET_GRAPHICS_PIPELINE = 1ull<<15, //!< asset::ICPUGraphicsPipeline
@@ -94,6 +94,7 @@ class IAsset : virtual public core::IReferenceCounted
9494
ET_COMPUTE_PIPELINE = 1ull<<20, //!< asset::ICPUComputePipeline
9595
ET_PIPELINE_CACHE = 1ull<<21, //!< asset::ICPUPipelineCache
9696
ET_SCENE = 1ull<<22, //!< reserved, to implement later
97+
ET_RAYTRACING_PIPELINE = 1ull << 23, //!< asset::ICPURayTracingPipeline
9798
ET_IMPLEMENTATION_SPECIFIC_METADATA = 1ull<<31u, //!< lights, etc.
9899
//! Reserved special value used for things like terminating lists of this enum
99100

@@ -155,30 +156,37 @@ class IAsset : virtual public core::IReferenceCounted
155156
//!
156157
inline bool isMutable() const {return m_mutable;}
157158

158-
//!
159-
virtual size_t getDependantCount() const = 0;
160-
inline IAsset* getDependant(const size_t ix)
161-
{
162-
if (ix<getDependantCount())
163-
return getDependant_impl(ix);
164-
return nullptr;
165-
}
166-
inline const IAsset* getDependant(const size_t ix) const
167-
{
168-
IAsset* const retval = const_cast<IAsset*>(this)->getDependant(ix);
169-
return retval;
170-
}
159+
inline void visitDependents(std::function<bool(const IAsset*)> visit) const
160+
{
161+
visitDependents_impl([&visit](const IAsset* dep)->bool
162+
{
163+
if (dep)
164+
return visit(dep);
165+
return true;
166+
});
167+
}
168+
169+
inline void visitDependents(std::function<bool(IAsset*)> visit)
170+
{
171+
assert(isMutable());
172+
visitDependents([&](const IAsset* dependent) -> bool
173+
{
174+
return visit(const_cast<IAsset*>(dependent));
175+
});
176+
}
177+
178+
virtual bool valid() const = 0;
171179

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

177-
virtual IAsset* getDependant_impl(const size_t ix) = 0;
178-
179185
private:
180186
friend IAssetManager;
181187
bool m_mutable = true;
188+
189+
virtual void visitDependents_impl(std::function<bool(const IAsset*)> visit) const = 0;
182190
};
183191

184192
template<typename T>

include/nbl/asset/IAssetManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ class NBL_API2 IAssetManager : public core::IReferenceCounted
136136

137137
inline system::ISystem* getSystem() const { return m_system.get(); }
138138

139-
const CGeometryCreator* getGeometryCreator() const;
140139
CPolygonGeometryManipulator* getPolygonGeometryManipulator();
141140
CCompilerSet* getCompilerSet() const { return m_compilerSet.get(); }
142141

include/nbl/asset/IBuffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct SBufferRange
100100
inline operator SBufferRange<const BufferType>&() {return *reinterpret_cast<SBufferRange<const BufferType>*>(this);}
101101
inline operator const SBufferRange<const BufferType>&() const {return *reinterpret_cast<const SBufferRange<const BufferType>*>(this);}
102102

103+
template<typename BT> requires std::is_same_v<std::remove_const_t<BT>,BufferType>
104+
inline operator SBufferBinding<BT>() const { return {.offset=offset,.buffer=buffer}; }
105+
103106
explicit inline operator bool() const {return isValid();}
104107

105108
inline bool isValid() const

include/nbl/asset/ICPUAccelerationStructure.h

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
135135
return cp;
136136
}
137137

138-
// Do not report anything as a dependant, we'll simply drop the data instead of discarding its contents
139-
inline size_t getDependantCount() const override {return 0;}
140138

141139
inline core::blake3_hash_t computeContentHash() const override
142140
{
@@ -233,11 +231,36 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
233231
return !m_geometryPrimitiveCount || !m_triangleGeoms && !m_AABBGeoms;
234232
}
235233

234+
inline bool valid() const override
235+
{
236+
if (!validBuildFlags(m_buildFlags)) return false;
237+
238+
size_t geometryCount = 0;
239+
if (m_buildFlags.hasFlags(BUILD_FLAGS::GEOMETRY_TYPE_IS_AABB_BIT))
240+
{
241+
if (!m_AABBGeoms || m_triangleGeoms) return false;
242+
geometryCount = m_AABBGeoms->size();
243+
}
244+
else
245+
{
246+
if (!m_triangleGeoms || m_AABBGeoms) return false;
247+
geometryCount = m_triangleGeoms->size();
248+
}
249+
250+
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkGetAccelerationStructureBuildSizesKHR.html#VUID-vkGetAccelerationStructureBuildSizesKHR-pBuildInfo-03619
251+
if (geometryCount == 0) {
252+
if (m_geometryPrimitiveCount && m_geometryPrimitiveCount->size() > 0) return false;
253+
}
254+
else
255+
{
256+
if (!m_geometryPrimitiveCount || m_geometryPrimitiveCount->size() != geometryCount) return false;
257+
}
258+
return true;
259+
}
260+
236261
protected:
237262
virtual ~ICPUBottomLevelAccelerationStructure() = default;
238263

239-
inline IAsset* getDependant_impl(const size_t ix) override {return nullptr;}
240-
241264
inline void discardContent_impl() override
242265
{
243266
m_triangleGeoms = nullptr;
@@ -251,6 +274,8 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
251274
core::smart_refctd_dynamic_array<AABBs<ICPUBuffer>> m_AABBGeoms = nullptr;
252275
core::smart_refctd_dynamic_array<uint32_t> m_geometryPrimitiveCount = nullptr;
253276
core::bitflag<BUILD_FLAGS> m_buildFlags = BUILD_FLAGS::PREFER_FAST_TRACE_BIT;
277+
278+
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override {}
254279
};
255280

256281
class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelAccelerationStructure
@@ -263,9 +288,6 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
263288
//
264289
ICPUTopLevelAccelerationStructure() = default;
265290

266-
//
267-
inline size_t getDependantCount() const override {return m_instances->size();}
268-
269291
//
270292
inline auto& getBuildRangeInfo()
271293
{
@@ -357,18 +379,32 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
357379
return cp;
358380
}
359381

360-
protected:
361-
virtual ~ICPUTopLevelAccelerationStructure() = default;
362-
363-
inline IAsset* getDependant_impl(const size_t ix) override
382+
inline bool valid() const override
364383
{
365-
return m_instances->operator[](ix).getBase().blas.get();
384+
if (!validBuildFlags(m_buildFlags)) return false;
385+
if (!m_instances) return false;
386+
for (const auto& instance : *m_instances)
387+
if (!instance.getBase().blas->valid()) return false;
388+
if (m_buildRangeInfo.instanceCount != m_instances->size()) return false;
389+
// https://registry.khronos.org/vulkan/specs/latest/man/html/VkAccelerationStructureBuildRangeInfoKHR.html#VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03660
390+
if (m_buildRangeInfo.instanceByteOffset % 16 != 0) return false;
391+
return true;
366392
}
367393

394+
protected:
395+
virtual ~ICPUTopLevelAccelerationStructure() = default;
396+
368397
private:
369398
core::smart_refctd_dynamic_array<PolymorphicInstance> m_instances = nullptr;
370399
hlsl::acceleration_structures::top_level::BuildRangeInfo m_buildRangeInfo;
371400
core::bitflag<BUILD_FLAGS> m_buildFlags = BUILD_FLAGS::PREFER_FAST_BUILD_BIT;
401+
402+
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
403+
{
404+
if (!m_instances) return;
405+
for (const auto& instance : *m_instances)
406+
if (!visit(instance.getBase().blas.get())) return;
407+
}
372408
};
373409

374410
}

include/nbl/asset/ICPUAnimationLibrary.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,16 @@ class ICPUAnimationLibrary final : public IAnimationLibrary<ICPUBuffer>, public
9595

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

99-
inline size_t getDependantCount() const override {return 3;}
100+
private:
100101

101-
protected:
102-
inline IAsset* getDependant_impl(const size_t ix) override
103-
{
104-
switch (ix)
105-
{
106-
case 0:
107-
return m_keyframeStorageBinding.buffer.get();
108-
case 1:
109-
return m_timestampStorageBinding.buffer.get();
110-
default:
111-
break;
112-
}
113-
return m_animationStorageRange.buffer.get();
114-
}
102+
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
103+
{
104+
if (!visit(m_keyframeStorageBinding.buffer.get())) return;
105+
if (!visit(m_timestampStorageBinding.buffer.get())) return;
106+
if (!visit(m_animationStorageRange.buffer.get())) return;
107+
}
115108
};
116109

117110
}

include/nbl/asset/ICPUBuffer.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace nbl::asset
2525
class ICPUBuffer final : public asset::IBuffer, public IPreHashed
2626
{
2727
public:
28+
// TODO: template to make `data` a `const void*` vs `void*`
2829
struct SCreationParams : asset::IBuffer::SCreationParams
2930
{
3031
void* data = nullptr;
@@ -75,8 +76,6 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
7576
constexpr static inline auto AssetType = ET_BUFFER;
7677
inline IAsset::E_TYPE getAssetType() const override final { return AssetType; }
7778

78-
inline size_t getDependantCount() const override { return 0; }
79-
8079
inline core::blake3_hash_t computeContentHash() const override
8180
{
8281
core::blake3_hasher hasher;
@@ -112,12 +111,15 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
112111
return true;
113112
}
114113

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

122+
protected:
121123
inline void discardContent_impl() override
122124
{
123125
if (m_data)
@@ -136,6 +138,8 @@ class ICPUBuffer final : public asset::IBuffer, public IPreHashed
136138
discardContent_impl();
137139
}
138140

141+
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override {}
142+
139143
void* m_data;
140144
core::smart_refctd_ptr<core::refctd_memory_resource> m_mem_resource;
141145
size_t m_alignment;

include/nbl/asset/ICPUBufferView.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class ICPUBufferView : public IBufferView<ICPUBuffer>, public IAsset
2828
constexpr static inline auto AssetType = ET_BUFFER_VIEW;
2929
inline IAsset::E_TYPE getAssetType() const override { return AssetType; }
3030

31-
inline size_t getDependantCount() const override {return 1;}
32-
3331
ICPUBuffer* getUnderlyingBuffer()
3432
{
3533
assert(isMutable());
@@ -48,12 +46,24 @@ class ICPUBufferView : public IBufferView<ICPUBuffer>, public IAsset
4846
m_size = _size;
4947
}
5048

49+
inline bool valid() const override
50+
{
51+
if (!m_buffer->valid()) return false;
52+
if (m_offset >= m_buffer->getSize()) return false;
53+
if (m_size <= 0) return false;
54+
if (m_offset >= m_buffer->getSize()) return false;
55+
if (m_size > m_buffer->getSize() - m_offset) return false;
56+
return true;
57+
}
58+
5159
protected:
5260
virtual ~ICPUBufferView() = default;
5361

54-
inline IAsset* getDependant_impl(const size_t ix) override
62+
private:
63+
64+
inline void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
5565
{
56-
return m_buffer.get();
66+
if (!visit(m_buffer.get())) return;
5767
}
5868
};
5969

0 commit comments

Comments
 (0)