You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
8 months ago
|
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) {
|
||
|
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,
|
||
|
);
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|