common: unify viewport types

This commit is contained in:
chyyran 2023-01-13 02:54:16 -05:00
parent abaebe56cc
commit e2ac7a1bfa
27 changed files with 122 additions and 132 deletions

View file

@ -3,7 +3,7 @@ use crate::ctypes::{
}; };
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::ffi_body; use crate::ffi::ffi_body;
use librashader::runtime::d3d11::{D3D11ImageView, Viewport}; use librashader::runtime::d3d11::{D3D11InputView, D3D11OutputView};
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::slice; use std::slice;
@ -13,6 +13,8 @@ use windows::Win32::Graphics::Direct3D11::{
pub use librashader::runtime::d3d11::options::FilterChainOptions; pub use librashader::runtime::d3d11::options::FilterChainOptions;
pub use librashader::runtime::d3d11::options::FrameOptions; pub use librashader::runtime::d3d11::options::FrameOptions;
use librashader::runtime::Viewport;
use librashader::Size; use librashader::Size;
/// OpenGL parameters for the source image. /// OpenGL parameters for the source image.
@ -26,14 +28,14 @@ pub struct libra_source_image_d3d11_t {
pub height: u32, pub height: u32,
} }
impl TryFrom<libra_source_image_d3d11_t> for D3D11ImageView { impl TryFrom<libra_source_image_d3d11_t> for D3D11InputView {
type Error = LibrashaderError; type Error = LibrashaderError;
fn try_from(value: libra_source_image_d3d11_t) -> Result<Self, Self::Error> { fn try_from(value: libra_source_image_d3d11_t) -> Result<Self, Self::Error> {
let handle = value.handle; let handle = value.handle;
assert_non_null!(noexport handle); assert_non_null!(noexport handle);
Ok(D3D11ImageView { Ok(D3D11InputView {
handle: unsafe { (&*handle).clone() }, handle: unsafe { (&*handle).clone() },
size: Size::new(value.width, value.height), size: Size::new(value.width, value.height),
}) })
@ -139,8 +141,10 @@ pub unsafe extern "C" fn libra_d3d11_filter_chain_frame(
let viewport = Viewport { let viewport = Viewport {
x: viewport.x, x: viewport.x,
y: viewport.y, y: viewport.y,
size: Size::new(viewport.width, viewport.height), output: D3D11OutputView {
output: unsafe { (&*out).clone() }, size: Size::new(viewport.width, viewport.height),
handle: unsafe { (&*out).clone() },
},
mvp, mvp,
}; };

View file

@ -3,7 +3,7 @@ use crate::ctypes::{
}; };
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::ffi_body; use crate::ffi::ffi_body;
use librashader::runtime::gl::{Framebuffer, GLImage, Viewport}; use librashader::runtime::gl::{Framebuffer, GLImage};
use std::ffi::{c_char, c_void, CString}; use std::ffi::{c_char, c_void, CString};
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::ptr::NonNull; use std::ptr::NonNull;
@ -11,6 +11,7 @@ use std::slice;
pub use librashader::runtime::gl::options::FilterChainOptions; pub use librashader::runtime::gl::options::FilterChainOptions;
pub use librashader::runtime::gl::options::FrameOptions; pub use librashader::runtime::gl::options::FrameOptions;
use librashader::runtime::Viewport;
use librashader::Size; use librashader::Size;
/// A GL function loader that librashader needs to be initialized with. /// A GL function loader that librashader needs to be initialized with.

View file

@ -14,6 +14,9 @@ pub mod dxgi;
#[cfg(feature = "d3d11")] #[cfg(feature = "d3d11")]
pub mod d3d11; pub mod d3d11;
mod viewport;
pub use viewport::Viewport;
use num_traits::AsPrimitive; use num_traits::AsPrimitive;
use std::convert::Infallible; use std::convert::Infallible;
use std::str::FromStr; use std::str::FromStr;

View file

@ -0,0 +1,12 @@
/// The rendering output of a filter chain.
pub struct Viewport<'a, T> {
/// The x offset to start rendering from.
pub x: f32,
/// The y offset to begin rendering from.
pub y: f32,
/// An optional pointer to an MVP to use when rendering
/// to the viewport.
pub mvp: Option<&'a [f32; 16]>,
/// The output handle to render the final image to.
pub output: T,
}

View file

@ -1,5 +1,5 @@
use crate::texture::{D3D11ImageView, LutTexture, Texture}; use crate::texture::{D3D11InputView, LutTexture, InputTexture};
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::cross::CrossHlslContext; use librashader_reflect::back::cross::CrossHlslContext;
@ -24,8 +24,7 @@ use crate::quad_render::DrawQuad;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::util::d3d11_compile_bound_shader; use crate::util::d3d11_compile_bound_shader;
use crate::viewport::Viewport; use crate::{D3D11OutputView, error, util};
use crate::{error, util};
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC,
@ -67,9 +66,9 @@ pub(crate) struct FilterCommon {
pub(crate) d3d11: Direct3D11, pub(crate) d3d11: Direct3D11,
pub(crate) luts: FxHashMap<usize, LutTexture>, pub(crate) luts: FxHashMap<usize, LutTexture>,
pub samplers: SamplerSet, pub samplers: SamplerSet,
pub output_textures: Box<[Option<Texture>]>, pub output_textures: Box<[Option<InputTexture>]>,
pub feedback_textures: Box<[Option<Texture>]>, pub feedback_textures: Box<[Option<InputTexture>]>,
pub history_textures: Box<[Option<Texture>]>, pub history_textures: Box<[Option<InputTexture>]>,
pub config: FilterMutable, pub config: FilterMutable,
pub disable_mipmaps: bool, pub disable_mipmaps: bool,
} }
@ -317,7 +316,7 @@ impl FilterChain {
device: &ID3D11Device, device: &ID3D11Device,
context: &ID3D11DeviceContext, context: &ID3D11DeviceContext,
filters: &Vec<FilterPass>, filters: &Vec<FilterPass>,
) -> error::Result<(VecDeque<OwnedFramebuffer>, Box<[Option<Texture>]>)> { ) -> error::Result<(VecDeque<OwnedFramebuffer>, Box<[Option<InputTexture>]>)> {
let mut required_images = 0; let mut required_images = 0;
for pass in filters { for pass in filters {
@ -365,7 +364,7 @@ impl FilterChain {
Ok((framebuffers, history_textures.into_boxed_slice())) Ok((framebuffers, history_textures.into_boxed_slice()))
} }
fn push_history(&mut self, input: &D3D11ImageView) -> error::Result<()> { fn push_history(&mut self, input: &D3D11InputView) -> error::Result<()> {
if let Some(mut back) = self.history_framebuffers.pop_back() { if let Some(mut back) = self.history_framebuffers.pop_back() {
back.copy_from(input)?; back.copy_from(input)?;
self.history_framebuffers.push_front(back) self.history_framebuffers.push_front(back)
@ -465,8 +464,8 @@ impl FilterChain {
/// Process a frame with the input image. /// Process a frame with the input image.
pub fn frame( pub fn frame(
&mut self, &mut self,
input: D3D11ImageView, input: D3D11InputView,
viewport: &Viewport, viewport: &Viewport<D3D11OutputView>,
frame_count: usize, frame_count: usize,
options: Option<&FrameOptions>, options: Option<&FrameOptions>,
) -> error::Result<()> { ) -> error::Result<()> {
@ -496,7 +495,7 @@ impl FilterChain {
.zip(self.feedback_framebuffers.iter()) .zip(self.feedback_framebuffers.iter())
.zip(passes.iter()) .zip(passes.iter())
{ {
*texture = Some(Texture::from_framebuffer( *texture = Some(InputTexture::from_framebuffer(
fbo, fbo,
pass.config.wrap_mode, pass.config.wrap_mode,
pass.config.filter, pass.config.filter,
@ -509,10 +508,10 @@ impl FilterChain {
.iter_mut() .iter_mut()
.zip(self.history_framebuffers.iter()) .zip(self.history_framebuffers.iter())
{ {
*texture = Some(Texture::from_framebuffer(fbo, wrap_mode, filter)?); *texture = Some(InputTexture::from_framebuffer(fbo, wrap_mode, filter)?);
} }
let original = Texture { let original = InputTexture {
view: input.clone(), view: input.clone(),
filter, filter,
wrap_mode, wrap_mode,
@ -525,7 +524,7 @@ impl FilterChain {
self.output_framebuffers[index].scale( self.output_framebuffers[index].scale(
pass.config.scaling.clone(), pass.config.scaling.clone(),
pass.get_format(), pass.get_format(),
&viewport.size, &viewport.output.size,
&original, &original,
&source, &source,
)?; )?;
@ -533,7 +532,7 @@ impl FilterChain {
self.feedback_framebuffers[index].scale( self.feedback_framebuffers[index].scale(
pass.config.scaling.clone(), pass.config.scaling.clone(),
pass.get_format(), pass.get_format(),
&viewport.size, &viewport.output.size,
&original, &original,
&source, &source,
)?; )?;
@ -561,8 +560,8 @@ impl FilterChain {
RenderTarget::new(target.as_output_framebuffer()?, None), RenderTarget::new(target.as_output_framebuffer()?, None),
)?; )?;
source = Texture { source = InputTexture {
view: D3D11ImageView { view: D3D11InputView {
handle: target.create_shader_resource_view()?, handle: target.create_shader_resource_view()?,
size, size,
}, },

View file

@ -1,6 +1,6 @@
use crate::filter_chain::FilterCommon; use crate::filter_chain::FilterCommon;
use crate::texture::Texture; use crate::texture::InputTexture;
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderPassConfig; use librashader_presets::ShaderPassConfig;
use librashader_reflect::back::cross::CrossHlslContext; use librashader_reflect::back::cross::CrossHlslContext;
@ -16,10 +16,9 @@ use windows::Win32::Graphics::Direct3D11::{
ID3D11ShaderResourceView, ID3D11VertexShader, D3D11_MAP_WRITE_DISCARD, ID3D11ShaderResourceView, ID3D11VertexShader, D3D11_MAP_WRITE_DISCARD,
}; };
use crate::error; use crate::{D3D11OutputView, error};
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::viewport::Viewport;
use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess}; use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess};
pub struct ConstantBufferBinding { pub struct ConstantBufferBinding {
@ -69,7 +68,7 @@ impl FilterPass {
texture_binding: &mut [Option<ID3D11ShaderResourceView>; 16], texture_binding: &mut [Option<ID3D11ShaderResourceView>; 16],
sampler_binding: &mut [Option<ID3D11SamplerState>; 16], sampler_binding: &mut [Option<ID3D11SamplerState>; 16],
binding: &TextureBinding, binding: &TextureBinding,
texture: &Texture, texture: &InputTexture,
) { ) {
texture_binding[binding.binding as usize] = Some(texture.view.handle.clone()); texture_binding[binding.binding as usize] = Some(texture.view.handle.clone());
sampler_binding[binding.binding as usize] = sampler_binding[binding.binding as usize] =
@ -86,8 +85,8 @@ impl FilterPass {
frame_direction: i32, frame_direction: i32,
fb_size: Size<u32>, fb_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
original: &Texture, original: &InputTexture,
source: &Texture, source: &InputTexture,
) -> ( ) -> (
[Option<ID3D11ShaderResourceView>; 16], [Option<ID3D11ShaderResourceView>; 16],
[Option<ID3D11SamplerState>; 16], [Option<ID3D11SamplerState>; 16],
@ -354,9 +353,9 @@ impl FilterPass {
parent: &FilterCommon, parent: &FilterCommon,
frame_count: u32, frame_count: u32,
frame_direction: i32, frame_direction: i32,
viewport: &Viewport, viewport: &Viewport<D3D11OutputView>,
original: &Texture, original: &InputTexture,
source: &Texture, source: &InputTexture,
output: RenderTarget, output: RenderTarget,
) -> error::Result<()> { ) -> error::Result<()> {
let _device = &parent.d3d11.device; let _device = &parent.d3d11.device;
@ -380,7 +379,7 @@ impl FilterPass {
frame_count, frame_count,
frame_direction, frame_direction,
output.output.size, output.output.size,
viewport.size, viewport.output.size,
original, original,
source, source,
); );

View file

@ -1,5 +1,5 @@
use crate::error; use crate::error;
use crate::texture::{D3D11ImageView, Texture}; 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;
@ -61,8 +61,8 @@ impl OwnedFramebuffer {
scaling: Scale2D, scaling: Scale2D,
format: ImageFormat, format: ImageFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
_original: &Texture, _original: &InputTexture,
source: &Texture, source: &InputTexture,
) -> error::Result<Size<u32>> { ) -> error::Result<Size<u32>> {
if self.is_raw { if self.is_raw {
return Ok(self.size); return Ok(self.size);
@ -152,7 +152,7 @@ impl OwnedFramebuffer {
}) })
} }
pub fn copy_from(&mut self, image: &D3D11ImageView) -> error::Result<()> { pub fn copy_from(&mut self, image: &D3D11InputView) -> error::Result<()> {
let original_resource: ID3D11Texture2D = unsafe { let original_resource: ID3D11Texture2D = unsafe {
let mut resource = None; let mut resource = None;
image.handle.GetResource(&mut resource); image.handle.GetResource(&mut resource);

View file

@ -228,11 +228,12 @@ pub mod d3d11_hello_triangle {
use crate::filter_chain::FilterChain; use crate::filter_chain::FilterChain;
use crate::options::FilterChainOptions; use crate::options::FilterChainOptions;
use crate::texture::D3D11ImageView; use crate::texture::D3D11InputView;
use crate::viewport::Viewport; use crate::viewport::Viewport;
use librashader_common::Size; use librashader_common::{Size, Viewport};
use std::slice; use std::slice;
use std::time::Instant; use std::time::Instant;
use crate::D3D11OutputView;
pub struct Sample { pub struct Sample {
pub dxgi_factory: IDXGIFactory4, pub dxgi_factory: IDXGIFactory4,
@ -492,7 +493,7 @@ pub mod d3d11_hello_triangle {
self.filter self.filter
.frame( .frame(
D3D11ImageView { D3D11InputView {
handle: srv, handle: srv,
size: Size { size: Size {
width: tex2d_desc.Width, width: tex2d_desc.Width,
@ -502,11 +503,13 @@ pub mod d3d11_hello_triangle {
&Viewport { &Viewport {
x: resources.viewport.TopLeftX, x: resources.viewport.TopLeftX,
y: resources.viewport.TopLeftY, y: resources.viewport.TopLeftY,
size: Size { output: D3D11OutputView {
width: tex2d_desc.Width, size: Size {
height: tex2d_desc.Height, width: tex2d_desc.Width,
height: tex2d_desc.Height,
},
handle: resources.rtv.clone(),
}, },
output: resources.rtv.clone(),
mvp: None, mvp: None,
}, },
resources.frame_count, resources.frame_count,

View file

@ -15,11 +15,10 @@ mod render_target;
mod samplers; mod samplers;
mod texture; mod texture;
mod util; mod util;
mod viewport;
pub use filter_chain::FilterChain; pub use filter_chain::FilterChain;
pub use texture::D3D11ImageView; pub use texture::D3D11InputView;
pub use viewport::Viewport; pub use texture::D3D11OutputView;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -1,6 +1,7 @@
use crate::framebuffer::OutputFramebuffer; use crate::framebuffer::OutputFramebuffer;
use crate::viewport::Viewport;
use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT; use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT;
use librashader_common::Viewport;
use crate::D3D11OutputView;
#[rustfmt::skip] #[rustfmt::skip]
static DEFAULT_MVP: &[f32; 16] = &[ static DEFAULT_MVP: &[f32; 16] = &[
@ -32,17 +33,17 @@ impl<'a> RenderTarget<'a> {
} }
} }
impl<'a> From<&Viewport<'a>> for RenderTarget<'a> { impl<'a> From<&Viewport<'a, D3D11OutputView>> for RenderTarget<'a> {
fn from(value: &Viewport<'a>) -> Self { fn from(value: &Viewport<'a, D3D11OutputView>) -> Self {
RenderTarget::new( RenderTarget::new(
OutputFramebuffer { OutputFramebuffer {
rtv: value.output.clone(), rtv: value.output.handle.clone(),
size: value.size, size: value.output.size,
viewport: D3D11_VIEWPORT { viewport: D3D11_VIEWPORT {
TopLeftX: value.x, TopLeftX: value.x,
TopLeftY: value.y, TopLeftY: value.y,
Width: value.size.width as f32, Width: value.output.size.width as f32,
Height: value.size.height as f32, Height: value.output.size.height as f32,
MinDepth: 0.0, MinDepth: 0.0,
MaxDepth: 1.0, MaxDepth: 1.0,
}, },

View file

@ -2,7 +2,7 @@ use librashader_common::{FilterMode, Size, WrapMode};
use librashader_runtime::image::Image; use librashader_runtime::image::Image;
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::{
ID3D11Device, ID3D11DeviceContext, ID3D11ShaderResourceView, ID3D11Texture2D, D3D11_BIND_FLAG, ID3D11Device, ID3D11DeviceContext, ID3D11ShaderResourceView, ID3D11RenderTargetView, ID3D11Texture2D, D3D11_BIND_FLAG,
D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_BOX, D3D11_CPU_ACCESS_FLAG, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_BOX, D3D11_CPU_ACCESS_FLAG,
D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS,
D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_SUBRESOURCE_DATA, D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_SUBRESOURCE_DATA,
@ -14,25 +14,32 @@ use crate::error::Result;
use crate::framebuffer::OwnedFramebuffer; use crate::framebuffer::OwnedFramebuffer;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct D3D11ImageView { pub struct D3D11InputView {
pub handle: ID3D11ShaderResourceView, pub handle: ID3D11ShaderResourceView,
pub size: Size<u32>, pub size: Size<u32>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct Texture { pub struct D3D11OutputView {
pub view: D3D11ImageView, pub handle: ID3D11RenderTargetView,
pub size: Size<u32>,
}
#[derive(Debug, Clone)]
pub(crate) struct InputTexture {
pub view: D3D11InputView,
pub filter: FilterMode, pub filter: FilterMode,
pub wrap_mode: WrapMode, pub wrap_mode: WrapMode,
} }
impl Texture { impl InputTexture {
pub fn from_framebuffer( pub fn from_framebuffer(
fbo: &OwnedFramebuffer, fbo: &OwnedFramebuffer,
wrap_mode: WrapMode, wrap_mode: WrapMode,
filter: FilterMode, filter: FilterMode,
) -> Result<Self> { ) -> Result<Self> {
Ok(Texture { Ok(InputTexture {
view: D3D11ImageView { view: D3D11InputView {
handle: fbo.create_shader_resource_view()?, handle: fbo.create_shader_resource_view()?,
size: fbo.size, size: fbo.size,
}, },
@ -49,7 +56,7 @@ pub(crate) struct LutTexture {
pub handle: ID3D11Texture2D, pub handle: ID3D11Texture2D,
#[allow(dead_code)] #[allow(dead_code)]
pub desc: D3D11_TEXTURE2D_DESC, pub desc: D3D11_TEXTURE2D_DESC,
pub image: Texture, pub image: InputTexture,
} }
impl LutTexture { impl LutTexture {
@ -166,8 +173,8 @@ impl LutTexture {
handle, handle,
// staging, // staging,
desc, desc,
image: Texture { image: InputTexture {
view: D3D11ImageView { view: D3D11InputView {
handle: srv, handle: srv,
size: source.size, size: source.size,
}, },

View file

@ -1,11 +0,0 @@
use librashader_common::Size;
use windows::Win32::Graphics::Direct3D11::ID3D11RenderTargetView;
#[derive(Debug, Clone)]
pub struct Viewport<'a> {
pub x: f32,
pub y: f32,
pub size: Size<u32>,
pub output: ID3D11RenderTargetView,
pub mvp: Option<&'a [f32; 16]>,
}

View file

@ -7,9 +7,9 @@ use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::Texture; use crate::texture::Texture;
use crate::util::{gl_get_version, gl_u16_to_version}; use crate::util::{gl_get_version, gl_u16_to_version};
use crate::{error, util, GLImage, Viewport}; use crate::{error, util, GLImage};
use gl::types::{GLenum, GLint, GLuint}; use gl::types::{GLenum, GLint, GLuint};
use librashader_common::{FilterMode, Size, WrapMode}; use librashader_common::{FilterMode, Size, Viewport, WrapMode};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::cross::{CrossGlslContext, GlslVersion}; use librashader_reflect::back::cross::{CrossGlslContext, GlslVersion};
@ -419,7 +419,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
pub fn frame( pub fn frame(
&mut self, &mut self,
count: usize, count: usize,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
input: &GLImage, input: &GLImage,
options: Option<&FrameOptions>, options: Option<&FrameOptions>,
) -> error::Result<()> { ) -> error::Result<()> {

View file

@ -6,7 +6,7 @@ use crate::error::{FilterChainError, Result};
use crate::filter_chain::filter_impl::FilterChainImpl; use crate::filter_chain::filter_impl::FilterChainImpl;
use crate::filter_chain::inner::FilterChainDispatch; use crate::filter_chain::inner::FilterChainDispatch;
use crate::options::{FilterChainOptions, FrameOptions}; use crate::options::{FilterChainOptions, FrameOptions};
use crate::{Framebuffer, GLImage, Viewport}; use crate::{Framebuffer, GLImage};
use librashader_presets::ShaderPreset; use librashader_presets::ShaderPreset;
mod filter_impl; mod filter_impl;
@ -14,7 +14,7 @@ mod inner;
mod parameters; mod parameters;
pub(crate) use filter_impl::FilterCommon; pub(crate) use filter_impl::FilterCommon;
use librashader_common::Size; use librashader_common::{Size, Viewport};
pub struct FilterChain { pub struct FilterChain {
pub(in crate::filter_chain) filter: FilterChainDispatch, pub(in crate::filter_chain) filter: FilterChainDispatch,
@ -60,7 +60,7 @@ impl FilterChain {
pub fn frame( pub fn frame(
&mut self, &mut self,
input: &GLImage, input: &GLImage,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
frame_count: usize, frame_count: usize,
options: Option<&FrameOptions>, options: Option<&FrameOptions>,
) -> Result<()> { ) -> Result<()> {

View file

@ -3,7 +3,7 @@ use librashader_reflect::back::cross::CrossGlslContext;
use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::back::ShaderCompilerOutput;
use librashader_reflect::reflect::ShaderReflection; use librashader_reflect::reflect::ShaderReflection;
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderPassConfig; use librashader_presets::ShaderPassConfig;
use librashader_reflect::reflect::semantics::{ use librashader_reflect::reflect::semantics::{
@ -13,9 +13,9 @@ use rustc_hash::FxHashMap;
use crate::binding::{GlUniformStorage, UniformLocation, VariableLocation}; use crate::binding::{GlUniformStorage, UniformLocation, VariableLocation};
use crate::filter_chain::FilterCommon; use crate::filter_chain::FilterCommon;
use crate::Framebuffer;
use crate::gl::{BindTexture, GLInterface, UboRing}; use crate::gl::{BindTexture, GLInterface, UboRing};
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::viewport::Viewport;
use crate::texture::Texture; use crate::texture::Texture;
@ -38,7 +38,7 @@ impl<T: GLInterface> FilterPass<T> {
parent: &FilterCommon, parent: &FilterCommon,
frame_count: u32, frame_count: u32,
frame_direction: i32, frame_direction: i32,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
original: &Texture, original: &Texture,
source: &Texture, source: &Texture,
output: RenderTarget, output: RenderTarget,
@ -123,7 +123,7 @@ impl<T: GLInterface> FilterPass<T> {
frame_count: u32, frame_count: u32,
frame_direction: i32, frame_direction: i32,
fb_size: Size<u32>, fb_size: Size<u32>,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
original: &Texture, original: &Texture,
source: &Texture, source: &Texture,
) { ) {

View file

@ -2,9 +2,8 @@ use crate::error::Result;
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use crate::texture::Texture; use crate::texture::Texture;
use crate::viewport::Viewport;
use gl::types::{GLenum, GLuint}; use gl::types::{GLenum, GLuint};
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
#[derive(Debug)] #[derive(Debug)]
@ -50,7 +49,7 @@ impl Framebuffer {
&mut self, &mut self,
scaling: Scale2D, scaling: Scale2D,
format: ImageFormat, format: ImageFormat,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
original: &Texture, original: &Texture,
source: &Texture, source: &Texture,
mipmap: bool, mipmap: bool,

View file

@ -3,9 +3,8 @@ use crate::framebuffer::GLImage;
use crate::gl::framebuffer::Framebuffer; use crate::gl::framebuffer::Framebuffer;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use crate::texture::Texture; use crate::texture::Texture;
use crate::viewport::Viewport;
use gl::types::{GLenum, GLint, GLsizei, GLuint}; use gl::types::{GLenum, GLint, GLsizei, GLuint};
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ViewportSize};
@ -39,7 +38,7 @@ impl FramebufferInterface for Gl3Framebuffer {
fb: &mut Framebuffer, fb: &mut Framebuffer,
scaling: Scale2D, scaling: Scale2D,
format: ImageFormat, format: ImageFormat,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
_original: &Texture, _original: &Texture,
source: &Texture, source: &Texture,
mipmap: bool, mipmap: bool,

View file

@ -3,9 +3,8 @@ use crate::framebuffer::GLImage;
use crate::gl::framebuffer::Framebuffer; use crate::gl::framebuffer::Framebuffer;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use crate::texture::Texture; use crate::texture::Texture;
use crate::viewport::Viewport;
use gl::types::{GLenum, GLint, GLsizei, GLuint}; use gl::types::{GLenum, GLint, GLsizei, GLuint};
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ViewportSize};
@ -37,7 +36,7 @@ impl FramebufferInterface for Gl46Framebuffer {
fb: &mut Framebuffer, fb: &mut Framebuffer,
scaling: Scale2D, scaling: Scale2D,
format: ImageFormat, format: ImageFormat,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
_original: &Texture, _original: &Texture,
source: &Texture, source: &Texture,
mipmap: bool, mipmap: bool,

View file

@ -7,10 +7,9 @@ use crate::error::Result;
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::Texture; use crate::texture::Texture;
use crate::viewport::Viewport;
pub use framebuffer::Framebuffer; pub use framebuffer::Framebuffer;
use gl::types::{GLenum, GLuint}; use gl::types::{GLenum, GLuint};
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::{Scale2D, TextureConfig}; use librashader_presets::{Scale2D, TextureConfig};
use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection}; use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection};
use librashader_runtime::uniforms::UniformStorageAccess; use librashader_runtime::uniforms::UniformStorageAccess;
@ -42,7 +41,7 @@ pub trait FramebufferInterface {
fb: &mut Framebuffer, fb: &mut Framebuffer,
scaling: Scale2D, scaling: Scale2D,
format: ImageFormat, format: ImageFormat,
viewport: &Viewport, viewport: &Viewport<&Framebuffer>,
_original: &Texture, _original: &Texture,
source: &Texture, source: &Texture,
mipmap: bool, mipmap: bool,

View file

@ -15,12 +15,10 @@ mod texture;
pub mod error; pub mod error;
pub mod options; pub mod options;
mod viewport;
pub use crate::gl::Framebuffer; pub use crate::gl::Framebuffer;
pub use filter_chain::FilterChain; pub use filter_chain::FilterChain;
pub use framebuffer::GLImage; pub use framebuffer::GLImage;
pub use viewport::Viewport;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -1,5 +1,5 @@
use librashader_common::Viewport;
use crate::gl::Framebuffer; use crate::gl::Framebuffer;
use crate::viewport::Viewport;
#[rustfmt::skip] #[rustfmt::skip]
static DEFAULT_MVP: &[f32; 16] = &[ static DEFAULT_MVP: &[f32; 16] = &[
@ -37,8 +37,8 @@ impl<'a> RenderTarget<'a> {
} }
} }
impl<'a> From<&Viewport<'a>> for RenderTarget<'a> { impl<'a> From<&Viewport<'a, &'a Framebuffer>> for RenderTarget<'a> {
fn from(value: &Viewport<'a>) -> Self { fn from(value: &Viewport<'a, &'a Framebuffer>) -> Self {
RenderTarget::new(value.output, value.mvp, value.x as i32, value.y as i32) RenderTarget::new(value.output, value.mvp, value.x as i32, value.y as i32)
} }
} }

View file

@ -1,9 +0,0 @@
use crate::gl::Framebuffer;
#[derive(Debug, Copy, Clone)]
pub struct Viewport<'a> {
pub x: f32,
pub y: f32,
pub output: &'a Framebuffer,
pub mvp: Option<&'a [f32; 16]>,
}

View file

@ -8,11 +8,10 @@ use crate::render_target::{RenderTarget, DEFAULT_MVP};
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::{InputImage, OwnedImage, VulkanImage}; use crate::texture::{InputImage, OwnedImage, VulkanImage};
use crate::ubo_ring::VkUboRing; use crate::ubo_ring::VkUboRing;
use crate::viewport::Viewport;
use crate::vulkan_state::VulkanGraphicsPipeline; use crate::vulkan_state::VulkanGraphicsPipeline;
use crate::{error, util}; use crate::{error, util};
use ash::vk; use ash::vk;
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::SpirV; use librashader_reflect::back::targets::SpirV;
@ -562,7 +561,7 @@ impl FilterChainVulkan {
pub fn frame( pub fn frame(
&mut self, &mut self,
count: usize, count: usize,
viewport: &Viewport, viewport: &Viewport<VulkanImage>,
input: &VulkanImage, input: &VulkanImage,
cmd: vk::CommandBuffer, cmd: vk::CommandBuffer,
options: Option<FrameOptions>, options: Option<FrameOptions>,

View file

@ -1,13 +1,12 @@
use crate::error; use crate::{error, VulkanImage};
use crate::filter_chain::FilterCommon; use crate::filter_chain::FilterCommon;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::InputImage; use crate::texture::InputImage;
use crate::ubo_ring::VkUboRing; use crate::ubo_ring::VkUboRing;
use crate::viewport::Viewport;
use crate::vulkan_state::VulkanGraphicsPipeline; use crate::vulkan_state::VulkanGraphicsPipeline;
use ash::vk; use ash::vk;
use librashader_common::{ImageFormat, Size}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderPassConfig; use librashader_presets::ShaderPassConfig;
use librashader_reflect::reflect::semantics::{ use librashader_reflect::reflect::semantics::{
@ -76,7 +75,7 @@ impl FilterPass {
parent: &FilterCommon, parent: &FilterCommon,
frame_count: u32, frame_count: u32,
frame_direction: i32, frame_direction: i32,
viewport: &Viewport, viewport: &Viewport<VulkanImage>,
original: &InputImage, original: &InputImage,
source: &InputImage, source: &InputImage,
output: &RenderTarget, output: &RenderTarget,

View file

@ -16,7 +16,6 @@ mod samplers;
mod texture; mod texture;
mod ubo_ring; mod ubo_ring;
mod util; mod util;
mod viewport;
mod vulkan_primitives; mod vulkan_primitives;
mod vulkan_state; mod vulkan_state;
@ -25,7 +24,6 @@ pub use filter_chain::FilterChainVulkan;
pub use filter_chain::Vulkan; pub use filter_chain::Vulkan;
pub use filter_chain::VulkanInstance; pub use filter_chain::VulkanInstance;
pub use texture::VulkanImage; pub use texture::VulkanImage;
pub use viewport::Viewport;
pub mod error; pub mod error;
pub mod options; pub mod options;

View file

@ -1,9 +0,0 @@
use crate::texture::VulkanImage;
#[derive(Clone)]
pub struct Viewport<'a> {
pub x: f32,
pub y: f32,
pub output: VulkanImage,
pub mvp: Option<&'a [f32; 16]>,
}

View file

@ -92,6 +92,7 @@ pub mod reflect {
#[cfg(feature = "runtime")] #[cfg(feature = "runtime")]
pub mod runtime { pub mod runtime {
pub use librashader_runtime::parameters::FilterChainParameters; pub use librashader_runtime::parameters::FilterChainParameters;
pub use librashader_common::Viewport;
#[cfg(feature = "gl")] #[cfg(feature = "gl")]
/// Shader runtime for OpenGL 3.3+. /// Shader runtime for OpenGL 3.3+.