@@ -13,18 +13,13 @@ use crate::{
13
13
} ;
14
14
15
15
#[ cfg( feature = "no-std" ) ]
16
- use spin:: Mutex ;
16
+ use spin:: { Mutex , RwLock } ;
17
17
18
18
use core:: any:: TypeId ;
19
19
#[ cfg( not( feature = "no-std" ) ) ]
20
- use std:: sync:: Mutex ;
20
+ use std:: sync:: { Mutex , RwLock } ;
21
21
22
- use std:: {
23
- collections:: HashMap ,
24
- marker:: PhantomData ,
25
- sync:: { Arc , RwLock } ,
26
- vec:: Vec ,
27
- } ;
22
+ use std:: { collections:: HashMap , marker:: PhantomData , sync:: Arc , vec:: Vec } ;
28
23
29
24
use super :: allocate:: round_to_buffer_alignment;
30
25
@@ -209,22 +204,37 @@ impl Webgpu {
209
204
Ok ( data)
210
205
}
211
206
207
+ #[ cfg( not( feature = "no-std" ) ) ]
212
208
pub ( crate ) fn shader_module_loaded ( & self , name : TypeId ) -> bool {
213
209
self . cs_cache . read ( ) . unwrap ( ) . contains_key ( & name)
214
210
}
215
211
212
+ #[ cfg( feature = "no-std" ) ]
213
+ pub ( crate ) fn shader_module_loaded ( & self , name : TypeId ) -> bool {
214
+ self . cs_cache . read ( ) . contains_key ( & name)
215
+ }
216
+
216
217
pub ( crate ) fn load_shader_module ( & self , name : TypeId , source : & str ) {
217
218
let module = Arc :: new ( self . dev . create_shader_module ( ShaderModuleDescriptor {
218
219
label : None ,
219
220
source : wgpu:: ShaderSource :: Wgsl ( source. into ( ) ) ,
220
221
} ) ) ;
222
+ #[ cfg( not( feature = "no-std" ) ) ]
221
223
self . cs_cache . write ( ) . unwrap ( ) . insert ( name, module) ;
224
+ #[ cfg( feature = "no-std" ) ]
225
+ self . cs_cache . write ( ) . insert ( name, module) ;
222
226
}
223
227
228
+ #[ cfg( not( feature = "no-std" ) ) ]
224
229
pub ( crate ) fn get_shader_module ( & self , name : TypeId ) -> Option < Arc < ShaderModule > > {
225
230
self . cs_cache . read ( ) . unwrap ( ) . get ( & name) . cloned ( )
226
231
}
227
232
233
+ #[ cfg( feature = "no-std" ) ]
234
+ pub ( crate ) fn get_shader_module ( & self , name : TypeId ) -> Option < Arc < ShaderModule > > {
235
+ self . cs_cache . read ( ) . get ( & name) . cloned ( )
236
+ }
237
+
228
238
// #[allow(unused)]
229
239
// pub(crate) unsafe fn get_workspace<E>(&self, len: usize) -> Result<MutexGuard<Buffer>, Error> {
230
240
// let num_bytes_required = len * std::mem::size_of::<E>();
@@ -369,7 +379,7 @@ impl<E: Unit> Storage<E> for Webgpu {
369
379
type Vec = CachableBuffer < E > ;
370
380
371
381
fn try_alloc_len ( & self , len : usize ) -> Result < Self :: Vec , Error > {
372
- let data = unsafe { self . alloc_empty :: < E > ( len) } ?;
382
+ let data = self . alloc_empty :: < E > ( len) ?;
373
383
Ok ( CachableBuffer {
374
384
dev : self . dev . clone ( ) ,
375
385
queue : self . queue . clone ( ) ,
0 commit comments