|
|
|
let thread_id = null;
|
|
|
|
let exports = null;
|
|
|
|
|
|
|
|
async function init(tid, memory, heap_base) {
|
|
|
|
thread_id = tid;
|
|
|
|
|
|
|
|
const result = await WebAssembly.instantiateStreaming(fetch('wasm/lod.wasm'), {
|
|
|
|
env: { 'memory': memory }
|
|
|
|
});
|
|
|
|
|
|
|
|
exports = result.instance.exports;
|
|
|
|
exports.set_sp(heap_base - thread_id * 16 * 4096); // 64K stack
|
|
|
|
|
|
|
|
postMessage({ 'type': 'init_done' });
|
|
|
|
}
|
|
|
|
|
|
|
|
function work(indices_base, indices_count, zoom, offsets) {
|
|
|
|
try {
|
|
|
|
exports.do_lod(
|
|
|
|
indices_base, indices_count, zoom,
|
|
|
|
offsets['coords_from'],
|
|
|
|
offsets['line_threshold'],
|
|
|
|
offsets['xs'],
|
|
|
|
offsets['ys'],
|
|
|
|
offsets['pressures'],
|
|
|
|
offsets['result_buffers'] + thread_id * 4,
|
|
|
|
offsets['result_counts'] + thread_id * 4,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('WASM:', e);
|
|
|
|
}
|
|
|
|
|
|
|
|
postMessage({ 'type': 'lod_done' });
|
|
|
|
}
|
|
|
|
|
|
|
|
onmessage = (e) => {
|
|
|
|
const d = e.data;
|
|
|
|
|
|
|
|
if (d.type === 'init') {
|
|
|
|
init(d.thread_id, d.memory, d.heap_base);
|
|
|
|
} else if (d.type === 'lod') {
|
|
|
|
work(d.indices_base, d.indices_count, d.zoom, d.offsets);
|
|
|
|
} else {
|
|
|
|
console.error('unexpected worker command:', d.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|