preset: add original scaletype

As defined in https://github.com/libretro/RetroArch/pull/15937
This commit is contained in:
chyyran 2024-02-12 01:02:46 -05:00 committed by Ronny Chan
parent 4762055dc1
commit 3c3f024ef8
16 changed files with 89 additions and 15 deletions

View file

@ -63,6 +63,8 @@ pub enum ScaleType {
Absolute, Absolute,
/// Scale by the size of the viewport. /// Scale by the size of the viewport.
Viewport, Viewport,
/// Scale by the size of the original input quad.
Original,
} }
/// The scaling factor for framebuffer scaling. /// The scaling factor for framebuffer scaling.
@ -119,6 +121,7 @@ impl FromStr for ScaleType {
"source" => Ok(ScaleType::Input), "source" => Ok(ScaleType::Input),
"viewport" => Ok(ScaleType::Viewport), "viewport" => Ok(ScaleType::Viewport),
"absolute" => Ok(ScaleType::Absolute), "absolute" => Ok(ScaleType::Absolute),
"original" => Ok(ScaleType::Original),
_ => Err(ParsePresetError::InvalidScaleType(s.to_string())), _ => Err(ParsePresetError::InvalidScaleType(s.to_string())),
} }
} }

View file

@ -441,6 +441,7 @@ impl FilterChainD3D11 {
OwnedImage::scale_framebuffers( OwnedImage::scale_framebuffers(
source.size(), source.size(),
viewport.output.size, viewport.output.size,
original.view.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
passes, passes,

View file

@ -69,9 +69,10 @@ impl OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
) -> error::Result<Size<u32>> { ) -> error::Result<Size<u32>> {
let size = source_size.scale_viewport(scaling, *viewport_size); let size = source_size.scale_viewport(scaling, *viewport_size, *original_size);
if self.size != size if self.size != size
|| (should_mipmap && self.max_mipmap == 1) || (should_mipmap && self.max_mipmap == 1)
@ -255,9 +256,17 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
_context: &Self::Context, _context: &Self::Context,
) -> Result<Size<u32>, Self::Error> { ) -> Result<Size<u32>, Self::Error> {
self.scale(scaling, format, viewport_size, source_size, should_mipmap) self.scale(
scaling,
format,
viewport_size,
source_size,
original_size,
should_mipmap,
)
} }
} }

View file

@ -668,6 +668,7 @@ impl FilterChainD3D12 {
OwnedImage::scale_framebuffers( OwnedImage::scale_framebuffers(
source.size(), source.size(),
viewport.output.size, viewport.output.size,
original.size(),
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
passes, passes,

View file

@ -319,9 +319,10 @@ impl OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> error::Result<Size<u32>> { ) -> error::Result<Size<u32>> {
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); let format = Self::get_format_support(&self.device, format.into(), mipmap);
if self.size != size if self.size != size
@ -346,9 +347,17 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
_context: &Self::Context, _context: &Self::Context,
) -> Result<Size<u32>, Self::Error> { ) -> Result<Size<u32>, Self::Error> {
self.scale(scaling, format, viewport_size, source_size, should_mipmap) self.scale(
scaling,
format,
viewport_size,
source_size,
original_size,
should_mipmap,
)
} }
} }

View file

@ -321,6 +321,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
<GLFramebuffer as ScaleFramebuffer<T::FramebufferInterface>>::scale_framebuffers( <GLFramebuffer as ScaleFramebuffer<T::FramebufferInterface>>::scale_framebuffers(
source.image.size, source.image.size,
viewport.output.size, viewport.output.size,
original.image.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
passes, passes,

View file

@ -53,9 +53,18 @@ impl GLFramebuffer {
format: ImageFormat, format: ImageFormat,
viewport: &Size<u32>, viewport: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> Result<Size<u32>> { ) -> Result<Size<u32>> {
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<T: FramebufferInterface>(&mut self, image: &GLImage) -> Result<()> { pub(crate) fn copy_from<T: FramebufferInterface>(&mut self, image: &GLImage) -> Result<()> {
@ -103,9 +112,17 @@ impl<T: FramebufferInterface> ScaleFramebuffer<T> for GLFramebuffer {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
_context: &Self::Context, _context: &Self::Context,
) -> Result<Size<u32>> { ) -> Result<Size<u32>> {
self.scale::<T>(scaling, format, viewport_size, source_size, should_mipmap) self.scale::<T>(
scaling,
format,
viewport_size,
source_size,
original_size,
should_mipmap,
)
} }
} }

View file

@ -39,13 +39,14 @@ impl FramebufferInterface for Gl3Framebuffer {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> Result<Size<u32>> { ) -> Result<Size<u32>> {
if fb.is_raw { if fb.is_raw {
return Ok(fb.size); 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) { if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) {
fb.size = size; fb.size = size;

View file

@ -37,13 +37,14 @@ impl FramebufferInterface for Gl46Framebuffer {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> Result<Size<u32>> { ) -> Result<Size<u32>> {
if fb.is_raw { if fb.is_raw {
return Ok(fb.size); 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) { if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) {
fb.size = size; fb.size = size;

View file

@ -52,6 +52,7 @@ pub(crate) trait FramebufferInterface {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> Result<Size<u32>>; ) -> Result<Size<u32>>;
fn clear<const REBIND: bool>(fb: &GLFramebuffer); fn clear<const REBIND: bool>(fb: &GLFramebuffer);

View file

@ -640,6 +640,7 @@ impl FilterChainVulkan {
OwnedImage::scale_framebuffers_with_context( OwnedImage::scale_framebuffers_with_context(
source.image.size, source.image.size,
viewport.output.size, viewport.output.size,
original.image.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
passes, passes,

View file

@ -122,10 +122,11 @@ impl OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
layout: Option<OwnedImageLayout>, layout: Option<OwnedImageLayout>,
) -> error::Result<Size<u32>> { ) -> error::Result<Size<u32>> {
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 if self.image.size != size
|| (mipmap && self.max_miplevels == 1) || (mipmap && self.max_miplevels == 1)
|| (!mipmap && self.max_miplevels != 1) || (!mipmap && self.max_miplevels != 1)
@ -519,6 +520,7 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
context: &Self::Context, context: &Self::Context,
) -> Result<Size<u32>, Self::Error> { ) -> Result<Size<u32>, Self::Error> {
@ -527,6 +529,7 @@ impl ScaleFramebuffer for OwnedImage {
format, format,
viewport_size, viewport_size,
source_size, source_size,
original_size,
should_mipmap, should_mipmap,
context.clone(), context.clone(),
) )

View file

@ -387,6 +387,7 @@ impl FilterChainWgpu {
OwnedImage::scale_framebuffers_with_context( OwnedImage::scale_framebuffers_with_context(
source.image.size().into(), source.image.size().into(),
viewport.output.size, viewport.output.size,
original.image.size().into(),
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
passes, passes,

View file

@ -81,9 +81,10 @@ impl OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> Size<u32> { ) -> Size<u32> {
let size = source_size.scale_viewport(scaling, *viewport_size); let size = source_size.scale_viewport(scaling, *viewport_size, *original_size);
let format: Option<wgpu::TextureFormat> = format.into(); let format: Option<wgpu::TextureFormat> = format.into();
let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm); let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
@ -144,9 +145,17 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
_context: &Self::Context, _context: &Self::Context,
) -> Result<Size<u32>, Self::Error> { ) -> Result<Size<u32>, 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,
))
} }
} }

View file

@ -12,7 +12,7 @@ where
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
/// Produce a `Size<T>` scaled with the input scaling options. /// Produce a `Size<T>` scaled with the input scaling options.
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>) -> Size<T>; fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>;
} }
impl<T> ViewportSize<T> for Size<T> impl<T> ViewportSize<T> for Size<T>
@ -20,12 +20,12 @@ where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>) -> Size<T> fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>
where where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
scaling::scale(scaling, self, viewport) scaling::scale(scaling, self, viewport, original)
} }
} }
@ -57,7 +57,7 @@ impl MipmapSize<u32> for Size<u32> {
} }
} }
fn scale<T>(scaling: Scale2D, source: Size<T>, viewport: Size<T>) -> Size<T> fn scale<T>(scaling: Scale2D, source: Size<T>, viewport: Size<T>, original: Size<T>) -> Size<T>
where where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
@ -75,6 +75,10 @@ where
scale_type: ScaleType::Viewport, scale_type: ScaleType::Viewport,
factor, factor,
} => viewport.width * factor, } => viewport.width * factor,
Scaling {
scale_type: ScaleType::Original,
factor,
} => original.width * factor,
}; };
let height = match scaling.y { let height = match scaling.y {
@ -90,6 +94,10 @@ where
scale_type: ScaleType::Viewport, scale_type: ScaleType::Viewport,
factor, factor,
} => viewport.height * factor, } => viewport.height * factor,
Scaling {
scale_type: ScaleType::Original,
factor,
} => original.height * factor,
}; };
Size { Size {
@ -109,6 +117,7 @@ pub trait ScaleFramebuffer<T = ()> {
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool, should_mipmap: bool,
context: &Self::Context, context: &Self::Context,
) -> Result<Size<u32>, Self::Error>; ) -> Result<Size<u32>, Self::Error>;
@ -118,6 +127,7 @@ pub trait ScaleFramebuffer<T = ()> {
fn scale_framebuffers<P>( fn scale_framebuffers<P>(
source_size: Size<u32>, source_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
original_size: Size<u32>,
output: &mut [Self], output: &mut [Self],
feedback: &mut [Self], feedback: &mut [Self],
passes: &[P], passes: &[P],
@ -131,6 +141,7 @@ pub trait ScaleFramebuffer<T = ()> {
scale_framebuffers_with_context_callback::<T, Self, Self::Error, Self::Context, _>( scale_framebuffers_with_context_callback::<T, Self, Self::Error, Self::Context, _>(
source_size, source_size,
viewport_size, viewport_size,
original_size,
output, output,
feedback, feedback,
passes, passes,
@ -144,6 +155,7 @@ pub trait ScaleFramebuffer<T = ()> {
fn scale_framebuffers_with_context<P>( fn scale_framebuffers_with_context<P>(
source_size: Size<u32>, source_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
original_size: Size<u32>,
output: &mut [Self], output: &mut [Self],
feedback: &mut [Self], feedback: &mut [Self],
passes: &[P], passes: &[P],
@ -157,6 +169,7 @@ pub trait ScaleFramebuffer<T = ()> {
scale_framebuffers_with_context_callback::<T, Self, Self::Error, Self::Context, _>( scale_framebuffers_with_context_callback::<T, Self, Self::Error, Self::Context, _>(
source_size, source_size,
viewport_size, viewport_size,
original_size,
output, output,
feedback, feedback,
passes, passes,
@ -172,6 +185,7 @@ pub trait ScaleFramebuffer<T = ()> {
fn scale_framebuffers_with_context_callback<T, F, E, C, P>( fn scale_framebuffers_with_context_callback<T, F, E, C, P>(
source_size: Size<u32>, source_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
original_size: Size<u32>,
output: &mut [F], output: &mut [F],
feedback: &mut [F], feedback: &mut [F],
passes: &[P], passes: &[P],
@ -195,6 +209,7 @@ where
pass.get_format(), pass.get_format(),
&viewport_size, &viewport_size,
&target_size, &target_size,
&original_size,
should_mipmap, should_mipmap,
context, context,
)?; )?;
@ -204,6 +219,7 @@ where
pass.get_format(), pass.get_format(),
&viewport_size, &viewport_size,
&target_size, &target_size,
&original_size,
should_mipmap, should_mipmap,
context, context,
)?; )?;