-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use error scope to handle errors on shader module creation (#3675)
related: #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.
- Loading branch information
1 parent
1b63d94
commit 551d9f6
Showing
4 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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()) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ pub mod prelude { | |
pub use crate::default; | ||
} | ||
|
||
pub mod futures; | ||
pub mod label; | ||
|
||
mod default; | ||
|