@@ -202,8 +202,6 @@ SingletonConstruction( uint32_t index, PrimitiveContainer& primitives, BoxNode*
202
202
leafType = InstanceType;
203
203
}
204
204
205
- primNodes[0 ].m_parentAddr = 0 ;
206
-
207
205
BoxNode root;
208
206
root.m_box0 = primitives.fetchAabb ( 0 );
209
207
root.m_box1 .reset ();
@@ -415,58 +413,78 @@ extern "C" __global__ void ComputeMortonCodes_InstanceList_MatrixFrame(
415
413
ComputeMortonCodes<InstanceList<MatrixFrame>>( primitives, centroidBox, mortonCodeKeys, mortonCodeValues );
416
414
}
417
415
418
- extern " C" __global__ void ResetCounters ( uint32_t primCount, BoxNode* boxNodes )
416
+ template <typename PrimitiveContainer, typename PrimitiveNode, typename Header>
417
+ __device__ void ResetCountersAndUpdateLeaves (
418
+ const Header* header, PrimitiveContainer& primitives, BoxNode* boxNodes, PrimitiveNode* primNodes )
419
419
{
420
420
const uint32_t index = threadIdx.x + blockIdx.x * blockDim.x ;
421
- if ( index < primCount ) boxNodes[index ].m_updateCounter = 0 ;
421
+
422
+ if ( index < header->m_boxNodeCount ) boxNodes[index ].m_updateCounter = 0 ;
423
+
424
+ if constexpr ( is_same<PrimitiveNode, TriangleNode>::value )
425
+ {
426
+ if ( index < header->m_primNodeCount )
427
+ {
428
+ primNodes[index ] = primitives.fetchTriangleNode ( { primNodes[index ].m_primIndex0 , primNodes[index ].m_primIndex1 } );
429
+ }
430
+ }
431
+ else if constexpr ( is_same<PrimitiveNode, InstanceNode>::value )
432
+ {
433
+ if ( index < primitives.getFrameCount () ) primitives.convertFrame ( index );
434
+
435
+ if ( index < header->m_primNodeCount )
436
+ {
437
+ const uint32_t primIndex = primNodes[index ].m_primIndex ;
438
+ hiprtTransformHeader transform = primitives.fetchTransformHeader ( primIndex );
439
+ primNodes[index ].m_mask = primitives.fetchMask ( primIndex );
440
+ if ( transform.frameCount == 1 )
441
+ primNodes[index ].m_identity =
442
+ primitives.copyInvTransformMatrix ( transform.frameIndex , primNodes[index ].m_matrix ) ? 1 : 0 ;
443
+ }
444
+ }
422
445
}
423
446
424
- template < typename InstanceList>
425
- __device__ void ResetCountersAndUpdateFrames ( InstanceList& instanceList , BoxNode* boxNodes )
447
+ extern " C " __global__ void ResetCountersAndUpdateLeaves_TriangleMesh_TriangleNode (
448
+ const GeomHeader* header, TriangleMesh primitives , BoxNode* boxNodes, TriangleNode* primNodes )
426
449
{
427
- const uint32_t index = threadIdx.x + blockIdx.x * blockDim.x ;
428
- if ( index < instanceList.getCount () ) boxNodes[index ].m_updateCounter = 0 ;
429
- if ( index < instanceList.getFrameCount () ) instanceList.convertFrame ( index );
450
+ ResetCountersAndUpdateLeaves ( header, primitives, boxNodes, primNodes );
430
451
}
431
452
432
- extern " C" __global__ void
433
- ResetCountersAndUpdateFrames_InstanceList_SRTFrame ( InstanceList<SRTFrame> instanceList, BoxNode* boxNodes )
453
+ extern " C" __global__ void ResetCountersAndUpdateLeaves_AabbList_CustomNode (
454
+ const GeomHeader* header, AabbList primitives, BoxNode* boxNodes, CustomNode* primNodes )
434
455
{
435
- ResetCountersAndUpdateFrames<InstanceList<SRTFrame>>( instanceList, boxNodes );
456
+ ResetCountersAndUpdateLeaves ( header, primitives, boxNodes, primNodes );
436
457
}
437
458
438
- extern " C" __global__ void
439
- ResetCountersAndUpdateFrames_InstanceList_MatrixFrame ( InstanceList<MatrixFrame> instanceList , BoxNode* boxNodes )
459
+ extern " C" __global__ void ResetCountersAndUpdateLeaves_InstanceList_MatrixFrame_InstanceNode (
460
+ const SceneHeader* header, InstanceList<MatrixFrame> primitives , BoxNode* boxNodes, InstanceNode* primNodes )
440
461
{
441
- ResetCountersAndUpdateFrames<InstanceList<MatrixFrame>>( instanceList, boxNodes );
462
+ ResetCountersAndUpdateLeaves ( header, primitives, boxNodes, primNodes );
442
463
}
443
464
444
- template <typename PrimitiveContainer, typename PrimitiveNode>
445
- __device__ void FitBounds ( PrimitiveContainer& primitives, BoxNode* boxNodes, PrimitiveNode* primNodes )
465
+ extern " C" __global__ void ResetCountersAndUpdateLeaves_InstanceList_SRTFrame_InstanceNode (
466
+ const SceneHeader* header, InstanceList<SRTFrame> primitives, BoxNode* boxNodes, InstanceNode* primNodes )
467
+ {
468
+ ResetCountersAndUpdateLeaves ( header, primitives, boxNodes, primNodes );
469
+ }
470
+
471
+ template <typename PrimitiveContainer, typename PrimitiveNode, typename Header>
472
+ __device__ void FitBounds ( Header* header, PrimitiveContainer& primitives, BoxNode* boxNodes, PrimitiveNode* primNodes )
446
473
{
447
474
uint32_t index = threadIdx.x + blockIdx.x * blockDim.x ;
448
475
449
- if ( index >= primitives. getCount () ) return ;
476
+ if ( index >= header-> m_boxNodeCount ) return ;
450
477
451
- uint32_t parentAddr = primNodes[index ].m_parentAddr ;
452
- if constexpr ( is_same<PrimitiveNode, TriangleNode>::value )
453
- {
454
- primNodes[index ] =
455
- primitives.fetchTriangleNode ( make_uint2 ( primNodes[index ].m_primIndex0 , primNodes[index ].m_primIndex1 ) );
456
- primNodes[index ].m_parentAddr = parentAddr;
457
- }
458
- else if constexpr ( is_same<PrimitiveNode, InstanceNode>::value )
478
+ BoxNode node = boxNodes[index ];
479
+ uint32_t internalCount = 0 ;
480
+ for ( uint32_t i = 0 ; i < node.m_childCount ; ++i )
459
481
{
460
- const uint32_t primIndex = primNodes[index ].m_primIndex ;
461
- hiprtTransformHeader transform = primitives.fetchTransformHeader ( primIndex );
462
- primNodes[index ].m_mask = primitives.fetchMask ( primIndex );
463
- if ( transform.frameCount == 1 )
464
- primNodes[index ].m_identity =
465
- primitives.copyInvTransformMatrix ( transform.frameIndex , primNodes[index ].m_matrix ) ? 1 : 0 ;
482
+ if ( node.getChildType ( i ) == BoxType ) internalCount++;
466
483
}
467
484
468
- index = parentAddr;
469
- while ( index != InvalidValue && atomicAdd ( &boxNodes[index ].m_updateCounter , 1 ) >= boxNodes[index ].m_childCount - 1 )
485
+ if ( internalCount > 0 ) return ;
486
+
487
+ while ( true )
470
488
{
471
489
__threadfence ();
472
490
@@ -484,33 +502,40 @@ __device__ void FitBounds( PrimitiveContainer& primitives, BoxNode* boxNodes, Pr
484
502
if ( node.m_childIndex3 != InvalidValue )
485
503
node.m_box3 = getNodeBox ( node.m_childIndex3 , primitives, boxNodes, primNodes );
486
504
487
- index = boxNodes[index ].m_parentAddr ;
505
+ internalCount = 0 ;
506
+ for ( uint32_t i = 0 ; i < node.m_childCount ; ++i )
507
+ {
508
+ if ( node.getChildType ( i ) == BoxType ) internalCount++;
509
+ }
488
510
489
511
__threadfence ();
512
+
513
+ if ( atomicAdd ( &node.m_updateCounter , 1 ) < internalCount - 1 ) break ;
490
514
}
491
515
}
492
516
493
517
extern " C" __global__ void
494
- FitBounds_TriangleMesh_TriangleNode ( TriangleMesh primitives, BoxNode* boxNodes, TriangleNode* primNodes )
518
+ FitBounds_TriangleMesh_TriangleNode ( GeomHeader* header, TriangleMesh primitives, BoxNode* boxNodes, TriangleNode* primNodes )
495
519
{
496
- FitBounds<TriangleMesh, TriangleNode>( primitives, boxNodes, primNodes );
520
+ FitBounds<TriangleMesh, TriangleNode>( header, primitives, boxNodes, primNodes );
497
521
}
498
522
499
- extern " C" __global__ void FitBounds_AabbList_CustomNode ( AabbList primitives, BoxNode* boxNodes, CustomNode* primNodes )
523
+ extern " C" __global__ void
524
+ FitBounds_AabbList_CustomNode ( GeomHeader* header, AabbList primitives, BoxNode* boxNodes, CustomNode* primNodes )
500
525
{
501
- FitBounds<AabbList, CustomNode>( primitives, boxNodes, primNodes );
526
+ FitBounds<AabbList, CustomNode>( header, primitives, boxNodes, primNodes );
502
527
}
503
528
504
- extern " C" __global__ void
505
- FitBounds_InstanceList_SRTFrame_InstanceNode ( InstanceList<SRTFrame> primitives, BoxNode* boxNodes, InstanceNode* primNodes )
529
+ extern " C" __global__ void FitBounds_InstanceList_SRTFrame_InstanceNode (
530
+ SceneHeader* header, InstanceList<SRTFrame> primitives, BoxNode* boxNodes, InstanceNode* primNodes )
506
531
{
507
- FitBounds<InstanceList<SRTFrame>, InstanceNode>( primitives, boxNodes, primNodes );
532
+ FitBounds<InstanceList<SRTFrame>, InstanceNode>( header, primitives, boxNodes, primNodes );
508
533
}
509
534
510
535
extern " C" __global__ void FitBounds_InstanceList_MatrixFrame_InstanceNode (
511
- InstanceList<MatrixFrame> primitives, BoxNode* boxNodes, InstanceNode* primNodes )
536
+ SceneHeader* header, InstanceList<MatrixFrame> primitives, BoxNode* boxNodes, InstanceNode* primNodes )
512
537
{
513
- FitBounds<InstanceList<MatrixFrame>, InstanceNode>( primitives, boxNodes, primNodes );
538
+ FitBounds<InstanceList<MatrixFrame>, InstanceNode>( header, primitives, boxNodes, primNodes );
514
539
}
515
540
516
541
template <typename PrimitiveContainer, typename PrimitiveNode, typename Header>
@@ -635,8 +660,7 @@ __device__ void Collapse(
635
660
else
636
661
primNodes[nodeAddr].m_transform = transform;
637
662
}
638
- primNodes[nodeAddr].m_parentAddr = parentAddr;
639
- done = true ;
663
+ done = true ;
640
664
}
641
665
}
642
666
0 commit comments