Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bluenoise_texture = ["bevy_image/ktx2", "bevy_image/zstd"]
shader_format_glsl = ["bevy_shader/shader_format_glsl"]
trace = ["bevy_render/trace"]
# Enables the meshlet renderer for dense high-poly scenes (experimental)
meshlet = ["dep:lz4_flex", "dep:range-alloc", "dep:bevy_tasks"]
meshlet = ["dep:lz4_flex", "dep:range-alloc"]
# Enables processing meshes into meshlet meshes
meshlet_processor = [
"meshlet",
Expand Down Expand Up @@ -55,7 +55,7 @@ bevy_render = { path = "../bevy_render", version = "0.18.0-dev", features = [
"morph",
] }
bevy_camera = { path = "../bevy_camera", version = "0.18.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.18.0-dev", optional = true }
bevy_tasks = { path = "../bevy_tasks", version = "0.18.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.18.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.18.0-dev" }
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-features = false, features = [
Expand Down
313 changes: 209 additions & 104 deletions crates/bevy_pbr/src/render/mesh.rs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions crates/bevy_platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ rayon = ["dep:rayon", "hashbrown/rayon"]

# Platform Compatibility

## Provides an implementation of `block_on` from `futures-lite`.
futures-lite = ["std", "dep:futures-lite", "futures-lite?/std"]

## Provides an implementation of `block_on` from `async-io`.
async-io = ["std", "dep:async-io"]

## Allows access to the `std` crate. Enabling this feature will prevent compilation
## on `no_std` targets, but provides access to certain additional features on
## supported platforms.
Expand Down Expand Up @@ -72,6 +78,8 @@ hashbrown = { version = "0.16.1", features = [
], optional = true, default-features = false }
serde = { version = "1", default-features = false, optional = true }
rayon = { version = "1", default-features = false, optional = true }
futures-lite = { version = "2.0.1", default-features = false, optional = true }
async-io = { version = "2.0.0", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-time = { version = "1.1", default-features = false, optional = true }
Expand Down
32 changes: 32 additions & 0 deletions crates/bevy_platform/src/future.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Platform-aware future utilities.

crate::cfg::switch! {
#[cfg(feature = "async-io")] => {
pub use async_io::block_on;
}
#[cfg(feature = "futures-lite")] => {
pub use futures_lite::future::block_on;
}
_ => {
/// Blocks on the supplied `future`.
/// This implementation will busy-wait until it is completed.
/// Consider enabling the `async-io` or `futures-lite` features.
pub fn block_on<T>(future: impl Future<Output = T>) -> T {
use core::task::{Poll, Context};

// Pin the future on the stack.
let mut future = core::pin::pin!(future);

// We don't care about the waker as we're just going to poll as fast as possible.
let cx = &mut Context::from_waker(core::task::Waker::noop());

// Keep polling until the future is ready.
loop {
match future.as_mut().poll(cx) {
Poll::Ready(output) => return output,
Poll::Pending => core::hint::spin_loop(),
}
}
}
}
}
1 change: 1 addition & 0 deletions crates/bevy_platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cfg::alloc! {

pub mod cell;
pub mod cfg;
pub mod future;
pub mod hash;
pub mod sync;
pub mod thread;
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ multi_threaded = [
async_executor = ["bevy_platform/std", "dep:async-executor", "futures-lite"]

# Provide an implementation of `block_on` from `futures-lite`.
futures-lite = ["bevy_platform/std", "futures-lite/std"]
futures-lite = ["bevy_platform/futures-lite"]

# Use async-io's implementation of block_on instead of futures-lite's implementation.
# This is preferred if your application uses async-io.
async-io = ["bevy_platform/std", "dep:async-io"]
async-io = ["bevy_platform/async-io"]

[dependencies]
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-features = false, features = [
Expand All @@ -46,7 +46,6 @@ derive_more = { version = "2", default-features = false, features = [
] }
async-executor = { version = "1.11", optional = true }
async-channel = { version = "2.3.0", optional = true }
async-io = { version = "2.0.0", optional = true }
concurrent-queue = { version = "2.0.0", optional = true }
atomic-waker = { version = "1", default-features = false }
crossbeam-queue = { version = "0.3", default-features = false, features = [
Expand Down
40 changes: 1 addition & 39 deletions crates/bevy_tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ pub mod cfg {
conditional_send
}

#[cfg(feature = "async-io")] => {
/// Indicates `async-io` will be used for the implementation of `block_on`.
async_io
}

#[cfg(feature = "futures-lite")] => {
/// Indicates `futures-lite` will be used for the implementation of `block_on`.
futures_lite
}
}
}

Expand Down Expand Up @@ -114,36 +105,7 @@ cfg::multi_threaded! {
}
}

cfg::switch! {
cfg::async_io => {
pub use async_io::block_on;
}
cfg::futures_lite => {
pub use futures_lite::future::block_on;
}
_ => {
/// Blocks on the supplied `future`.
/// This implementation will busy-wait until it is completed.
/// Consider enabling the `async-io` or `futures-lite` features.
pub fn block_on<T>(future: impl Future<Output = T>) -> T {
use core::task::{Poll, Context};

// Pin the future on the stack.
let mut future = core::pin::pin!(future);

// We don't care about the waker as we're just going to poll as fast as possible.
let cx = &mut Context::from_waker(core::task::Waker::noop());

// Keep polling until the future is ready.
loop {
match future.as_mut().poll(cx) {
Poll::Ready(output) => return output,
Poll::Pending => core::hint::spin_loop(),
}
}
}
}
}
pub use bevy_platform::future::block_on;

/// The tasks prelude.
///
Expand Down
8 changes: 7 additions & 1 deletion crates/bevy_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = ["parallel"]
default = ["parallel", "buffered_channel"]

# Provides access to the `Parallel` type.
parallel = ["bevy_platform/std", "dep:thread_local"]

buffered_channel = ["bevy_platform/std", "dep:async-channel"]

std = ["disqualified/alloc"]

debug = ["bevy_platform/alloc"]
Expand All @@ -23,9 +25,13 @@ bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-fea

disqualified = { version = "1.0", default-features = false }
thread_local = { version = "1.0", optional = true }
async-channel = { version = "2.3.0", optional = true }

[dev-dependencies]
static_assertions = "1.1.0"
bevy_ecs = { path = "../bevy_ecs", version = "0.18.0-dev", default-features = false }
bevy_app = { path = "../bevy_app", version = "0.18.0-dev", default-features = false }
bevy_tasks = { path = "../bevy_tasks", version = "0.18.0-dev", default-features = false }

[lints]
workspace = true
Expand Down
Loading