1
1
// =============================================================================
2
- // Copyright (c) 2021-2022 Advanced Micro Devices, Inc. All rights reserved.
2
+ // Copyright (c) 2021-2023 Advanced Micro Devices, Inc. All rights reserved.
3
3
// / @author AMD Developer Tools Team
4
4
// / @file
5
5
// / @brief RT IP 1.1 (Navi2x) specific top level acceleration structure
@@ -25,9 +25,45 @@ namespace rta
25
25
{
26
26
}
27
27
28
- const std::vector<dxr::amd::InstanceNode>& EncodedRtIp11TopLevelBvh::GetInstanceNodes () const
28
+ std::int32_t EncodedRtIp11TopLevelBvh::GetInstanceNodeSize () const
29
29
{
30
- return instance_nodes_;
30
+ if (GetHeader ().GetPostBuildInfo ().GetFusedInstances () == true )
31
+ {
32
+ return dxr::amd::kFusedInstanceNodeSize ;
33
+ }
34
+ else
35
+ {
36
+ return dxr::amd::kInstanceNodeSize ;
37
+ }
38
+ }
39
+
40
+ const dxr::amd::InstanceNode* EncodedRtIp11TopLevelBvh::GetInstanceNode (const dxr::amd::NodePointer* node_ptr) const
41
+ {
42
+ const auto & header_offsets = GetHeader ().GetBufferOffsets ();
43
+ uint32_t byte_offset = node_ptr->GetByteOffset ();
44
+ byte_offset -= header_offsets.leaf_nodes ;
45
+
46
+ if (byte_offset >= instance_node_data_.size ())
47
+ {
48
+ return nullptr ;
49
+ }
50
+
51
+ return reinterpret_cast <const dxr::amd::InstanceNode*>(&instance_node_data_[byte_offset]);
52
+ }
53
+
54
+ int32_t EncodedRtIp11TopLevelBvh::GetInstanceIndex (const dxr::amd::NodePointer* node_ptr) const
55
+ {
56
+ const auto & header_offsets = GetHeader ().GetBufferOffsets ();
57
+ uint32_t byte_offset = node_ptr->GetByteOffset ();
58
+ byte_offset -= header_offsets.leaf_nodes ;
59
+
60
+ if (byte_offset >= instance_node_data_.size ())
61
+ {
62
+ return -1 ;
63
+ }
64
+
65
+ uint32_t instance_node_size = GetInstanceNodeSize ();
66
+ return byte_offset / instance_node_size;
31
67
}
32
68
33
69
bool EncodedRtIp11TopLevelBvh::HasBvhReferences () const
@@ -93,11 +129,12 @@ namespace rta
93
129
auto rt_ip11_header = CreateRtIp11AccelerationStructureHeader ();
94
130
rt_ip11_header->LoadFromBuffer (dxr::amd::kAccelerationStructureHeaderSize , buffer.data () + chunk_header.header_offset );
95
131
96
- instance_nodes_ = std::vector<dxr::amd::InstanceNode>(rt_ip11_header->GetPrimitiveCount ());
97
- buffer_stream.Read (dxr::amd::kInstanceNodeSize * instance_nodes_.size (), instance_nodes_.data ());
132
+ int32_t num_instance_nodes = rt_ip11_header->GetPrimitiveCount ();
133
+ instance_node_data_.resize (num_instance_nodes * GetInstanceNodeSize ());
134
+ buffer_stream.Read (instance_node_data_.size (), instance_node_data_.data ());
98
135
99
- const auto prim_node_ptr_size = instance_nodes_. size () * sizeof (dxr::amd::NodePointer);
100
- primitive_node_ptrs_.resize (instance_nodes_. size () );
136
+ const auto prim_node_ptr_size = num_instance_nodes * sizeof (dxr::amd::NodePointer);
137
+ primitive_node_ptrs_.resize (prim_node_ptr_size );
101
138
buffer_stream.Read (prim_node_ptr_size, primitive_node_ptrs_.data ());
102
139
103
140
buffer_stream.Close ();
@@ -109,7 +146,7 @@ namespace rta
109
146
{
110
147
bool result = BuildInstanceList ();
111
148
ScanTreeDepth ();
112
- instance_surface_area_heuristic_.resize (instance_nodes_. size (), 0 );
149
+ instance_surface_area_heuristic_.resize (header_-> GetPrimitiveCount (), 0 );
113
150
return result;
114
151
}
115
152
@@ -124,29 +161,31 @@ namespace rta
124
161
else
125
162
{
126
163
// Fix up the instance node addresses.
127
- for (auto & instance_node : instance_nodes_)
164
+ int32_t byte_offset = 0 ;
165
+ while (byte_offset < instance_node_data_.size ())
128
166
{
129
- if (instance_node.IsInactive ())
167
+ dxr::amd::InstanceNode* instance_node = reinterpret_cast <dxr::amd::InstanceNode*>(&instance_node_data_[byte_offset]);
168
+ if (!instance_node->IsInactive ())
130
169
{
131
- continue ;
132
- }
170
+ uint64_t address = instance_node->GetDesc ().GetBottomLevelBvhGpuVa (dxr::InstanceDescType::kRaw );
171
+ uint32_t meta_data_size = instance_node->GetExtraData ().GetBottomLevelBvhMetaDataSize ();
172
+ const GpuVirtualAddress old_reference = address - meta_data_size;
133
173
134
- uint64_t address = instance_node.GetDesc ().GetBottomLevelBvhGpuVa (dxr::InstanceDescType::kRaw );
135
- uint32_t meta_data_size = instance_node.GetExtraData ().GetBottomLevelBvhMetaDataSize ();
136
- const GpuVirtualAddress old_reference = address - meta_data_size;
137
-
138
- const auto it = reference_map.find (old_reference);
139
- if (it != reference_map.end ())
140
- {
141
- const auto new_relative_reference = it->second ;
142
- instance_node.GetDesc ().SetBottomLevelBvhGpuVa (new_relative_reference << 3 , dxr::InstanceDescType::kRaw );
143
- }
144
- else
145
- {
146
- missing_set.insert (old_reference);
147
- const auto new_relative_reference = 0 ;
148
- instance_node.GetDesc ().SetBottomLevelBvhGpuVa (new_relative_reference << 3 , dxr::InstanceDescType::kRaw );
174
+ const auto it = reference_map.find (old_reference);
175
+ if (it != reference_map.end ())
176
+ {
177
+ const auto new_relative_reference = it->second ;
178
+ instance_node->GetDesc ().SetBottomLevelBvhGpuVa (new_relative_reference << 3 , dxr::InstanceDescType::kRaw );
179
+ }
180
+ else
181
+ {
182
+ missing_set.insert (old_reference);
183
+ const auto new_relative_reference = 0 ;
184
+ instance_node->GetDesc ().SetBottomLevelBvhGpuVa (new_relative_reference << 3 , dxr::InstanceDescType::kRaw );
185
+ }
149
186
}
187
+
188
+ byte_offset += GetInstanceNodeSize ();
150
189
}
151
190
}
152
191
}
@@ -184,18 +223,13 @@ namespace rta
184
223
if (node_ptr.IsInstanceNode ())
185
224
{
186
225
auto byte_offset = node_ptr.GetByteOffset () - header_offsets.leaf_nodes ;
187
-
188
- uint32_t instance_node_size = sizeof (dxr::amd::InstanceNode);
189
- uint32_t instance_index = byte_offset / instance_node_size;
190
-
191
- const auto & instance_nodes = GetInstanceNodes ();
192
- if (instance_index < instance_nodes.size ())
226
+ if (byte_offset < instance_node_data_.size ())
193
227
{
194
- const dxr::amd::InstanceNode* instance_node = &instance_nodes[instance_index];
195
- const auto & desc = instance_node->GetDesc ();
228
+ const dxr::amd::InstanceNode* instance_node = reinterpret_cast <const dxr::amd::InstanceNode*>(&instance_node_data_[byte_offset]);
196
229
230
+ const auto & desc = instance_node->GetDesc ();
197
231
uint64_t blas_index = desc.GetBottomLevelBvhGpuVa (dxr::InstanceDescType::kRaw ) >> 3 ;
198
- uint32_t address = (instance_index * sizeof (dxr::amd::InstanceNode)) + header_offsets.leaf_nodes ;
232
+ uint32_t address = byte_offset + header_offsets.leaf_nodes ;
199
233
dxr::amd::NodePointer new_node = dxr::amd::NodePointer (dxr::amd::NodeType::kAmdNodeInstance , address);
200
234
201
235
if (instance_list_.find (blas_index) == instance_list_.end ())
@@ -259,12 +293,16 @@ namespace rta
259
293
uint64_t EncodedRtIp11TopLevelBvh::GetInactiveInstanceCountImpl () const
260
294
{
261
295
uint64_t inactive_count{0 };
262
- for (auto & instance_node : instance_nodes_)
296
+ int32_t byte_offset = 0 ;
297
+ while (byte_offset < instance_node_data_.size ())
263
298
{
264
- if (instance_node.IsInactive ())
299
+ const dxr::amd::InstanceNode* instance_node = reinterpret_cast <const dxr::amd::InstanceNode*>(&instance_node_data_[byte_offset]);
300
+ if (instance_node->IsInactive ())
265
301
{
266
302
++inactive_count;
267
303
}
304
+
305
+ byte_offset += GetInstanceNodeSize ();
268
306
}
269
307
return inactive_count;
270
308
}
@@ -361,20 +399,16 @@ namespace rta
361
399
362
400
float EncodedRtIp11TopLevelBvh::GetLeafNodeSurfaceAreaHeuristic (const dxr::amd::NodePointer node_ptr) const
363
401
{
364
- const uint32_t byte_offset = node_ptr.GetByteOffset ();
365
- const uint32_t leaf_nodes = GetHeader ().GetBufferOffsets ().leaf_nodes ;
366
- const uint32_t index = (byte_offset - leaf_nodes) / sizeof (dxr::amd::InstanceNode);
367
- assert (index < instance_nodes_.size ());
402
+ const uint32_t index = GetInstanceIndex (&node_ptr);
403
+ assert (index != -1 );
368
404
assert (index < instance_surface_area_heuristic_.size ());
369
405
return instance_surface_area_heuristic_[index ];
370
406
}
371
407
372
408
void EncodedRtIp11TopLevelBvh::SetLeafNodeSurfaceAreaHeuristic (const dxr::amd::NodePointer node_ptr, float surface_area_heuristic)
373
409
{
374
- const uint32_t byte_offset = node_ptr.GetByteOffset ();
375
- const uint32_t leaf_nodes = GetHeader ().GetBufferOffsets ().leaf_nodes ;
376
- const uint32_t index = (byte_offset - leaf_nodes) / sizeof (dxr::amd::InstanceNode);
377
- assert (index < instance_nodes_.size ());
410
+ const uint32_t index = GetInstanceIndex (&node_ptr);
411
+ assert (index != -1 );
378
412
assert (index < instance_surface_area_heuristic_.size ());
379
413
instance_surface_area_heuristic_[index ] = surface_area_heuristic;
380
414
}
0 commit comments