fmt: general format and clean up

This commit is contained in:
chyyran 2023-02-07 02:19:37 -05:00
parent c8a1d4d196
commit 6d75dc5100
13 changed files with 43 additions and 67 deletions

View file

@ -32,6 +32,7 @@ pub struct ShaderPassConfig {
impl ShaderPassConfig { impl ShaderPassConfig {
/// If the framebuffer expects a different format than what was defined in the /// If the framebuffer expects a different format than what was defined in the
/// shader source, returns such format. /// shader source, returns such format.
#[inline(always)]
pub fn get_format_override(&self) -> Option<ImageFormat> { pub fn get_format_override(&self) -> Option<ImageFormat> {
if self.srgb_framebuffer { if self.srgb_framebuffer {
return Some(ImageFormat::R8G8B8A8Srgb); return Some(ImageFormat::R8G8B8A8Srgb);
@ -40,6 +41,15 @@ impl ShaderPassConfig {
} }
None 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)] #[repr(i32)]

View file

@ -25,9 +25,8 @@ use crate::util::d3d11_compile_bound_shader;
use crate::{error, util, D3D11OutputView}; use crate::{error, util, D3D11OutputView};
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact}; use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
use librashader_runtime::binding::{BindingUtil, TextureInput}; use librashader_runtime::binding::{BindingUtil, TextureInput};
use librashader_runtime::filter_pass::FilterPassMeta;
use librashader_runtime::quad::{QuadType, IDENTITY_MVP}; 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 librashader_runtime::uniforms::UniformStorage;
use rayon::prelude::*; use rayon::prelude::*;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
@ -299,7 +298,7 @@ impl FilterChainD3D11 {
uniform_buffer: ubo_cbuffer, uniform_buffer: ubo_cbuffer,
push_buffer: push_cbuffer, push_buffer: push_cbuffer,
source, source,
config: config.clone(), config,
}) })
}) })
.collect(); .collect();
@ -454,7 +453,7 @@ impl FilterChainD3D11 {
viewport.output.size, viewport.output.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
&passes, passes,
)?; )?;
let passes_len = passes.len(); let passes_len = passes.len();
@ -473,11 +472,7 @@ impl FilterChainD3D11 {
pass.draw( pass.draw(
index, index,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
frame_count % pass.config.frame_count_mod as usize
} else {
frame_count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,
@ -505,16 +500,12 @@ impl FilterChainD3D11 {
pass.draw( pass.draw(
passes_len - 1, passes_len - 1,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
frame_count % pass.config.frame_count_mod as usize
} else {
frame_count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,
&source, &source,
viewport.into(), RenderTarget::from(viewport),
QuadType::Final, QuadType::Final,
)?; )?;
} }

View file

@ -90,12 +90,12 @@ impl D3D11State {
let saved_rs = context.RSGetState().ok(); let saved_rs = context.RSGetState().ok();
D3D11StateSaveGuard { D3D11StateSaveGuard {
ctx: &context, ctx: context,
saved_blend, saved_blend,
saved_blend_factor, saved_blend_factor,
saved_blend_mask, saved_blend_mask,
saved_rs, saved_rs,
state: &self, state: self,
} }
}; };

View file

@ -31,7 +31,6 @@ mod tests {
use super::*; use super::*;
use crate::options::FilterChainOptionsD3D11; use crate::options::FilterChainOptionsD3D11;
use librashader_runtime::image::{Image, UVDirection}; use librashader_runtime::image::{Image, UVDirection};
use std::env;
// "../test/slang-shaders/scalefx/scalefx-9x.slangp", // "../test/slang-shaders/scalefx/scalefx-9x.slangp",
// "../test/slang-shaders/bezel/koko-aio/monitor-bloom.slangp", // "../test/slang-shaders/bezel/koko-aio/monitor-bloom.slangp",

View file

@ -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::Threading::{CreateEventA, ResetEvent, WaitForSingleObject};
use windows::Win32::System::WindowsProgramming::INFINITE; use windows::Win32::System::WindowsProgramming::INFINITE;
use librashader_runtime::filter_pass::FilterPassMeta;
use librashader_runtime::scaling::{scale_framebuffers_with_context_callback, MipmapSize}; use librashader_runtime::scaling::{scale_framebuffers_with_context_callback, MipmapSize};
use rayon::prelude::*; use rayon::prelude::*;
@ -531,7 +530,7 @@ impl FilterChainD3D12 {
frame_count: usize, frame_count: usize,
options: Option<&FrameOptionsD3D12>, options: Option<&FrameOptionsD3D12>,
) -> error::Result<()> { ) -> error::Result<()> {
drop(self.residuals.drain(..)); self.residuals.clear();
if let Some(options) = options { if let Some(options) = options {
if options.clear_history { if options.clear_history {
@ -585,7 +584,7 @@ impl FilterChainD3D12 {
} }
let original = unsafe { InputTexture::new_from_raw(input, filter, wrap_mode) }; 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 // swap output and feedback **before** recording command buffers
std::mem::swap( std::mem::swap(
@ -599,7 +598,7 @@ impl FilterChainD3D12 {
viewport.output.size, viewport.output.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
&passes, passes,
(), (),
|index: usize, pass: &FilterPass, output: &OwnedImage, feedback: &OwnedImage| { |index: usize, pass: &FilterPass, output: &OwnedImage, feedback: &OwnedImage| {
// refresh inputs // refresh inputs
@ -676,11 +675,7 @@ impl FilterChainD3D12 {
cmd, cmd,
index, index,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
frame_count % pass.config.frame_count_mod as usize
} else {
frame_count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,
@ -717,11 +712,7 @@ impl FilterChainD3D12 {
cmd, cmd,
passes_len - 1, passes_len - 1,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
frame_count % pass.config.frame_count_mod as usize
} else {
frame_count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,

View file

@ -232,7 +232,7 @@ pub fn d3d12_get_resource_transition_subresource(
after: D3D12_RESOURCE_STATES, after: D3D12_RESOURCE_STATES,
subresource: u32, subresource: u32,
) -> D3D12_RESOURCE_BARRIER { ) -> D3D12_RESOURCE_BARRIER {
let barrier = D3D12_RESOURCE_BARRIER { D3D12_RESOURCE_BARRIER {
Type: D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, Type: D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
Flags: D3D12_RESOURCE_BARRIER_FLAG_NONE, Flags: D3D12_RESOURCE_BARRIER_FLAG_NONE,
Anonymous: D3D12_RESOURCE_BARRIER_0 { Anonymous: D3D12_RESOURCE_BARRIER_0 {
@ -243,9 +243,7 @@ pub fn d3d12_get_resource_transition_subresource(
StateAfter: after, StateAfter: after,
}), }),
}, },
}; }
barrier
} }
#[inline(always)] #[inline(always)]

View file

@ -21,7 +21,6 @@ use librashader_reflect::reflect::semantics::{BindingMeta, ShaderSemantics, Unif
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact}; use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
use librashader_reflect::reflect::ReflectShader; use librashader_reflect::reflect::ReflectShader;
use librashader_runtime::binding::BindingUtil; use librashader_runtime::binding::BindingUtil;
use librashader_runtime::filter_pass::FilterPassMeta;
use librashader_runtime::scaling::scale_framebuffers; use librashader_runtime::scaling::scale_framebuffers;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use spirv_cross::spirv::Decoration; use spirv_cross::spirv::Decoration;
@ -319,7 +318,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
/// When this frame returns, GL_FRAMEBUFFER is bound to 0. /// When this frame returns, GL_FRAMEBUFFER is bound to 0.
pub fn frame( pub fn frame(
&mut self, &mut self,
count: usize, frame_count: usize,
viewport: &Viewport<&Framebuffer>, viewport: &Viewport<&Framebuffer>,
input: &GLImage, input: &GLImage,
options: Option<&FrameOptionsGL>, options: Option<&FrameOptionsGL>,
@ -386,7 +385,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
viewport.output.size, viewport.output.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
&passes, passes,
)?; )?;
let passes_len = passes.len(); let passes_len = passes.len();
@ -401,11 +400,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
pass.draw( pass.draw(
index, index,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
count % pass.config.frame_count_mod as usize
} else {
count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,
@ -428,11 +423,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
pass.draw( pass.draw(
passes_len - 1, passes_len - 1,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
count % pass.config.frame_count_mod as usize
} else {
count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,

View file

@ -3,7 +3,7 @@ use crate::framebuffer::GLImage;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use crate::texture::InputTexture; use crate::texture::InputTexture;
use gl::types::{GLenum, GLuint}; 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_presets::Scale2D;
use librashader_runtime::scaling::ScaleableFramebuffer; use librashader_runtime::scaling::ScaleableFramebuffer;

View file

@ -3,7 +3,7 @@ use crate::framebuffer::GLImage;
use crate::gl::framebuffer::Framebuffer; use crate::gl::framebuffer::Framebuffer;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use gl::types::{GLenum, GLint, GLsizei}; use gl::types::{GLenum, GLint, GLsizei};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ViewportSize};

View file

@ -3,7 +3,7 @@ use crate::framebuffer::GLImage;
use crate::gl::framebuffer::Framebuffer; use crate::gl::framebuffer::Framebuffer;
use crate::gl::FramebufferInterface; use crate::gl::FramebufferInterface;
use gl::types::{GLenum, GLint, GLsizei}; use gl::types::{GLenum, GLint, GLsizei};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ViewportSize};

View file

@ -9,7 +9,7 @@ use crate::samplers::SamplerSet;
use crate::texture::InputTexture; use crate::texture::InputTexture;
pub use framebuffer::Framebuffer; pub use framebuffer::Framebuffer;
use gl::types::{GLenum, GLuint}; use gl::types::{GLenum, GLuint};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size};
use librashader_presets::{Scale2D, TextureConfig}; use librashader_presets::{Scale2D, TextureConfig};
use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection}; use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection};
use librashader_runtime::uniforms::UniformStorageAccess; use librashader_runtime::uniforms::UniformStorageAccess;

View file

@ -8,7 +8,6 @@ use crate::queue_selection::get_graphics_queue;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::{InputImage, OwnedImage, OwnedImageLayout, VulkanImage}; use crate::texture::{InputImage, OwnedImage, OwnedImageLayout, VulkanImage};
// use crate::ubo_ring::VkUboRing;
use crate::vulkan_primitives::RawVulkanBuffer; use crate::vulkan_primitives::RawVulkanBuffer;
use crate::vulkan_state::VulkanGraphicsPipeline; use crate::vulkan_state::VulkanGraphicsPipeline;
use crate::{error, util}; use crate::{error, util};
@ -31,7 +30,6 @@ use std::collections::VecDeque;
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use librashader_runtime::filter_pass::FilterPassMeta;
use librashader_runtime::scaling::scale_framebuffers_with_context_callback; use librashader_runtime::scaling::scale_framebuffers_with_context_callback;
use rayon::prelude::*; use rayon::prelude::*;
@ -539,10 +537,10 @@ impl FilterChainVulkan {
input: &VulkanImage, input: &VulkanImage,
viewport: &Viewport<VulkanImage>, viewport: &Viewport<VulkanImage>,
cmd: vk::CommandBuffer, cmd: vk::CommandBuffer,
count: usize, frame_count: usize,
options: Option<&FrameOptionsVulkan>, options: Option<&FrameOptionsVulkan>,
) -> error::Result<()> { ) -> error::Result<()> {
let intermediates = &mut self.residuals[count % self.residuals.len()]; let intermediates = &mut self.residuals[frame_count % self.residuals.len()];
intermediates.dispose(); intermediates.dispose();
// limit number of passes to those enabled. // limit number of passes to those enabled.
@ -621,7 +619,7 @@ impl FilterChainVulkan {
viewport.output.size, viewport.output.size,
&mut self.output_framebuffers, &mut self.output_framebuffers,
&mut self.feedback_framebuffers, &mut self.feedback_framebuffers,
&passes, passes,
Some(OwnedImageLayout { Some(OwnedImageLayout {
dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, dst_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
dst_access: vk::AccessFlags::SHADER_READ, dst_access: vk::AccessFlags::SHADER_READ,
@ -662,11 +660,7 @@ impl FilterChainVulkan {
cmd, cmd,
index, index,
&self.common, &self.common,
if pass.config.frame_count_mod > 0 { pass.config.get_frame_count(frame_count),
count % pass.config.frame_count_mod as usize
} else {
count
} as u32,
frame_direction, frame_direction,
viewport, viewport,
&original, &original,
@ -704,8 +698,8 @@ impl FilterChainVulkan {
cmd, cmd,
passes_len - 1, passes_len - 1,
&self.common, &self.common,
count as u32, pass.config.get_frame_count(frame_count),
0, frame_direction,
viewport, viewport,
&original, &original,
&source, &source,
@ -717,7 +711,7 @@ impl FilterChainVulkan {
intermediates.dispose_framebuffers(residual_fb); intermediates.dispose_framebuffers(residual_fb);
} }
self.push_history(input, cmd, count)?; self.push_history(input, cmd, frame_count)?;
Ok(()) Ok(())
} }
} }

View file

@ -112,6 +112,7 @@ pub trait ScaleableFramebuffer<T> {
} }
/// Scale framebuffers according to the pass configs, source and viewport size. /// Scale framebuffers according to the pass configs, source and viewport size.
#[inline(always)]
pub fn scale_framebuffers<T, F, E, P>( pub fn scale_framebuffers<T, F, E, P>(
source_size: Size<u32>, source_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
@ -136,6 +137,7 @@ where
/// Scale framebuffers according to the pass configs, source and viewport size /// 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. /// passing a context into the scale function and a callback for each framebuffer rescale.
#[inline(always)]
pub fn scale_framebuffers_with_context_callback<T, F, E, C, P>( pub fn scale_framebuffers_with_context_callback<T, F, E, C, P>(
source_size: Size<u32>, source_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
@ -178,7 +180,7 @@ where
target_size = next_size; target_size = next_size;
callback(index, &pass, &output[index], &feedback[index])?; callback(index, pass, &output[index], &feedback[index])?;
} }
Ok(()) Ok(())