Skip to content

Commit f6a3eef

Browse files
committed
change Device.create_shader_module to return an Arc<ShaderModule<A>
1 parent d8b1c57 commit f6a3eef

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

wgpu-core/src/device/global.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ use hal::Device as _;
2828

2929
use wgt::{BufferAddress, TextureFormat};
3030

31-
use std::{
32-
borrow::Cow,
33-
ptr::NonNull,
34-
sync::{atomic::Ordering, Arc},
35-
};
31+
use std::{borrow::Cow, ptr::NonNull, sync::atomic::Ordering};
3632

3733
use super::{ImplicitPipelineIds, UserClosures};
3834

@@ -996,7 +992,7 @@ impl Global {
996992
Err(e) => break 'error e,
997993
};
998994

999-
let id = fid.assign(Arc::new(shader));
995+
let id = fid.assign(shader);
1000996
api_log!("Device::create_shader_module -> {id:?}");
1001997
return (id, None);
1002998
};
@@ -1050,7 +1046,7 @@ impl Global {
10501046
Ok(shader) => shader,
10511047
Err(e) => break 'error e,
10521048
};
1053-
let id = fid.assign(Arc::new(shader));
1049+
let id = fid.assign(shader);
10541050
api_log!("Device::create_shader_module_spirv -> {id:?}");
10551051
return (id, None);
10561052
};

wgpu-core/src/device/resource.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl<A: HalApi> Device<A> {
14291429
self: &Arc<Self>,
14301430
desc: &pipeline::ShaderModuleDescriptor<'a>,
14311431
source: pipeline::ShaderModuleSource<'a>,
1432-
) -> Result<pipeline::ShaderModule<A>, pipeline::CreateShaderModuleError> {
1432+
) -> Result<Arc<pipeline::ShaderModule<A>>, pipeline::CreateShaderModuleError> {
14331433
self.check_is_valid()?;
14341434

14351435
let (module, source) = match source {
@@ -1546,20 +1546,24 @@ impl<A: HalApi> Device<A> {
15461546
}
15471547
};
15481548

1549-
Ok(pipeline::ShaderModule {
1549+
let module = pipeline::ShaderModule {
15501550
raw: Some(raw),
15511551
device: self.clone(),
15521552
interface: Some(interface),
15531553
label: desc.label.to_string(),
1554-
})
1554+
};
1555+
1556+
let module = Arc::new(module);
1557+
1558+
Ok(module)
15551559
}
15561560

15571561
#[allow(unused_unsafe)]
15581562
pub(crate) unsafe fn create_shader_module_spirv<'a>(
15591563
self: &Arc<Self>,
15601564
desc: &pipeline::ShaderModuleDescriptor<'a>,
15611565
source: &'a [u32],
1562-
) -> Result<pipeline::ShaderModule<A>, pipeline::CreateShaderModuleError> {
1566+
) -> Result<Arc<pipeline::ShaderModule<A>>, pipeline::CreateShaderModuleError> {
15631567
self.check_is_valid()?;
15641568

15651569
self.require_features(wgt::Features::SPIRV_SHADER_PASSTHROUGH)?;
@@ -1588,12 +1592,16 @@ impl<A: HalApi> Device<A> {
15881592
}
15891593
};
15901594

1591-
Ok(pipeline::ShaderModule {
1595+
let module = pipeline::ShaderModule {
15921596
raw: Some(raw),
15931597
device: self.clone(),
15941598
interface: None,
15951599
label: desc.label.to_string(),
1596-
})
1600+
};
1601+
1602+
let module = Arc::new(module);
1603+
1604+
Ok(module)
15971605
}
15981606

15991607
pub(crate) fn create_command_encoder(

0 commit comments

Comments
 (0)