20
20
namespace nbl ::asset
21
21
{
22
22
23
- class IAccelerationStructure : public IDescriptor
23
+ class IAccelerationStructure : public virtual core::IReferenceCounted
24
24
{
25
25
public:
26
+ // build flags, we don't expose flags that don't make sense for certain levels
27
+ enum class BUILD_FLAGS : uint8_t
28
+ {
29
+ ALLOW_UPDATE_BIT = 0x1u << 0u ,
30
+ ALLOW_COMPACTION_BIT = 0x1u << 1u ,
31
+ PREFER_FAST_TRACE_BIT = 0x1u << 2u ,
32
+ PREFER_FAST_BUILD_BIT = 0x1u << 3u ,
33
+ LOW_MEMORY_BIT = 0x1u << 4u ,
34
+ // Provided by VK_NV_ray_tracing_motion_blur, but is ignored for BLASes and we always override and deduce from TLAS creation flag because of
35
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-dstAccelerationStructure-04927
36
+ // MOTION_BIT = 0x1u<<5u,
37
+ ALL_MASK = (01u <<5u )-1 ,
38
+ };
39
+
26
40
// we don't expose the GENERIC type because Vulkan only intends it for API-translation layers like VKD3D or MoltenVK
27
41
virtual bool isBLAS () const = 0;
28
42
29
- // !
30
- inline E_CATEGORY getTypeCategory () const override { return EC_ACCELERATION_STRUCTURE; }
43
+ virtual bool usesMotion () const = 0;
31
44
32
45
protected:
33
46
IAccelerationStructure () = default ;
34
47
};
35
48
36
- template <class AccelerationStructure >
37
- class IBottomLevelAccelerationStructure : public AccelerationStructure
49
+ NBL_ENUM_ADD_BITWISE_OPERATORS (IAccelerationStructure::BUILD_FLAGS);
50
+
51
+ // To avoid having duplicate instantiations of flags, etc.
52
+ class IBottomLevelAccelerationStructure : public IAccelerationStructure
38
53
{
39
- static_assert (std::is_base_of_v<IAccelerationStructure,AccelerationStructure>);
54
+ using base_build_flags_t = IAccelerationStructure::BUILD_FLAGS;
55
+
40
56
public:
41
- inline bool isBLAS () const override {return true ;}
57
+ inline bool isBLAS () const override { return true ; }
42
58
43
59
// build flags, we don't expose flags that don't make sense for certain levels
44
60
enum class BUILD_FLAGS : uint16_t
45
61
{
46
- ALLOW_UPDATE_BIT = 0x1u << 0u ,
47
- ALLOW_COMPACTION_BIT = 0x1u << 1u ,
48
- PREFER_FAST_TRACE_BIT = 0x1u << 2u ,
49
- PREFER_FAST_BUILD_BIT = 0x1u << 3u ,
50
- LOW_MEMORY_BIT = 0x1u << 4u ,
62
+ ALLOW_UPDATE_BIT = base_build_flags_t ::ALLOW_UPDATE_BIT ,
63
+ ALLOW_COMPACTION_BIT = base_build_flags_t ::ALLOW_COMPACTION_BIT ,
64
+ PREFER_FAST_TRACE_BIT = base_build_flags_t ::PREFER_FAST_TRACE_BIT ,
65
+ PREFER_FAST_BUILD_BIT = base_build_flags_t ::PREFER_FAST_BUILD_BIT ,
66
+ LOW_MEMORY_BIT = base_build_flags_t ::LOW_MEMORY_BIT ,
51
67
// Synthetic flag we use to indicate that the build data are AABBs instead of triangles, we've taken away the per-geometry choice thanks to:
52
68
// https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03792
53
69
GEOMETRY_TYPE_IS_AABB_BIT = 0x1u <<5u ,
54
- // Provided by VK_NV_ray_tracing_motion_blur, but is ignored for BLASes
55
- // MOTION_BIT = 0x1u<<5u
56
70
// Provided by VK_EXT_opacity_micromap
57
71
ALLOW_OPACITY_MICROMAP_UPDATE_BIT = 0x1u <<6u ,
58
72
ALLOW_DISABLE_OPACITY_MICROMAPS_BIT = 0x1u <<7u ,
@@ -62,18 +76,7 @@ class IBottomLevelAccelerationStructure : public AccelerationStructure
62
76
// Provided by VK_KHR_ray_tracing_position_fetch
63
77
ALLOW_DATA_ACCESS = 0x1u <<11u ,
64
78
};
65
- static inline bool validBuildFlags (const core::bitflag<BUILD_FLAGS> flags)
66
- {
67
- // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-03796
68
- if (flags.hasFlags (BUILD_FLAGS::PREFER_FAST_BUILD_BIT) && flags.hasFlags (BUILD_FLAGS::PREFER_FAST_TRACE_BIT))
69
- return false ;
70
79
71
- // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-07334
72
- if (flags.hasFlags (BUILD_FLAGS::ALLOW_OPACITY_MICROMAP_UPDATE_BIT) && flags.hasFlags (BUILD_FLAGS::ALLOW_OPACITY_MICROMAP_DATA_UPDATE_BIT))
73
- return false ;
74
-
75
- return true ;
76
- }
77
80
78
81
// Apparently Vulkan allows setting these on TLAS Geometry (which are instances) but applying them to a TLAS doesn't make any SENSE AT ALL!
79
82
enum class GEOMETRY_FLAGS : uint8_t
@@ -132,42 +135,40 @@ class IBottomLevelAccelerationStructure : public AccelerationStructure
132
135
using AABB_t = core::aabbox3d<float >;
133
136
134
137
protected:
135
- using AccelerationStructure::AccelerationStructure;
138
+ using base_build_flags_t = IAccelerationStructure::BUILD_FLAGS;
139
+ using IAccelerationStructure::IAccelerationStructure;
136
140
virtual ~IBottomLevelAccelerationStructure () = default ;
141
+
142
+ static inline bool validBuildFlags (const core::bitflag<BUILD_FLAGS> flags)
143
+ {
144
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-03796
145
+ if (flags.hasFlags (BUILD_FLAGS::PREFER_FAST_BUILD_BIT) && flags.hasFlags (BUILD_FLAGS::PREFER_FAST_TRACE_BIT))
146
+ return false ;
147
+
148
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-07334
149
+ if (flags.hasFlags (BUILD_FLAGS::ALLOW_OPACITY_MICROMAP_UPDATE_BIT) && flags.hasFlags (BUILD_FLAGS::ALLOW_OPACITY_MICROMAP_DATA_UPDATE_BIT))
150
+ return false ;
151
+
152
+ return true ;
153
+ }
137
154
};
155
+ NBL_ENUM_ADD_BITWISE_OPERATORS (IBottomLevelAccelerationStructure::BUILD_FLAGS);
138
156
139
157
// forward declare for `static_assert`
140
158
class ICPUBottomLevelAccelerationStructure ;
141
159
142
- // TODO: maybe we should introduce a base class so that flags and Instance declarations aren't doubled up
143
- template <class AccelerationStructure >
144
- class ITopLevelAccelerationStructure : public AccelerationStructure
160
+ class ITopLevelAccelerationStructure : public IDescriptor , public IAccelerationStructure
145
161
{
146
- static_assert (std::is_base_of_v<IAccelerationStructure,AccelerationStructure>) ;
162
+ using base_build_flags_t = IAccelerationStructure::BUILD_FLAGS ;
147
163
148
164
public:
149
- inline bool isBLAS () const override {return false ;}
165
+ // !
166
+ inline E_CATEGORY getTypeCategory () const override {return EC_ACCELERATION_STRUCTURE;}
150
167
151
- // build flags, we don't expose flags that don't make sense for certain levels
152
- enum class BUILD_FLAGS : uint8_t
153
- {
154
- ALLOW_UPDATE_BIT = 0x1u <<0u ,
155
- ALLOW_COMPACTION_BIT = 0x1u <<1u ,
156
- PREFER_FAST_TRACE_BIT = 0x1u <<2u ,
157
- PREFER_FAST_BUILD_BIT = 0x1u <<3u ,
158
- LOW_MEMORY_BIT = 0x1u <<4u ,
159
- // Provided by VK_NV_ray_tracing_motion_blur, but we always override and deduce from creation flag because of
160
- // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-dstAccelerationStructure-04927
161
- // MOTION_BIT = 0x1u<<5u,
162
- };
163
- static inline bool validBuildFlags (const core::bitflag<BUILD_FLAGS> flags)
164
- {
165
- // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-03796
166
- if (flags.hasFlags (BUILD_FLAGS::PREFER_FAST_BUILD_BIT) && flags.hasFlags (BUILD_FLAGS::PREFER_FAST_TRACE_BIT))
167
- return false ;
168
+ inline bool isBLAS () const override {return false ;}
168
169
169
- return true ;
170
- }
170
+ // No extra flags for TLAS builds
171
+ using BUILD_FLAGS = base_build_flags_t ;
171
172
172
173
enum class INSTANCE_FLAGS : uint8_t
173
174
{
@@ -253,7 +254,7 @@ class ITopLevelAccelerationStructure : public AccelerationStructure
253
254
switch (type)
254
255
{
255
256
case INSTANCE_TYPE::SRT_MOTION:
256
- return sizeof (SRTMotionInstance<ptrdiff_t >);
257
+ return sizeof ( SRTMotionInstance<ptrdiff_t >);
257
258
break ;
258
259
case INSTANCE_TYPE::MATRIX_MOTION:
259
260
return sizeof (MatrixMotionInstance<ptrdiff_t >);
@@ -265,8 +266,16 @@ class ITopLevelAccelerationStructure : public AccelerationStructure
265
266
}
266
267
267
268
protected:
268
- using AccelerationStructure::AccelerationStructure ;
269
+ using IAccelerationStructure::IAccelerationStructure ;
269
270
virtual ~ITopLevelAccelerationStructure () = default ;
271
+
272
+ static inline bool validBuildFlags (const core::bitflag<BUILD_FLAGS> flags)
273
+ {
274
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-03796
275
+ if (flags.hasFlags (BUILD_FLAGS::PREFER_FAST_BUILD_BIT) && flags.hasFlags (BUILD_FLAGS::PREFER_FAST_TRACE_BIT))
276
+ return false ;
277
+ return true ;
278
+ }
270
279
};
271
280
272
281
} // end namespace nbl::asset
0 commit comments