Skip to content

Commit 16fb038

Browse files
author
devsh
committed
remove the INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB flag, moveit as a bool to IGPUTopLevelAccelerationStructure
The ICPUTopLevelAccelerationStructure had no business knowing about encoding of input instance data during a Device build.
1 parent 2fafa6d commit 16fb038

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

include/nbl/asset/IAccelerationStructure.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ class ITopLevelAccelerationStructure : public AccelerationStructure
154154
PREFER_FAST_TRACE_BIT = 0x1u<<2u,
155155
PREFER_FAST_BUILD_BIT = 0x1u<<3u,
156156
LOW_MEMORY_BIT = 0x1u<<4u,
157-
// Synthetic flag we use to indicate `VkAccelerationStructureGeometryInstancesDataKHR::arrayOfPointers`
158-
INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB = 0x1u<<5u, // this flag really shouldn't be settable outside of `video::IGPU`
159157
// Provided by VK_NV_ray_tracing_motion_blur, but we always override and deduce from creation flag because of
160158
// https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-dstAccelerationStructure-04927
161159
//MOTION_BIT = 0x1u<<5u,
@@ -237,7 +235,7 @@ class ITopLevelAccelerationStructure : public AccelerationStructure
237235
static_assert(alignof(Instance<blas_ref_t>)==8ull);
238236
};
239237

240-
// enum for distinguishing unions of Instance Types when there is no `INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB` in build flags
238+
// enum for distinguishing unions of Instance Types when using a polymorphic instance
241239
enum class INSTANCE_TYPE : uint32_t
242240
{
243241
// StaticInstance

include/nbl/asset/ICPUAccelerationStructure.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ class ICPUTopLevelAccelerationStructure final : public ITopLevelAccelerationStru
311311
if(!isMutable())
312312
return;
313313
m_buildFlags = buildFlags;
314-
// we always clear this flag as we always store instances as polymorphic for ICPUTopLevelAccelerationStructure
315-
m_buildFlags &= ~BUILD_FLAGS::INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB;
316314
}
317315

318316
//

include/nbl/video/IGPUAccelerationStructure.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
411411
if (buildRangeInfo.instanceCount>dstAS->getMaxInstanceCount())
412412
return false;
413413

414-
const bool arrayOfPointers = buildFlags.hasFlags(BUILD_FLAGS::INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB);
414+
const bool arrayOfPointers = instanceDataTypeEncodedInPointersLSB;
415415
constexpr bool HostBuild = std::is_same_v<BufferType,asset::ICPUBuffer>;
416416
// I'm not gonna do the `std::conditional_t<HostBuild,,>` to get the correct Instance struct type as they're the same size essentially
417417
const size_t instanceSize = arrayOfPointers ? sizeof(void*):(
@@ -467,11 +467,13 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
467467

468468

469469
core::bitflag<BUILD_FLAGS> buildFlags = BUILD_FLAGS::PREFER_FAST_BUILD_BIT;
470+
// What we use to indicate `VkAccelerationStructureGeometryInstancesDataKHR::arrayOfPointers`
471+
uint8_t instanceDataTypeEncodedInPointersLSB : 1 = false;
470472
const IGPUTopLevelAccelerationStructure* srcAS = nullptr;
471473
IGPUTopLevelAccelerationStructure* dstAS = nullptr;
472-
// depending on the presence certain bits in `buildFlags` this buffer will be filled with:
474+
// depending on value of certain build info members this buffer will be filled with:
473475
// - addresses to `StaticInstance`, `MatrixMotionInstance`, `SRTMotionInstance` packed in upper 60 bits
474-
// and struct type in lower 4 bits if and only if `buildFlags.hasFlags(INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB)`, otherwise:
476+
// and struct type in lower 4 bits if and only if `instanceDataTypeEncodedInPointersLSB`, otherwise:
475477
// + an array of `PolymorphicInstance` if our `SCreationParams::flags.hasFlags(MOTION_BIT)`, otherwise
476478
// + an array of `StaticInstance`
477479
asset::SBufferBinding<const BufferType> instanceData = {};
@@ -482,7 +484,6 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
482484
using HostBuildInfo = BuildInfo<asset::ICPUBuffer>;
483485

484486
//! BEWARE, OUR RESOURCE LIFETIME TRACKING DOES NOT WORK ACROSS TLAS->BLAS boundaries with these types of BLAS references!
485-
// TODO: Investigate `EXT_private_data` to be able to go ` -> IGPUBottomLevelAccelerationStructure` on Host Builds
486487
using DeviceInstance = Instance<IGPUBottomLevelAccelerationStructure::device_op_ref_t>;
487488
using HostInstance = Instance<IGPUBottomLevelAccelerationStructure::host_op_ref_t>;
488489
static_assert(sizeof(DeviceInstance)==sizeof(HostInstance));

src/nbl/video/CVulkanAccelerationStructure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void getVkASGeometryFrom(const IGPUTopLevelAccelerationStructure::BuildInfo<Buff
172172
{
173173
outBase = {VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR,nullptr,VK_GEOMETRY_TYPE_INSTANCES_KHR};
174174
outBase.geometry.instances = {VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR,nullptr};
175-
outBase.geometry.instances.arrayOfPointers = info.buildFlags.hasFlags(IGPUTopLevelAccelerationStructure::BUILD_FLAGS::INSTANCE_DATA_IS_POINTERS_TYPE_ENCODED_LSB);
175+
outBase.geometry.instances.arrayOfPointers = info.instanceDataTypeEncodedInPointersLSB;
176176
outBase.geometry.instances.data = QueryOnly ? NullAddress:getVkDeviceOrHostAddress<const BufferType>(info.instanceData);
177177
// no "geometry flags" are valid for all instances!
178178
outBase.flags = static_cast<VkGeometryFlagsKHR>(0u);

0 commit comments

Comments
 (0)