Skip to content

Commit c7cff1d

Browse files
author
kevyuu
committed
Remove valid implementation on IAsset and implement valid for all derived class of IAsset
1 parent 73a17a0 commit c7cff1d

10 files changed

+74
-8
lines changed

include/nbl/asset/IAsset.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ class IAsset : virtual public core::IReferenceCounted
175175
});
176176
}
177177

178-
virtual bool valid() const
179-
{
180-
//TODO(kevinyu): Temporary set this to true to make changes compile. Will revisit this later for each asset
181-
return true;
182-
}
178+
virtual bool valid() const = 0;
183179

184180
protected:
185181
inline IAsset() = default;

include/nbl/asset/ICPUAccelerationStructure.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,33 @@ class ICPUBottomLevelAccelerationStructure final : public IPreHashed, public IBo
231231
return !m_geometryPrimitiveCount || !m_triangleGeoms && !m_AABBGeoms;
232232
}
233233

234+
inline virtual 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+
234261
protected:
235262
virtual ~ICPUBottomLevelAccelerationStructure() = default;
236263

@@ -352,6 +379,17 @@ class ICPUTopLevelAccelerationStructure final : public IAsset, public ITopLevelA
352379
return cp;
353380
}
354381

382+
inline virtual bool valid() const override
383+
{
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+
if (m_buildRangeInfo.instanceByteOffset % 16 != 0) return false;
390+
return true;
391+
}
392+
355393
protected:
356394
virtual ~ICPUTopLevelAccelerationStructure() = default;
357395

include/nbl/asset/ICPUAnimationLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ 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 virtual bool valid() const override { return true; }
9899

99100
private:
100101

include/nbl/asset/ICPUImage.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ class NBL_API2 ICPUImage final : public IImage, public IPreHashed
199199
{
200200
if (!validateCreationParameters(m_creationParams)) return false;
201201
if (info != m_creationParams.format) return false;
202-
if (!buffer->valid()) return false;
203-
for (const auto& region : regions)
204-
if (!region.isValid()) return false;
202+
if (buffer && !buffer->valid()) return false;
203+
if (regions)
204+
for (const auto& region : *regions)
205+
if (!region.isValid()) return false;
205206
return true;
206207
}
207208

include/nbl/asset/ICPUMesh.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ class ICPUMesh final : public IMesh<ICPUMeshBuffer>, public IAsset
8181
return cp;
8282
}
8383

84+
inline virtual bool valid() const override
85+
{
86+
for (const auto& meshBuffer : m_meshBuffers)
87+
{
88+
if (!meshBuffer) return false;
89+
if (!meshBuffer->valid()) return false;
90+
}
91+
return true;
92+
}
93+
8494
protected:
8595

8696
private:

include/nbl/asset/ICPUMeshBuffer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,12 @@ class ICPUMeshBuffer final : public IMeshBuffer<ICPUBuffer,ICPUDescriptorSet,ICP
610610
assert(isMutable());
611611
return const_cast<core::aabbox3df*>(const_cast<const ICPUMeshBuffer*>(this)->getJointAABBs());
612612
}
613+
inline virtual bool valid() const override
614+
{
615+
return true;
616+
}
613617

618+
private:
614619
inline virtual void visitDependents_impl(std::function<bool(const IAsset*)> visit) const override
615620
{
616621
}

include/nbl/asset/ICPURenderpassIndependentPipeline.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline,
9393
m_layout = std::move(_layout);
9494
}
9595

96+
inline virtual bool valid() const override
97+
{
98+
return m_layout && m_layout->valid();
99+
}
100+
96101
#if 0
97102
// The getters are weird because the shader pointer needs patching
98103
inline IShader::SSpecInfo<ICPUShader> getSpecInfos(const hlsl::ShaderStage stage)

include/nbl/asset/ICPUSampler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ICPUSampler : public ISampler, public IAsset
6868

6969
constexpr static inline auto AssetType = ET_SAMPLER;
7070
inline IAsset::E_TYPE getAssetType() const override { return AssetType; }
71+
inline virtual bool valid() const override { return true; }
7172

7273
private:
7374

include/nbl/asset/ICPUSkeleton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class ICPUSkeleton final : public ISkeleton<ICPUBuffer>, public IAsset
7878

7979
constexpr static inline auto AssetType = ET_SKELETON;
8080
inline E_TYPE getAssetType() const override { return AssetType; }
81+
inline virtual bool valid() const override { return true; }
8182

8283
private:
8384

include/nbl/asset/IShader.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ class IShader : public IAsset
8787

8888
// TODO: `void setContent(core::smart_refctd_ptr<const ICPUBuffer>&&,const E_CONTENT_TYPE)`
8989

90+
inline virtual bool valid() const override
91+
{
92+
if (!m_code) return false;
93+
if (m_contentType == E_CONTENT_TYPE::ECT_UNKNOWN) return false;
94+
// Note(kevyuu) : Should we check for m_filepathHint if content type is not spirv. What if no pragma includ in the source code. Do we even need m_filepathHint in that case?
95+
return true;
96+
}
97+
9098
// alias for legacy reasons
9199
using E_SHADER_STAGE = hlsl::ShaderStage;
92100

0 commit comments

Comments
 (0)