Skip to content

Commit e2f981f

Browse files
rework the BLAS exports of geometry collections completely
1 parent 08d3808 commit e2f981f

3 files changed

Lines changed: 47 additions & 28 deletions

File tree

include/nbl/asset/ICPUGeometryCollection.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ class NBL_API2 ICPUGeometryCollection : public IAsset, public IGeometryCollectio
8484
}
8585

8686
//
87-
template<typename Iterator>// requires std::is_same_v<decltype(*declval<Iterator>()),decltype(ICPUBottomLevelAccelerationStructure::Triangles&)>
88-
inline Iterator exportForBLAS(Iterator out, uint32_t* pWrittenOrdinals=nullptr) const
87+
class CBLASExporter final : public IBLASExporter
8988
{
90-
return exportForBLAS(std::forward<Iterator>(out),[](const hlsl::float32_t3x4& lhs, const hlsl::float32_t3x4& rhs)->void
89+
protected:
90+
inline void setTransform(BLASTriangles& out, const uint32_t geomIndex) override
9191
{
92-
lhs = rhs;
93-
if (pWrittenOrdinals)
94-
*(pWrittenOrdinals++) = (ptrdiff_t(&rhs)-offsetof(SGeometryReference,transform)-ptrdiff_t(base_t::m_geometries.data()))/sizeof(SGeometryReference);
92+
out.transform = m_geoms[geomIndex].transform;
9593
}
96-
);
97-
}
94+
95+
public:
96+
inline CBLASExporter(const core::vector<SGeometryReference>& _geoms) : IBLASExporter(_geoms) {}
97+
};
9898

9999
protected:
100100
//

include/nbl/asset/IGeometryCollection.h

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,45 @@ class NBL_API2 IGeometryCollection : public virtual core::IReferenceCounted
5656
inline bool isSkinned() const {return getJointCount()>0;}
5757
// View of matrices being the inverse bind pose
5858
inline const SDataView& getInverseBindPoseView() const {return m_inverseBindPoseView;}
59+
60+
61+
//
62+
class IBLASExporter
63+
{
64+
protected:
65+
using BLASTriangles = IBottomLevelAccelerationStructure::Triangles<std::remove_const_t<BufferType>>;
5966

67+
inline IBLASExporter(const core::vector<SGeometryReference>& _geoms) : m_geoms(_geoms) {}
68+
virtual void setTransform(BLASTriangles& out, const uint32_t geomIndex) = 0;
69+
70+
const core::vector<SGeometryReference>& m_geoms;
71+
72+
public:
73+
template<typename TriIter, typename PrimCountIter> // requires (std::is_same_v<decltype(*declval<TriIter>()),decltype(BLASTriangles&)> && PrimCountIter is integral && OrdinalIter is also)
74+
inline TriIter operator()(TriIter outIt, PrimCountIter outPrimCount, uint32_t* pWrittenOrdinals=nullptr)
75+
{
76+
for (const auto& ref : m_geoms)
77+
{
78+
// not a polygon geometry
79+
const auto* geo = ref.geometry.get();
80+
if (geo->getPrimitiveType()!=IGeometryBase::EPrimitiveType::Polygon)
81+
continue;
82+
const auto ordinal = std::distance(m_geoms.data(),&ref);
83+
const auto* polyGeo = static_cast<const IPolygonGeometry<BufferType>*>(geo);
84+
*outIt = polyGeo->exportForBLAS();
85+
if (outIt->vertexData[0])
86+
{
87+
if (pWrittenOrdinals)
88+
*(pWrittenOrdinals++) = ordinal;
89+
*(outPrimCount++) = polyGeo->getPrimitiveCount();
90+
if (ref.hasTransform())
91+
setTransform(*outIt,ordinal);
92+
outIt++;
93+
}
94+
}
95+
return outIt;
96+
}
97+
};
6098

6199
protected:
62100
virtual ~IGeometryCollection() = default;
@@ -93,25 +131,6 @@ class NBL_API2 IGeometryCollection : public virtual core::IReferenceCounted
93131
m_jointAABBView = std::move(jointAABBView);
94132
return true;
95133
}
96-
97-
// need to be protected because of the mess around `transform` requires us to provide diffferent signatures for ICPUGeometryCollection and IGPUGeometryCollection
98-
using BLASTriangles = IBottomLevelAccelerationStructure::Triangles<std::remove_const_t<BufferType>>;
99-
template<typename Iterator, typename Callback>// requires std::is_same_v<decltype(*declval<Iterator>()),decltype(BLASTriangles&)>
100-
inline Iterator exportForBLAS(Iterator out, Callback& setTransform) const
101-
{
102-
for (const auto& ref : m_geometries)
103-
{
104-
// not a polygon geometry
105-
const auto* geo = ref.geometry.get();
106-
if (geo->getPrimitiveType()==IGeometryBase::EPrimitiveType::Polygon)
107-
continue;
108-
const auto* polyGeo = static_cast<const IPolygonGeometry<BufferType>*>(geo);
109-
*out = polyGeo->exportForBLAS();
110-
if (out->vertexData[0])
111-
out++;
112-
}
113-
return out;
114-
}
115134

116135

117136
// For the entire collection, as always it should NOT include any geometry which is affected by a joint.

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ SAssetBundle CMitsubaLoader::loadAsset(system::IFile* _file, const IAssetLoader:
261261
return;
262262
}
263263
const auto index = instances.size();
264-
instances.resize(index+1);
264+
instances.resize(index+1,true);
265265
instances.getMorphTargets()[index] = core::smart_refctd_ptr<ICPUMorphTargets>(const_cast<ICPUMorphTargets*>(targets.get()));
266266
// TODO: add materials (incl emission) to the instances
267267
/*

0 commit comments

Comments
 (0)