diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index 2cdcc68..e287bf9 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -63,6 +63,8 @@ pub enum ScaleType { Absolute, /// Scale by the size of the viewport. Viewport, + /// Scale by the size of the original input quad. + Original, } /// The scaling factor for framebuffer scaling. @@ -119,6 +121,7 @@ impl FromStr for ScaleType { "source" => Ok(ScaleType::Input), "viewport" => Ok(ScaleType::Viewport), "absolute" => Ok(ScaleType::Absolute), + "original" => Ok(ScaleType::Original), _ => Err(ParsePresetError::InvalidScaleType(s.to_string())), } } diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 794bd8e..d757a26 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -441,6 +441,7 @@ impl FilterChainD3D11 { OwnedImage::scale_framebuffers( source.size(), viewport.output.size, + original.view.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, passes, diff --git a/librashader-runtime-d3d11/src/framebuffer.rs b/librashader-runtime-d3d11/src/framebuffer.rs index 1ddd3b2..33b6d17 100644 --- a/librashader-runtime-d3d11/src/framebuffer.rs +++ b/librashader-runtime-d3d11/src/framebuffer.rs @@ -69,9 +69,10 @@ impl OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, ) -> error::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 || (should_mipmap && self.max_mipmap == 1) @@ -255,9 +256,17 @@ impl ScaleFramebuffer for OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, _context: &Self::Context, ) -> Result, Self::Error> { - self.scale(scaling, format, viewport_size, source_size, should_mipmap) + self.scale( + scaling, + format, + viewport_size, + source_size, + original_size, + should_mipmap, + ) } } diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index 2e1d237..cbf0a1f 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -668,6 +668,7 @@ impl FilterChainD3D12 { OwnedImage::scale_framebuffers( source.size(), viewport.output.size, + original.size(), &mut self.output_framebuffers, &mut self.feedback_framebuffers, passes, diff --git a/librashader-runtime-d3d12/src/framebuffer.rs b/librashader-runtime-d3d12/src/framebuffer.rs index 8fd711f..b482d2f 100644 --- a/librashader-runtime-d3d12/src/framebuffer.rs +++ b/librashader-runtime-d3d12/src/framebuffer.rs @@ -319,9 +319,10 @@ impl OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> error::Result> { - let size = source_size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); let format = Self::get_format_support(&self.device, format.into(), mipmap); if self.size != size @@ -346,9 +347,17 @@ impl ScaleFramebuffer for OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, _context: &Self::Context, ) -> Result, Self::Error> { - self.scale(scaling, format, viewport_size, source_size, should_mipmap) + self.scale( + scaling, + format, + viewport_size, + source_size, + original_size, + should_mipmap, + ) } } diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index c382d86..3561370 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -321,6 +321,7 @@ impl FilterChainImpl { >::scale_framebuffers( source.image.size, viewport.output.size, + original.image.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, passes, diff --git a/librashader-runtime-gl/src/gl/framebuffer.rs b/librashader-runtime-gl/src/gl/framebuffer.rs index 7877938..a8d31ea 100644 --- a/librashader-runtime-gl/src/gl/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/framebuffer.rs @@ -53,9 +53,18 @@ impl GLFramebuffer { format: ImageFormat, viewport: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> Result> { - T::scale(self, scaling, format, viewport, source_size, mipmap) + T::scale( + self, + scaling, + format, + viewport, + source_size, + original_size, + mipmap, + ) } pub(crate) fn copy_from(&mut self, image: &GLImage) -> Result<()> { @@ -103,9 +112,17 @@ impl ScaleFramebuffer for GLFramebuffer { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, _context: &Self::Context, ) -> Result> { - self.scale::(scaling, format, viewport_size, source_size, should_mipmap) + self.scale::( + scaling, + format, + viewport_size, + source_size, + original_size, + should_mipmap, + ) } } diff --git a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs index 12316a2..8b55809 100644 --- a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs @@ -39,13 +39,14 @@ impl FramebufferInterface for Gl3Framebuffer { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> Result> { if fb.is_raw { return Ok(fb.size); } - let size = source_size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { fb.size = size; diff --git a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs index de1f2ea..88e4750 100644 --- a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs @@ -37,13 +37,14 @@ impl FramebufferInterface for Gl46Framebuffer { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> Result> { if fb.is_raw { return Ok(fb.size); } - let size = source_size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { fb.size = size; diff --git a/librashader-runtime-gl/src/gl/mod.rs b/librashader-runtime-gl/src/gl/mod.rs index d73854e..7f70db9 100644 --- a/librashader-runtime-gl/src/gl/mod.rs +++ b/librashader-runtime-gl/src/gl/mod.rs @@ -52,6 +52,7 @@ pub(crate) trait FramebufferInterface { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> Result>; fn clear(fb: &GLFramebuffer); diff --git a/librashader-runtime-metal/src/graphics_pipeline.rs b/librashader-runtime-metal/src/graphics_pipeline.rs deleted file mode 100644 index e69de29..0000000 diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 94a46bd..cbf739a 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -640,6 +640,7 @@ impl FilterChainVulkan { OwnedImage::scale_framebuffers_with_context( source.image.size, viewport.output.size, + original.image.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, passes, diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index 81bbeba..8bd892d 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -122,10 +122,11 @@ impl OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, layout: Option, ) -> error::Result> { - let size = source_size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); if self.image.size != size || (mipmap && self.max_miplevels == 1) || (!mipmap && self.max_miplevels != 1) @@ -519,6 +520,7 @@ impl ScaleFramebuffer for OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, context: &Self::Context, ) -> Result, Self::Error> { @@ -527,6 +529,7 @@ impl ScaleFramebuffer for OwnedImage { format, viewport_size, source_size, + original_size, should_mipmap, context.clone(), ) diff --git a/librashader-runtime-wgpu/src/filter_chain.rs b/librashader-runtime-wgpu/src/filter_chain.rs index 3537fca..ff560fe 100644 --- a/librashader-runtime-wgpu/src/filter_chain.rs +++ b/librashader-runtime-wgpu/src/filter_chain.rs @@ -387,6 +387,7 @@ impl FilterChainWgpu { OwnedImage::scale_framebuffers_with_context( source.image.size().into(), viewport.output.size, + original.image.size().into(), &mut self.output_framebuffers, &mut self.feedback_framebuffers, passes, diff --git a/librashader-runtime-wgpu/src/texture.rs b/librashader-runtime-wgpu/src/texture.rs index 9b532f0..d90b2ea 100644 --- a/librashader-runtime-wgpu/src/texture.rs +++ b/librashader-runtime-wgpu/src/texture.rs @@ -81,9 +81,10 @@ impl OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, mipmap: bool, ) -> Size { - let size = source_size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); let format: Option = format.into(); let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm); @@ -144,9 +145,17 @@ impl ScaleFramebuffer for OwnedImage { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, _context: &Self::Context, ) -> Result, Self::Error> { - Ok(self.scale(scaling, format, viewport_size, source_size, should_mipmap)) + Ok(self.scale( + scaling, + format, + viewport_size, + source_size, + original_size, + should_mipmap, + )) } } diff --git a/librashader-runtime/src/scaling.rs b/librashader-runtime/src/scaling.rs index bf35a16..ab4e74e 100644 --- a/librashader-runtime/src/scaling.rs +++ b/librashader-runtime/src/scaling.rs @@ -12,7 +12,7 @@ where f32: AsPrimitive, { /// Produce a `Size` scaled with the input scaling options. - fn scale_viewport(self, scaling: Scale2D, viewport: Size) -> Size; + fn scale_viewport(self, scaling: Scale2D, viewport: Size, original: Size) -> Size; } impl ViewportSize for Size @@ -20,12 +20,12 @@ where T: Mul + Copy + 'static, f32: AsPrimitive, { - fn scale_viewport(self, scaling: Scale2D, viewport: Size) -> Size + fn scale_viewport(self, scaling: Scale2D, viewport: Size, original: Size) -> Size where T: Mul + Copy + 'static, f32: AsPrimitive, { - scaling::scale(scaling, self, viewport) + scaling::scale(scaling, self, viewport, original) } } @@ -57,7 +57,7 @@ impl MipmapSize for Size { } } -fn scale(scaling: Scale2D, source: Size, viewport: Size) -> Size +fn scale(scaling: Scale2D, source: Size, viewport: Size, original: Size) -> Size where T: Mul + Copy + 'static, f32: AsPrimitive, @@ -75,6 +75,10 @@ where scale_type: ScaleType::Viewport, factor, } => viewport.width * factor, + Scaling { + scale_type: ScaleType::Original, + factor, + } => original.width * factor, }; let height = match scaling.y { @@ -90,6 +94,10 @@ where scale_type: ScaleType::Viewport, factor, } => viewport.height * factor, + Scaling { + scale_type: ScaleType::Original, + factor, + } => original.height * factor, }; Size { @@ -109,6 +117,7 @@ pub trait ScaleFramebuffer { format: ImageFormat, viewport_size: &Size, source_size: &Size, + original_size: &Size, should_mipmap: bool, context: &Self::Context, ) -> Result, Self::Error>; @@ -118,6 +127,7 @@ pub trait ScaleFramebuffer { fn scale_framebuffers

( source_size: Size, viewport_size: Size, + original_size: Size, output: &mut [Self], feedback: &mut [Self], passes: &[P], @@ -131,6 +141,7 @@ pub trait ScaleFramebuffer { scale_framebuffers_with_context_callback::( source_size, viewport_size, + original_size, output, feedback, passes, @@ -144,6 +155,7 @@ pub trait ScaleFramebuffer { fn scale_framebuffers_with_context

( source_size: Size, viewport_size: Size, + original_size: Size, output: &mut [Self], feedback: &mut [Self], passes: &[P], @@ -157,6 +169,7 @@ pub trait ScaleFramebuffer { scale_framebuffers_with_context_callback::( source_size, viewport_size, + original_size, output, feedback, passes, @@ -172,6 +185,7 @@ pub trait ScaleFramebuffer { fn scale_framebuffers_with_context_callback( source_size: Size, viewport_size: Size, + original_size: Size, output: &mut [F], feedback: &mut [F], passes: &[P], @@ -195,6 +209,7 @@ where pass.get_format(), &viewport_size, &target_size, + &original_size, should_mipmap, context, )?; @@ -204,6 +219,7 @@ where pass.get_format(), &viewport_size, &target_size, + &original_size, should_mipmap, context, )?;