diff --git a/librashader-capi/src/ctypes.rs b/librashader-capi/src/ctypes.rs index a87e8d0..96810d3 100644 --- a/librashader-capi/src/ctypes.rs +++ b/librashader-capi/src/ctypes.rs @@ -7,11 +7,11 @@ pub type libra_shader_preset_t = Option>; pub type libra_error_t = Option>; #[cfg(feature = "runtime-opengl")] -pub type libra_gl_filter_chain_t = Option>; +pub type libra_gl_filter_chain_t = Option>; #[cfg(feature = "runtime-d3d11")] pub type libra_d3d11_filter_chain_t = - Option>; + Option>; /// Parameters for the output viewport. #[repr(C)] diff --git a/librashader-capi/src/runtime/d3d11/filter_chain.rs b/librashader-capi/src/runtime/d3d11/filter_chain.rs index 647ae83..9fbdc25 100644 --- a/librashader-capi/src/runtime/d3d11/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d11/filter_chain.rs @@ -11,8 +11,8 @@ use windows::Win32::Graphics::Direct3D11::{ ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, }; -pub use librashader::runtime::d3d11::options::FilterChainOptionsD3D11; -pub use librashader::runtime::d3d11::options::FrameOptionsD3D11; +pub use librashader::runtime::d3d11::options::FilterChainOptions; +pub use librashader::runtime::d3d11::options::FrameOptions; use librashader::Size; /// OpenGL parameters for the source image. @@ -42,7 +42,7 @@ impl TryFrom for D3D11ImageView { pub type PFN_lbr_d3d11_filter_chain_create = unsafe extern "C" fn( preset: *mut libra_shader_preset_t, - options: *const FilterChainOptionsD3D11, + options: *const FilterChainOptions, device: *const ID3D11Device, out: *mut MaybeUninit, ) -> libra_error_t; @@ -58,7 +58,7 @@ pub type PFN_lbr_d3d11_filter_chain_create = unsafe extern "C" fn( #[no_mangle] pub unsafe extern "C" fn libra_d3d11_filter_chain_create( preset: *mut libra_shader_preset_t, - options: *const FilterChainOptionsD3D11, + options: *const FilterChainOptions, device: *const ID3D11Device, out: *mut MaybeUninit, ) -> libra_error_t { @@ -77,7 +77,7 @@ pub unsafe extern "C" fn libra_d3d11_filter_chain_create( Some(unsafe { &*options }) }; - let chain = librashader::runtime::d3d11::FilterChainD3D11::load_from_preset( + let chain = librashader::runtime::d3d11::FilterChain::load_from_preset( unsafe { &*device }, *preset, options, @@ -98,7 +98,7 @@ pub type PFN_lbr_d3d11_filter_chain_frame = unsafe extern "C" fn( viewport: libra_viewport_t, out: *const ID3D11RenderTargetView, mvp: *const f32, - opt: *const FrameOptionsD3D11, + opt: *const FrameOptions, ) -> libra_error_t; /// Draw a frame with the given parameters for the given filter chain. @@ -118,7 +118,7 @@ pub unsafe extern "C" fn libra_d3d11_filter_chain_frame( viewport: libra_viewport_t, out: *const ID3D11RenderTargetView, mvp: *const f32, - opt: *const FrameOptionsD3D11, + opt: *const FrameOptions, ) -> libra_error_t { ffi_body!(mut |chain| { assert_some_ptr!(mut chain); diff --git a/librashader-capi/src/runtime/gl/filter_chain.rs b/librashader-capi/src/runtime/gl/filter_chain.rs index b76f0bc..461058a 100644 --- a/librashader-capi/src/runtime/gl/filter_chain.rs +++ b/librashader-capi/src/runtime/gl/filter_chain.rs @@ -3,15 +3,14 @@ use crate::ctypes::{ }; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::ffi::ffi_body; -use librashader::runtime::gl::{GLImage, Viewport}; -use librashader::runtime::FilterChain; +use librashader::runtime::gl::{Framebuffer, GLImage, Viewport}; use std::ffi::{c_char, c_void, CString}; use std::mem::MaybeUninit; use std::ptr::NonNull; use std::slice; -pub use librashader::runtime::gl::options::FilterChainOptionsGL; -pub use librashader::runtime::gl::options::FrameOptionsGL; +pub use librashader::runtime::gl::options::FilterChainOptions; +pub use librashader::runtime::gl::options::FrameOptions; use librashader::Size; /// A GL function loader that librashader needs to be initialized with. @@ -37,7 +36,7 @@ pub unsafe extern "C" fn libra_gl_init_context(loader: gl_loader_t) -> libra_err pub type PFN_lbr_gl_filter_chain_create = unsafe extern "C" fn( preset: *mut libra_shader_preset_t, - options: *const FilterChainOptionsGL, + options: *const FilterChainOptions, out: *mut MaybeUninit, ) -> libra_error_t; /// Create the filter chain given the shader preset. @@ -52,7 +51,7 @@ pub type PFN_lbr_gl_filter_chain_create = unsafe extern "C" fn( #[no_mangle] pub unsafe extern "C" fn libra_gl_filter_chain_create( preset: *mut libra_shader_preset_t, - options: *const FilterChainOptionsGL, + options: *const FilterChainOptions, out: *mut MaybeUninit, ) -> libra_error_t { ffi_body!({ @@ -69,7 +68,7 @@ pub unsafe extern "C" fn libra_gl_filter_chain_create( Some(unsafe { &*options }) }; - let chain = librashader::runtime::gl::FilterChainGL::load_from_preset(*preset, options)?; + let chain = librashader::runtime::gl::FilterChain::load_from_preset(*preset, options)?; unsafe { out.write(MaybeUninit::new(NonNull::new(Box::into_raw(Box::new( @@ -121,7 +120,7 @@ pub type PFN_lbr_gl_filter_chain_frame = unsafe extern "C" fn( viewport: libra_viewport_t, out: libra_draw_framebuffer_gl_t, mvp: *const f32, - opt: *const FrameOptionsGL, + opt: *const FrameOptions, ) -> libra_error_t; /// Draw a frame with the given parameters for the given filter chain. @@ -141,7 +140,7 @@ pub unsafe extern "C" fn libra_gl_filter_chain_frame( viewport: libra_viewport_t, out: libra_draw_framebuffer_gl_t, mvp: *const f32, - opt: *const FrameOptionsGL, + opt: *const FrameOptions, ) -> libra_error_t { ffi_body!(mut |chain| { assert_some_ptr!(mut chain); @@ -159,10 +158,11 @@ pub unsafe extern "C" fn libra_gl_filter_chain_frame( Some(unsafe { opt.read() }) }; + let framebuffer = Framebuffer::new_from_raw(out.texture, out.handle, out.format, Size::new(viewport.width, viewport.height), 1); let viewport = Viewport { x: viewport.x, y: viewport.y, - output: &chain.create_framebuffer_raw(out.texture, out.handle, out.format, Size::new(viewport.width, viewport.height), 1), + output: &framebuffer, mvp, }; chain.frame(&image, &viewport, frame_count, opt.as_ref())?; diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index b325f6c..d7e60bf 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -19,7 +19,7 @@ use std::path::Path; use crate::error::FilterChainError; use crate::filter_pass::{ConstantBufferBinding, FilterPass}; use crate::framebuffer::OwnedFramebuffer; -use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11}; +use crate::options::{FilterChainOptions, FrameOptions}; use crate::quad_render::DrawQuad; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; @@ -47,7 +47,7 @@ type ShaderPassMeta = ( >, ); -pub struct FilterChainD3D11 { +pub struct FilterChain { pub(crate) common: FilterCommon, pub(crate) passes: Vec, pub(crate) output_framebuffers: Box<[OwnedFramebuffer]>, @@ -74,13 +74,13 @@ pub(crate) struct FilterCommon { pub disable_mipmaps: bool, } -impl FilterChainD3D11 { +impl FilterChain { /// Load the shader preset at the given path into a filter chain. pub fn load_from_path( device: &ID3D11Device, path: impl AsRef, - options: Option<&FilterChainOptionsD3D11>, - ) -> error::Result { + options: Option<&FilterChainOptions>, + ) -> error::Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; Self::load_from_preset(device, preset, options) @@ -90,16 +90,16 @@ impl FilterChainD3D11 { pub fn load_from_preset( device: &ID3D11Device, preset: ShaderPreset, - options: Option<&FilterChainOptionsD3D11>, - ) -> error::Result { - let (passes, semantics) = FilterChainD3D11::load_preset(preset.shaders, &preset.textures)?; + options: Option<&FilterChainOptions>, + ) -> error::Result { + let (passes, semantics) = FilterChain::load_preset(preset.shaders, &preset.textures)?; let use_deferred_context = options.map(|f| f.use_deferred_context).unwrap_or(false); let samplers = SamplerSet::new(device)?; // initialize passes - let filters = FilterChainD3D11::init_passes(device, passes, &semantics)?; + let filters = FilterChain::init_passes(device, passes, &semantics)?; let mut immediate_context = None; unsafe { @@ -154,15 +154,15 @@ impl FilterChainD3D11 { feedback_textures.resize_with(filters.len(), || None); // load luts - let luts = FilterChainD3D11::load_luts(device, ¤t_context, &preset.textures)?; + let luts = FilterChain::load_luts(device, ¤t_context, &preset.textures)?; let (history_framebuffers, history_textures) = - FilterChainD3D11::init_history(device, ¤t_context, &filters)?; + FilterChain::init_history(device, ¤t_context, &filters)?; let draw_quad = DrawQuad::new(device, ¤t_context)?; // todo: make vbo: d3d11.c 1376 - Ok(FilterChainD3D11 { + Ok(FilterChain { passes: filters, output_framebuffers: output_framebuffers.into_boxed_slice(), feedback_framebuffers: feedback_framebuffers.into_boxed_slice(), @@ -194,7 +194,7 @@ impl FilterChainD3D11 { } } -impl FilterChainD3D11 { +impl FilterChain { fn create_constant_buffer(device: &ID3D11Device, size: u32) -> error::Result { unsafe { let buffer = device.CreateBuffer( @@ -247,7 +247,7 @@ impl FilterChainD3D11 { )?; let ubo_cbuffer = if let Some(ubo) = &reflection.ubo && ubo.size != 0 { - let buffer = FilterChainD3D11::create_constant_buffer(device, ubo.size)?; + let buffer = FilterChain::create_constant_buffer(device, ubo.size)?; Some(ConstantBufferBinding { binding: ubo.binding, size: ubo.size, @@ -259,7 +259,7 @@ impl FilterChainD3D11 { }; let push_cbuffer = if let Some(push) = &reflection.push_constant && push.size != 0 { - let buffer = FilterChainD3D11::create_constant_buffer(device, push.size)?; + let buffer = FilterChain::create_constant_buffer(device, push.size)?; Some(ConstantBufferBinding { binding: if ubo_cbuffer.is_some() { 1 } else { 0 }, size: push.size, @@ -468,7 +468,7 @@ impl FilterChainD3D11 { input: D3D11ImageView, viewport: &Viewport, frame_count: usize, - options: Option<&FrameOptionsD3D11>, + options: Option<&FrameOptions>, ) -> error::Result<()> { let passes = &mut self.passes[0..self.common.config.passes_enabled]; if let Some(options) = options { @@ -612,20 +612,3 @@ impl FilterChainD3D11 { Ok(()) } } - -impl librashader_runtime::filter_chain::FilterChain for FilterChainD3D11 { - type Error = FilterChainError; - type Input<'a> = D3D11ImageView; - type Viewport<'a> = Viewport<'a>; - type FrameOptions = FrameOptionsD3D11; - - fn frame<'a>( - &mut self, - input: Self::Input<'a>, - viewport: &Self::Viewport<'a>, - frame_count: usize, - options: Option<&Self::FrameOptions>, - ) -> Result<(), Self::Error> { - self.frame(input, viewport, frame_count, options) - } -} diff --git a/librashader-runtime-d3d11/src/hello_triangle.rs b/librashader-runtime-d3d11/src/hello_triangle.rs index f79dccc..19f0356 100644 --- a/librashader-runtime-d3d11/src/hello_triangle.rs +++ b/librashader-runtime-d3d11/src/hello_triangle.rs @@ -225,9 +225,9 @@ pub mod d3d11_hello_triangle { use super::*; use std::path::Path; - use crate::filter_chain::FilterChainD3D11; + use crate::filter_chain::FilterChain; - use crate::options::FilterChainOptionsD3D11; + use crate::options::FilterChainOptions; use crate::texture::D3D11ImageView; use crate::viewport::Viewport; use librashader_common::Size; @@ -239,7 +239,7 @@ pub mod d3d11_hello_triangle { pub device: ID3D11Device, pub context: ID3D11DeviceContext, pub resources: Option, - pub filter: FilterChainD3D11, + pub filter: FilterChain, } pub struct Resources { @@ -266,10 +266,10 @@ pub mod d3d11_hello_triangle { impl Sample { pub(crate) fn new( filter: impl AsRef, - filter_options: Option<&FilterChainOptionsD3D11>, + filter_options: Option<&FilterChainOptions>, ) -> Result { let (dxgi_factory, device, context) = create_device()?; - let filter = FilterChainD3D11::load_from_path(&device, filter, filter_options).unwrap(); + let filter = FilterChain::load_from_path(&device, filter, filter_options).unwrap(); Ok(Sample { filter, dxgi_factory, diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index debf737..e71766a 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -17,21 +17,21 @@ mod texture; mod util; mod viewport; -pub use filter_chain::FilterChainD3D11; +pub use filter_chain::FilterChain; pub use texture::D3D11ImageView; pub use viewport::Viewport; #[cfg(test)] mod tests { use super::*; - use crate::options::FilterChainOptionsD3D11; + use crate::options::FilterChainOptions; #[test] fn triangle_d3d11() { let sample = hello_triangle::d3d11_hello_triangle::Sample::new( "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", // "../test/basic.slangp", - Some(&FilterChainOptionsD3D11 { + Some(&FilterChainOptions { use_deferred_context: false, force_no_mipmaps: false, }), diff --git a/librashader-runtime-d3d11/src/options.rs b/librashader-runtime-d3d11/src/options.rs index 5bdd5f1..27028a9 100644 --- a/librashader-runtime-d3d11/src/options.rs +++ b/librashader-runtime-d3d11/src/options.rs @@ -1,7 +1,7 @@ /// Options for each Direct3D11 shader frame. #[repr(C)] #[derive(Debug, Clone)] -pub struct FrameOptionsD3D11 { +pub struct FrameOptions { /// Whether or not to clear the history buffers. pub clear_history: bool, /// The direction of the frame. 1 should be vertical. @@ -11,7 +11,7 @@ pub struct FrameOptionsD3D11 { /// Options for Direct3D11 filter chain creation. #[repr(C)] #[derive(Debug, Clone)] -pub struct FilterChainOptionsD3D11 { +pub struct FilterChainOptions { /// Use a deferred context to record shader rendering state. /// /// The deferred context will be executed on the immediate context diff --git a/librashader-runtime-d3d11/src/parameters.rs b/librashader-runtime-d3d11/src/parameters.rs index f2e1b92..9211f6c 100644 --- a/librashader-runtime-d3d11/src/parameters.rs +++ b/librashader-runtime-d3d11/src/parameters.rs @@ -1,8 +1,8 @@ -use crate::FilterChainD3D11; +use crate::FilterChain; use librashader_runtime::parameters::FilterChainParameters; use std::collections::hash_map::Iter; -impl FilterChainParameters for FilterChainD3D11 { +impl FilterChainParameters for FilterChain { fn get_enabled_pass_count(&self) -> usize { self.common.config.passes_enabled } diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index 7e16792..2c632ee 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -2,7 +2,7 @@ use crate::binding::{GlUniformStorage, UniformLocation, VariableLocation}; use crate::error::FilterChainError; use crate::filter_pass::FilterPass; use crate::gl::{DrawQuad, Framebuffer, FramebufferInterface, GLInterface, LoadLut, UboRing}; -use crate::options::{FilterChainOptionsGL, FrameOptionsGL}; +use crate::options::{FilterChainOptions, FrameOptions}; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::texture::Texture; @@ -88,20 +88,10 @@ type ShaderPassMeta = ( ); impl FilterChainImpl { - pub(crate) fn create_framebuffer_raw( - &self, - texture: GLuint, - handle: GLuint, - format: GLenum, - size: Size, - miplevels: u32, - ) -> Framebuffer { - T::FramebufferInterface::new_from_raw(texture, handle, format, size, miplevels) - } /// Load a filter chain from a pre-parsed `ShaderPreset`. pub(crate) fn load_from_preset( preset: ShaderPreset, - options: Option<&FilterChainOptionsGL>, + options: Option<&FilterChainOptions>, ) -> error::Result { let (passes, semantics) = Self::load_preset(preset.shaders, &preset.textures)?; @@ -431,7 +421,7 @@ impl FilterChainImpl { count: usize, viewport: &Viewport, input: &GLImage, - options: Option<&FrameOptionsGL>, + options: Option<&FrameOptions>, ) -> error::Result<()> { // limit number of passes to those enabled. let passes = &mut self.passes[0..self.common.config.passes_enabled]; diff --git a/librashader-runtime-gl/src/filter_chain/mod.rs b/librashader-runtime-gl/src/filter_chain/mod.rs index 2eec666..92c0e83 100644 --- a/librashader-runtime-gl/src/filter_chain/mod.rs +++ b/librashader-runtime-gl/src/filter_chain/mod.rs @@ -5,7 +5,7 @@ use std::path::Path; use crate::error::{FilterChainError, Result}; use crate::filter_chain::filter_impl::FilterChainImpl; use crate::filter_chain::inner::FilterChainDispatch; -use crate::options::{FilterChainOptionsGL, FrameOptionsGL}; +use crate::options::{FilterChainOptions, FrameOptions}; use crate::{Framebuffer, GLImage, Viewport}; use librashader_presets::ShaderPreset; @@ -16,31 +16,14 @@ mod parameters; pub(crate) use filter_impl::FilterCommon; use librashader_common::Size; -pub struct FilterChainGL { +pub struct FilterChain { pub(in crate::filter_chain) filter: FilterChainDispatch, } -impl FilterChainGL { - pub fn create_framebuffer_raw( - &self, - texture: GLuint, - handle: GLuint, - format: GLenum, - size: Size, - miplevels: u32, - ) -> Framebuffer { - match &self.filter { - FilterChainDispatch::DirectStateAccess(p) => { - p.create_framebuffer_raw(texture, handle, format, size, miplevels) - } - FilterChainDispatch::Compatibility(p) => { - p.create_framebuffer_raw(texture, handle, format, size, miplevels) - } - } - } +impl FilterChain { pub fn load_from_preset( preset: ShaderPreset, - options: Option<&FilterChainOptionsGL>, + options: Option<&FilterChainOptions>, ) -> Result { let result = catch_unwind(|| { if let Some(options) = options && options.use_dsa { @@ -63,7 +46,7 @@ impl FilterChainGL { /// Load the shader preset at the given path into a filter chain. pub fn load_from_path( path: impl AsRef, - options: Option<&FilterChainOptionsGL>, + options: Option<&FilterChainOptions>, ) -> Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; @@ -72,13 +55,14 @@ impl FilterChainGL { /// Process a frame with the input image. /// - /// When this frame returns, GL_FRAMEBUFFER is bound to 0 if not using Direct State Access. - pub(crate) fn frame( + /// When this frame returns, `GL_FRAMEBUFFER` is bound to 0 if not using Direct State Access. + /// Otherwise, it is untouched. + pub fn frame( &mut self, input: &GLImage, viewport: &Viewport, frame_count: usize, - options: Option<&FrameOptionsGL>, + options: Option<&FrameOptions>, ) -> Result<()> { match &mut self.filter { FilterChainDispatch::DirectStateAccess(p) => { @@ -88,20 +72,3 @@ impl FilterChainGL { } } } - -impl librashader_runtime::filter_chain::FilterChain for FilterChainGL { - type Error = FilterChainError; - type Input<'a> = &'a GLImage; - type Viewport<'a> = Viewport<'a>; - type FrameOptions = FrameOptionsGL; - - fn frame<'a>( - &mut self, - input: Self::Input<'a>, - viewport: &Self::Viewport<'a>, - frame_count: usize, - options: Option<&Self::FrameOptions>, - ) -> std::result::Result<(), Self::Error> { - self.frame(input, viewport, frame_count, options) - } -} diff --git a/librashader-runtime-gl/src/filter_chain/parameters.rs b/librashader-runtime-gl/src/filter_chain/parameters.rs index 670aee6..4eba994 100644 --- a/librashader-runtime-gl/src/filter_chain/parameters.rs +++ b/librashader-runtime-gl/src/filter_chain/parameters.rs @@ -1,7 +1,7 @@ use crate::filter_chain::filter_impl::FilterChainImpl; use crate::filter_chain::inner::FilterChainDispatch; use crate::gl::GLInterface; -use crate::FilterChainGL; +use crate::FilterChain; use librashader_runtime::parameters::FilterChainParameters; use std::collections::hash_map::Iter; @@ -23,7 +23,7 @@ impl AsMut for FilterChainDispatch { } } -impl FilterChainParameters for FilterChainGL { +impl FilterChainParameters for FilterChain { fn get_enabled_pass_count(&self) -> usize { self.filter.as_ref().get_enabled_pass_count() } diff --git a/librashader-runtime-gl/src/gl/framebuffer.rs b/librashader-runtime-gl/src/gl/framebuffer.rs index f38a41e..649af47 100644 --- a/librashader-runtime-gl/src/gl/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/framebuffer.rs @@ -9,35 +9,44 @@ use librashader_presets::Scale2D; #[derive(Debug)] pub struct Framebuffer { - pub image: GLuint, - pub handle: GLuint, - pub size: Size, - pub format: GLenum, - pub max_levels: u32, - pub mip_levels: u32, - pub is_raw: bool, + pub(crate) image: GLuint, + pub(crate) handle: GLuint, + pub(crate) size: Size, + pub(crate) format: GLenum, + pub(crate) max_levels: u32, + pub(crate) mip_levels: u32, + pub(crate) is_raw: bool, } impl Framebuffer { - pub fn new(max_levels: u32) -> Self { + pub(crate) fn new(max_levels: u32) -> Self { T::new(max_levels) } - pub fn new_from_raw( + /// Create a framebuffer from an already initialized texture and framebuffer. + pub fn new_from_raw( texture: GLuint, - handle: GLuint, + fbo: GLuint, format: GLenum, size: Size, - mip_levels: u32, - ) -> Self { - T::new_from_raw(texture, handle, format, size, mip_levels) + miplevels: u32, + ) -> Framebuffer { + Framebuffer { + image: texture, + size, + format, + max_levels: miplevels, + mip_levels: miplevels, + handle: fbo, + is_raw: true, + } } - pub fn clear(&self) { + pub(crate) fn clear(&self) { T::clear::(self) } - pub fn scale( + pub(crate) fn scale( &mut self, scaling: Scale2D, format: ImageFormat, @@ -49,11 +58,11 @@ impl Framebuffer { T::scale(self, scaling, format, viewport, original, source, mipmap) } - pub fn copy_from(&mut self, image: &GLImage) -> Result<()> { + pub(crate) fn copy_from(&mut self, image: &GLImage) -> Result<()> { T::copy_from(self, image) } - pub fn as_texture(&self, filter: FilterMode, wrap_mode: WrapMode) -> Texture { + pub(crate) fn as_texture(&self, filter: FilterMode, wrap_mode: WrapMode) -> Texture { Texture { image: GLImage { handle: self.image, @@ -70,6 +79,10 @@ impl Framebuffer { impl Drop for Framebuffer { fn drop(&mut self) { + if self.is_raw { + return; + } + unsafe { if self.handle != 0 { gl::DeleteFramebuffers(1, &self.handle); diff --git a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs index 61d36d2..70e2f45 100644 --- a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs @@ -34,23 +34,6 @@ impl FramebufferInterface for Gl3Framebuffer { is_raw: false, } } - fn new_from_raw( - texture: GLuint, - handle: GLuint, - format: GLenum, - size: Size, - miplevels: u32, - ) -> Framebuffer { - Framebuffer { - image: texture, - size, - format, - max_levels: miplevels, - mip_levels: miplevels, - handle, - is_raw: true, - } - } fn scale( fb: &mut Framebuffer, diff --git a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs index 7df8ee2..51c494f 100644 --- a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs @@ -7,7 +7,7 @@ use glfw::{Context, Glfw, Window, WindowEvent}; use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint}; use librashader_common::Size; -use crate::filter_chain::FilterChainGL; +use crate::filter_chain::FilterChain; use crate::framebuffer::GLImage; use crate::gl::gl3::CompatibilityGL; use crate::gl::{FramebufferInterface, GLInterface}; @@ -268,7 +268,7 @@ pub fn do_loop( events: Receiver<(f64, WindowEvent)>, triangle_program: GLuint, triangle_vao: GLuint, - filter: &mut FilterChainGL, + filter: &mut FilterChain, ) { let mut framecount = 0; let mut rendered_framebuffer = 0; diff --git a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs index 95ee8a6..1d33369 100644 --- a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs @@ -32,24 +32,7 @@ impl FramebufferInterface for Gl46Framebuffer { is_raw: false, } } - fn new_from_raw( - texture: GLuint, - handle: GLuint, - format: GLenum, - size: Size, - miplevels: u32, - ) -> Framebuffer { - Framebuffer { - image: texture, - size, - format, - max_levels: miplevels, - mip_levels: miplevels, - handle, - is_raw: true, - } - } - + fn scale( fb: &mut Framebuffer, scaling: Scale2D, diff --git a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs index 7b89075..5fae0c1 100644 --- a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs @@ -7,7 +7,7 @@ use glfw::{Context, Glfw, Window, WindowEvent}; use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint}; use librashader_common::Size; -use crate::filter_chain::FilterChainGL; +use crate::filter_chain::FilterChain; use crate::framebuffer::GLImage; use crate::gl::gl46::DirectStateAccessGL; use crate::gl::{FramebufferInterface, GLInterface}; @@ -259,7 +259,7 @@ pub fn do_loop( events: Receiver<(f64, WindowEvent)>, triangle_program: GLuint, triangle_vao: GLuint, - filter: &mut FilterChainGL, + filter: &mut FilterChain, ) { let mut framecount = 0; let mut rendered_framebuffer = 0; diff --git a/librashader-runtime-gl/src/gl/mod.rs b/librashader-runtime-gl/src/gl/mod.rs index abe54c7..2f7264f 100644 --- a/librashader-runtime-gl/src/gl/mod.rs +++ b/librashader-runtime-gl/src/gl/mod.rs @@ -38,13 +38,6 @@ pub trait UboRing { pub trait FramebufferInterface { fn new(max_levels: u32) -> Framebuffer; - fn new_from_raw( - texture: GLuint, - handle: GLuint, - format: GLenum, - size: Size, - miplevels: u32, - ) -> Framebuffer; fn scale( fb: &mut Framebuffer, scaling: Scale2D, diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index ca49b20..d22e984 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -18,22 +18,22 @@ pub mod options; mod viewport; pub use crate::gl::Framebuffer; -pub use filter_chain::FilterChainGL; +pub use filter_chain::FilterChain; pub use framebuffer::GLImage; pub use viewport::Viewport; #[cfg(test)] mod tests { use super::*; - use crate::filter_chain::FilterChainGL; - use crate::options::FilterChainOptionsGL; + use crate::filter_chain::FilterChain; + use crate::options::FilterChainOptions; #[test] fn triangle_gl() { let (glfw, window, events, shader, vao) = gl::gl3::hello_triangle::setup(); - let mut filter = FilterChainGL::load_from_path( + let mut filter = FilterChain::load_from_path( "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", - Some(&FilterChainOptionsGL { + Some(&FilterChainOptions { gl_version: 0, use_dsa: false, force_no_mipmaps: false, @@ -47,10 +47,10 @@ mod tests { #[test] fn triangle_gl46() { let (glfw, window, events, shader, vao) = gl::gl46::hello_triangle::setup(); - let mut filter = FilterChainGL::load_from_path( + let mut filter = FilterChain::load_from_path( // "../test/slang-shaders/vhs/VHSPro.slangp", "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", - Some(&FilterChainOptionsGL { + Some(&FilterChainOptions { gl_version: 0, use_dsa: true, force_no_mipmaps: false, diff --git a/librashader-runtime-gl/src/options.rs b/librashader-runtime-gl/src/options.rs index 6542141..83a3b18 100644 --- a/librashader-runtime-gl/src/options.rs +++ b/librashader-runtime-gl/src/options.rs @@ -1,7 +1,7 @@ /// Options for each OpenGL shader frame. #[repr(C)] #[derive(Debug, Clone)] -pub struct FrameOptionsGL { +pub struct FrameOptions { /// Whether or not to clear the history buffers. pub clear_history: bool, /// The direction of the frame. 1 should be vertical. @@ -11,7 +11,7 @@ pub struct FrameOptionsGL { /// Options for filter chain creation. #[repr(C)] #[derive(Debug, Clone)] -pub struct FilterChainOptionsGL { +pub struct FilterChainOptions { /// The GLSL version. Should be at least `330`. pub gl_version: u16, /// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+. diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 3a88006..b744b98 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -27,7 +27,7 @@ use librashader_runtime::uniforms::UniformStorage; use rustc_hash::FxHashMap; use std::collections::VecDeque; use std::path::Path; -use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan}; +use crate::options::{FilterChainOptions, FrameOptions}; pub struct Vulkan { pub(crate) device: ash::Device, @@ -44,7 +44,7 @@ type ShaderPassMeta = ( /// A collection of handles needed to access the Vulkan instance. #[derive(Clone)] -pub struct VulkanInfo { +pub struct VulkanInstance { /// A `VkDevice` handle. pub device: vk::Device, /// A `VkInstance` handle. @@ -55,10 +55,10 @@ pub struct VulkanInfo { pub get_instance_proc_addr: vk::PFN_vkGetInstanceProcAddr, } -impl TryFrom for Vulkan { +impl TryFrom for Vulkan { type Error = FilterChainError; - fn try_from(vulkan: VulkanInfo) -> Result { + fn try_from(vulkan: VulkanInstance) -> Result { unsafe { let instance = ash::Instance::load( &vk::StaticFn { @@ -179,7 +179,7 @@ impl FilterChainVulkan { pub fn load_from_path( vulkan: impl TryInto, path: impl AsRef, - options: Option<&FilterChainOptionsVulkan>, + options: Option<&FilterChainOptions>, ) -> error::Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; @@ -189,7 +189,7 @@ impl FilterChainVulkan { pub fn load_from_preset( vulkan: impl TryInto, preset: ShaderPreset, - options: Option<&FilterChainOptionsVulkan>, + options: Option<&FilterChainOptions>, ) -> error::Result { let (passes, semantics) = FilterChainVulkan::load_preset(preset.shaders, &preset.textures)?; let device = vulkan.try_into()?; @@ -565,7 +565,7 @@ impl FilterChainVulkan { viewport: &Viewport, input: &VulkanImage, cmd: vk::CommandBuffer, - options: Option, + options: Option, ) -> error::Result { // limit number of passes to those enabled. let passes = &mut self.passes[0..self.common.config.passes_enabled]; diff --git a/librashader-runtime-vk/src/lib.rs b/librashader-runtime-vk/src/lib.rs index fd65d3f..b0f53d8 100644 --- a/librashader-runtime-vk/src/lib.rs +++ b/librashader-runtime-vk/src/lib.rs @@ -23,7 +23,7 @@ mod vulkan_state; pub use filter_chain::FrameIntermediates; pub use filter_chain::FilterChainVulkan; pub use filter_chain::Vulkan; -pub use filter_chain::VulkanInfo; +pub use filter_chain::VulkanInstance; pub use texture::VulkanImage; pub use viewport::Viewport; diff --git a/librashader-runtime-vk/src/options.rs b/librashader-runtime-vk/src/options.rs index aaec1fb..9c9113c 100644 --- a/librashader-runtime-vk/src/options.rs +++ b/librashader-runtime-vk/src/options.rs @@ -1,7 +1,7 @@ /// Options for each Vulkan shader frame. #[repr(C)] #[derive(Debug, Clone)] -pub struct FrameOptionsVulkan { +pub struct FrameOptions { /// Whether or not to clear the history buffers. pub clear_history: bool, /// The direction of the frame. 1 should be vertical. @@ -11,7 +11,7 @@ pub struct FrameOptionsVulkan { /// Options for filter chain creation. #[repr(C)] #[derive(Debug, Clone)] -pub struct FilterChainOptionsVulkan { +pub struct FilterChainOptions { /// Whether or not to explicitly disable mipmap generation regardless of shader preset settings. pub force_no_mipmaps: bool, } diff --git a/librashader-runtime/src/filter_chain.rs b/librashader-runtime/src/filter_chain.rs deleted file mode 100644 index 97cd35d..0000000 --- a/librashader-runtime/src/filter_chain.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::error::Error; - -/// Common trait for filter chains. -pub trait FilterChain { - /// The error type for a filter chain. - type Error: Error; - - /// The type for the input surface to apply a filter chain to. - type Input<'a>; - - /// The type for the output surface, including viewport information, to output the result of a - /// filter chain to. - type Viewport<'a>; - - /// The per-frame options to pass to the filter chain. - type FrameOptions; - - /// Process a frame with the input image. - /// - /// The output image should be written to the viewport. It is expected that the viewport - /// contains some sort of handle with interior mutability to a GPU buffer, e.g. a - /// `RenderTargetView`, `vkImage`, or a texture `GLuint`. - fn frame<'a>( - &mut self, - input: Self::Input<'a>, - viewport: &Self::Viewport<'a>, - frame_count: usize, - options: Option<&Self::FrameOptions>, - ) -> Result<(), Self::Error>; -} diff --git a/librashader-runtime/src/lib.rs b/librashader-runtime/src/lib.rs index 9497d8b..418f6ed 100644 --- a/librashader-runtime/src/lib.rs +++ b/librashader-runtime/src/lib.rs @@ -13,9 +13,6 @@ pub mod uniforms; /// Parameter reflection helpers and traits. pub mod parameters; -/// Filter chain helpers and traits. -pub mod filter_chain; - /// Image handling helpers. pub mod image; diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index 7580000..8ed41b7 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -7,7 +7,7 @@ //! //! ## Usage //! The core objects in librashader are the [`ShaderPreset`](crate::presets::ShaderPreset) and the -//! [`FilterChain`](crate::runtime::FilterChain), the implementation of which is runtime dependent. +//! filter chain implementations. //! //! The basic workflow involves parsing a `ShaderPreset`, which can then be used to construct //! a `FilterChain`. All shaders will then be compiled, after which `FilterChain::frame` can be @@ -91,7 +91,6 @@ pub mod reflect { /// Shader runtimes to execute a filter chain on a GPU surface. #[cfg(feature = "runtime")] pub mod runtime { - pub use librashader_runtime::filter_chain::FilterChain; pub use librashader_runtime::parameters::FilterChainParameters; #[cfg(feature = "gl")]