From e2ac7a1bfa210fc2db5458b4c70dba0082a98be3 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 13 Jan 2023 02:54:16 -0500 Subject: [PATCH] common: unify viewport types --- .../src/runtime/d3d11/filter_chain.rs | 14 +++++--- .../src/runtime/gl/filter_chain.rs | 3 +- librashader-common/src/lib.rs | 3 ++ librashader-common/src/viewport.rs | 12 +++++++ librashader-runtime-d3d11/src/filter_chain.rs | 35 +++++++++---------- librashader-runtime-d3d11/src/filter_pass.rs | 21 ++++++----- librashader-runtime-d3d11/src/framebuffer.rs | 8 ++--- .../src/hello_triangle.rs | 17 +++++---- librashader-runtime-d3d11/src/lib.rs | 5 ++- .../src/render_target.rs | 15 ++++---- librashader-runtime-d3d11/src/texture.rs | 27 ++++++++------ librashader-runtime-d3d11/src/viewport.rs | 11 ------ .../src/filter_chain/filter_impl.rs | 6 ++-- .../src/filter_chain/mod.rs | 6 ++-- librashader-runtime-gl/src/filter_pass.rs | 8 ++--- librashader-runtime-gl/src/gl/framebuffer.rs | 5 ++- .../src/gl/gl3/framebuffer.rs | 5 ++- .../src/gl/gl46/framebuffer.rs | 7 ++-- librashader-runtime-gl/src/gl/mod.rs | 5 ++- librashader-runtime-gl/src/lib.rs | 2 -- librashader-runtime-gl/src/render_target.rs | 6 ++-- librashader-runtime-gl/src/viewport.rs | 9 ----- librashader-runtime-vk/src/filter_chain.rs | 5 ++- librashader-runtime-vk/src/filter_pass.rs | 7 ++-- librashader-runtime-vk/src/lib.rs | 2 -- librashader-runtime-vk/src/viewport.rs | 9 ----- librashader/src/lib.rs | 1 + 27 files changed, 122 insertions(+), 132 deletions(-) create mode 100644 librashader-common/src/viewport.rs delete mode 100644 librashader-runtime-d3d11/src/viewport.rs delete mode 100644 librashader-runtime-vk/src/viewport.rs diff --git a/librashader-capi/src/runtime/d3d11/filter_chain.rs b/librashader-capi/src/runtime/d3d11/filter_chain.rs index 9fbdc25..7dd2ecc 100644 --- a/librashader-capi/src/runtime/d3d11/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d11/filter_chain.rs @@ -3,7 +3,7 @@ use crate::ctypes::{ }; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::ffi::ffi_body; -use librashader::runtime::d3d11::{D3D11ImageView, Viewport}; +use librashader::runtime::d3d11::{D3D11InputView, D3D11OutputView}; use std::mem::MaybeUninit; use std::ptr::NonNull; 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::FrameOptions; + +use librashader::runtime::Viewport; use librashader::Size; /// OpenGL parameters for the source image. @@ -26,14 +28,14 @@ pub struct libra_source_image_d3d11_t { pub height: u32, } -impl TryFrom for D3D11ImageView { +impl TryFrom for D3D11InputView { type Error = LibrashaderError; fn try_from(value: libra_source_image_d3d11_t) -> Result { let handle = value.handle; assert_non_null!(noexport handle); - Ok(D3D11ImageView { + Ok(D3D11InputView { handle: unsafe { (&*handle).clone() }, size: Size::new(value.width, value.height), }) @@ -139,8 +141,10 @@ pub unsafe extern "C" fn libra_d3d11_filter_chain_frame( let viewport = Viewport { x: viewport.x, y: viewport.y, - size: Size::new(viewport.width, viewport.height), - output: unsafe { (&*out).clone() }, + output: D3D11OutputView { + size: Size::new(viewport.width, viewport.height), + handle: unsafe { (&*out).clone() }, + }, mvp, }; diff --git a/librashader-capi/src/runtime/gl/filter_chain.rs b/librashader-capi/src/runtime/gl/filter_chain.rs index 461058a..9f13522 100644 --- a/librashader-capi/src/runtime/gl/filter_chain.rs +++ b/librashader-capi/src/runtime/gl/filter_chain.rs @@ -3,7 +3,7 @@ use crate::ctypes::{ }; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; 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::mem::MaybeUninit; use std::ptr::NonNull; @@ -11,6 +11,7 @@ use std::slice; pub use librashader::runtime::gl::options::FilterChainOptions; pub use librashader::runtime::gl::options::FrameOptions; +use librashader::runtime::Viewport; use librashader::Size; /// A GL function loader that librashader needs to be initialized with. diff --git a/librashader-common/src/lib.rs b/librashader-common/src/lib.rs index 4a36304..9e209c7 100644 --- a/librashader-common/src/lib.rs +++ b/librashader-common/src/lib.rs @@ -14,6 +14,9 @@ pub mod dxgi; #[cfg(feature = "d3d11")] pub mod d3d11; +mod viewport; +pub use viewport::Viewport; + use num_traits::AsPrimitive; use std::convert::Infallible; use std::str::FromStr; diff --git a/librashader-common/src/viewport.rs b/librashader-common/src/viewport.rs new file mode 100644 index 0000000..f3768ae --- /dev/null +++ b/librashader-common/src/viewport.rs @@ -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, +} \ No newline at end of file diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index d7e60bf..40e0bcc 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -1,5 +1,5 @@ -use crate::texture::{D3D11ImageView, LutTexture, Texture}; -use librashader_common::{ImageFormat, Size}; +use crate::texture::{D3D11InputView, LutTexture, InputTexture}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_reflect::back::cross::CrossHlslContext; @@ -24,8 +24,7 @@ use crate::quad_render::DrawQuad; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::util::d3d11_compile_bound_shader; -use crate::viewport::Viewport; -use crate::{error, util}; +use crate::{D3D11OutputView, error, util}; use librashader_runtime::uniforms::UniformStorage; use windows::Win32::Graphics::Direct3D11::{ ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, @@ -67,9 +66,9 @@ pub(crate) struct FilterCommon { pub(crate) d3d11: Direct3D11, pub(crate) luts: FxHashMap, pub samplers: SamplerSet, - pub output_textures: Box<[Option]>, - pub feedback_textures: Box<[Option]>, - pub history_textures: Box<[Option]>, + pub output_textures: Box<[Option]>, + pub feedback_textures: Box<[Option]>, + pub history_textures: Box<[Option]>, pub config: FilterMutable, pub disable_mipmaps: bool, } @@ -317,7 +316,7 @@ impl FilterChain { device: &ID3D11Device, context: &ID3D11DeviceContext, filters: &Vec, - ) -> error::Result<(VecDeque, Box<[Option]>)> { + ) -> error::Result<(VecDeque, Box<[Option]>)> { let mut required_images = 0; for pass in filters { @@ -365,7 +364,7 @@ impl FilterChain { 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() { back.copy_from(input)?; self.history_framebuffers.push_front(back) @@ -465,8 +464,8 @@ impl FilterChain { /// Process a frame with the input image. pub fn frame( &mut self, - input: D3D11ImageView, - viewport: &Viewport, + input: D3D11InputView, + viewport: &Viewport, frame_count: usize, options: Option<&FrameOptions>, ) -> error::Result<()> { @@ -496,7 +495,7 @@ impl FilterChain { .zip(self.feedback_framebuffers.iter()) .zip(passes.iter()) { - *texture = Some(Texture::from_framebuffer( + *texture = Some(InputTexture::from_framebuffer( fbo, pass.config.wrap_mode, pass.config.filter, @@ -509,10 +508,10 @@ impl FilterChain { .iter_mut() .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(), filter, wrap_mode, @@ -525,7 +524,7 @@ impl FilterChain { self.output_framebuffers[index].scale( pass.config.scaling.clone(), pass.get_format(), - &viewport.size, + &viewport.output.size, &original, &source, )?; @@ -533,7 +532,7 @@ impl FilterChain { self.feedback_framebuffers[index].scale( pass.config.scaling.clone(), pass.get_format(), - &viewport.size, + &viewport.output.size, &original, &source, )?; @@ -561,8 +560,8 @@ impl FilterChain { RenderTarget::new(target.as_output_framebuffer()?, None), )?; - source = Texture { - view: D3D11ImageView { + source = InputTexture { + view: D3D11InputView { handle: target.create_shader_resource_view()?, size, }, diff --git a/librashader-runtime-d3d11/src/filter_pass.rs b/librashader-runtime-d3d11/src/filter_pass.rs index 55fd661..4f9cffb 100644 --- a/librashader-runtime-d3d11/src/filter_pass.rs +++ b/librashader-runtime-d3d11/src/filter_pass.rs @@ -1,6 +1,6 @@ use crate::filter_chain::FilterCommon; -use crate::texture::Texture; -use librashader_common::{ImageFormat, Size}; +use crate::texture::InputTexture; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::back::cross::CrossHlslContext; @@ -16,10 +16,9 @@ use windows::Win32::Graphics::Direct3D11::{ ID3D11ShaderResourceView, ID3D11VertexShader, D3D11_MAP_WRITE_DISCARD, }; -use crate::error; +use crate::{D3D11OutputView, error}; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; -use crate::viewport::Viewport; use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess}; pub struct ConstantBufferBinding { @@ -69,7 +68,7 @@ impl FilterPass { texture_binding: &mut [Option; 16], sampler_binding: &mut [Option; 16], binding: &TextureBinding, - texture: &Texture, + texture: &InputTexture, ) { texture_binding[binding.binding as usize] = Some(texture.view.handle.clone()); sampler_binding[binding.binding as usize] = @@ -86,8 +85,8 @@ impl FilterPass { frame_direction: i32, fb_size: Size, viewport_size: Size, - original: &Texture, - source: &Texture, + original: &InputTexture, + source: &InputTexture, ) -> ( [Option; 16], [Option; 16], @@ -354,9 +353,9 @@ impl FilterPass { parent: &FilterCommon, frame_count: u32, frame_direction: i32, - viewport: &Viewport, - original: &Texture, - source: &Texture, + viewport: &Viewport, + original: &InputTexture, + source: &InputTexture, output: RenderTarget, ) -> error::Result<()> { let _device = &parent.d3d11.device; @@ -380,7 +379,7 @@ impl FilterPass { frame_count, frame_direction, output.output.size, - viewport.size, + viewport.output.size, original, source, ); diff --git a/librashader-runtime-d3d11/src/framebuffer.rs b/librashader-runtime-d3d11/src/framebuffer.rs index 2f5aa3e..a756e0e 100644 --- a/librashader-runtime-d3d11/src/framebuffer.rs +++ b/librashader-runtime-d3d11/src/framebuffer.rs @@ -1,5 +1,5 @@ use crate::error; -use crate::texture::{D3D11ImageView, Texture}; +use crate::texture::{D3D11InputView, InputTexture}; use crate::util::d3d11_get_closest_format; use librashader_common::{ImageFormat, Size}; use librashader_presets::Scale2D; @@ -61,8 +61,8 @@ impl OwnedFramebuffer { scaling: Scale2D, format: ImageFormat, viewport_size: &Size, - _original: &Texture, - source: &Texture, + _original: &InputTexture, + source: &InputTexture, ) -> error::Result> { if self.is_raw { 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 mut resource = None; image.handle.GetResource(&mut resource); diff --git a/librashader-runtime-d3d11/src/hello_triangle.rs b/librashader-runtime-d3d11/src/hello_triangle.rs index 19f0356..7f76b2c 100644 --- a/librashader-runtime-d3d11/src/hello_triangle.rs +++ b/librashader-runtime-d3d11/src/hello_triangle.rs @@ -228,11 +228,12 @@ pub mod d3d11_hello_triangle { use crate::filter_chain::FilterChain; use crate::options::FilterChainOptions; - use crate::texture::D3D11ImageView; + use crate::texture::D3D11InputView; use crate::viewport::Viewport; - use librashader_common::Size; + use librashader_common::{Size, Viewport}; use std::slice; use std::time::Instant; + use crate::D3D11OutputView; pub struct Sample { pub dxgi_factory: IDXGIFactory4, @@ -492,7 +493,7 @@ pub mod d3d11_hello_triangle { self.filter .frame( - D3D11ImageView { + D3D11InputView { handle: srv, size: Size { width: tex2d_desc.Width, @@ -502,11 +503,13 @@ pub mod d3d11_hello_triangle { &Viewport { x: resources.viewport.TopLeftX, y: resources.viewport.TopLeftY, - size: Size { - width: tex2d_desc.Width, - height: tex2d_desc.Height, + output: D3D11OutputView { + size: Size { + width: tex2d_desc.Width, + height: tex2d_desc.Height, + }, + handle: resources.rtv.clone(), }, - output: resources.rtv.clone(), mvp: None, }, resources.frame_count, diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index e71766a..86add14 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -15,11 +15,10 @@ mod render_target; mod samplers; mod texture; mod util; -mod viewport; pub use filter_chain::FilterChain; -pub use texture::D3D11ImageView; -pub use viewport::Viewport; +pub use texture::D3D11InputView; +pub use texture::D3D11OutputView; #[cfg(test)] mod tests { diff --git a/librashader-runtime-d3d11/src/render_target.rs b/librashader-runtime-d3d11/src/render_target.rs index 8a7d943..2f249ee 100644 --- a/librashader-runtime-d3d11/src/render_target.rs +++ b/librashader-runtime-d3d11/src/render_target.rs @@ -1,6 +1,7 @@ use crate::framebuffer::OutputFramebuffer; -use crate::viewport::Viewport; use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT; +use librashader_common::Viewport; +use crate::D3D11OutputView; #[rustfmt::skip] static DEFAULT_MVP: &[f32; 16] = &[ @@ -32,17 +33,17 @@ impl<'a> RenderTarget<'a> { } } -impl<'a> From<&Viewport<'a>> for RenderTarget<'a> { - fn from(value: &Viewport<'a>) -> Self { +impl<'a> From<&Viewport<'a, D3D11OutputView>> for RenderTarget<'a> { + fn from(value: &Viewport<'a, D3D11OutputView>) -> Self { RenderTarget::new( OutputFramebuffer { - rtv: value.output.clone(), - size: value.size, + rtv: value.output.handle.clone(), + size: value.output.size, viewport: D3D11_VIEWPORT { TopLeftX: value.x, TopLeftY: value.y, - Width: value.size.width as f32, - Height: value.size.height as f32, + Width: value.output.size.width as f32, + Height: value.output.size.height as f32, MinDepth: 0.0, MaxDepth: 1.0, }, diff --git a/librashader-runtime-d3d11/src/texture.rs b/librashader-runtime-d3d11/src/texture.rs index 8d4ac5d..e1c3625 100644 --- a/librashader-runtime-d3d11/src/texture.rs +++ b/librashader-runtime-d3d11/src/texture.rs @@ -2,7 +2,7 @@ use librashader_common::{FilterMode, Size, WrapMode}; use librashader_runtime::image::Image; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; 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_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, @@ -14,25 +14,32 @@ use crate::error::Result; use crate::framebuffer::OwnedFramebuffer; #[derive(Debug, Clone)] -pub struct D3D11ImageView { +pub struct D3D11InputView { pub handle: ID3D11ShaderResourceView, pub size: Size, } + #[derive(Debug, Clone)] -pub(crate) struct Texture { - pub view: D3D11ImageView, +pub struct D3D11OutputView { + pub handle: ID3D11RenderTargetView, + pub size: Size, +} + +#[derive(Debug, Clone)] +pub(crate) struct InputTexture { + pub view: D3D11InputView, pub filter: FilterMode, pub wrap_mode: WrapMode, } -impl Texture { +impl InputTexture { pub fn from_framebuffer( fbo: &OwnedFramebuffer, wrap_mode: WrapMode, filter: FilterMode, ) -> Result { - Ok(Texture { - view: D3D11ImageView { + Ok(InputTexture { + view: D3D11InputView { handle: fbo.create_shader_resource_view()?, size: fbo.size, }, @@ -49,7 +56,7 @@ pub(crate) struct LutTexture { pub handle: ID3D11Texture2D, #[allow(dead_code)] pub desc: D3D11_TEXTURE2D_DESC, - pub image: Texture, + pub image: InputTexture, } impl LutTexture { @@ -166,8 +173,8 @@ impl LutTexture { handle, // staging, desc, - image: Texture { - view: D3D11ImageView { + image: InputTexture { + view: D3D11InputView { handle: srv, size: source.size, }, diff --git a/librashader-runtime-d3d11/src/viewport.rs b/librashader-runtime-d3d11/src/viewport.rs deleted file mode 100644 index aa34f21..0000000 --- a/librashader-runtime-d3d11/src/viewport.rs +++ /dev/null @@ -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, - pub output: ID3D11RenderTargetView, - pub mvp: Option<&'a [f32; 16]>, -} diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index 2c632ee..06fcd0b 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -7,9 +7,9 @@ use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::texture::Texture; 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 librashader_common::{FilterMode, Size, WrapMode}; +use librashader_common::{FilterMode, Size, Viewport, WrapMode}; use librashader_preprocess::ShaderSource; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_reflect::back::cross::{CrossGlslContext, GlslVersion}; @@ -419,7 +419,7 @@ impl FilterChainImpl { pub fn frame( &mut self, count: usize, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, input: &GLImage, options: Option<&FrameOptions>, ) -> error::Result<()> { diff --git a/librashader-runtime-gl/src/filter_chain/mod.rs b/librashader-runtime-gl/src/filter_chain/mod.rs index 92c0e83..f96c930 100644 --- a/librashader-runtime-gl/src/filter_chain/mod.rs +++ b/librashader-runtime-gl/src/filter_chain/mod.rs @@ -6,7 +6,7 @@ use crate::error::{FilterChainError, Result}; use crate::filter_chain::filter_impl::FilterChainImpl; use crate::filter_chain::inner::FilterChainDispatch; use crate::options::{FilterChainOptions, FrameOptions}; -use crate::{Framebuffer, GLImage, Viewport}; +use crate::{Framebuffer, GLImage}; use librashader_presets::ShaderPreset; mod filter_impl; @@ -14,7 +14,7 @@ mod inner; mod parameters; pub(crate) use filter_impl::FilterCommon; -use librashader_common::Size; +use librashader_common::{Size, Viewport}; pub struct FilterChain { pub(in crate::filter_chain) filter: FilterChainDispatch, @@ -60,7 +60,7 @@ impl FilterChain { pub fn frame( &mut self, input: &GLImage, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, frame_count: usize, options: Option<&FrameOptions>, ) -> Result<()> { diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index 3bc7b2e..1a345e2 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -3,7 +3,7 @@ use librashader_reflect::back::cross::CrossGlslContext; use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::reflect::ShaderReflection; -use librashader_common::{ImageFormat, Size}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{ @@ -13,9 +13,9 @@ use rustc_hash::FxHashMap; use crate::binding::{GlUniformStorage, UniformLocation, VariableLocation}; use crate::filter_chain::FilterCommon; +use crate::Framebuffer; use crate::gl::{BindTexture, GLInterface, UboRing}; use crate::render_target::RenderTarget; -use crate::viewport::Viewport; use crate::texture::Texture; @@ -38,7 +38,7 @@ impl FilterPass { parent: &FilterCommon, frame_count: u32, frame_direction: i32, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, original: &Texture, source: &Texture, output: RenderTarget, @@ -123,7 +123,7 @@ impl FilterPass { frame_count: u32, frame_direction: i32, fb_size: Size, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, original: &Texture, source: &Texture, ) { diff --git a/librashader-runtime-gl/src/gl/framebuffer.rs b/librashader-runtime-gl/src/gl/framebuffer.rs index 649af47..3f0759e 100644 --- a/librashader-runtime-gl/src/gl/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/framebuffer.rs @@ -2,9 +2,8 @@ use crate::error::Result; use crate::framebuffer::GLImage; use crate::gl::FramebufferInterface; use crate::texture::Texture; -use crate::viewport::Viewport; use gl::types::{GLenum, GLuint}; -use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; +use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; use librashader_presets::Scale2D; #[derive(Debug)] @@ -50,7 +49,7 @@ impl Framebuffer { &mut self, scaling: Scale2D, format: ImageFormat, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, original: &Texture, source: &Texture, mipmap: bool, diff --git a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs index 70e2f45..7206753 100644 --- a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs @@ -3,9 +3,8 @@ use crate::framebuffer::GLImage; use crate::gl::framebuffer::Framebuffer; use crate::gl::FramebufferInterface; use crate::texture::Texture; -use crate::viewport::Viewport; use gl::types::{GLenum, GLint, GLsizei, GLuint}; -use librashader_common::{ImageFormat, Size}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::Scale2D; use librashader_runtime::scaling::{MipmapSize, ViewportSize}; @@ -39,7 +38,7 @@ impl FramebufferInterface for Gl3Framebuffer { fb: &mut Framebuffer, scaling: Scale2D, format: ImageFormat, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, _original: &Texture, source: &Texture, mipmap: bool, diff --git a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs index 1d33369..4e995d5 100644 --- a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs @@ -3,9 +3,8 @@ use crate::framebuffer::GLImage; use crate::gl::framebuffer::Framebuffer; use crate::gl::FramebufferInterface; use crate::texture::Texture; -use crate::viewport::Viewport; use gl::types::{GLenum, GLint, GLsizei, GLuint}; -use librashader_common::{ImageFormat, Size}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::Scale2D; use librashader_runtime::scaling::{MipmapSize, ViewportSize}; @@ -32,12 +31,12 @@ impl FramebufferInterface for Gl46Framebuffer { is_raw: false, } } - + fn scale( fb: &mut Framebuffer, scaling: Scale2D, format: ImageFormat, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, _original: &Texture, source: &Texture, mipmap: bool, diff --git a/librashader-runtime-gl/src/gl/mod.rs b/librashader-runtime-gl/src/gl/mod.rs index 2f7264f..01fe411 100644 --- a/librashader-runtime-gl/src/gl/mod.rs +++ b/librashader-runtime-gl/src/gl/mod.rs @@ -7,10 +7,9 @@ use crate::error::Result; use crate::framebuffer::GLImage; use crate::samplers::SamplerSet; use crate::texture::Texture; -use crate::viewport::Viewport; pub use framebuffer::Framebuffer; use gl::types::{GLenum, GLuint}; -use librashader_common::{ImageFormat, Size}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::{Scale2D, TextureConfig}; use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection}; use librashader_runtime::uniforms::UniformStorageAccess; @@ -42,7 +41,7 @@ pub trait FramebufferInterface { fb: &mut Framebuffer, scaling: Scale2D, format: ImageFormat, - viewport: &Viewport, + viewport: &Viewport<&Framebuffer>, _original: &Texture, source: &Texture, mipmap: bool, diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index d22e984..ecc9452 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -15,12 +15,10 @@ mod texture; pub mod error; pub mod options; -mod viewport; pub use crate::gl::Framebuffer; pub use filter_chain::FilterChain; pub use framebuffer::GLImage; -pub use viewport::Viewport; #[cfg(test)] mod tests { diff --git a/librashader-runtime-gl/src/render_target.rs b/librashader-runtime-gl/src/render_target.rs index 727b812..ce42b8c 100644 --- a/librashader-runtime-gl/src/render_target.rs +++ b/librashader-runtime-gl/src/render_target.rs @@ -1,5 +1,5 @@ +use librashader_common::Viewport; use crate::gl::Framebuffer; -use crate::viewport::Viewport; #[rustfmt::skip] static DEFAULT_MVP: &[f32; 16] = &[ @@ -37,8 +37,8 @@ impl<'a> RenderTarget<'a> { } } -impl<'a> From<&Viewport<'a>> for RenderTarget<'a> { - fn from(value: &Viewport<'a>) -> Self { +impl<'a> From<&Viewport<'a, &'a Framebuffer>> for RenderTarget<'a> { + fn from(value: &Viewport<'a, &'a Framebuffer>) -> Self { RenderTarget::new(value.output, value.mvp, value.x as i32, value.y as i32) } } diff --git a/librashader-runtime-gl/src/viewport.rs b/librashader-runtime-gl/src/viewport.rs index 3d5c9ca..e69de29 100644 --- a/librashader-runtime-gl/src/viewport.rs +++ b/librashader-runtime-gl/src/viewport.rs @@ -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]>, -} diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index b744b98..3ac60d0 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -8,11 +8,10 @@ use crate::render_target::{RenderTarget, DEFAULT_MVP}; use crate::samplers::SamplerSet; use crate::texture::{InputImage, OwnedImage, VulkanImage}; use crate::ubo_ring::VkUboRing; -use crate::viewport::Viewport; use crate::vulkan_state::VulkanGraphicsPipeline; use crate::{error, util}; use ash::vk; -use librashader_common::{ImageFormat, Size}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_reflect::back::targets::SpirV; @@ -562,7 +561,7 @@ impl FilterChainVulkan { pub fn frame( &mut self, count: usize, - viewport: &Viewport, + viewport: &Viewport, input: &VulkanImage, cmd: vk::CommandBuffer, options: Option, diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index eb088bd..30b77c7 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -1,13 +1,12 @@ -use crate::error; +use crate::{error, VulkanImage}; use crate::filter_chain::FilterCommon; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::texture::InputImage; use crate::ubo_ring::VkUboRing; -use crate::viewport::Viewport; use crate::vulkan_state::VulkanGraphicsPipeline; use ash::vk; -use librashader_common::{ImageFormat, Size}; +use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{ @@ -76,7 +75,7 @@ impl FilterPass { parent: &FilterCommon, frame_count: u32, frame_direction: i32, - viewport: &Viewport, + viewport: &Viewport, original: &InputImage, source: &InputImage, output: &RenderTarget, diff --git a/librashader-runtime-vk/src/lib.rs b/librashader-runtime-vk/src/lib.rs index b0f53d8..598bb64 100644 --- a/librashader-runtime-vk/src/lib.rs +++ b/librashader-runtime-vk/src/lib.rs @@ -16,7 +16,6 @@ mod samplers; mod texture; mod ubo_ring; mod util; -mod viewport; mod vulkan_primitives; mod vulkan_state; @@ -25,7 +24,6 @@ pub use filter_chain::FilterChainVulkan; pub use filter_chain::Vulkan; pub use filter_chain::VulkanInstance; pub use texture::VulkanImage; -pub use viewport::Viewport; pub mod error; pub mod options; diff --git a/librashader-runtime-vk/src/viewport.rs b/librashader-runtime-vk/src/viewport.rs deleted file mode 100644 index a2d0cc9..0000000 --- a/librashader-runtime-vk/src/viewport.rs +++ /dev/null @@ -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]>, -} diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index 8ed41b7..6ab5eb4 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -92,6 +92,7 @@ pub mod reflect { #[cfg(feature = "runtime")] pub mod runtime { pub use librashader_runtime::parameters::FilterChainParameters; + pub use librashader_common::Viewport; #[cfg(feature = "gl")] /// Shader runtime for OpenGL 3.3+.