diff --git a/librashader-runtime-metal/src/filter_chain.rs b/librashader-runtime-metal/src/filter_chain.rs index 08a1b8b..61c80d9 100644 --- a/librashader-runtime-metal/src/filter_chain.rs +++ b/librashader-runtime-metal/src/filter_chain.rs @@ -59,6 +59,7 @@ pub struct FilterChainMetal { feedback_framebuffers: Box<[OwnedTexture]>, history_framebuffers: VecDeque, disable_mipmaps: bool, + default_options: FrameOptionsMetal } impl Debug for FilterChainMetal { @@ -309,6 +310,7 @@ impl FilterChainMetal { feedback_framebuffers, history_framebuffers, disable_mipmaps: options.map(|f| f.force_no_mipmaps).unwrap_or(false), + default_options: Default::default(), }) } @@ -370,6 +372,7 @@ impl FilterChainMetal { OwnedTexture::scale_framebuffers_with_context( get_texture_size(&source.texture).into(), get_texture_size(viewport.output), + get_texture_size(&original.texture).into(), &mut self.output_framebuffers, &mut self.feedback_framebuffers, passes, @@ -389,7 +392,7 @@ impl FilterChainMetal { let passes_len = passes.len(); let (pass, last) = passes.split_at_mut(passes_len - 1); - let frame_direction = options.map_or(1, |f| f.frame_direction); + let options = options.unwrap_or(&self.default_options); let mipmapper = cmd_buffer .blitCommandEncoder() @@ -407,7 +410,7 @@ impl FilterChainMetal { index, &self.common, pass.config.get_frame_count(frame_count), - frame_direction, + options, viewport, &original, &source, @@ -445,7 +448,7 @@ impl FilterChainMetal { passes_len - 1, &self.common, pass.config.get_frame_count(frame_count), - frame_direction, + options, viewport, &original, &source, diff --git a/librashader-runtime-metal/src/filter_pass.rs b/librashader-runtime-metal/src/filter_pass.rs index 683f268..fcaccbb 100644 --- a/librashader-runtime-metal/src/filter_pass.rs +++ b/librashader-runtime-metal/src/filter_pass.rs @@ -10,13 +10,14 @@ use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{MemberOffset, TextureBinding, UniformBinding}; use librashader_reflect::reflect::ShaderReflection; -use librashader_runtime::binding::{BindSemantics, TextureInput}; +use librashader_runtime::binding::{BindSemantics, TextureInput, UniformInputs}; use librashader_runtime::filter_pass::FilterPassMeta; use librashader_runtime::quad::QuadType; use librashader_runtime::render_target::RenderTarget; use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage}; use objc2::runtime::ProtocolObject; use rustc_hash::FxHashMap; +use crate::options::FrameOptionsMetal; impl TextureInput for InputTexture { fn size(&self) -> Size { @@ -66,7 +67,7 @@ impl FilterPass { pass_index: usize, parent: &FilterCommon, frame_count: u32, - frame_direction: i32, + options: &FrameOptionsMetal, viewport: &Viewport<&ProtocolObject>, original: &InputTexture, source: &InputTexture, @@ -80,7 +81,7 @@ impl FilterPass { parent, output.mvp, frame_count, - frame_direction, + options, get_texture_size(output.output), get_texture_size(viewport.output), original, @@ -120,7 +121,7 @@ impl FilterPass { parent: &FilterCommon, mvp: &[f32; 16], frame_count: u32, - frame_direction: i32, + options: &FrameOptionsMetal, fb_size: Size, viewport_size: Size, original: &InputTexture, @@ -132,11 +133,16 @@ impl FilterPass { &parent.samplers, &mut self.uniform_storage, &mut renderpass, - mvp, - frame_count, - frame_direction, - fb_size, - viewport_size, + UniformInputs { + mvp, + frame_count, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + frame_direction: options.frame_direction, + framebuffer_size: fb_size, + viewport_size, + }, original, source, &self.uniform_bindings, diff --git a/librashader-runtime-metal/src/options.rs b/librashader-runtime-metal/src/options.rs index 0f585db..08085a9 100644 --- a/librashader-runtime-metal/src/options.rs +++ b/librashader-runtime-metal/src/options.rs @@ -1,15 +1,7 @@ //! Metal shader runtime options. -/// Options for each Vulkan shader frame. -#[repr(C)] -#[derive(Default, Debug, Clone)] -pub struct FrameOptionsMetal { - /// Whether or not to clear the history buffers. - pub clear_history: bool, - /// The direction of rendering. - /// -1 indicates that the frames are played in reverse order. - pub frame_direction: i32, -} +use librashader_runtime::impl_default_frame_options; +impl_default_frame_options!(FrameOptionsMetal); /// Options for filter chain creation. #[repr(C)] diff --git a/librashader-runtime-metal/src/texture.rs b/librashader-runtime-metal/src/texture.rs index 54bb9cc..65c596a 100644 --- a/librashader-runtime-metal/src/texture.rs +++ b/librashader-runtime-metal/src/texture.rs @@ -92,9 +92,10 @@ impl OwnedTexture { format: MTLPixelFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> Result> { - let size = source_size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); if self.size != size || (mipmap && self.max_miplevels == 1) @@ -155,6 +156,7 @@ impl ScaleFramebuffer for OwnedTexture { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, context: &Self::Context, ) -> std::result::Result, Self::Error> { @@ -164,6 +166,7 @@ impl ScaleFramebuffer for OwnedTexture { format.into(), viewport_size, source_size, + original_size, should_mipmap, )?) }