Skip to content

Commit

Permalink
Merge pull request #5 from niklaskorz/master
Browse files Browse the repository at this point in the history
Fix compiler errors for Metal backend
  • Loading branch information
gents83 authored Apr 7, 2023
2 parents aa4424e + e1c9b91 commit 669636a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
12 changes: 7 additions & 5 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{

use arrayvec::ArrayVec;
use foreign_types::ForeignTypeRef as _;
use parking_lot::Mutex;
use parking_lot::{Mutex, RwLock};

#[derive(Clone)]
pub struct Api;
Expand Down Expand Up @@ -300,8 +300,8 @@ pub struct Device {
pub struct Surface {
view: Option<NonNull<objc::runtime::Object>>,
render_layer: Mutex<metal::MetalLayer>,
swapchain_format: Option<wgt::TextureFormat>,
extent: wgt::Extent3d,
swapchain_format: RwLock<Option<wgt::TextureFormat>>,
extent: RwLock<wgt::Extent3d>,
main_thread_id: thread::ThreadId,
// Useful for UI-intensive applications that are sensitive to
// window resizing.
Expand Down Expand Up @@ -329,7 +329,7 @@ unsafe impl Sync for SurfaceTexture {}

impl crate::Queue<Api> for Queue {
unsafe fn submit(
&mut self,
&self,
command_buffers: &[&CommandBuffer],
signal_fence: Option<(&mut Fence, crate::FenceValue)>,
) -> Result<(), crate::DeviceError> {
Expand Down Expand Up @@ -376,7 +376,7 @@ impl crate::Queue<Api> for Queue {
Ok(())
}
unsafe fn present(
&mut self,
&self,
_surface: &Surface,
texture: SurfaceTexture,
) -> Result<(), crate::SurfaceError> {
Expand Down Expand Up @@ -654,6 +654,7 @@ impl PipelineStageInfo {
}
}

#[derive(Debug)]
pub struct RenderPipeline {
raw: metal::RenderPipelineState,
#[allow(dead_code)]
Expand All @@ -673,6 +674,7 @@ pub struct RenderPipeline {
unsafe impl Send for RenderPipeline {}
unsafe impl Sync for RenderPipeline {}

#[derive(Debug)]
pub struct ComputePipeline {
raw: metal::ComputePipelineState,
#[allow(dead_code)]
Expand Down
20 changes: 11 additions & 9 deletions wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use objc::{
runtime::{Class, Object, Sel, BOOL, NO, YES},
sel, sel_impl,
};
use parking_lot::Mutex;
use parking_lot::{Mutex, RwLock};

#[cfg(target_os = "macos")]
#[link(name = "QuartzCore", kind = "framework")]
Expand Down Expand Up @@ -63,8 +63,8 @@ impl super::Surface {
Self {
view,
render_layer: Mutex::new(layer),
swapchain_format: None,
extent: wgt::Extent3d::default(),
swapchain_format: RwLock::new(None),
extent: RwLock::new(wgt::Extent3d::default()),
main_thread_id: thread::current().id(),
present_with_transaction: false,
}
Expand Down Expand Up @@ -178,8 +178,8 @@ impl crate::Surface<super::Api> for super::Surface {
log::info!("build swapchain {:?}", config);

let caps = &device.shared.private_caps;
self.swapchain_format = Some(config.format);
self.extent = config.extent;
*self.swapchain_format.write() = Some(config.format);
*self.extent.write() = config.extent;

let render_layer = self.render_layer.lock();
let framebuffer_only = config.usage == crate::TextureUses::COLOR_TARGET;
Expand Down Expand Up @@ -234,7 +234,7 @@ impl crate::Surface<super::Api> for super::Surface {
}

unsafe fn unconfigure(&self, _device: &super::Device) {
self.swapchain_format = None;
*self.swapchain_format.write() = None;
}

unsafe fn acquire_texture(
Expand All @@ -251,16 +251,18 @@ impl crate::Surface<super::Api> for super::Surface {
None => return Ok(None),
};

let swapchain_format = self.swapchain_format.read().unwrap();
let extent = self.extent.read();
let suf_texture = super::SurfaceTexture {
texture: super::Texture {
raw: texture,
format: self.swapchain_format.unwrap(),
format: swapchain_format,
raw_type: metal::MTLTextureType::D2,
array_layers: 1,
mip_levels: 1,
copy_size: crate::CopyExtent {
width: self.extent.width,
height: self.extent.height,
width: extent.width,
height: extent.height,
depth: 1,
},
},
Expand Down

0 comments on commit 669636a

Please sign in to comment.