diff --git a/librashader-runtime-mtl/src/filter_chain.rs b/librashader-runtime-mtl/src/filter_chain.rs index 2137994..ddc853f 100644 --- a/librashader-runtime-mtl/src/filter_chain.rs +++ b/librashader-runtime-mtl/src/filter_chain.rs @@ -27,7 +27,7 @@ use librashader_runtime::quad::QuadType; use librashader_runtime::render_target::RenderTarget; use librashader_runtime::scaling::ScaleFramebuffer; use librashader_runtime::uniforms::UniformStorage; -use objc2::rc::Id; +use objc2::rc::{Id, Retained}; use objc2::runtime::ProtocolObject; use objc2_foundation::NSString; use objc2_metal::{ @@ -204,8 +204,8 @@ impl FilterChainMetal { fn push_history( &mut self, - input: &ProtocolObject, cmd: &ProtocolObject, + input: &ProtocolObject, ) -> error::Result<()> { let mipmapper = cmd .blitCommandEncoder() @@ -227,10 +227,11 @@ impl FilterChainMetal { } back.copy_from(&mipmapper, input)?; - + mipmapper.endEncoding(); self.history_framebuffers.push_front(back); + } else { + mipmapper.endEncoding(); } - mipmapper.endEncoding(); Ok(()) } @@ -326,20 +327,7 @@ impl FilterChainMetal { options: Option<&FrameOptionsMetal>, ) -> error::Result<()> { let max = std::cmp::min(self.passes.len(), self.common.config.passes_enabled()); - let passes = &mut self.passes[0..max]; if let Some(options) = &options { - let desc = unsafe { - let desc = MTLRenderPassDescriptor::new(); - desc.colorAttachments() - .objectAtIndexedSubscript(0) - .setLoadAction(MTLLoadAction::Clear); - - desc.colorAttachments() - .objectAtIndexedSubscript(0) - .setStoreAction(MTLStoreAction::DontCare); - desc - }; - let clear_desc = unsafe { MTLRenderPassDescriptor::new() }; if options.clear_history { for (index, history) in self.history_framebuffers.iter().enumerate() { @@ -352,13 +340,17 @@ impl FilterChainMetal { ca.setStoreAction(MTLStoreAction::Store); } } - } - let clearpass = cmd - .renderCommandEncoderWithDescriptor(&desc) - .ok_or(FilterChainError::FailedToCreateCommandBuffer)?; - clearpass.endEncoding(); + let clearpass = cmd + .renderCommandEncoderWithDescriptor(&clear_desc) + .ok_or(FilterChainError::FailedToCreateCommandBuffer)?; + clearpass.endEncoding(); + } } + + self.push_history(&cmd, &input)?; + + let passes = &mut self.passes[0..max]; if passes.is_empty() { return Ok(()); } @@ -482,7 +474,6 @@ impl FilterChainMetal { )?; } - self.push_history(&input, &cmd)?; self.common.internal_frame_count = self.common.internal_frame_count.wrapping_add(1); Ok(()) } diff --git a/librashader-runtime-mtl/src/lib.rs b/librashader-runtime-mtl/src/lib.rs index ba21b8f..6610697 100644 --- a/librashader-runtime-mtl/src/lib.rs +++ b/librashader-runtime-mtl/src/lib.rs @@ -28,5 +28,5 @@ fn select_optimal_pixel_format(format: MTLPixelFormat) -> MTLPixelFormat { if format == MTLPixelFormat::RGBA8Unorm_sRGB { return MTLPixelFormat::BGRA8Unorm_sRGB; } - return format; + format } diff --git a/librashader-runtime-mtl/src/texture.rs b/librashader-runtime-mtl/src/texture.rs index 18c2cb9..abad665 100644 --- a/librashader-runtime-mtl/src/texture.rs +++ b/librashader-runtime-mtl/src/texture.rs @@ -70,11 +70,11 @@ impl OwnedTexture { 1 }); - descriptor.setStorageMode(MTLStorageMode::Private); descriptor.setUsage( MTLTextureUsage::ShaderRead | MTLTextureUsage::ShaderWrite - | MTLTextureUsage::RenderTarget, + | MTLTextureUsage::RenderTarget + | MTLTextureUsage::PixelFormatView, ); descriptor @@ -106,7 +106,7 @@ impl OwnedTexture { || (!mipmap && self.max_miplevels != 1) || format != select_optimal_pixel_format(format) { - let mut new = OwnedTexture::new(device, size, self.max_miplevels, format)?; + let mut new = OwnedTexture::new(device, size, self.max_miplevels, select_optimal_pixel_format(format))?; std::mem::swap(self, &mut new); } Ok(size)