Skip to content

Commit

Permalink
preset: add original scaletype
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Feb 12, 2024
1 parent 4762055 commit 3c3f024
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 15 deletions.
3 changes: 3 additions & 0 deletions librashader-presets/src/preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())),
}
}
Expand Down
1 change: 1 addition & 0 deletions librashader-runtime-d3d11/src/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions librashader-runtime-d3d11/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ impl OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
) -> 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
|| (should_mipmap && self.max_mipmap == 1)
Expand Down Expand Up @@ -255,9 +256,17 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
_context: &Self::Context,
) -> 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,
)
}
}
1 change: 1 addition & 0 deletions librashader-runtime-d3d12/src/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions librashader-runtime-d3d12/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ impl OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
) -> 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);

if self.size != size
Expand All @@ -346,9 +347,17 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
_context: &Self::Context,
) -> 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,
)
}
}
1 change: 1 addition & 0 deletions librashader-runtime-gl/src/filter_chain/filter_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
<GLFramebuffer as ScaleFramebuffer<T::FramebufferInterface>>::scale_framebuffers(
source.image.size,
viewport.output.size,
original.image.size,
&mut self.output_framebuffers,
&mut self.feedback_framebuffers,
passes,
Expand Down
21 changes: 19 additions & 2 deletions librashader-runtime-gl/src/gl/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ impl GLFramebuffer {
format: ImageFormat,
viewport: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
) -> 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<()> {
Expand Down Expand Up @@ -103,9 +112,17 @@ impl<T: FramebufferInterface> ScaleFramebuffer<T> for GLFramebuffer {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
_context: &Self::Context,
) -> 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,
)
}
}
3 changes: 2 additions & 1 deletion librashader-runtime-gl/src/gl/gl3/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ impl FramebufferInterface for Gl3Framebuffer {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
) -> Result<Size<u32>> {
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;
Expand Down
3 changes: 2 additions & 1 deletion librashader-runtime-gl/src/gl/gl46/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ impl FramebufferInterface for Gl46Framebuffer {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
) -> Result<Size<u32>> {
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;
Expand Down
1 change: 1 addition & 0 deletions librashader-runtime-gl/src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub(crate) trait FramebufferInterface {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
) -> Result<Size<u32>>;
fn clear<const REBIND: bool>(fb: &GLFramebuffer);
Expand Down
Empty file.
1 change: 1 addition & 0 deletions librashader-runtime-vk/src/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion librashader-runtime-vk/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ impl OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
layout: Option<OwnedImageLayout>,
) -> 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
|| (mipmap && self.max_miplevels == 1)
|| (!mipmap && self.max_miplevels != 1)
Expand Down Expand Up @@ -519,6 +520,7 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
context: &Self::Context,
) -> Result<Size<u32>, Self::Error> {
Expand All @@ -527,6 +529,7 @@ impl ScaleFramebuffer for OwnedImage {
format,
viewport_size,
source_size,
original_size,
should_mipmap,
context.clone(),
)
Expand Down
1 change: 1 addition & 0 deletions librashader-runtime-wgpu/src/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions librashader-runtime-wgpu/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ impl OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
mipmap: bool,
) -> 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 = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);

Expand Down Expand Up @@ -144,9 +145,17 @@ impl ScaleFramebuffer for OwnedImage {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
_context: &Self::Context,
) -> 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,
))
}
}
24 changes: 20 additions & 4 deletions librashader-runtime/src/scaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ where
f32: AsPrimitive<T>,
{
/// 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>
where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
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
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
f32: AsPrimitive<T>,
{
scaling::scale(scaling, self, viewport)
scaling::scale(scaling, self, viewport, original)
}
}

Expand Down Expand Up @@ -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
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
f32: AsPrimitive<T>,
Expand All @@ -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 {
Expand All @@ -90,6 +94,10 @@ where
scale_type: ScaleType::Viewport,
factor,
} => viewport.height * factor,
Scaling {
scale_type: ScaleType::Original,
factor,
} => original.height * factor,
};

Size {
Expand All @@ -109,6 +117,7 @@ pub trait ScaleFramebuffer<T = ()> {
format: ImageFormat,
viewport_size: &Size<u32>,
source_size: &Size<u32>,
original_size: &Size<u32>,
should_mipmap: bool,
context: &Self::Context,
) -> Result<Size<u32>, Self::Error>;
Expand All @@ -118,6 +127,7 @@ pub trait ScaleFramebuffer<T = ()> {
fn scale_framebuffers<P>(
source_size: Size<u32>,
viewport_size: Size<u32>,
original_size: Size<u32>,
output: &mut [Self],
feedback: &mut [Self],
passes: &[P],
Expand All @@ -131,6 +141,7 @@ pub trait ScaleFramebuffer<T = ()> {
scale_framebuffers_with_context_callback::<T, Self, Self::Error, Self::Context, _>(
source_size,
viewport_size,
original_size,
output,
feedback,
passes,
Expand All @@ -144,6 +155,7 @@ pub trait ScaleFramebuffer<T = ()> {
fn scale_framebuffers_with_context<P>(
source_size: Size<u32>,
viewport_size: Size<u32>,
original_size: Size<u32>,
output: &mut [Self],
feedback: &mut [Self],
passes: &[P],
Expand All @@ -157,6 +169,7 @@ pub trait ScaleFramebuffer<T = ()> {
scale_framebuffers_with_context_callback::<T, Self, Self::Error, Self::Context, _>(
source_size,
viewport_size,
original_size,
output,
feedback,
passes,
Expand All @@ -172,6 +185,7 @@ pub trait ScaleFramebuffer<T = ()> {
fn scale_framebuffers_with_context_callback<T, F, E, C, P>(
source_size: Size<u32>,
viewport_size: Size<u32>,
original_size: Size<u32>,
output: &mut [F],
feedback: &mut [F],
passes: &[P],
Expand All @@ -195,6 +209,7 @@ where
pass.get_format(),
&viewport_size,
&target_size,
&original_size,
should_mipmap,
context,
)?;
Expand All @@ -204,6 +219,7 @@ where
pass.get_format(),
&viewport_size,
&target_size,
&original_size,
should_mipmap,
context,
)?;
Expand Down

0 comments on commit 3c3f024

Please sign in to comment.