Skip to content

Commit 8860540

Browse files
inline now_or_never to get rid of futures-util dependency
1 parent 9151787 commit 8860540

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

crates/bevy_render/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@ flate2 = { version = "1.0.22", optional = true }
6666
ruzstd = { version = "0.2.4", optional = true }
6767
# For transcoding of UASTC/ETC1S universal formats, and for .basis file support
6868
basis-universal = { version = "0.2.0", optional = true }
69-
futures-util = "0.3"

crates/bevy_render/src/render_resource/pipeline_cache.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ impl ShaderCache {
9090
.wgpu_device()
9191
.push_error_scope(wgpu::ErrorFilter::Validation);
9292
let shader_module = render_device.create_shader_module(&module_descriptor);
93-
use futures_util::future::FutureExt;
9493
let error = render_device.wgpu_device().pop_error_scope();
9594
if let Some(Some(wgpu::Error::Validation { description, .. })) =
96-
error.now_or_never()
95+
futures_helper::now_or_never(error)
9796
{
9897
return Err(RenderPipelineError::CreateShaderModule(description));
9998
}
@@ -541,3 +540,37 @@ impl<'a> Iterator for ErrorSources<'a> {
541540
current
542541
}
543542
}
543+
544+
mod futures_helper {
545+
use std::{
546+
future::Future,
547+
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
548+
};
549+
550+
pub fn now_or_never<F: Future>(future: F) -> Option<F::Output> {
551+
let noop_waker = noop_waker();
552+
let mut cx = Context::from_waker(&noop_waker);
553+
554+
futures_lite::pin!(future);
555+
match future.poll(&mut cx) {
556+
Poll::Ready(x) => Some(x),
557+
_ => None,
558+
}
559+
}
560+
561+
unsafe fn noop_clone(_data: *const ()) -> RawWaker {
562+
noop_raw_waker()
563+
}
564+
565+
unsafe fn noop(_data: *const ()) {}
566+
567+
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
568+
569+
fn noop_raw_waker() -> RawWaker {
570+
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
571+
}
572+
573+
fn noop_waker() -> Waker {
574+
unsafe { Waker::from_raw(noop_raw_waker()) }
575+
}
576+
}

0 commit comments

Comments
 (0)