Skip to content

Commit a3be452

Browse files
author
devsh
committed
add utilities to get TLAS instance size from type and encode the type in a Device or Host reference
1 parent 0b306e0 commit a3be452

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

include/nbl/asset/IAccelerationStructure.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ class IBottomLevelAccelerationStructure : public AccelerationStructure
139139
// forward declare for `static_assert`
140140
class ICPUBottomLevelAccelerationStructure;
141141

142+
// TODO: maybe we should introduce a base class so that flags and Instance declarations aren't doubled up
142143
template<class AccelerationStructure>
143144
class ITopLevelAccelerationStructure : public AccelerationStructure
144145
{
145146
static_assert(std::is_base_of_v<IAccelerationStructure,AccelerationStructure>);
147+
146148
public:
147149
inline bool isBLAS() const override {return false;}
148150

@@ -246,6 +248,22 @@ class ITopLevelAccelerationStructure : public AccelerationStructure
246248
SRT_MOTION
247249
};
248250

251+
static uint16_t getInstanceSize(const INSTANCE_TYPE type)
252+
{
253+
switch (type)
254+
{
255+
case INSTANCE_TYPE::SRT_MOTION:
256+
return sizeof(SRTMotionInstance<ptrdiff_t>);
257+
break;
258+
case INSTANCE_TYPE::MATRIX_MOTION:
259+
return sizeof(MatrixMotionInstance<ptrdiff_t>);
260+
break;
261+
default:
262+
break;
263+
}
264+
return sizeof(StaticInstance<ptrdiff_t>);
265+
}
266+
249267
protected:
250268
using AccelerationStructure::AccelerationStructure;
251269
virtual ~ITopLevelAccelerationStructure() = default;

include/nbl/video/IGPUAccelerationStructure.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,41 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
483483
using DeviceBuildInfo = BuildInfo<IGPUBuffer>;
484484
using HostBuildInfo = BuildInfo<asset::ICPUBuffer>;
485485

486+
static inline auto encodeTypeInRef(const INSTANCE_TYPE type, IGPUBottomLevelAccelerationStructure::device_op_ref_t ref)
487+
{
488+
// aligned to 16 bytes as per the spec
489+
assert(ref.deviceAddress%16==0);
490+
switch (type)
491+
{
492+
case INSTANCE_TYPE::SRT_MOTION:
493+
ref.deviceAddress += 2;
494+
break;
495+
case INSTANCE_TYPE::MATRIX_MOTION:
496+
ref.deviceAddress += 1;
497+
break;
498+
default:
499+
break;
500+
}
501+
return ref;
502+
}
503+
static inline auto encodeTypeInRef(const INSTANCE_TYPE type, IGPUBottomLevelAccelerationStructure::host_op_ref_t ref)
504+
{
505+
// aligned to 16 bytes as per the spec
506+
assert(ref.apiHandle%16==0);
507+
switch (type)
508+
{
509+
case INSTANCE_TYPE::SRT_MOTION:
510+
ref.apiHandle += 2;
511+
break;
512+
case INSTANCE_TYPE::MATRIX_MOTION:
513+
ref.apiHandle += 1;
514+
break;
515+
default:
516+
break;
517+
}
518+
return ref;
519+
}
520+
486521
//! BEWARE, OUR RESOURCE LIFETIME TRACKING DOES NOT WORK ACROSS TLAS->BLAS boundaries with these types of BLAS references!
487522
using DeviceInstance = Instance<IGPUBottomLevelAccelerationStructure::device_op_ref_t>;
488523
using HostInstance = Instance<IGPUBottomLevelAccelerationStructure::host_op_ref_t>;

0 commit comments

Comments
 (0)