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

View File

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

View File

@ -136,7 +136,8 @@ const wasmPack = () => {
"-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", "-C", "target-feature=+atomics,+bulk-memory,+mutable-globals",
# Enables the possibility to import memory into wasm. # Enables the possibility to import memory into wasm.
# Without --shared-memory it is not possible to use shared WebAssembly.Memory. # 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', [ let cargo = spawnSync('cargo', [

View File

@ -3,9 +3,9 @@ import {Spector} from "spectorjs"
import {checkRequirements, checkWasmFeatures} from "./browser"; import {checkRequirements, checkWasmFeatures} from "./browser";
import {preventDefaultTouchActions} from "./canvas"; import {preventDefaultTouchActions} from "./canvas";
// @ts-ignore esbuild plugin is handling this // @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 // @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) => { export const startMapLibre = async (wasmPath: string | undefined, workerPath: string | undefined) => {
await checkWasmFeatures() await checkWasmFeatures()
@ -58,7 +58,7 @@ export const startMapLibre = async (wasmPath: string | undefined, workerPath: st
callback[0] = (message) => { callback[0] = (message) => {
// @ts-ignore TODO unsync_main_entry may not be defined // @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) 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: // This will queue further commands up until the module is fully initialised:
await initialised; await initialised;
// @ts-ignore TODO may not exist // @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 procedure_ptr = message.data[0];
let input = message.data[1]; let input = message.data[1];
// @ts-ignore TODO // @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< WinitEnvironment<
NopScheduler, NopScheduler,
WHATWGFetchHttpClient, WHATWGFetchHttpClient,
platform::unsync::transferables::LinearTransferables, platform::singlethreaded::transferables::LinearTransferables,
platform::unsync::apc::PassingAsyncProcedureCall, platform::singlethreaded::apc::PassingAsyncProcedureCall,
>, >,
>; >;
#[cfg(target_feature = "atomics")] #[cfg(target_feature = "atomics")]
pub type MapType = Map< pub type MapType = Map<
WinitEnvironment< WinitEnvironment<
platform::sync::pool_scheduler::WebWorkerPoolScheduler, platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler,
WHATWGFetchHttpClient, WHATWGFetchHttpClient,
maplibre::io::transferables::DefaultTransferables, maplibre::io::transferables::DefaultTransferables,
maplibre::io::apc::SchedulerAsyncProcedureCall< maplibre::io::apc::SchedulerAsyncProcedureCall<
WHATWGFetchHttpClient, 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 builder = builder
.with_apc(maplibre::io::apc::SchedulerAsyncProcedureCall::new( .with_apc(maplibre::io::apc::SchedulerAsyncProcedureCall::new(
WHATWGFetchHttpClient::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( .with_scheduler(
new_worker, platform::multithreaded::pool_scheduler::WebWorkerPoolScheduler::new(new_worker),
)); );
} }
#[cfg(not(target_feature = "atomics"))] #[cfg(not(target_feature = "atomics"))]
{ {
builder = builder builder = builder
.with_apc(platform::unsync::apc::PassingAsyncProcedureCall::new( .with_apc(platform::singlethreaded::apc::PassingAsyncProcedureCall::new(new_worker, 4))
new_worker, 4,
))
.with_scheduler(NopScheduler); .with_scheduler(NopScheduler);
} }

View File

@ -4,7 +4,7 @@ use maplibre::error::Error;
pub mod http_client; pub mod http_client;
#[cfg(target_feature = "atomics")] #[cfg(target_feature = "atomics")]
pub mod sync; pub mod multithreaded;
#[cfg(not(target_feature = "atomics"))] #[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. /// Entry point invoked by the worker.
#[wasm_bindgen] #[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) }; let ptr = unsafe { Box::from_raw(ptr as *mut Work) };
JsFuture::from((ptr.func)()).await?; JsFuture::from((ptr.func)()).await?;
Ok(()) Ok(())

View File

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