diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index c0df367..1b3054c 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -23,6 +23,7 @@ use crate::samplers::SamplerSet; use crate::util::d3d11_compile_bound_shader; use crate::{error, util, D3D11OutputView}; use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact}; +use librashader_runtime::binding::TextureInput; use librashader_runtime::uniforms::UniformStorage; use windows::Win32::Graphics::Direct3D11::{ ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, @@ -30,7 +31,6 @@ use windows::Win32::Graphics::Direct3D11::{ D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_USAGE_DYNAMIC, }; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM; -use librashader_runtime::binding::TextureInput; pub struct FilterMutable { pub(crate) passes_enabled: usize, @@ -121,7 +121,7 @@ impl FilterChainD3D11 { ¤t_context, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, - false + false, ) }); @@ -141,7 +141,7 @@ impl FilterChainD3D11 { ¤t_context, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, - false + false, ) }); // resolve all results @@ -353,7 +353,13 @@ impl FilterChainD3D11 { // eprintln!("[history] using frame history with {required_images} images"); let mut framebuffers = VecDeque::with_capacity(required_images); framebuffers.resize_with(required_images, || { - OwnedFramebuffer::new(device, context, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, false) + OwnedFramebuffer::new( + device, + context, + Size::new(1, 1), + ImageFormat::R8G8B8A8Unorm, + false, + ) }); let framebuffers = framebuffers @@ -481,7 +487,7 @@ impl FilterChainD3D11 { pass.get_format(), &viewport.output.size, &source_size, - should_mipmap + should_mipmap, )?; self.feedback_framebuffers[index].scale( @@ -489,7 +495,7 @@ impl FilterChainD3D11 { pass.get_format(), &viewport.output.size, &source_size, - should_mipmap + should_mipmap, )?; source_size = next_size; diff --git a/librashader-runtime-d3d11/src/framebuffer.rs b/librashader-runtime-d3d11/src/framebuffer.rs index 01a9a50..e31542e 100644 --- a/librashader-runtime-d3d11/src/framebuffer.rs +++ b/librashader-runtime-d3d11/src/framebuffer.rs @@ -1,6 +1,6 @@ use crate::error; use crate::error::assume_d3d11_init; -use crate::texture::{D3D11InputView, InputTexture}; +use crate::texture::{D3D11InputView}; use crate::util::d3d11_get_closest_format; use librashader_common::{ImageFormat, Size}; use librashader_presets::Scale2D; @@ -57,7 +57,11 @@ impl OwnedFramebuffer { device: device.clone(), context: context.clone(), is_raw: false, - max_mipmap: if mipmap { size.calculate_miplevels() } else { 1 }, + max_mipmap: if mipmap { + size.calculate_miplevels() + } else { + 1 + }, }) } } diff --git a/librashader-runtime-d3d11/src/hello_triangle.rs b/librashader-runtime-d3d11/src/hello_triangle.rs index b60b241..85f9ea3 100644 --- a/librashader-runtime-d3d11/src/hello_triangle.rs +++ b/librashader-runtime-d3d11/src/hello_triangle.rs @@ -180,8 +180,8 @@ fn sample_wndproc(sample: &mut S, message: u32, wparam: WPARAM) -> } WM_SIZE => { sample.resize(LOWORD(wparam.0), HIWORD(wparam.0)).unwrap(); - true - }, + true + } _ => false, } } @@ -242,13 +242,13 @@ pub mod d3d11_hello_triangle { use crate::filter_chain::FilterChainD3D11; - use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11}; + use crate::options::{FilterChainOptionsD3D11}; use crate::texture::{D3D11InputView, LutTexture}; use crate::D3D11OutputView; use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; + use librashader_runtime::image::Image; use std::slice; use std::time::Instant; - use librashader_runtime::image::Image; pub struct Sample { pub dxgi_factory: IDXGIFactory4, @@ -256,7 +256,7 @@ pub mod d3d11_hello_triangle { pub context: ID3D11DeviceContext, pub resources: Option, pub filter: FilterChainD3D11, - pub lut: Option + pub lut: Option, } pub struct Resources { @@ -291,21 +291,29 @@ pub mod d3d11_hello_triangle { let (dxgi_factory, device, context) = create_device()?; let filter = FilterChainD3D11::load_from_path(&device, filter, filter_options).unwrap(); let lut = if let Some(image) = image { - let lut = LutTexture::new(&device, &context, &image, D3D11_TEXTURE2D_DESC { - Width: image.size.width, - Height: image.size.height, - MipLevels: 1, - ArraySize: 0, - Format: ImageFormat::R8G8B8A8Unorm.into(), - SampleDesc: DXGI_SAMPLE_DESC { - Count: 1, - Quality: 0, - }, - Usage: D3D11_USAGE_DYNAMIC, - BindFlags: D3D11_BIND_SHADER_RESOURCE, - CPUAccessFlags: Default::default(), - MiscFlags: Default::default(), - }, FilterMode::Linear, WrapMode::ClampToEdge).unwrap(); + let lut = LutTexture::new( + &device, + &context, + &image, + D3D11_TEXTURE2D_DESC { + Width: image.size.width, + Height: image.size.height, + MipLevels: 1, + ArraySize: 0, + Format: ImageFormat::R8G8B8A8Unorm.into(), + SampleDesc: DXGI_SAMPLE_DESC { + Count: 1, + Quality: 0, + }, + Usage: D3D11_USAGE_DYNAMIC, + BindFlags: D3D11_BIND_SHADER_RESOURCE, + CPUAccessFlags: Default::default(), + MiscFlags: Default::default(), + }, + FilterMode::Linear, + WrapMode::ClampToEdge, + ) + .unwrap(); Some(lut.handle) } else { None @@ -372,11 +380,12 @@ pub mod d3d11_hello_triangle { backbuffer.GetDesc(&mut desc); desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; - self.device.CreateTexture2D(&desc, None, Some(&mut renderbuffer))?; + self.device + .CreateTexture2D(&desc, None, Some(&mut renderbuffer))?; let renderbuffer = renderbuffer.unwrap(); - self.device.CreateRenderTargetView(&renderbuffer, None, Some(&mut rtv))?; + self.device + .CreateRenderTargetView(&renderbuffer, None, Some(&mut rtv))?; (renderbuffer, rtv.unwrap()) - }; self.resources = Some(Resources { swapchain, @@ -411,14 +420,15 @@ pub mod d3d11_hello_triangle { Ok(()) } - fn resize(&mut self, w: u32, h: u32) -> Result<()> { + fn resize(&mut self, _w: u32, _h: u32) -> Result<()> { unsafe { if let Some(resources) = self.resources.as_mut() { drop(resources.backbuffer_rtv.take()); drop(resources.backbuffer.take()); - resources.swapchain.ResizeBuffers(0, 0, - 0, DXGI_FORMAT_UNKNOWN, 0) - .unwrap_or_else(|f| eprintln!("{:?}", f)); + resources + .swapchain + .ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0) + .unwrap_or_else(|f| eprintln!("{f:?}")); let (rtv, backbuffer) = create_rtv(&self.device, &resources.swapchain)?; resources.backbuffer = Some(backbuffer); @@ -525,7 +535,11 @@ pub mod d3d11_hello_triangle { let mut tex2d_desc = Default::default(); input.GetDesc(&mut tex2d_desc); let mut backbuffer_desc = Default::default(); - resources.backbuffer.as_ref().unwrap().GetDesc(&mut backbuffer_desc); + resources + .backbuffer + .as_ref() + .unwrap() + .GetDesc(&mut backbuffer_desc); let mut input_srv = None; self.device.CreateShaderResourceView( diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index 41211ab..21301eb 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -27,22 +27,22 @@ pub use texture::D3D11OutputView; #[cfg(test)] mod tests { - use librashader_runtime::image::{Image, UVDirection}; use super::*; use crate::options::FilterChainOptionsD3D11; + use librashader_runtime::image::{Image, UVDirection}; #[test] fn triangle_d3d11() { let sample = hello_triangle::d3d11_hello_triangle::Sample::new( "../test/slang-shaders/crt/crt-royale.slangp", - // "../test/slang-shaders/presets/crt-geom-ntsc-upscale-sharp.slangp", + // "../test/slang-shaders/presets/crt-geom-ntsc-upscale-sharp.slangp", // "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", // "../test/null.slangp", Some(&FilterChainOptionsD3D11 { use_deferred_context: false, force_no_mipmaps: false, }), - Some(Image::load("../test/sf2.png", UVDirection::TopLeft).unwrap()) + Some(Image::load("../test/sf2.png", UVDirection::TopLeft).unwrap()), ) .unwrap(); // let sample = hello_triangle_old::d3d11_hello_triangle::Sample::new( diff --git a/librashader-runtime-d3d11/src/texture.rs b/librashader-runtime-d3d11/src/texture.rs index 14ff259..2e6f0d1 100644 --- a/librashader-runtime-d3d11/src/texture.rs +++ b/librashader-runtime-d3d11/src/texture.rs @@ -1,5 +1,6 @@ use librashader_common::{FilterMode, Size, WrapMode}; use librashader_runtime::image::Image; +use librashader_runtime::scaling::MipmapSize; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; use windows::Win32::Graphics::Direct3D11::{ ID3D11Device, ID3D11DeviceContext, ID3D11RenderTargetView, ID3D11ShaderResourceView, @@ -10,7 +11,6 @@ use windows::Win32::Graphics::Direct3D11::{ D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING, }; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; -use librashader_runtime::scaling::MipmapSize; use crate::error::{assume_d3d11_init, Result}; use crate::framebuffer::OwnedFramebuffer; diff --git a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs index df3674b..6c37a58 100644 --- a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs @@ -2,7 +2,6 @@ use crate::error::{FilterChainError, Result}; use crate::framebuffer::GLImage; use crate::gl::framebuffer::Framebuffer; use crate::gl::FramebufferInterface; -use crate::texture::InputTexture; use gl::types::{GLenum, GLint, GLsizei}; use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::Scale2D; @@ -46,8 +45,7 @@ impl FramebufferInterface for Gl3Framebuffer { return Ok(fb.size); } - let size = source_size - .scale_viewport(scaling, viewport.output.size); + let size = source_size.scale_viewport(scaling, viewport.output.size); if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { fb.size = size; diff --git a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs index eba3620..07e9289 100644 --- a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs @@ -2,7 +2,6 @@ use crate::error::{FilterChainError, Result}; use crate::framebuffer::GLImage; use crate::gl::framebuffer::Framebuffer; use crate::gl::FramebufferInterface; -use crate::texture::InputTexture; use gl::types::{GLenum, GLint, GLsizei}; use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::Scale2D; @@ -44,8 +43,7 @@ impl FramebufferInterface for Gl46Framebuffer { return Ok(fb.size); } - let size = source_size - .scale_viewport(scaling, viewport.output.size); + let size = source_size.scale_viewport(scaling, viewport.output.size); if fb.size != size || (mipmap && fb.max_levels == 1) || (!mipmap && fb.max_levels != 1) { fb.size = size;