diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index e37a4e3..c0df367 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -30,6 +30,7 @@ use windows::Win32::Graphics::Direct3D11::{ D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC, }; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM; +use librashader_runtime::binding::TextureInput; pub struct FilterMutable { pub(crate) passes_enabled: usize, @@ -468,18 +469,18 @@ impl FilterChainD3D11 { let mut iterator = passes.iter_mut().enumerate().peekable(); // rescale render buffers to ensure all bindings are valid. + let mut source_size = source.size(); while let Some((index, pass)) = iterator.next() { let should_mipmap = iterator .peek() .map(|(_, p)| p.config.mipmap_input) .unwrap_or(false); - self.output_framebuffers[index].scale( + let next_size = self.output_framebuffers[index].scale( pass.config.scaling.clone(), pass.get_format(), &viewport.output.size, - &original, - &source, + &source_size, should_mipmap )?; @@ -487,10 +488,11 @@ impl FilterChainD3D11 { pass.config.scaling.clone(), pass.get_format(), &viewport.output.size, - &original, - &source, + &source_size, should_mipmap )?; + + source_size = next_size; } let passes_len = passes.len(); diff --git a/librashader-runtime-d3d11/src/framebuffer.rs b/librashader-runtime-d3d11/src/framebuffer.rs index 9705858..01a9a50 100644 --- a/librashader-runtime-d3d11/src/framebuffer.rs +++ b/librashader-runtime-d3d11/src/framebuffer.rs @@ -4,7 +4,7 @@ use crate::texture::{D3D11InputView, InputTexture}; use crate::util::d3d11_get_closest_format; use librashader_common::{ImageFormat, Size}; use librashader_presets::Scale2D; -use librashader_runtime::scaling::{calculate_miplevels, MipmapSize, ViewportSize}; +use librashader_runtime::scaling::{MipmapSize, ViewportSize}; use windows::core::Interface; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; use windows::Win32::Graphics::Direct3D11::{ @@ -67,15 +67,14 @@ impl OwnedFramebuffer { scaling: Scale2D, format: ImageFormat, viewport_size: &Size, - _original: &InputTexture, - source: &InputTexture, + source_size: &Size, should_mipmap: bool, ) -> error::Result> { if self.is_raw { return Ok(self.size); } - let size = source.view.size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size); if self.size != size || (should_mipmap && self.max_mipmap == 1) @@ -113,7 +112,6 @@ impl OwnedFramebuffer { | D3D11_FORMAT_SUPPORT_RENDER_TARGET.0, ); - // todo: fix mipmap handling let desc = default_desc(size, format, self.max_mipmap); unsafe { let mut texture = None; diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index 75ca6b1..57d2698 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -439,6 +439,7 @@ impl FilterChainImpl { let mut source = original; + let mut source_size = source.image.size; // rescale render buffers to ensure all bindings are valid. let mut iterator = passes.iter_mut().enumerate().peekable(); while let Some((index, pass)) = iterator.next() { @@ -447,12 +448,11 @@ impl FilterChainImpl { .map(|(_, p)| p.config.mipmap_input) .unwrap_or(false); - self.output_framebuffers[index].scale::( + let next_size = self.output_framebuffers[index].scale::( pass.config.scaling.clone(), pass.get_format(), viewport, - &original, - &source, + &source_size, should_mipmap, )?; @@ -460,10 +460,11 @@ impl FilterChainImpl { pass.config.scaling.clone(), pass.get_format(), viewport, - &original, - &source, + &source_size, should_mipmap, )?; + + source_size = next_size } let passes_len = passes.len(); diff --git a/librashader-runtime-gl/src/gl/framebuffer.rs b/librashader-runtime-gl/src/gl/framebuffer.rs index a5fcec2..fecbd2f 100644 --- a/librashader-runtime-gl/src/gl/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/framebuffer.rs @@ -51,11 +51,10 @@ impl Framebuffer { scaling: Scale2D, format: ImageFormat, viewport: &Viewport<&Framebuffer>, - original: &InputTexture, - source: &InputTexture, + source_size: &Size, mipmap: bool, ) -> Result> { - T::scale(self, scaling, format, viewport, original, source, mipmap) + T::scale(self, scaling, format, viewport, source_size, mipmap) } pub(crate) fn copy_from(&mut self, image: &GLImage) -> Result<()> { diff --git a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs index d45e27e..df3674b 100644 --- a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs @@ -39,17 +39,14 @@ impl FramebufferInterface for Gl3Framebuffer { scaling: Scale2D, format: ImageFormat, viewport: &Viewport<&Framebuffer>, - _original: &InputTexture, - source: &InputTexture, + source_size: &Size, mipmap: bool, ) -> Result> { if fb.is_raw { return Ok(fb.size); } - let size = source - .image - .size + let size = source_size .scale_viewport(scaling, viewport.output.size); if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { diff --git a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs index ce74633..eba3620 100644 --- a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs @@ -37,17 +37,14 @@ impl FramebufferInterface for Gl46Framebuffer { scaling: Scale2D, format: ImageFormat, viewport: &Viewport<&Framebuffer>, - _original: &InputTexture, - source: &InputTexture, + source_size: &Size, mipmap: bool, ) -> Result> { if fb.is_raw { return Ok(fb.size); } - let size = source - .image - .size + let size = source_size .scale_viewport(scaling, viewport.output.size); if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { diff --git a/librashader-runtime-gl/src/gl/mod.rs b/librashader-runtime-gl/src/gl/mod.rs index 08808cd..de1b071 100644 --- a/librashader-runtime-gl/src/gl/mod.rs +++ b/librashader-runtime-gl/src/gl/mod.rs @@ -42,8 +42,7 @@ pub trait FramebufferInterface { scaling: Scale2D, format: ImageFormat, viewport: &Viewport<&Framebuffer>, - _original: &InputTexture, - source: &InputTexture, + source_size: &Size, mipmap: bool, ) -> Result>; fn clear(fb: &Framebuffer); diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 7efcea4..49ec109 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -640,6 +640,7 @@ impl FilterChainVulkan { ); // rescale render buffers to ensure all bindings are valid. + let mut source_size = source.image.size; let mut iterator = passes.iter_mut().enumerate().peekable(); while let Some((index, pass)) = iterator.next() { let should_mipmap = iterator @@ -653,12 +654,11 @@ impl FilterChainVulkan { // // since scaling is hopefully a rare occurrence (since it's tested for if the output size // requires changing) it should be ok. - self.output_framebuffers[index].scale( + let next_size = self.output_framebuffers[index].scale( pass.config.scaling.clone(), pass.get_format(), &viewport.output.size, - &original, - source, + &source_size, should_mipmap, Some(OwnedImageLayout { dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, @@ -673,8 +673,7 @@ impl FilterChainVulkan { pass.config.scaling.clone(), pass.get_format(), &viewport.output.size, - &original, - source, + &source_size, should_mipmap, Some(OwnedImageLayout { dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, @@ -685,6 +684,7 @@ impl FilterChainVulkan { }), )?; + source_size = next_size; // refresh inputs self.common.feedback_inputs[index] = Some( self.feedback_framebuffers[index] diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index f695714..cd7c33a 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -134,12 +134,11 @@ impl OwnedImage { scaling: Scale2D, format: ImageFormat, viewport_size: &Size, - _original: &InputImage, - source: &InputImage, + source_size: &Size, mipmap: bool, layout: Option, ) -> error::Result> { - let size = source.image.size.scale_viewport(scaling, *viewport_size); + let size = source_size.scale_viewport(scaling, *viewport_size); if self.image.size != size || (mipmap && self.max_miplevels == 1) || (!mipmap && self.max_miplevels != 1)