Skip to content

Commit 04360b6

Browse files
committed
Added additional comments
1 parent 0e4b4f9 commit 04360b6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/sample/bitonicSort/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ SampleInitFactoryWebGPU(
547547
).style.position = 'absolute';
548548
}
549549

550+
// Mouse listener that determines values of hoveredCell and swappedCell
550551
canvas.addEventListener('mousemove', (event) => {
551552
const currWidth = canvas.getBoundingClientRect().width;
552553
const currHeight = canvas.getBoundingClientRect().height;
@@ -627,27 +628,33 @@ SampleInitFactoryWebGPU(
627628
computePassEncoder.setBindGroup(0, computeBGCluster.bindGroups[0]);
628629
computePassEncoder.dispatchWorkgroups(settings['Workgroups Per Step']);
629630
computePassEncoder.end();
630-
//stepIndexController.setValue(settings['Step Index'] + 1);
631631
settings['Step Index'] = settings['Step Index'] + 1;
632632
currentStepController.setValue(
633633
`${settings['Step Index']} of ${settings['Total Steps']}`
634634
);
635635
prevStepController.setValue(settings['Next Step']);
636636
prevBlockHeightController.setValue(settings['Next Swap Span']);
637637
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
638640
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
639642
highestBlockHeight *= 2;
640643
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.
641645
nextStepController.setValue('NONE');
642646
nextBlockHeightController.setValue(0);
643647
} 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.
644649
nextStepController.setValue('FLIP_GLOBAL');
645650
nextBlockHeightController.setValue(highestBlockHeight);
646651
} else {
652+
// The next cycle's maximum swap span can be executed on a range of indices local to the workgroup.
647653
nextStepController.setValue('FLIP_LOCAL');
648654
nextBlockHeightController.setValue(highestBlockHeight);
649655
}
650656
} else {
657+
// Otherwise, execute the next disperse operation
651658
settings['Next Swap Span'] > settings['Workgroup Size'] * 2
652659
? nextStepController.setValue('DISPERSE_GLOBAL')
653660
: nextStepController.setValue('DISPERSE_LOCAL');

0 commit comments

Comments
 (0)