@@ -38,7 +38,8 @@ class CAssetConverter : public core::IReferenceCounted
38
38
asset::ICPUSampler,
39
39
asset::ICPUShader,
40
40
asset::ICPUBuffer,
41
- // acceleration structures,
41
+ asset::ICPUBottomLevelAccelerationStructure,
42
+ asset::ICPUTopLevelAccelerationStructure,
42
43
asset::ICPUImage,
43
44
asset::ICPUBufferView,
44
45
asset::ICPUImageView,
@@ -71,6 +72,14 @@ class CAssetConverter : public core::IReferenceCounted
71
72
{
72
73
if (!params.valid ())
73
74
return nullptr ;
75
+ #ifndef _NBL_DEBUG
76
+ if (!params.optimizer )
77
+ {
78
+ using pass_e = asset::ISPIRVOptimizer::E_OPTIMIZER_PASS;
79
+ // shall we do others?
80
+ params.optimizer = core::make_smart_rectd_ptr<asset::ISPIRVOptimizer>({EOP_STRIP_DEBUG_INFO});
81
+ }
82
+ #endif
74
83
return core::smart_refctd_ptr<CAssetConverter>(new CAssetConverter (std::move (params)),core::dont_grab);
75
84
}
76
85
// When getting dependents, the creation parameters of GPU objects will be produced and patched appropriately.
@@ -149,6 +158,71 @@ class CAssetConverter : public core::IReferenceCounted
149
158
return {true ,retval};
150
159
}
151
160
};
161
+ struct NBL_API2 acceleration_structure_patch_base
162
+ {
163
+ public:
164
+ enum class BuildPreference : uint8_t
165
+ {
166
+ None = 0 ,
167
+ FastTrace = 1 ,
168
+ FastBuild = 2 ,
169
+ Invalid = 3
170
+ };
171
+
172
+ // ! select build flags
173
+ uint8_t allowUpdate : 1 = false ;
174
+ uint8_t allowCompaction : 1 = false ;
175
+ uint8_t allowDataAccess : 1 = false ;
176
+ BuildPreference preference : 2 = BuildPreference::Invalid;
177
+ uint8_t lowMemory : 1 = false ;
178
+ // ! things that control the build
179
+ uint8_t hostBuild : 1 = false ;
180
+ uint8_t compactAfterBuild : 1 = false ;
181
+
182
+ protected:
183
+ bool valid (const ILogicalDevice* device);
184
+
185
+ template <typename CRTP>
186
+ std::pair<bool ,CRTP> combine_impl (const CRTP& _this, const CRTP& other) const
187
+ {
188
+ if (_this.preference !=other.preference || _this.preference ==BuildPreference::Invalid)
189
+ return {false ,_this};
190
+ CRTP retval = _this;
191
+ retval.allowUpdate |= other.allowUpdate ;
192
+ retval.allowCompaction |= other.allowCompaction ;
193
+ retval.allowDataAccess |= other.allowDataAccess ;
194
+ retval.lowMemory |= other.lowMemory ;
195
+ retval.hostBuild |= other.hostBuild ;
196
+ retval.compactAfterBuild |= other.compactAfterBuild ;
197
+ return {true ,retval};
198
+ }
199
+ };
200
+ template <>
201
+ struct NBL_API2 patch_impl_t <asset::ICPUBottomLevelAccelerationStructure> : acceleration_structure_patch_base
202
+ {
203
+ public:
204
+ PATCH_IMPL_BOILERPLATE (asset::ICPUBottomLevelAccelerationStructure);
205
+
206
+ protected:
207
+ using build_flags_t = asset::ICPUBottomLevelAccelerationStructure::BUILD_FLAGS;
208
+ inline std::pair<bool ,this_t > combine (const this_t & other) const
209
+ {
210
+ return combine_impl<this_t >(*this ,other);
211
+ }
212
+ };
213
+ template <>
214
+ struct NBL_API2 patch_impl_t <asset::ICPUTopLevelAccelerationStructure> : acceleration_structure_patch_base
215
+ {
216
+ public:
217
+ PATCH_IMPL_BOILERPLATE (asset::ICPUTopLevelAccelerationStructure);
218
+
219
+ protected:
220
+ using build_flags_t = asset::ICPUTopLevelAccelerationStructure::BUILD_FLAGS;
221
+ inline std::pair<bool ,this_t > combine (const this_t & other) const
222
+ {
223
+ return combine_impl<this_t >(*this ,other);
224
+ }
225
+ };
152
226
template <>
153
227
struct NBL_API2 patch_impl_t <asset::ICPUImage>
154
228
{
@@ -458,6 +532,8 @@ class CAssetConverter : public core::IReferenceCounted
458
532
virtual const patch_t <asset::ICPUSampler>* operator ()(const lookup_t <asset::ICPUSampler>&) const = 0;
459
533
virtual const patch_t <asset::ICPUShader>* operator ()(const lookup_t <asset::ICPUShader>&) const = 0;
460
534
virtual const patch_t <asset::ICPUBuffer>* operator ()(const lookup_t <asset::ICPUBuffer>&) const = 0;
535
+ virtual const patch_t <asset::ICPUBottomLevelAccelerationStructure>* operator ()(const lookup_t <asset::ICPUBottomLevelAccelerationStructure>&) const = 0;
536
+ virtual const patch_t <asset::ICPUTopLevelAccelerationStructure>* operator ()(const lookup_t <asset::ICPUTopLevelAccelerationStructure>&) const = 0;
461
537
virtual const patch_t <asset::ICPUImage>* operator ()(const lookup_t <asset::ICPUImage>&) const = 0;
462
538
virtual const patch_t <asset::ICPUBufferView>* operator ()(const lookup_t <asset::ICPUBufferView>&) const = 0;
463
539
virtual const patch_t <asset::ICPUImageView>* operator ()(const lookup_t <asset::ICPUImageView>&) const = 0;
@@ -577,6 +653,8 @@ class CAssetConverter : public core::IReferenceCounted
577
653
bool operator ()(lookup_t <asset::ICPUSampler>);
578
654
bool operator ()(lookup_t <asset::ICPUShader>);
579
655
bool operator ()(lookup_t <asset::ICPUBuffer>);
656
+ bool operator ()(lookup_t <asset::ICPUBottomLevelAccelerationStructure>);
657
+ bool operator ()(lookup_t <asset::ICPUTopLevelAccelerationStructure>);
580
658
bool operator ()(lookup_t <asset::ICPUImage>);
581
659
bool operator ()(lookup_t <asset::ICPUBufferView>);
582
660
bool operator ()(lookup_t <asset::ICPUImageView>);
@@ -829,6 +907,8 @@ class CAssetConverter : public core::IReferenceCounted
829
907
IUtilities* utilities = nullptr ;
830
908
// optional, last submit (compute, transfer if no compute needed) signals these in addition to the scratch semaphore
831
909
std::span<const IQueue::SSubmitInfo::SSemaphoreInfo> extraSignalSemaphores = {};
910
+ // specific to Acceleration Structure Build, they need to be at least as large as the largest amount of scratch required for an AS build
911
+ CAsyncSingleBufferSubAllocatorST<>* scratchForASBuild = nullptr ;
832
912
// specific to mip-map recomputation, these are okay defaults for the size of our Descriptor Indexed temporary descriptor set
833
913
uint32_t sampledImageBindingCount = 1 <<10 ;
834
914
uint32_t storageImageBindingCount = 11 <<10 ;
@@ -853,6 +933,11 @@ class CAssetConverter : public core::IReferenceCounted
853
933
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdCopyBufferToImage.html#VUID-vkCmdCopyBufferToImage-commandBuffer-07739
854
934
inline core::bitflag<IQueue::FAMILY_FLAGS> getRequiredQueueFlags () const {return m_queueFlags;}
855
935
936
+ // just enough memory to build the Acceleration Structures one by one waiting for each build to complete inbetween
937
+ inline uint64_t getMinASBuildScratchSize () const {return m_minASBuildScratchSize;}
938
+ // enough memory to build and compact the all Acceleration Structures at once, obviously respecting order of BLAS (build->compact) -> TLAS (build->compact)
939
+ inline uint64_t getMaxASBuildScratchSize () const {return m_maxASBuildScratchSize;}
940
+
856
941
//
857
942
inline operator bool () const {return bool (m_converter);}
858
943
@@ -924,12 +1009,15 @@ class CAssetConverter : public core::IReferenceCounted
924
1009
using conversion_requests_t = core::vector<ConversionRequest<AssetType>>;
925
1010
using convertible_asset_types = core::type_list<
926
1011
asset::ICPUBuffer,
927
- asset::ICPUImage/* ,
1012
+ asset::ICPUImage,
928
1013
asset::ICPUBottomLevelAccelerationStructure,
929
- asset::ICPUTopLevelAccelerationStructure*/
1014
+ asset::ICPUTopLevelAccelerationStructure
930
1015
>;
931
1016
core::tuple_transform_t <conversion_requests_t ,convertible_asset_types> m_conversionRequests;
932
1017
1018
+ //
1019
+ uint64_t m_minASBuildScratchSize = 0 ;
1020
+ uint64_t m_maxASBuildScratchSize = 0 ;
933
1021
//
934
1022
core::bitflag<IQueue::FAMILY_FLAGS> m_queueFlags = IQueue::FAMILY_FLAGS::NONE;
935
1023
};
0 commit comments