runtime: scale output framebuffers according to the previous inputs rather than original size.
This commit is contained in:
parent
3c13dc8277
commit
92caad292c
9 changed files with 30 additions and 38 deletions
|
@ -30,6 +30,7 @@ use windows::Win32::Graphics::Direct3D11::{
|
||||||
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC,
|
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC,
|
||||||
};
|
};
|
||||||
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
|
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
use librashader_runtime::binding::TextureInput;
|
||||||
|
|
||||||
pub struct FilterMutable {
|
pub struct FilterMutable {
|
||||||
pub(crate) passes_enabled: usize,
|
pub(crate) passes_enabled: usize,
|
||||||
|
@ -468,18 +469,18 @@ impl FilterChainD3D11 {
|
||||||
let mut iterator = passes.iter_mut().enumerate().peekable();
|
let mut iterator = passes.iter_mut().enumerate().peekable();
|
||||||
|
|
||||||
// rescale render buffers to ensure all bindings are valid.
|
// rescale render buffers to ensure all bindings are valid.
|
||||||
|
let mut source_size = source.size();
|
||||||
while let Some((index, pass)) = iterator.next() {
|
while let Some((index, pass)) = iterator.next() {
|
||||||
let should_mipmap = iterator
|
let should_mipmap = iterator
|
||||||
.peek()
|
.peek()
|
||||||
.map(|(_, p)| p.config.mipmap_input)
|
.map(|(_, p)| p.config.mipmap_input)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
self.output_framebuffers[index].scale(
|
let next_size = self.output_framebuffers[index].scale(
|
||||||
pass.config.scaling.clone(),
|
pass.config.scaling.clone(),
|
||||||
pass.get_format(),
|
pass.get_format(),
|
||||||
&viewport.output.size,
|
&viewport.output.size,
|
||||||
&original,
|
&source_size,
|
||||||
&source,
|
|
||||||
should_mipmap
|
should_mipmap
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -487,10 +488,11 @@ impl FilterChainD3D11 {
|
||||||
pass.config.scaling.clone(),
|
pass.config.scaling.clone(),
|
||||||
pass.get_format(),
|
pass.get_format(),
|
||||||
&viewport.output.size,
|
&viewport.output.size,
|
||||||
&original,
|
&source_size,
|
||||||
&source,
|
|
||||||
should_mipmap
|
should_mipmap
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
source_size = next_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
let passes_len = passes.len();
|
let passes_len = passes.len();
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::texture::{D3D11InputView, InputTexture};
|
||||||
use crate::util::d3d11_get_closest_format;
|
use crate::util::d3d11_get_closest_format;
|
||||||
use librashader_common::{ImageFormat, Size};
|
use librashader_common::{ImageFormat, Size};
|
||||||
use librashader_presets::Scale2D;
|
use librashader_presets::Scale2D;
|
||||||
use librashader_runtime::scaling::{calculate_miplevels, MipmapSize, ViewportSize};
|
use librashader_runtime::scaling::{MipmapSize, ViewportSize};
|
||||||
use windows::core::Interface;
|
use windows::core::Interface;
|
||||||
use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D;
|
use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D;
|
||||||
use windows::Win32::Graphics::Direct3D11::{
|
use windows::Win32::Graphics::Direct3D11::{
|
||||||
|
@ -67,15 +67,14 @@ impl OwnedFramebuffer {
|
||||||
scaling: Scale2D,
|
scaling: Scale2D,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
viewport_size: &Size<u32>,
|
viewport_size: &Size<u32>,
|
||||||
_original: &InputTexture,
|
source_size: &Size<u32>,
|
||||||
source: &InputTexture,
|
|
||||||
should_mipmap: bool,
|
should_mipmap: bool,
|
||||||
) -> error::Result<Size<u32>> {
|
) -> error::Result<Size<u32>> {
|
||||||
if self.is_raw {
|
if self.is_raw {
|
||||||
return Ok(self.size);
|
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
|
if self.size != size
|
||||||
|| (should_mipmap && self.max_mipmap == 1)
|
|| (should_mipmap && self.max_mipmap == 1)
|
||||||
|
@ -113,7 +112,6 @@ impl OwnedFramebuffer {
|
||||||
| D3D11_FORMAT_SUPPORT_RENDER_TARGET.0,
|
| D3D11_FORMAT_SUPPORT_RENDER_TARGET.0,
|
||||||
);
|
);
|
||||||
|
|
||||||
// todo: fix mipmap handling
|
|
||||||
let desc = default_desc(size, format, self.max_mipmap);
|
let desc = default_desc(size, format, self.max_mipmap);
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut texture = None;
|
let mut texture = None;
|
||||||
|
|
|
@ -439,6 +439,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
|
|
||||||
let mut source = original;
|
let mut source = original;
|
||||||
|
|
||||||
|
let mut source_size = source.image.size;
|
||||||
// rescale render buffers to ensure all bindings are valid.
|
// rescale render buffers to ensure all bindings are valid.
|
||||||
let mut iterator = passes.iter_mut().enumerate().peekable();
|
let mut iterator = passes.iter_mut().enumerate().peekable();
|
||||||
while let Some((index, pass)) = iterator.next() {
|
while let Some((index, pass)) = iterator.next() {
|
||||||
|
@ -447,12 +448,11 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
.map(|(_, p)| p.config.mipmap_input)
|
.map(|(_, p)| p.config.mipmap_input)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
self.output_framebuffers[index].scale::<T::FramebufferInterface>(
|
let next_size = self.output_framebuffers[index].scale::<T::FramebufferInterface>(
|
||||||
pass.config.scaling.clone(),
|
pass.config.scaling.clone(),
|
||||||
pass.get_format(),
|
pass.get_format(),
|
||||||
viewport,
|
viewport,
|
||||||
&original,
|
&source_size,
|
||||||
&source,
|
|
||||||
should_mipmap,
|
should_mipmap,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -460,10 +460,11 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
pass.config.scaling.clone(),
|
pass.config.scaling.clone(),
|
||||||
pass.get_format(),
|
pass.get_format(),
|
||||||
viewport,
|
viewport,
|
||||||
&original,
|
&source_size,
|
||||||
&source,
|
|
||||||
should_mipmap,
|
should_mipmap,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
source_size = next_size
|
||||||
}
|
}
|
||||||
|
|
||||||
let passes_len = passes.len();
|
let passes_len = passes.len();
|
||||||
|
|
|
@ -51,11 +51,10 @@ impl Framebuffer {
|
||||||
scaling: Scale2D,
|
scaling: Scale2D,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
viewport: &Viewport<&Framebuffer>,
|
viewport: &Viewport<&Framebuffer>,
|
||||||
original: &InputTexture,
|
source_size: &Size<u32>,
|
||||||
source: &InputTexture,
|
|
||||||
mipmap: bool,
|
mipmap: bool,
|
||||||
) -> Result<Size<u32>> {
|
) -> Result<Size<u32>> {
|
||||||
T::scale(self, scaling, format, viewport, original, source, mipmap)
|
T::scale(self, scaling, format, viewport, source_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<()> {
|
||||||
|
|
|
@ -39,17 +39,14 @@ impl FramebufferInterface for Gl3Framebuffer {
|
||||||
scaling: Scale2D,
|
scaling: Scale2D,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
viewport: &Viewport<&Framebuffer>,
|
viewport: &Viewport<&Framebuffer>,
|
||||||
_original: &InputTexture,
|
source_size: &Size<u32>,
|
||||||
source: &InputTexture,
|
|
||||||
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
|
let size = source_size
|
||||||
.image
|
|
||||||
.size
|
|
||||||
.scale_viewport(scaling, viewport.output.size);
|
.scale_viewport(scaling, viewport.output.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) {
|
||||||
|
|
|
@ -37,17 +37,14 @@ impl FramebufferInterface for Gl46Framebuffer {
|
||||||
scaling: Scale2D,
|
scaling: Scale2D,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
viewport: &Viewport<&Framebuffer>,
|
viewport: &Viewport<&Framebuffer>,
|
||||||
_original: &InputTexture,
|
source_size: &Size<u32>,
|
||||||
source: &InputTexture,
|
|
||||||
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
|
let size = source_size
|
||||||
.image
|
|
||||||
.size
|
|
||||||
.scale_viewport(scaling, viewport.output.size);
|
.scale_viewport(scaling, viewport.output.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) {
|
||||||
|
|
|
@ -42,8 +42,7 @@ pub trait FramebufferInterface {
|
||||||
scaling: Scale2D,
|
scaling: Scale2D,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
viewport: &Viewport<&Framebuffer>,
|
viewport: &Viewport<&Framebuffer>,
|
||||||
_original: &InputTexture,
|
source_size: &Size<u32>,
|
||||||
source: &InputTexture,
|
|
||||||
mipmap: bool,
|
mipmap: bool,
|
||||||
) -> Result<Size<u32>>;
|
) -> Result<Size<u32>>;
|
||||||
fn clear<const REBIND: bool>(fb: &Framebuffer);
|
fn clear<const REBIND: bool>(fb: &Framebuffer);
|
||||||
|
|
|
@ -640,6 +640,7 @@ impl FilterChainVulkan {
|
||||||
);
|
);
|
||||||
|
|
||||||
// rescale render buffers to ensure all bindings are valid.
|
// rescale render buffers to ensure all bindings are valid.
|
||||||
|
let mut source_size = source.image.size;
|
||||||
let mut iterator = passes.iter_mut().enumerate().peekable();
|
let mut iterator = passes.iter_mut().enumerate().peekable();
|
||||||
while let Some((index, pass)) = iterator.next() {
|
while let Some((index, pass)) = iterator.next() {
|
||||||
let should_mipmap = iterator
|
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
|
// since scaling is hopefully a rare occurrence (since it's tested for if the output size
|
||||||
// requires changing) it should be ok.
|
// requires changing) it should be ok.
|
||||||
self.output_framebuffers[index].scale(
|
let next_size = self.output_framebuffers[index].scale(
|
||||||
pass.config.scaling.clone(),
|
pass.config.scaling.clone(),
|
||||||
pass.get_format(),
|
pass.get_format(),
|
||||||
&viewport.output.size,
|
&viewport.output.size,
|
||||||
&original,
|
&source_size,
|
||||||
source,
|
|
||||||
should_mipmap,
|
should_mipmap,
|
||||||
Some(OwnedImageLayout {
|
Some(OwnedImageLayout {
|
||||||
dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
|
dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
|
||||||
|
@ -673,8 +673,7 @@ impl FilterChainVulkan {
|
||||||
pass.config.scaling.clone(),
|
pass.config.scaling.clone(),
|
||||||
pass.get_format(),
|
pass.get_format(),
|
||||||
&viewport.output.size,
|
&viewport.output.size,
|
||||||
&original,
|
&source_size,
|
||||||
source,
|
|
||||||
should_mipmap,
|
should_mipmap,
|
||||||
Some(OwnedImageLayout {
|
Some(OwnedImageLayout {
|
||||||
dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
|
dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
|
||||||
|
@ -685,6 +684,7 @@ impl FilterChainVulkan {
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
source_size = next_size;
|
||||||
// refresh inputs
|
// refresh inputs
|
||||||
self.common.feedback_inputs[index] = Some(
|
self.common.feedback_inputs[index] = Some(
|
||||||
self.feedback_framebuffers[index]
|
self.feedback_framebuffers[index]
|
||||||
|
|
|
@ -134,12 +134,11 @@ impl OwnedImage {
|
||||||
scaling: Scale2D,
|
scaling: Scale2D,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
viewport_size: &Size<u32>,
|
viewport_size: &Size<u32>,
|
||||||
_original: &InputImage,
|
source_size: &Size<u32>,
|
||||||
source: &InputImage,
|
|
||||||
mipmap: bool,
|
mipmap: bool,
|
||||||
layout: Option<OwnedImageLayout>,
|
layout: Option<OwnedImageLayout>,
|
||||||
) -> error::Result<Size<u32>> {
|
) -> error::Result<Size<u32>> {
|
||||||
let size = source.image.size.scale_viewport(scaling, *viewport_size);
|
let size = source_size.scale_viewport(scaling, *viewport_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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue