Make multithreading named consistantly

This commit is contained in:
Maximilian Ammann 2022-09-18 11:53:08 +02:00
parent dd6c7481e2
commit 6dd67e8906
14 changed files with 32 additions and 31 deletions

View File

@ -17,7 +17,7 @@ on:
webgl:
required: true
type: boolean
multithreading:
multithreaded:
required: true
type: boolean
@ -34,7 +34,7 @@ jobs:
just nightly-toolchain
just nightly-targets wasm32-unknown-unknown
- name: Install rust sources (build-std)
if: inputs.multithreading
if: inputs.multithreaded
shell: bash
run: |
just nightly-install-src
@ -46,7 +46,7 @@ jobs:
- uses: Swatinem/rust-cache@v1
- name: Build lib
shell: bash
run: just web-lib build --release ${{ inputs.webgl && '--webgl' || '' }} ${{ inputs.multithreading && '--multithreading' || '' }}
run: just web-lib build --release ${{ inputs.webgl && '--webgl' || '' }} ${{ inputs.multithreaded && '--multithreaded' || '' }}
- name: Build demo
shell: bash
run: just web-demo build
@ -73,7 +73,7 @@ jobs:
name: ${{ inputs.name }}
path: demo
- name: Set HTTP Headers for Cloudflare
if: inputs.multithreading
if: inputs.multithreaded
shell: bash
run: |
echo "/*

View File

@ -24,14 +24,14 @@ jobs:
with:
name: maplibre-rs-demo-webgl
webgl: true
multithreading: false
multithreaded: false
deploy: true
library-web-webgpu:
uses: ./.github/workflows/library-web.yml
with:
name: maplibre-rs-demo-webgpu
webgl: false
multithreading: false
multithreaded: false
deploy: true
library-apple:
uses: ./.github/workflows/library-apple.yml

View File

@ -136,7 +136,8 @@ const wasmPack = () => {
"-C", "target-feature=+atomics,+bulk-memory,+mutable-globals",
# Enables the possibility to import memory into wasm.
# Without --shared-memory it is not possible to use shared WebAssembly.Memory.
"-C", "link-args=--shared-memory --import-memory",
# Set maximum memory to 200MB
"-C", "link-args=--shared-memory --import-memory --max-memory=209715200"
]`
let cargo = spawnSync('cargo', [

View File

@ -3,9 +3,9 @@ import {Spector} from "spectorjs"
import {checkRequirements, checkWasmFeatures} from "./browser";
import {preventDefaultTouchActions} from "./canvas";
// @ts-ignore esbuild plugin is handling this
import MultithreadedPoolWorker from './sync/multithreaded-pool.worker.js';
import MultithreadedPoolWorker from './multithreaded/multithreaded-pool.worker.js';
// @ts-ignore esbuild plugin is handling this
import PoolWorker from './unsync/pool.worker.js';
import PoolWorker from './singlethreaded/pool.worker.js';
export const startMapLibre = async (wasmPath: string | undefined, workerPath: string | undefined) => {
await checkWasmFeatures()
@ -58,7 +58,7 @@ export const startMapLibre = async (wasmPath: string | undefined, workerPath: st
callback[0] = (message) => {
// @ts-ignore TODO unsync_main_entry may not be defined
maplibre.unsync_main_entry(clonedMap, message.data[0], new Uint8Array(message.data[1]))
maplibre.singlethreaded_main_entry(clonedMap, message.data[0], new Uint8Array(message.data[1]))
}
await maplibre.run(map)

View File

@ -14,6 +14,6 @@ onmessage = async message => {
// This will queue further commands up until the module is fully initialised:
await initialised;
// @ts-ignore TODO may not exist
await maplibre.sync_worker_entry(message.data);
await maplibre.multithreaded_worker_entry(message.data);
};
}

View File

@ -18,6 +18,6 @@ onmessage = async message => {
let procedure_ptr = message.data[0];
let input = message.data[1];
// @ts-ignore TODO
await maplibre.unsync_worker_entry(procedure_ptr, input);
await maplibre.singlethreaded_worker_entry(procedure_ptr, input);
};
}

View File

@ -43,20 +43,20 @@ pub type MapType = Map<
WinitEnvironment<
NopScheduler,
WHATWGFetchHttpClient,
platform::unsync::transferables::LinearTransferables,
platform::unsync::apc::PassingAsyncProcedureCall,
platform::singlethreaded::transferables::LinearTransferables,
platform::singlethreaded::apc::PassingAsyncProcedureCall,
>,
>;
#[cfg(target_feature = "atomics")]
pub type MapType = Map<
WinitEnvironment<
platform::sync::pool_scheduler::WebWorkerPoolScheduler,
platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler,
WHATWGFetchHttpClient,
maplibre::io::transferables::DefaultTransferables,
maplibre::io::apc::SchedulerAsyncProcedureCall<
WHATWGFetchHttpClient,
platform::sync::pool_scheduler::WebWorkerPoolScheduler,
platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler,
>,
>,
>;
@ -73,19 +73,19 @@ pub async fn create_map(new_worker: js_sys::Function) -> u32 {
builder = builder
.with_apc(maplibre::io::apc::SchedulerAsyncProcedureCall::new(
WHATWGFetchHttpClient::new(),
platform::sync::pool_scheduler::WebWorkerPoolScheduler::new(new_worker.clone()),
platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler::new(
new_worker.clone(),
),
))
.with_scheduler(platform::sync::pool_scheduler::WebWorkerPoolScheduler::new(
new_worker,
));
.with_scheduler(
platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler::new(new_worker),
);
}
#[cfg(not(target_feature = "atomics"))]
{
builder = builder
.with_apc(platform::unsync::apc::PassingAsyncProcedureCall::new(
new_worker, 4,
))
.with_apc(platform::singlethreaded::apc::PassingAsyncProcedureCall::new(new_worker, 4))
.with_scheduler(NopScheduler);
}

View File

@ -4,7 +4,7 @@ use maplibre::error::Error;
pub mod http_client;
#[cfg(target_feature = "atomics")]
pub mod sync;
pub mod multithreaded;
#[cfg(not(target_feature = "atomics"))]
pub mod unsync;
pub mod singlethreaded;

View File

@ -146,7 +146,7 @@ impl PoolState {
/// Entry point invoked by the worker.
#[wasm_bindgen]
pub async fn sync_worker_entry(ptr: u32) -> Result<(), JsValue> {
pub async fn multithreaded_worker_entry(ptr: u32) -> Result<(), JsValue> {
let ptr = unsafe { Box::from_raw(ptr as *mut Work) };
JsFuture::from((ptr.func)()).await?;
Ok(())

View File

@ -28,7 +28,9 @@ use wasm_bindgen::{prelude::*, JsCast, JsValue};
use web_sys::{DedicatedWorkerGlobalScope, Worker};
use crate::{
platform::unsync::transferables::{InnerData, LinearTessellatedLayer, LinearTransferables},
platform::singlethreaded::transferables::{
InnerData, LinearTessellatedLayer, LinearTransferables,
},
MapType, WHATWGFetchHttpClient,
};
@ -124,9 +126,7 @@ impl AsyncProcedureCall<UsedTransferables, UsedHttpClient> for PassingAsyncProce
/// Entry point invoked by the worker.
#[wasm_bindgen]
pub async fn unsync_worker_entry(procedure_ptr: u32, input: String) -> Result<(), JsValue> {
log::info!("worker_entry unsync");
pub async fn singlethreaded_worker_entry(procedure_ptr: u32, input: String) -> Result<(), JsValue> {
let procedure: AsyncProcedure<UsedContext> = unsafe { std::mem::transmute(procedure_ptr) };
let input = serde_json::from_str::<Input>(&input).unwrap(); // FIXME (wasm-executor): Remove unwrap
@ -142,7 +142,7 @@ pub async fn unsync_worker_entry(procedure_ptr: u32, input: String) -> Result<()
/// Entry point invoked by the main thread.
#[wasm_bindgen]
pub fn unsync_main_entry(
pub fn singlethreaded_main_entry(
map_ptr: *const RefCell<MapType>,
tag: u32,
data: Uint8Array,