From 8047bf80c8566516d2eb719c3f2eb954912b8591 Mon Sep 17 00:00:00 2001 From: chyyran Date: Wed, 11 Jan 2023 18:25:31 -0500 Subject: [PATCH] gl/d3d11: add option to force mipmap generation off --- librashader-runtime-d3d11/src/filter_chain.rs | 2 ++ librashader-runtime-d3d11/src/filter_pass.rs | 2 +- librashader-runtime-d3d11/src/lib.rs | 6 +++++- librashader-runtime-d3d11/src/options.rs | 4 ++++ librashader-runtime-gl/src/error.rs | 2 ++ librashader-runtime-gl/src/filter_chain/filter_impl.rs | 4 +++- librashader-runtime-gl/src/filter_pass.rs | 2 +- librashader-runtime-gl/src/lib.rs | 2 ++ librashader-runtime-gl/src/options.rs | 2 ++ 9 files changed, 22 insertions(+), 4 deletions(-) diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 4979943..8732322 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -71,6 +71,7 @@ pub(crate) struct FilterCommon { pub feedback_textures: Box<[Option]>, pub history_textures: Box<[Option]>, pub config: FilterMutable, + pub disable_mipmaps: bool, } impl FilterChainD3D11 { @@ -182,6 +183,7 @@ impl FilterChainD3D11 { .map(|param| (param.name, param.value)) .collect(), }, + disable_mipmaps: options.map_or(false, |o| o.force_no_mipmaps), luts, samplers, output_textures: output_textures.into_boxed_slice(), diff --git a/librashader-runtime-d3d11/src/filter_pass.rs b/librashader-runtime-d3d11/src/filter_pass.rs index e67edd9..55fd661 100644 --- a/librashader-runtime-d3d11/src/filter_pass.rs +++ b/librashader-runtime-d3d11/src/filter_pass.rs @@ -362,7 +362,7 @@ impl FilterPass { let _device = &parent.d3d11.device; let context = &parent.d3d11.current_context; - if self.config.mipmap_input { + if self.config.mipmap_input && !parent.disable_mipmaps { unsafe { context.GenerateMips(&source.view.handle); } diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index 2685a3d..0a8e669 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -23,13 +23,17 @@ pub use viewport::Viewport; #[cfg(test)] mod tests { + use crate::options::FilterChainOptionsD3D11; use super::*; #[test] fn triangle_d3d11() { let sample = hello_triangle::d3d11_hello_triangle::Sample::new( "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp", - None, + Some(&FilterChainOptionsD3D11 { + use_deferred_context: false, + force_no_mipmaps: false, + }), ) .unwrap(); // let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new( diff --git a/librashader-runtime-d3d11/src/options.rs b/librashader-runtime-d3d11/src/options.rs index 83b0cff..5bdd5f1 100644 --- a/librashader-runtime-d3d11/src/options.rs +++ b/librashader-runtime-d3d11/src/options.rs @@ -17,4 +17,8 @@ pub struct FilterChainOptionsD3D11 { /// The deferred context will be executed on the immediate context /// with `RenderContextState = true`. pub use_deferred_context: bool, + + /// Whether or not to explicitly disable mipmap + /// generation regardless of shader preset settings. + pub force_no_mipmaps: bool, } diff --git a/librashader-runtime-gl/src/error.rs b/librashader-runtime-gl/src/error.rs index 2ff7a44..b181656 100644 --- a/librashader-runtime-gl/src/error.rs +++ b/librashader-runtime-gl/src/error.rs @@ -23,6 +23,8 @@ pub enum FilterChainError { LutLoadError(#[from] ImageError), #[error("opengl was not initialized")] GLLoadError, + #[error("opengl could not link program")] + GLLinkError, } pub type Result = std::result::Result; diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index c5a478a..ff9b8e8 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -42,6 +42,7 @@ pub(crate) struct FilterCommon { pub output_textures: Box<[Texture]>, pub feedback_textures: Box<[Texture]>, pub history_textures: Box<[Texture]>, + pub disable_mipmaps: bool, } pub struct FilterMutable { @@ -155,6 +156,7 @@ impl FilterChainImpl { .map(|param| (param.name, param.value)) .collect(), }, + disable_mipmaps: options.map_or(false, |o| o.force_no_mipmaps), luts, samplers, output_textures: output_textures.into_boxed_slice(), @@ -259,7 +261,7 @@ impl FilterChainImpl { let mut status = 0; gl::GetProgramiv(program, gl::LINK_STATUS, &mut status); if status != 1 { - panic!("failed to link program") + return Err(FilterChainError::GLLinkError) } gl::UseProgram(program); diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index b309d04..3bc7b2e 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -45,7 +45,7 @@ impl FilterPass { ) { let framebuffer = output.framebuffer; - if self.config.mipmap_input { + if self.config.mipmap_input && !parent.disable_mipmaps { T::BindTexture::gen_mipmaps(source); } diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index acb2471..1a5443b 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -36,6 +36,7 @@ mod tests { Some(&FilterChainOptionsGL { gl_version: 0, use_dsa: false, + force_no_mipmaps: false, }), ) // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) @@ -52,6 +53,7 @@ mod tests { Some(&FilterChainOptionsGL { gl_version: 0, use_dsa: true, + force_no_mipmaps: false, }), ) // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) diff --git a/librashader-runtime-gl/src/options.rs b/librashader-runtime-gl/src/options.rs index 0f60f1c..6542141 100644 --- a/librashader-runtime-gl/src/options.rs +++ b/librashader-runtime-gl/src/options.rs @@ -16,4 +16,6 @@ pub struct FilterChainOptionsGL { pub gl_version: u16, /// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+. pub use_dsa: bool, + /// Whether or not to explicitly disable mipmap generation regardless of shader preset settings. + pub force_no_mipmaps: bool, }