@@ -90,10 +90,9 @@ impl ShaderCache {
90
90
. wgpu_device ( )
91
91
. push_error_scope ( wgpu:: ErrorFilter :: Validation ) ;
92
92
let shader_module = render_device. create_shader_module ( & module_descriptor) ;
93
- use futures_util:: future:: FutureExt ;
94
93
let error = render_device. wgpu_device ( ) . pop_error_scope ( ) ;
95
94
if let Some ( Some ( wgpu:: Error :: Validation { description, .. } ) ) =
96
- error . now_or_never ( )
95
+ futures_helper :: now_or_never ( error )
97
96
{
98
97
return Err ( RenderPipelineError :: CreateShaderModule ( description) ) ;
99
98
}
@@ -541,3 +540,37 @@ impl<'a> Iterator for ErrorSources<'a> {
541
540
current
542
541
}
543
542
}
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