diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index c409ca5..2cdcc68 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -32,6 +32,7 @@ pub struct ShaderPassConfig { impl ShaderPassConfig { /// If the framebuffer expects a different format than what was defined in the /// shader source, returns such format. + #[inline(always)] pub fn get_format_override(&self) -> Option { if self.srgb_framebuffer { return Some(ImageFormat::R8G8B8A8Srgb); @@ -40,6 +41,15 @@ impl ShaderPassConfig { } None } + + #[inline(always)] + pub fn get_frame_count(&self, count: usize) -> u32 { + (if self.frame_count_mod > 0 { + count % self.frame_count_mod as usize + } else { + count + }) as u32 + } } #[repr(i32)] diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index a51b983..5e6c6c9 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -25,9 +25,8 @@ use crate::util::d3d11_compile_bound_shader; use crate::{error, util, D3D11OutputView}; use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact}; use librashader_runtime::binding::{BindingUtil, TextureInput}; -use librashader_runtime::filter_pass::FilterPassMeta; use librashader_runtime::quad::{QuadType, IDENTITY_MVP}; -use librashader_runtime::scaling::{scale_framebuffers, scale_framebuffers_with_context_callback}; +use librashader_runtime::scaling::scale_framebuffers; use librashader_runtime::uniforms::UniformStorage; use rayon::prelude::*; use windows::Win32::Graphics::Direct3D11::{ @@ -299,7 +298,7 @@ impl FilterChainD3D11 { uniform_buffer: ubo_cbuffer, push_buffer: push_cbuffer, source, - config: config.clone(), + config, }) }) .collect(); @@ -454,7 +453,7 @@ impl FilterChainD3D11 { viewport.output.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, - &passes, + passes, )?; let passes_len = passes.len(); @@ -473,11 +472,7 @@ impl FilterChainD3D11 { pass.draw( index, &self.common, - if pass.config.frame_count_mod > 0 { - frame_count % pass.config.frame_count_mod as usize - } else { - frame_count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, @@ -505,16 +500,12 @@ impl FilterChainD3D11 { pass.draw( passes_len - 1, &self.common, - if pass.config.frame_count_mod > 0 { - frame_count % pass.config.frame_count_mod as usize - } else { - frame_count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, &source, - viewport.into(), + RenderTarget::from(viewport), QuadType::Final, )?; } diff --git a/librashader-runtime-d3d11/src/graphics_pipeline.rs b/librashader-runtime-d3d11/src/graphics_pipeline.rs index 20f902c..1059b2c 100644 --- a/librashader-runtime-d3d11/src/graphics_pipeline.rs +++ b/librashader-runtime-d3d11/src/graphics_pipeline.rs @@ -90,12 +90,12 @@ impl D3D11State { let saved_rs = context.RSGetState().ok(); D3D11StateSaveGuard { - ctx: &context, + ctx: context, saved_blend, saved_blend_factor, saved_blend_mask, saved_rs, - state: &self, + state: self, } }; diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index 260b43a..eb7ae13 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -31,7 +31,6 @@ mod tests { use super::*; use crate::options::FilterChainOptionsD3D11; use librashader_runtime::image::{Image, UVDirection}; - use std::env; // "../test/slang-shaders/scalefx/scalefx-9x.slangp", // "../test/slang-shaders/bezel/koko-aio/monitor-bloom.slangp", diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index f61c34f..1647fdf 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -46,7 +46,6 @@ use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_UNKNOWN; use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleObject}; use windows::Win32::System::WindowsProgramming::INFINITE; -use librashader_runtime::filter_pass::FilterPassMeta; use librashader_runtime::scaling::{scale_framebuffers_with_context_callback, MipmapSize}; use rayon::prelude::*; @@ -531,7 +530,7 @@ impl FilterChainD3D12 { frame_count: usize, options: Option<&FrameOptionsD3D12>, ) -> error::Result<()> { - drop(self.residuals.drain(..)); + self.residuals.clear(); if let Some(options) = options { if options.clear_history { @@ -585,7 +584,7 @@ impl FilterChainD3D12 { } let original = unsafe { InputTexture::new_from_raw(input, filter, wrap_mode) }; - let mut source = unsafe { original.clone() }; + let mut source = original.clone(); // swap output and feedback **before** recording command buffers std::mem::swap( @@ -599,7 +598,7 @@ impl FilterChainD3D12 { viewport.output.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, - &passes, + passes, (), |index: usize, pass: &FilterPass, output: &OwnedImage, feedback: &OwnedImage| { // refresh inputs @@ -676,11 +675,7 @@ impl FilterChainD3D12 { cmd, index, &self.common, - if pass.config.frame_count_mod > 0 { - frame_count % pass.config.frame_count_mod as usize - } else { - frame_count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, @@ -717,11 +712,7 @@ impl FilterChainD3D12 { cmd, passes_len - 1, &self.common, - if pass.config.frame_count_mod > 0 { - frame_count % pass.config.frame_count_mod as usize - } else { - frame_count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, diff --git a/librashader-runtime-d3d12/src/util.rs b/librashader-runtime-d3d12/src/util.rs index 28ae96a..69dd351 100644 --- a/librashader-runtime-d3d12/src/util.rs +++ b/librashader-runtime-d3d12/src/util.rs @@ -232,7 +232,7 @@ pub fn d3d12_get_resource_transition_subresource( after: D3D12_RESOURCE_STATES, subresource: u32, ) -> D3D12_RESOURCE_BARRIER { - let barrier = D3D12_RESOURCE_BARRIER { + D3D12_RESOURCE_BARRIER { Type: D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, Flags: D3D12_RESOURCE_BARRIER_FLAG_NONE, Anonymous: D3D12_RESOURCE_BARRIER_0 { @@ -243,9 +243,7 @@ pub fn d3d12_get_resource_transition_subresource( StateAfter: after, }), }, - }; - - barrier + } } #[inline(always)] diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index 4cfc325..179a6b1 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -21,7 +21,6 @@ use librashader_reflect::reflect::semantics::{BindingMeta, ShaderSemantics, Unif use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact}; use librashader_reflect::reflect::ReflectShader; use librashader_runtime::binding::BindingUtil; -use librashader_runtime::filter_pass::FilterPassMeta; use librashader_runtime::scaling::scale_framebuffers; use rustc_hash::FxHashMap; use spirv_cross::spirv::Decoration; @@ -319,7 +318,7 @@ impl FilterChainImpl { /// When this frame returns, GL_FRAMEBUFFER is bound to 0. pub fn frame( &mut self, - count: usize, + frame_count: usize, viewport: &Viewport<&Framebuffer>, input: &GLImage, options: Option<&FrameOptionsGL>, @@ -386,7 +385,7 @@ impl FilterChainImpl { viewport.output.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, - &passes, + passes, )?; let passes_len = passes.len(); @@ -401,11 +400,7 @@ impl FilterChainImpl { pass.draw( index, &self.common, - if pass.config.frame_count_mod > 0 { - count % pass.config.frame_count_mod as usize - } else { - count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, @@ -428,11 +423,7 @@ impl FilterChainImpl { pass.draw( passes_len - 1, &self.common, - if pass.config.frame_count_mod > 0 { - count % pass.config.frame_count_mod as usize - } else { - count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, diff --git a/librashader-runtime-gl/src/gl/framebuffer.rs b/librashader-runtime-gl/src/gl/framebuffer.rs index 590e4c9..e35446c 100644 --- a/librashader-runtime-gl/src/gl/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/framebuffer.rs @@ -3,7 +3,7 @@ use crate::framebuffer::GLImage; use crate::gl::FramebufferInterface; use crate::texture::InputTexture; use gl::types::{GLenum, GLuint}; -use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; +use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_presets::Scale2D; use librashader_runtime::scaling::ScaleableFramebuffer; diff --git a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs index 2d20398..cf63acc 100644 --- a/librashader-runtime-gl/src/gl/gl3/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl3/framebuffer.rs @@ -3,7 +3,7 @@ use crate::framebuffer::GLImage; use crate::gl::framebuffer::Framebuffer; use crate::gl::FramebufferInterface; use gl::types::{GLenum, GLint, GLsizei}; -use librashader_common::{ImageFormat, Size, Viewport}; +use librashader_common::{ImageFormat, Size}; use librashader_presets::Scale2D; use librashader_runtime::scaling::{MipmapSize, ViewportSize}; diff --git a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs index 262c5f0..d2895c8 100644 --- a/librashader-runtime-gl/src/gl/gl46/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/gl46/framebuffer.rs @@ -3,7 +3,7 @@ use crate::framebuffer::GLImage; use crate::gl::framebuffer::Framebuffer; use crate::gl::FramebufferInterface; use gl::types::{GLenum, GLint, GLsizei}; -use librashader_common::{ImageFormat, Size, Viewport}; +use librashader_common::{ImageFormat, Size}; use librashader_presets::Scale2D; use librashader_runtime::scaling::{MipmapSize, ViewportSize}; diff --git a/librashader-runtime-gl/src/gl/mod.rs b/librashader-runtime-gl/src/gl/mod.rs index 3053d68..8764fa0 100644 --- a/librashader-runtime-gl/src/gl/mod.rs +++ b/librashader-runtime-gl/src/gl/mod.rs @@ -9,7 +9,7 @@ use crate::samplers::SamplerSet; use crate::texture::InputTexture; pub use framebuffer::Framebuffer; use gl::types::{GLenum, GLuint}; -use librashader_common::{ImageFormat, Size, Viewport}; +use librashader_common::{ImageFormat, Size}; use librashader_presets::{Scale2D, TextureConfig}; use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection}; use librashader_runtime::uniforms::UniformStorageAccess; diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index e414c38..86a7ea1 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -8,7 +8,6 @@ use crate::queue_selection::get_graphics_queue; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::texture::{InputImage, OwnedImage, OwnedImageLayout, VulkanImage}; -// use crate::ubo_ring::VkUboRing; use crate::vulkan_primitives::RawVulkanBuffer; use crate::vulkan_state::VulkanGraphicsPipeline; use crate::{error, util}; @@ -31,7 +30,6 @@ use std::collections::VecDeque; use std::path::Path; use std::sync::Arc; -use librashader_runtime::filter_pass::FilterPassMeta; use librashader_runtime::scaling::scale_framebuffers_with_context_callback; use rayon::prelude::*; @@ -539,10 +537,10 @@ impl FilterChainVulkan { input: &VulkanImage, viewport: &Viewport, cmd: vk::CommandBuffer, - count: usize, + frame_count: usize, options: Option<&FrameOptionsVulkan>, ) -> error::Result<()> { - let intermediates = &mut self.residuals[count % self.residuals.len()]; + let intermediates = &mut self.residuals[frame_count % self.residuals.len()]; intermediates.dispose(); // limit number of passes to those enabled. @@ -621,7 +619,7 @@ impl FilterChainVulkan { viewport.output.size, &mut self.output_framebuffers, &mut self.feedback_framebuffers, - &passes, + passes, Some(OwnedImageLayout { dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, dst_access: vk::AccessFlags::SHADER_READ, @@ -662,11 +660,7 @@ impl FilterChainVulkan { cmd, index, &self.common, - if pass.config.frame_count_mod > 0 { - count % pass.config.frame_count_mod as usize - } else { - count - } as u32, + pass.config.get_frame_count(frame_count), frame_direction, viewport, &original, @@ -704,8 +698,8 @@ impl FilterChainVulkan { cmd, passes_len - 1, &self.common, - count as u32, - 0, + pass.config.get_frame_count(frame_count), + frame_direction, viewport, &original, &source, @@ -717,7 +711,7 @@ impl FilterChainVulkan { intermediates.dispose_framebuffers(residual_fb); } - self.push_history(input, cmd, count)?; + self.push_history(input, cmd, frame_count)?; Ok(()) } } diff --git a/librashader-runtime/src/scaling.rs b/librashader-runtime/src/scaling.rs index 8473c91..d27f821 100644 --- a/librashader-runtime/src/scaling.rs +++ b/librashader-runtime/src/scaling.rs @@ -112,6 +112,7 @@ pub trait ScaleableFramebuffer { } /// Scale framebuffers according to the pass configs, source and viewport size. +#[inline(always)] pub fn scale_framebuffers( source_size: Size, viewport_size: Size, @@ -136,6 +137,7 @@ where /// Scale framebuffers according to the pass configs, source and viewport size /// passing a context into the scale function and a callback for each framebuffer rescale. +#[inline(always)] pub fn scale_framebuffers_with_context_callback( source_size: Size, viewport_size: Size, @@ -178,7 +180,7 @@ where target_size = next_size; - callback(index, &pass, &output[index], &feedback[index])?; + callback(index, pass, &output[index], &feedback[index])?; } Ok(())