Commit a5ee32a4 authored by Alex Butler's avatar Alex Butler

Merge branch 'no-wasm-multithread' into 'master'

Disable multithread dependencies on wasm32

See merge request redox-os/rusttype!143
parents 53f75cea 58279365
Pipeline #4489 passed with stages
in 10 minutes and 43 seconds
......@@ -33,6 +33,8 @@ approx = { version = "0.3", default-features = false }
linked-hash-map = { version = "0.5", optional = true }
rustc-hash = { version = "1", optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossbeam-deque = { version = "0.7", optional = true }
crossbeam-utils = { version = "0.6", optional = true }
num_cpus = { version = "1.0", optional = true }
......@@ -47,6 +49,7 @@ blake2 = "0.8"
[features]
# Compiles benchmark code, to be avoided normally as this currently requires nightly rust
bench = ["gpu_cache"]
# Adds `gpu_cache` module
gpu_cache = ["linked-hash-map", "rustc-hash", "crossbeam-deque", "crossbeam-utils", "num_cpus"]
[[example]]
......
......@@ -365,6 +365,10 @@ impl CacheBuilder {
///
/// Significantly reduces worst case latency in multicore environments.
///
/// # Platform-specific behaviour
///
/// This option has no effect on wasm32.
///
/// # Example (set to default value)
///
/// ```
......@@ -381,10 +385,12 @@ impl CacheBuilder {
assert!(self.position_tolerance >= 0.0);
let scale_tolerance = self.scale_tolerance.max(0.001);
let position_tolerance = self.position_tolerance.max(0.001);
#[cfg(not(target_arch = "wasm32"))]
let multithread = self.multithread && num_cpus::get() > 1;
Self {
scale_tolerance,
position_tolerance,
#[cfg(not(target_arch = "wasm32"))]
multithread,
..self
}
......@@ -812,65 +818,73 @@ impl<'font> Cache<'font> {
}
if queue_success {
let glyph_count = draw_and_upload.len();
if self.multithread && glyph_count > 1 {
// multithread rasterization
use crossbeam_deque::Steal;
use std::{
mem,
sync::mpsc::{self, TryRecvError},
};
let rasterize_queue = crossbeam_deque::Injector::new();
let (to_main, from_stealers) = mpsc::channel();
let pad_glyphs = self.pad_glyphs;
for el in draw_and_upload {
rasterize_queue.push(el);
}
crossbeam_utils::thread::scope(|scope| {
for _ in 0..num_cpus::get().min(glyph_count).saturating_sub(1) {
let rasterize_queue = &rasterize_queue;
let to_main = to_main.clone();
scope.spawn(move |_| loop {
#[cfg(not(target_arch = "wasm32"))] {
let glyph_count = draw_and_upload.len();
if self.multithread && glyph_count > 1 {
// multithread rasterization
use crossbeam_deque::Steal;
use std::{
mem,
sync::mpsc::{self, TryRecvError},
};
let rasterize_queue = crossbeam_deque::Injector::new();
let (to_main, from_stealers) = mpsc::channel();
let pad_glyphs = self.pad_glyphs;
for el in draw_and_upload {
rasterize_queue.push(el);
}
crossbeam_utils::thread::scope(|scope| {
for _ in 0..num_cpus::get().min(glyph_count).saturating_sub(1) {
let rasterize_queue = &rasterize_queue;
let to_main = to_main.clone();
scope.spawn(move |_| loop {
match rasterize_queue.steal() {
Steal::Success((tex_coords, glyph)) => {
let pixels = draw_glyph(tex_coords, glyph, pad_glyphs);
to_main.send((tex_coords, pixels)).unwrap();
}
Steal::Empty => break,
Steal::Retry => {}
}
});
}
mem::drop(to_main);
let mut workers_finished = false;
loop {
match rasterize_queue.steal() {
Steal::Success((tex_coords, glyph)) => {
let pixels = draw_glyph(tex_coords, glyph, pad_glyphs);
to_main.send((tex_coords, pixels)).unwrap();
uploader(tex_coords, pixels.as_slice());
}
Steal::Empty => break,
Steal::Retry => {}
Steal::Empty if workers_finished => break,
Steal::Empty | Steal::Retry => {}
}
});
}
mem::drop(to_main);
let mut workers_finished = false;
loop {
match rasterize_queue.steal() {
Steal::Success((tex_coords, glyph)) => {
let pixels = draw_glyph(tex_coords, glyph, pad_glyphs);
uploader(tex_coords, pixels.as_slice());
}
Steal::Empty if workers_finished => break,
Steal::Empty | Steal::Retry => {}
}
while !workers_finished {
match from_stealers.try_recv() {
Ok((tex_coords, pixels)) => {
uploader(tex_coords, pixels.as_slice())
while !workers_finished {
match from_stealers.try_recv() {
Ok((tex_coords, pixels)) => {
uploader(tex_coords, pixels.as_slice())
}
Err(TryRecvError::Disconnected) => workers_finished = true,
Err(TryRecvError::Empty) => break,
}
Err(TryRecvError::Disconnected) => workers_finished = true,
Err(TryRecvError::Empty) => break,
}
}
})
.unwrap();
} else {
// single thread rasterization
for (tex_coords, glyph) in draw_and_upload {
let pixels = draw_glyph(tex_coords, glyph, self.pad_glyphs);
uploader(tex_coords, pixels.as_slice());
}
})
.unwrap();
} else {
// single thread rasterization
}
}
#[cfg(target_arch = "wasm32")] {
for (tex_coords, glyph) in draw_and_upload {
let pixels = draw_glyph(tex_coords, glyph, self.pad_glyphs);
uploader(tex_coords, pixels.as_slice());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment