|
|
@@ -12,7 +12,7 @@
|
|
|
<br /> This example demonstrates a bitonic sort running step by step in a compute shader.
|
|
|
<br /> The left canvas swaps values within workgroup local arrays. The right swaps values within storage buffers.
|
|
|
<br /> Reference implementation by <a href="https://poniesandlight.co.uk/reflect/bitonic_merge_sort/">Tim Gfrerer</a>
|
|
|
- <br />
|
|
|
+ <br />
|
|
|
<div id="local_swap" style="
|
|
|
position: absolute;
|
|
|
top: 150px;
|
|
|
@@ -112,14 +112,14 @@
|
|
|
|
|
|
effectController.highlight.value = 0;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
effectController.highlight.value = 1;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
} );
|
|
|
|
|
|
if ( WebGPU.isAvailable() === false ) {
|
|
|
@@ -276,7 +276,7 @@
|
|
|
// Get ids of indices needed to populate workgroup local buffer.
|
|
|
// Use .toVar() to prevent these values from being recalculated multiple times.
|
|
|
const localOffset = uint( WORKGROUP_SIZE[ 0 ] ).mul( 2 ).mul( workgroupId.x ).toVar();
|
|
|
-
|
|
|
+
|
|
|
const localID1 = invocationLocalIndex.mul( 2 );
|
|
|
const localID2 = invocationLocalIndex.mul( 2 ).add( 1 );
|
|
|
|
|
|
@@ -343,7 +343,7 @@
|
|
|
if ( forceGlobalSwap ) {
|
|
|
|
|
|
If( highestBlockHeight.equal( size * 2 ), () => {
|
|
|
-
|
|
|
+
|
|
|
nextAlgo.assign( StepType.NONE );
|
|
|
nextBlockHeight.assign( 0 );
|
|
|
|
|
|
@@ -357,7 +357,7 @@
|
|
|
} else {
|
|
|
|
|
|
If( highestBlockHeight.equal( size * 2 ), () => {
|
|
|
-
|
|
|
+
|
|
|
nextAlgo.assign( StepType.NONE );
|
|
|
nextBlockHeight.assign( 0 );
|
|
|
|
|
|
@@ -403,7 +403,7 @@
|
|
|
const computeResetBuffersFn = Fn( () => {
|
|
|
|
|
|
currentElementsStorage.element( instanceIndex ).assign( randomizedElementsStorage.element( instanceIndex ) );
|
|
|
-
|
|
|
+
|
|
|
} );
|
|
|
|
|
|
const computeResetAlgoFn = Fn( () => {
|
|
|
@@ -487,7 +487,7 @@
|
|
|
renderer.domElement.style.left = '50%';
|
|
|
|
|
|
scene.background = new THREE.Color( 0x212121 );
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
scene.background = new THREE.Color( 0x313131 );
|
|
|
@@ -509,9 +509,9 @@
|
|
|
if ( nextStepGlobal ) {
|
|
|
|
|
|
renderer.compute( computeAlignCurrent );
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
renderer.compute( computeSetAlgo );
|
|
|
|
|
|
currentStep ++;
|
|
|
@@ -522,16 +522,16 @@
|
|
|
renderer.compute( computeResetAlgo );
|
|
|
|
|
|
currentStep = 0;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
renderer.resolveTimestampsAsync( THREE.TimestampQuery.COMPUTE );
|
|
|
|
|
|
|
|
|
const algo = new Uint32Array( await renderer.getArrayBufferAsync( nextAlgoBuffer ) );
|
|
|
- algo > StepType.DISPERSE_LOCAL ? ( nextStepGlobal = true ) : ( nextStepGlobal = false );
|
|
|
+ nextStepGlobal = algo[ 0 ] > StepType.DISPERSE_LOCAL;
|
|
|
const totalSwaps = new Uint32Array( await renderer.getArrayBufferAsync( counterBuffer ) );
|
|
|
-
|
|
|
+
|
|
|
renderer.render( scene, camera );
|
|
|
renderer.resolveTimestampsAsync( THREE.TimestampQuery.RENDER );
|
|
|
|
|
|
@@ -545,17 +545,17 @@
|
|
|
to Region
|
|
|
<div style="background-color: ${ forceGlobalSwap ? globalColors[ 1 ] : localColors[ 1 ]}; width:12.5px; height: 1em; border-radius: 20%;"></div>
|
|
|
</div>`;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
if ( currentStep === MAX_STEPS ) {
|
|
|
|
|
|
setTimeout( stepAnimation, 1000 );
|
|
|
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
setTimeout( stepAnimation, 50 );
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
};
|