@group(0) @binding(0) var compare: array; @group(0) @binding(1) var threadPassIndices: array; @group(0) @binding(2) var kArray: array; @group(0) @binding(3) var jArray: array; @group(0) @binding(4) var totalCount: u32; @compute @workgroup_size( 256 ) fn main( @builtin(global_invocation_id) global_id : vec3 ) { let idx = global_id.x; let threadPassIndex = threadPassIndices[ idx ]; threadPassIndices[idx] = threadPassIndices[idx] + 1; let j = jArray[ threadPassIndex ]; let k = kArray[ threadPassIndex ]; let ixj = idx ^ j; if (idx >= totalCount || ixj <= idx || ixj >= totalCount) { return; } if (ixj > idx) { let ascending = (idx & k) == 0u; let dist_idx = compare[idx]; let dist_ixj = compare[ixj]; var swap = false; if (ascending) { if (dist_idx > dist_ixj) { swap = true; } } else { if (dist_idx < dist_ixj) { swap = true; } } if (swap) { let tempDist = compare[idx]; compare[idx] = compare[ixj]; compare[ixj] = tempDist; } } }