@@ -547,6 +547,7 @@ SampleInitFactoryWebGPU(
547
547
) . style . position = 'absolute' ;
548
548
}
549
549
550
+ // Mouse listener that determines values of hoveredCell and swappedCell
550
551
canvas . addEventListener ( 'mousemove' , ( event ) => {
551
552
const currWidth = canvas . getBoundingClientRect ( ) . width ;
552
553
const currHeight = canvas . getBoundingClientRect ( ) . height ;
@@ -627,27 +628,33 @@ SampleInitFactoryWebGPU(
627
628
computePassEncoder . setBindGroup ( 0 , computeBGCluster . bindGroups [ 0 ] ) ;
628
629
computePassEncoder . dispatchWorkgroups ( settings [ 'Workgroups Per Step' ] ) ;
629
630
computePassEncoder . end ( ) ;
630
- //stepIndexController.setValue(settings['Step Index'] + 1);
631
631
settings [ 'Step Index' ] = settings [ 'Step Index' ] + 1 ;
632
632
currentStepController . setValue (
633
633
`${ settings [ 'Step Index' ] } of ${ settings [ 'Total Steps' ] } `
634
634
) ;
635
635
prevStepController . setValue ( settings [ 'Next Step' ] ) ;
636
636
prevBlockHeightController . setValue ( settings [ 'Next Swap Span' ] ) ;
637
637
nextBlockHeightController . setValue ( settings [ 'Next Swap Span' ] / 2 ) ;
638
+ // Each cycle of a bitonic sort contains a flip operation followed by multiple disperse operations
639
+ // Next Swap Span will equal one when the sort needs to begin a new cycle of flip and disperse operations
638
640
if ( settings [ 'Next Swap Span' ] === 1 ) {
641
+ // The next cycle's flip operation will have a maximum swap span 2 times that of the previous cycle
639
642
highestBlockHeight *= 2 ;
640
643
if ( highestBlockHeight === settings [ 'Total Elements' ] * 2 ) {
644
+ // The next cycle's maximum swap span exceeds the total number of elements. Thus, the sort is over.
641
645
nextStepController . setValue ( 'NONE' ) ;
642
646
nextBlockHeightController . setValue ( 0 ) ;
643
647
} else if ( highestBlockHeight > settings [ 'Workgroup Size' ] * 2 ) {
648
+ // The next cycle's maximum swap span exceeds the range of a single workgroup, so our next flip will operate on global indices.
644
649
nextStepController . setValue ( 'FLIP_GLOBAL' ) ;
645
650
nextBlockHeightController . setValue ( highestBlockHeight ) ;
646
651
} else {
652
+ // The next cycle's maximum swap span can be executed on a range of indices local to the workgroup.
647
653
nextStepController . setValue ( 'FLIP_LOCAL' ) ;
648
654
nextBlockHeightController . setValue ( highestBlockHeight ) ;
649
655
}
650
656
} else {
657
+ // Otherwise, execute the next disperse operation
651
658
settings [ 'Next Swap Span' ] > settings [ 'Workgroup Size' ] * 2
652
659
? nextStepController . setValue ( 'DISPERSE_GLOBAL' )
653
660
: nextStepController . setValue ( 'DISPERSE_LOCAL' ) ;
0 commit comments