
related: https://github.com/bevyengine/bevy/pull/3289 In addition to validating shaders early when debug assertions are enabled, use the new [error scopes](https://gpuweb.github.io/gpuweb/#error-scopes) API when creating a shader module. I chose to keep the early validation (and thereby parsing twice) when debug assertions are enabled in, because it lets as handle errors ourselves and display them with pretty colors, while the error scopes API just gives us a string we can display. This change pulls in `futures-util` as a new dependency for `future.now_or_never()`. I can inline that part of futures-lite into `bevy_render` to keep the compilation time lower if that's preferred.
34 lines
873 B
Rust
34 lines
873 B
Rust
use std::{
|
|
future::Future,
|
|
pin::Pin,
|
|
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
|
|
};
|
|
|
|
pub fn now_or_never<F: Future>(mut future: F) -> Option<F::Output> {
|
|
let noop_waker = noop_waker();
|
|
let mut cx = Context::from_waker(&noop_waker);
|
|
|
|
// Safety: `future` is not moved and the original value is shadowed
|
|
let future = unsafe { Pin::new_unchecked(&mut future) };
|
|
|
|
match future.poll(&mut cx) {
|
|
Poll::Ready(x) => Some(x),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
unsafe fn noop_clone(_data: *const ()) -> RawWaker {
|
|
noop_raw_waker()
|
|
}
|
|
unsafe fn noop(_data: *const ()) {}
|
|
|
|
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
|
|
|
|
fn noop_raw_waker() -> RawWaker {
|
|
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
|
|
}
|
|
|
|
fn noop_waker() -> Waker {
|
|
unsafe { Waker::from_raw(noop_raw_waker()) }
|
|
}
|