gl/d3d11: add option to force mipmap generation off

This commit is contained in:
chyyran 2023-01-11 18:25:31 -05:00
parent 4c7dd75d9f
commit 8047bf80c8
9 changed files with 22 additions and 4 deletions

View file

@ -71,6 +71,7 @@ pub(crate) struct FilterCommon {
pub feedback_textures: Box<[Option<Texture>]>, pub feedback_textures: Box<[Option<Texture>]>,
pub history_textures: Box<[Option<Texture>]>, pub history_textures: Box<[Option<Texture>]>,
pub config: FilterMutable, pub config: FilterMutable,
pub disable_mipmaps: bool,
} }
impl FilterChainD3D11 { impl FilterChainD3D11 {
@ -182,6 +183,7 @@ impl FilterChainD3D11 {
.map(|param| (param.name, param.value)) .map(|param| (param.name, param.value))
.collect(), .collect(),
}, },
disable_mipmaps: options.map_or(false, |o| o.force_no_mipmaps),
luts, luts,
samplers, samplers,
output_textures: output_textures.into_boxed_slice(), output_textures: output_textures.into_boxed_slice(),

View file

@ -362,7 +362,7 @@ impl FilterPass {
let _device = &parent.d3d11.device; let _device = &parent.d3d11.device;
let context = &parent.d3d11.current_context; let context = &parent.d3d11.current_context;
if self.config.mipmap_input { if self.config.mipmap_input && !parent.disable_mipmaps {
unsafe { unsafe {
context.GenerateMips(&source.view.handle); context.GenerateMips(&source.view.handle);
} }

View file

@ -23,13 +23,17 @@ pub use viewport::Viewport;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::options::FilterChainOptionsD3D11;
use super::*; use super::*;
#[test] #[test]
fn triangle_d3d11() { fn triangle_d3d11() {
let sample = hello_triangle::d3d11_hello_triangle::Sample::new( let sample = hello_triangle::d3d11_hello_triangle::Sample::new(
"../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp", "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp",
None, Some(&FilterChainOptionsD3D11 {
use_deferred_context: false,
force_no_mipmaps: false,
}),
) )
.unwrap(); .unwrap();
// let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new( // let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new(

View file

@ -17,4 +17,8 @@ pub struct FilterChainOptionsD3D11 {
/// The deferred context will be executed on the immediate context /// The deferred context will be executed on the immediate context
/// with `RenderContextState = true`. /// with `RenderContextState = true`.
pub use_deferred_context: bool, pub use_deferred_context: bool,
/// Whether or not to explicitly disable mipmap
/// generation regardless of shader preset settings.
pub force_no_mipmaps: bool,
} }

View file

@ -23,6 +23,8 @@ pub enum FilterChainError {
LutLoadError(#[from] ImageError), LutLoadError(#[from] ImageError),
#[error("opengl was not initialized")] #[error("opengl was not initialized")]
GLLoadError, GLLoadError,
#[error("opengl could not link program")]
GLLinkError,
} }
pub type Result<T> = std::result::Result<T, FilterChainError>; pub type Result<T> = std::result::Result<T, FilterChainError>;

View file

@ -42,6 +42,7 @@ pub(crate) struct FilterCommon {
pub output_textures: Box<[Texture]>, pub output_textures: Box<[Texture]>,
pub feedback_textures: Box<[Texture]>, pub feedback_textures: Box<[Texture]>,
pub history_textures: Box<[Texture]>, pub history_textures: Box<[Texture]>,
pub disable_mipmaps: bool,
} }
pub struct FilterMutable { pub struct FilterMutable {
@ -155,6 +156,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
.map(|param| (param.name, param.value)) .map(|param| (param.name, param.value))
.collect(), .collect(),
}, },
disable_mipmaps: options.map_or(false, |o| o.force_no_mipmaps),
luts, luts,
samplers, samplers,
output_textures: output_textures.into_boxed_slice(), output_textures: output_textures.into_boxed_slice(),
@ -259,7 +261,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
let mut status = 0; let mut status = 0;
gl::GetProgramiv(program, gl::LINK_STATUS, &mut status); gl::GetProgramiv(program, gl::LINK_STATUS, &mut status);
if status != 1 { if status != 1 {
panic!("failed to link program") return Err(FilterChainError::GLLinkError)
} }
gl::UseProgram(program); gl::UseProgram(program);

View file

@ -45,7 +45,7 @@ impl<T: GLInterface> FilterPass<T> {
) { ) {
let framebuffer = output.framebuffer; let framebuffer = output.framebuffer;
if self.config.mipmap_input { if self.config.mipmap_input && !parent.disable_mipmaps {
T::BindTexture::gen_mipmaps(source); T::BindTexture::gen_mipmaps(source);
} }

View file

@ -36,6 +36,7 @@ mod tests {
Some(&FilterChainOptionsGL { Some(&FilterChainOptionsGL {
gl_version: 0, gl_version: 0,
use_dsa: false, use_dsa: false,
force_no_mipmaps: false,
}), }),
) )
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) // 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 { Some(&FilterChainOptionsGL {
gl_version: 0, gl_version: 0,
use_dsa: true, use_dsa: true,
force_no_mipmaps: false,
}), }),
) )
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)

View file

@ -16,4 +16,6 @@ pub struct FilterChainOptionsGL {
pub gl_version: u16, pub gl_version: u16,
/// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+. /// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+.
pub use_dsa: bool, pub use_dsa: bool,
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
pub force_no_mipmaps: bool,
} }