diff --git a/wgpu/src/api/device.rs b/wgpu/src/api/device.rs
index ac97e3748..c0a60c22e 100644
--- a/wgpu/src/api/device.rs
+++ b/wgpu/src/api/device.rs
@@ -363,13 +363,7 @@ impl Device {
) -> Texture {
let texture = unsafe {
let core_device = self.inner.as_core();
- core_device.context.create_texture_from_hal::(
- hal_texture,
- core_device,
- desc,
- initial_state,
- cleared,
- )
+ core_device.create_texture_from_hal::(hal_texture, desc, initial_state, cleared)
};
Texture {
inner: texture.into(),
@@ -622,9 +616,7 @@ impl Device {
let buffer = unsafe {
let core_device = self.inner.as_core();
- core_device
- .context
- .create_buffer_from_hal::(hal_buffer, core_device, desc)
+ core_device.create_buffer_from_hal::(hal_buffer, desc)
};
Buffer {
@@ -816,7 +808,7 @@ impl Device {
&self,
) -> Option + WasmNotSendSync> {
let device = self.inner.as_core_opt()?;
- unsafe { device.context.device_as_hal::(device) }
+ unsafe { device.as_hal::() }
}
/// Destroy this device.
diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs
index df17b0238..783f0f0de 100644
--- a/wgpu/src/backend/wgpu_core.rs
+++ b/wgpu/src/backend/wgpu_core.rs
@@ -104,69 +104,11 @@ impl ContextWgpuCore {
)
}?;
let device = CoreDevice {
- context: self.clone(),
wgpu_device: device.clone(),
};
let queue = CoreQueue { wgpu_queue: queue };
Ok((device, queue))
}
-
- pub unsafe fn create_texture_from_hal(
- &self,
- hal_texture: A::Texture,
- device: &CoreDevice,
- desc: &TextureDescriptor<'_>,
- initial_state: wgt::TextureUses,
- cleared: bool,
- ) -> CoreTexture {
- let descriptor = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec());
- let (wgpu_texture, error) = unsafe {
- device.wgpu_device.create_texture_from_hal(
- Box::new(hal_texture),
- &descriptor,
- initial_state,
- cleared,
- )
- };
- if let Some(cause) = error {
- device
- .wgpu_device
- .handle_error(cause, desc.label, "Device::create_texture_from_hal");
- }
- CoreTexture { wgpu_texture }
- }
-
- /// # Safety
- ///
- /// - `hal_buffer` must be created from `device`.
- /// - `hal_buffer` must be created respecting `desc`
- /// - `hal_buffer` must be initialized
- /// - `hal_buffer` must not have zero size.
- pub unsafe fn create_buffer_from_hal(
- &self,
- hal_buffer: A::Buffer,
- device: &CoreDevice,
- desc: &BufferDescriptor<'_>,
- ) -> CoreBuffer {
- let (wgpu_buffer, error) = unsafe {
- device
- .wgpu_device
- .create_buffer_from_hal(Box::new(hal_buffer), &desc.map_label(|l| l.map(Borrowed)))
- };
- if let Some(cause) = error {
- device
- .wgpu_device
- .handle_error(cause, desc.label, "Device::create_buffer_from_hal");
- }
- CoreBuffer { wgpu_buffer }
- }
-
- pub unsafe fn device_as_hal(
- &self,
- device: &CoreDevice,
- ) -> Option> {
- unsafe { device.wgpu_device.clone().as_hal::() }
- }
}
fn map_buffer_copy_view(
@@ -266,11 +208,59 @@ impl fmt::Debug for CoreAdapter {
#[derive(Debug, Clone)]
pub struct CoreDevice {
- pub(crate) context: ContextWgpuCore,
pub(crate) wgpu_device: Arc,
}
impl CoreDevice {
+ pub unsafe fn as_hal(&self) -> Option> {
+ unsafe { self.wgpu_device.clone().as_hal::() }
+ }
+
+ pub unsafe fn create_texture_from_hal(
+ &self,
+ hal_texture: A::Texture,
+ desc: &TextureDescriptor<'_>,
+ initial_state: wgt::TextureUses,
+ cleared: bool,
+ ) -> CoreTexture {
+ let descriptor = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec());
+ let (wgpu_texture, error) = unsafe {
+ self.wgpu_device.create_texture_from_hal(
+ Box::new(hal_texture),
+ &descriptor,
+ initial_state,
+ cleared,
+ )
+ };
+ if let Some(cause) = error {
+ self.wgpu_device
+ .handle_error(cause, desc.label, "Device::create_texture_from_hal");
+ }
+ CoreTexture { wgpu_texture }
+ }
+
+ /// # Safety
+ ///
+ /// - `hal_buffer` must be created from `device`.
+ /// - `hal_buffer` must be created respecting `desc`
+ /// - `hal_buffer` must be initialized
+ /// - `hal_buffer` must not have zero size.
+ pub unsafe fn create_buffer_from_hal(
+ &self,
+ hal_buffer: A::Buffer,
+ desc: &BufferDescriptor<'_>,
+ ) -> CoreBuffer {
+ let (wgpu_buffer, error) = unsafe {
+ self.wgpu_device
+ .create_buffer_from_hal(Box::new(hal_buffer), &desc.map_label(|l| l.map(Borrowed)))
+ };
+ if let Some(cause) = error {
+ self.wgpu_device
+ .handle_error(cause, desc.label, "Device::create_buffer_from_hal");
+ }
+ CoreBuffer { wgpu_buffer }
+ }
+
/// Returns `true` if `texture` was created on `device`.
#[cfg(webgl)]
pub fn texture_belongs_to_device(&self, texture: &CoreTexture) -> bool {
@@ -730,7 +720,6 @@ impl dispatch::AdapterInterface for CoreAdapter {
}
};
let device = CoreDevice {
- context: self.context.clone(),
wgpu_device: device,
};
let queue = CoreQueue { wgpu_queue: queue };