diff --git a/librashader-capi/src/ctypes.rs b/librashader-capi/src/ctypes.rs index b6caab9..a5b0d55 100644 --- a/librashader-capi/src/ctypes.rs +++ b/librashader-capi/src/ctypes.rs @@ -21,7 +21,7 @@ pub type libra_d3d11_filter_chain_t = /// A handle to a Vulkan filter chain. #[cfg(feature = "runtime-vulkan")] pub type libra_vk_filter_chain_t = -Option>; + Option>; /// Defines the output viewport for a rendered frame. #[repr(C)] diff --git a/librashader-capi/src/error.rs b/librashader-capi/src/error.rs index d5acf0f..b3e7631 100644 --- a/librashader-capi/src/error.rs +++ b/librashader-capi/src/error.rs @@ -28,7 +28,10 @@ pub enum LibrashaderError { #[cfg(feature = "runtime-opengl")] #[error("There was an error in the OpenGL filter chain.")] OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError), - #[cfg(any(feature = "docsrs", all(target_os = "windows", feature = "runtime-d3d11")))] + #[cfg(any( + feature = "docsrs", + all(target_os = "windows", feature = "runtime-d3d11") + ))] #[error("There was an error in the D3D11 filter chain.")] D3D11FilterError(#[from] librashader::runtime::d3d11::error::FilterChainError), #[cfg(feature = "runtime-vulkan")] @@ -111,7 +114,7 @@ pub extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 { /// Function pointer definition for libra_error_write pub type PFN_libra_error_write = -extern "C" fn(error: libra_error_t, out: *mut MaybeUninit<*mut c_char>) -> i32; + extern "C" fn(error: libra_error_t, out: *mut MaybeUninit<*mut c_char>) -> i32; #[no_mangle] /// Writes the error message into `out` /// @@ -174,13 +177,14 @@ impl LibrashaderError { LibrashaderError::PreprocessError(_) => LIBRA_ERRNO::PREPROCESS_ERROR, LibrashaderError::ShaderCompileError(_) | LibrashaderError::ShaderReflectError(_) => { LIBRA_ERRNO::REFLECT_ERROR - }, - LibrashaderError::UnknownShaderParameter(_) => { - LIBRA_ERRNO::SHADER_PARAMETER_ERROR } + LibrashaderError::UnknownShaderParameter(_) => LIBRA_ERRNO::SHADER_PARAMETER_ERROR, #[cfg(feature = "runtime-opengl")] LibrashaderError::OpenGlFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR, - #[cfg(any(feature = "docsrs", all(target_os = "windows", feature = "runtime-d3d11")))] + #[cfg(any( + feature = "docsrs", + all(target_os = "windows", feature = "runtime-d3d11") + ))] LibrashaderError::D3D11FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR, #[cfg(feature = "runtime-vulkan")] LibrashaderError::VulkanFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR, diff --git a/librashader-capi/src/presets.rs b/librashader-capi/src/presets.rs index 849ecb4..5c1b948 100644 --- a/librashader-capi/src/presets.rs +++ b/librashader-capi/src/presets.rs @@ -1,6 +1,6 @@ //! The librashader preset C API (`libra_preset_*`). -use crate::ctypes::{libra_shader_preset_t}; -use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; +use crate::ctypes::libra_shader_preset_t; +use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::ffi::extern_fn; use librashader::presets::ShaderPreset; use std::ffi::{c_char, CStr, CString}; diff --git a/librashader-capi/src/runtime/d3d11/filter_chain.rs b/librashader-capi/src/runtime/d3d11/filter_chain.rs index eaf27d8..2f8447d 100644 --- a/librashader-capi/src/runtime/d3d11/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d11/filter_chain.rs @@ -1,13 +1,11 @@ -use std::ffi::CStr; -use crate::ctypes::{ - libra_d3d11_filter_chain_t, libra_shader_preset_t, libra_viewport_t, -}; +use crate::ctypes::{libra_d3d11_filter_chain_t, libra_shader_preset_t, libra_viewport_t}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::ffi::extern_fn; use librashader::runtime::d3d11::{D3D11InputView, D3D11OutputView}; +use std::ffi::c_char; +use std::ffi::CStr; use std::mem::MaybeUninit; use std::ptr::NonNull; -use std::ffi::c_char; use std::slice; use windows::Win32::Graphics::Direct3D11::{ ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, diff --git a/librashader-capi/src/runtime/gl/filter_chain.rs b/librashader-capi/src/runtime/gl/filter_chain.rs index af40633..1af1bfc 100644 --- a/librashader-capi/src/runtime/gl/filter_chain.rs +++ b/librashader-capi/src/runtime/gl/filter_chain.rs @@ -1,19 +1,17 @@ -use crate::ctypes::{ - libra_gl_filter_chain_t, libra_shader_preset_t, libra_viewport_t, -}; +use crate::ctypes::{libra_gl_filter_chain_t, libra_shader_preset_t, libra_viewport_t}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::ffi::extern_fn; use librashader::runtime::gl::{Framebuffer, GLImage}; +use std::ffi::CStr; use std::ffi::{c_char, c_void, CString}; use std::mem::MaybeUninit; use std::ptr::NonNull; use std::slice; -use std::ffi::CStr; pub use librashader::runtime::gl::capi::options::FilterChainOptionsGL; pub use librashader::runtime::gl::capi::options::FrameOptionsGL; -use librashader::runtime::{Size, Viewport}; use librashader::runtime::FilterChainParameters; +use librashader::runtime::{Size, Viewport}; /// A GL function loader that librashader needs to be initialized with. pub type libra_gl_loader_t = unsafe extern "system" fn(*const c_char) -> *const c_void; diff --git a/librashader-capi/src/runtime/mod.rs b/librashader-capi/src/runtime/mod.rs index eddd1b1..4721a4d 100644 --- a/librashader-capi/src/runtime/mod.rs +++ b/librashader-capi/src/runtime/mod.rs @@ -2,7 +2,10 @@ #[cfg(feature = "runtime-opengl")] pub mod gl; -#[cfg(any(feature = "docsrs", all(target_os = "windows", feature = "runtime-d3d11")))] +#[cfg(any( + feature = "docsrs", + all(target_os = "windows", feature = "runtime-d3d11") +))] pub mod d3d11; #[cfg(feature = "runtime-vulkan")] diff --git a/librashader-capi/src/runtime/vk/filter_chain.rs b/librashader-capi/src/runtime/vk/filter_chain.rs index 721f1f2..190f19b 100644 --- a/librashader-capi/src/runtime/vk/filter_chain.rs +++ b/librashader-capi/src/runtime/vk/filter_chain.rs @@ -1,27 +1,25 @@ -use std::ffi::{c_char, c_void}; -use crate::ctypes::{ - libra_vk_filter_chain_t, libra_shader_preset_t, libra_viewport_t, -}; +use crate::ctypes::{libra_shader_preset_t, libra_viewport_t, libra_vk_filter_chain_t}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::ffi::extern_fn; use librashader::runtime::vk::{VulkanImage, VulkanInstance}; +use std::ffi::CStr; +use std::ffi::{c_char, c_void}; use std::mem::MaybeUninit; use std::ptr::NonNull; use std::slice; -use std::ffi::CStr; pub use librashader::runtime::vk::capi::options::FilterChainOptionsVulkan; pub use librashader::runtime::vk::capi::options::FrameOptionsVulkan; -use librashader::runtime::{Size, Viewport}; use librashader::runtime::FilterChainParameters; +use librashader::runtime::{Size, Viewport}; use ash::vk; pub use ash::vk::PFN_vkGetInstanceProcAddr; /// A Vulkan instance function loader that the Vulkan filter chain needs to be initialized with. -pub type libra_PFN_vkGetInstanceProcAddr = unsafe extern "system" fn(instance: *mut c_void, p_name: *const c_char); - +pub type libra_PFN_vkGetInstanceProcAddr = + unsafe extern "system" fn(instance: *mut c_void, p_name: *const c_char); /// Vulkan parameters for the source image. #[repr(C)] @@ -49,7 +47,7 @@ pub struct libra_device_vk_t { /// for the device attached to the instance that will perform rendering. pub device: vk::Device, /// The entry loader for the Vulkan library. - pub entry: vk::PFN_vkGetInstanceProcAddr + pub entry: vk::PFN_vkGetInstanceProcAddr, } impl From for VulkanImage { @@ -165,7 +163,6 @@ extern_fn! { } } - extern_fn! { /// Sets a parameter for the filter chain. /// diff --git a/librashader-common/src/viewport.rs b/librashader-common/src/viewport.rs index f3768ae..8a6a53e 100644 --- a/librashader-common/src/viewport.rs +++ b/librashader-common/src/viewport.rs @@ -9,4 +9,4 @@ pub struct Viewport<'a, T> { pub mvp: Option<&'a [f32; 16]>, /// The output handle to render the final image to. pub output: T, -} \ No newline at end of file +} diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index e8cf864..ac2eb4a 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -1,4 +1,4 @@ -use crate::texture::{D3D11InputView, LutTexture, InputTexture}; +use crate::texture::{D3D11InputView, InputTexture, LutTexture}; use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; @@ -24,7 +24,7 @@ use crate::quad_render::DrawQuad; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::util::d3d11_compile_bound_shader; -use crate::{D3D11OutputView, error, util}; +use crate::{error, util, D3D11OutputView}; use librashader_runtime::uniforms::UniformStorage; use windows::Win32::Graphics::Direct3D11::{ ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, diff --git a/librashader-runtime-d3d11/src/filter_pass.rs b/librashader-runtime-d3d11/src/filter_pass.rs index 4d02f92..b556eed 100644 --- a/librashader-runtime-d3d11/src/filter_pass.rs +++ b/librashader-runtime-d3d11/src/filter_pass.rs @@ -11,15 +11,15 @@ use librashader_reflect::reflect::semantics::{ use librashader_reflect::reflect::ShaderReflection; use rustc_hash::FxHashMap; +use librashader_runtime::binding::{BindSemantics, TextureInput}; use windows::Win32::Graphics::Direct3D11::{ ID3D11Buffer, ID3D11InputLayout, ID3D11PixelShader, ID3D11SamplerState, ID3D11ShaderResourceView, ID3D11VertexShader, D3D11_MAP_WRITE_DISCARD, }; -use librashader_runtime::binding::{BindSemantics, TextureInput}; -use crate::{D3D11OutputView, error}; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; +use crate::{error, D3D11OutputView}; use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess}; pub struct ConstantBufferBinding { @@ -60,14 +60,20 @@ impl TextureInput for InputTexture { impl BindSemantics for FilterPass { type InputTexture = InputTexture; type SamplerSet = SamplerSet; - type DescriptorSet<'a> = (&'a mut [Option; 16], &'a mut [Option; 16]); + type DescriptorSet<'a> = ( + &'a mut [Option; 16], + &'a mut [Option; 16], + ); type DeviceContext = (); type UniformOffset = MemberOffset; fn bind_texture<'a>( - descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, - binding: &TextureBinding, texture: &Self::InputTexture, - _device: &Self::DeviceContext) { + descriptors: &mut Self::DescriptorSet<'a>, + samplers: &Self::SamplerSet, + binding: &TextureBinding, + texture: &Self::InputTexture, + _device: &Self::DeviceContext, + ) { let (texture_binding, sampler_binding) = descriptors; texture_binding[binding.binding as usize] = Some(texture.view.handle.clone()); sampler_binding[binding.binding as usize] = @@ -110,7 +116,10 @@ impl FilterPass { frame_direction: i32, fb_size: Size, viewport_size: Size, - mut descriptors: (&'a mut [Option; 16], &'a mut [Option; 16]), + mut descriptors: ( + &'a mut [Option; 16], + &'a mut [Option; 16], + ), original: &InputTexture, source: &InputTexture, ) { @@ -128,16 +137,14 @@ impl FilterPass { source, &self.uniform_bindings, &self.reflection.meta.texture_meta, - parent.output_textures[0..pass_index].iter() + parent.output_textures[0..pass_index] + .iter() .map(|o| o.as_ref()), - parent.feedback_textures.iter() - .map(|o| o.as_ref()), - parent.history_textures.iter() - .map(|o| o.as_ref()), - parent.luts.iter() - .map(|(u, i)| (*u, i.as_ref())), + parent.feedback_textures.iter().map(|o| o.as_ref()), + parent.history_textures.iter().map(|o| o.as_ref()), + parent.luts.iter().map(|(u, i)| (*u, i.as_ref())), &self.source.parameters, - &parent.config.parameters + &parent.config.parameters, ); } diff --git a/librashader-runtime-d3d11/src/hello_triangle.rs b/librashader-runtime-d3d11/src/hello_triangle.rs index 2c55219..8d7f09c 100644 --- a/librashader-runtime-d3d11/src/hello_triangle.rs +++ b/librashader-runtime-d3d11/src/hello_triangle.rs @@ -229,10 +229,10 @@ pub mod d3d11_hello_triangle { use crate::options::FilterChainOptionsD3D11; use crate::texture::D3D11InputView; + use crate::D3D11OutputView; use librashader_common::{Size, Viewport}; use std::slice; use std::time::Instant; - use crate::D3D11OutputView; pub struct Sample { pub dxgi_factory: IDXGIFactory4, diff --git a/librashader-runtime-d3d11/src/render_target.rs b/librashader-runtime-d3d11/src/render_target.rs index 2f249ee..5e27326 100644 --- a/librashader-runtime-d3d11/src/render_target.rs +++ b/librashader-runtime-d3d11/src/render_target.rs @@ -1,7 +1,7 @@ use crate::framebuffer::OutputFramebuffer; -use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT; -use librashader_common::Viewport; use crate::D3D11OutputView; +use librashader_common::Viewport; +use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT; #[rustfmt::skip] static DEFAULT_MVP: &[f32; 16] = &[ diff --git a/librashader-runtime-d3d11/src/texture.rs b/librashader-runtime-d3d11/src/texture.rs index 3d65acf..82f6b37 100644 --- a/librashader-runtime-d3d11/src/texture.rs +++ b/librashader-runtime-d3d11/src/texture.rs @@ -2,18 +2,18 @@ use librashader_common::{FilterMode, Size, WrapMode}; use librashader_runtime::image::Image; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; use windows::Win32::Graphics::Direct3D11::{ - ID3D11Device, ID3D11DeviceContext, ID3D11ShaderResourceView, ID3D11RenderTargetView, ID3D11Texture2D, D3D11_BIND_FLAG, - D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_BOX, D3D11_CPU_ACCESS_FLAG, - D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS, - D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_SUBRESOURCE_DATA, - D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING, + ID3D11Device, ID3D11DeviceContext, ID3D11RenderTargetView, ID3D11ShaderResourceView, + ID3D11Texture2D, D3D11_BIND_FLAG, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, + D3D11_BOX, D3D11_CPU_ACCESS_FLAG, D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, + D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_SHADER_RESOURCE_VIEW_DESC, + D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_SUBRESOURCE_DATA, D3D11_TEX2D_SRV, + D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING, }; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; use crate::error::Result; use crate::framebuffer::OwnedFramebuffer; - /// An image view for use as a shader resource. /// /// Contains an `ID3D11ShaderResourceView`, and a size. diff --git a/librashader-runtime-gl/src/error.rs b/librashader-runtime-gl/src/error.rs index fa604fd..53fc0da 100644 --- a/librashader-runtime-gl/src/error.rs +++ b/librashader-runtime-gl/src/error.rs @@ -29,7 +29,7 @@ pub enum FilterChainError { #[error("opengl could not link program")] GLLinkError, #[error("opengl could not compile program")] - GlCompileError + GlCompileError, } /// Result type for OpenGL filter chains. diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index 59f8e45..6bc946b 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -227,7 +227,8 @@ impl FilterChainImpl { // todo: split this out. let (program, ubo_location) = unsafe { let vertex = util::gl_compile_shader(gl::VERTEX_SHADER, glsl.vertex.as_str())?; - let fragment = util::gl_compile_shader(gl::FRAGMENT_SHADER, glsl.fragment.as_str())?; + let fragment = + util::gl_compile_shader(gl::FRAGMENT_SHADER, glsl.fragment.as_str())?; let program = gl::CreateProgram(); gl::AttachShader(program, vertex); @@ -304,21 +305,30 @@ impl FilterChainImpl { for param in reflection.meta.parameter_meta.values() { uniform_bindings.insert( UniformBinding::Parameter(param.id.clone()), - UniformOffset::new(Self::reflect_uniform_location(program, param), param.offset), + UniformOffset::new( + Self::reflect_uniform_location(program, param), + param.offset, + ), ); } for (semantics, param) in &reflection.meta.unique_meta { uniform_bindings.insert( UniformBinding::SemanticVariable(*semantics), - UniformOffset::new(Self::reflect_uniform_location(program, param), param.offset), + UniformOffset::new( + Self::reflect_uniform_location(program, param), + param.offset, + ), ); } for (semantics, param) in &reflection.meta.texture_size_meta { uniform_bindings.insert( UniformBinding::TextureSize(*semantics), - UniformOffset::new(Self::reflect_uniform_location(program, param), param.offset), + UniformOffset::new( + Self::reflect_uniform_location(program, param), + param.offset, + ), ); } diff --git a/librashader-runtime-gl/src/filter_chain/mod.rs b/librashader-runtime-gl/src/filter_chain/mod.rs index 569977f..97b5ee8 100644 --- a/librashader-runtime-gl/src/filter_chain/mod.rs +++ b/librashader-runtime-gl/src/filter_chain/mod.rs @@ -1,4 +1,3 @@ - use std::panic::catch_unwind; use std::path::Path; @@ -14,7 +13,7 @@ mod inner; mod parameters; pub(crate) use filter_impl::FilterCommon; -use librashader_common::{Viewport}; +use librashader_common::Viewport; /// An OpenGL filter chain. pub struct FilterChainGL { diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index a2fcba0..06c6c32 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -6,30 +6,29 @@ use librashader_reflect::reflect::ShaderReflection; use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; -use librashader_reflect::reflect::semantics::{MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics}; -use rustc_hash::FxHashMap; +use librashader_reflect::reflect::semantics::{ + MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, +}; use librashader_runtime::binding::{BindSemantics, ContextOffset, TextureInput}; +use rustc_hash::FxHashMap; use crate::binding::{GlUniformBinder, GlUniformStorage, UniformLocation, VariableLocation}; use crate::filter_chain::FilterCommon; -use crate::Framebuffer; use crate::gl::{BindTexture, GLInterface, UboRing}; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; +use crate::Framebuffer; use crate::texture::InputTexture; pub struct UniformOffset { pub location: VariableLocation, - pub offset: MemberOffset + pub offset: MemberOffset, } impl UniformOffset { pub fn new(location: VariableLocation, offset: MemberOffset) -> Self { - Self { - location, - offset - } + Self { location, offset } } } @@ -69,9 +68,12 @@ impl BindSemantics> for type UniformOffset = UniformOffset; fn bind_texture<'a>( - _descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, - binding: &TextureBinding, texture: &Self::InputTexture, - _device: &Self::DeviceContext) { + _descriptors: &mut Self::DescriptorSet<'a>, + samplers: &Self::SamplerSet, + binding: &TextureBinding, + texture: &Self::InputTexture, + _device: &Self::DeviceContext, + ) { T::BindTexture::bind_texture(&samplers, binding, texture); } } @@ -186,16 +188,14 @@ impl FilterPass { source, &self.uniform_bindings, &self.reflection.meta.texture_meta, - parent.output_textures[0..pass_index].iter() + parent.output_textures[0..pass_index] + .iter() .map(|o| o.bound()), - parent.feedback_textures.iter() - .map(|o| o.bound()), - parent.history_textures.iter() - .map(|o| o.bound()), - parent.luts.iter() - .map(|(u, i)| (*u, i)), + parent.feedback_textures.iter().map(|o| o.bound()), + parent.history_textures.iter().map(|o| o.bound()), + parent.luts.iter().map(|(u, i)| (*u, i)), &self.source.parameters, - &parent.config.parameters + &parent.config.parameters, ); } } diff --git a/librashader-runtime-gl/src/gl/framebuffer.rs b/librashader-runtime-gl/src/gl/framebuffer.rs index 2f93981..a5fcec2 100644 --- a/librashader-runtime-gl/src/gl/framebuffer.rs +++ b/librashader-runtime-gl/src/gl/framebuffer.rs @@ -6,7 +6,6 @@ use gl::types::{GLenum, GLuint}; use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; use librashader_presets::Scale2D; - /// A handle to an OpenGL FBO and its backing texture with format and size information. /// /// Generally for use as render targets. diff --git a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs index 11ae5f8..9834383 100644 --- a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs @@ -8,10 +8,10 @@ use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint}; use librashader_common::{Size, Viewport}; use crate::filter_chain::FilterChainGL; -use crate::Framebuffer; use crate::framebuffer::GLImage; use crate::gl::gl3::CompatibilityGL; use crate::gl::{FramebufferInterface, GLInterface}; +use crate::Framebuffer; const WIDTH: u32 = 800; const HEIGHT: u32 = 600; diff --git a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs index 1f393eb..f0418bf 100644 --- a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs @@ -8,10 +8,10 @@ use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint}; use librashader_common::{Size, Viewport}; use crate::filter_chain::FilterChainGL; -use crate::Framebuffer; use crate::framebuffer::GLImage; use crate::gl::gl46::DirectStateAccessGL; use crate::gl::{FramebufferInterface, GLInterface}; +use crate::Framebuffer; const WIDTH: u32 = 800; const HEIGHT: u32 = 600; diff --git a/librashader-runtime-gl/src/render_target.rs b/librashader-runtime-gl/src/render_target.rs index ce42b8c..f07369d 100644 --- a/librashader-runtime-gl/src/render_target.rs +++ b/librashader-runtime-gl/src/render_target.rs @@ -1,5 +1,5 @@ -use librashader_common::Viewport; use crate::gl::Framebuffer; +use librashader_common::Viewport; #[rustfmt::skip] static DEFAULT_MVP: &[f32; 16] = &[ diff --git a/librashader-runtime-gl/src/texture.rs b/librashader-runtime-gl/src/texture.rs index 39363ef..798a4ed 100644 --- a/librashader-runtime-gl/src/texture.rs +++ b/librashader-runtime-gl/src/texture.rs @@ -1,5 +1,5 @@ -use gl::types::GLuint; use crate::framebuffer::GLImage; +use gl::types::GLuint; use librashader_common::{FilterMode, WrapMode}; #[derive(Default, Debug, Copy, Clone)] @@ -29,4 +29,4 @@ impl AsRef for InputTexture { fn as_ref(&self) -> &InputTexture { self } -} \ No newline at end of file +} diff --git a/librashader-runtime-gl/src/util.rs b/librashader-runtime-gl/src/util.rs index e8c193a..8dfec75 100644 --- a/librashader-runtime-gl/src/util.rs +++ b/librashader-runtime-gl/src/util.rs @@ -1,8 +1,8 @@ use gl::types::{GLenum, GLuint}; -use librashader_reflect::back::cross::GlslVersion; use crate::error; use crate::error::FilterChainError; +use librashader_reflect::back::cross::GlslVersion; pub unsafe fn gl_compile_shader(stage: GLenum, source: &str) -> error::Result { let shader = gl::CreateShader(stage); diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 18c18a1..8a8293e 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -3,6 +3,7 @@ use crate::error::FilterChainError; use crate::filter_pass::FilterPass; use crate::framebuffer::OutputImage; use crate::luts::LutTexture; +use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan}; use crate::queue_selection::get_graphics_queue; use crate::render_target::{RenderTarget, DEFAULT_MVP}; use crate::samplers::SamplerSet; @@ -27,7 +28,6 @@ use rustc_hash::FxHashMap; use std::collections::VecDeque; use std::path::Path; use std::sync::Arc; -use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan}; /// A Vulkan device and metadata that is required by the shader runtime. pub struct VulkanObjects { @@ -78,7 +78,7 @@ impl TryFrom for VulkanObjects { instance.get_physical_device_memory_properties(vulkan.physical_device); Ok(VulkanObjects { - device: Arc::new(device), + device: Arc::new(device), queue, pipeline_cache, memory_properties, @@ -91,11 +91,14 @@ impl TryFrom for VulkanObjects { impl TryFrom<(vk::PhysicalDevice, ash::Instance, Arc)> for VulkanObjects { type Error = FilterChainError; - fn try_from(value: (vk::PhysicalDevice, ash::Instance, Arc)) -> error::Result { + fn try_from( + value: (vk::PhysicalDevice, ash::Instance, Arc), + ) -> error::Result { unsafe { let device = value.2; - let pipeline_cache = device.create_pipeline_cache(&vk::PipelineCacheCreateInfo::default(), None)?; + let pipeline_cache = + device.create_pipeline_cache(&vk::PipelineCacheCreateInfo::default(), None)?; let queue = get_graphics_queue(&value.1, &device, value.0); @@ -245,7 +248,9 @@ impl FilterChainVulkan { feedback_textures.resize_with(filters.len(), || None); let mut intermediates = Vec::new(); - intermediates.resize_with(frames_in_flight as usize, || FrameResiduals::new(&device.device)); + intermediates.resize_with(frames_in_flight as usize, || { + FrameResiduals::new(&device.device) + }); Ok(FilterChainVulkan { common: FilterCommon { diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index 9413b45..643e0df 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -1,11 +1,10 @@ -use std::sync::Arc; -use crate::{error, VulkanImage}; use crate::filter_chain::FilterCommon; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::texture::InputImage; use crate::ubo_ring::VkUboRing; use crate::vulkan_state::VulkanGraphicsPipeline; +use crate::{error, VulkanImage}; use ash::vk; use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; @@ -14,9 +13,12 @@ use librashader_reflect::reflect::semantics::{ BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, }; use librashader_reflect::reflect::ShaderReflection; -use librashader_runtime::uniforms::{BindUniform, NoUniformBinder, UniformStorage, UniformStorageAccess}; -use rustc_hash::FxHashMap; use librashader_runtime::binding::{BindSemantics, TextureInput}; +use librashader_runtime::uniforms::{ + BindUniform, NoUniformBinder, UniformStorage, UniformStorageAccess, +}; +use rustc_hash::FxHashMap; +use std::sync::Arc; pub struct FilterPass { pub device: Arc, @@ -45,8 +47,12 @@ impl BindSemantics for FilterPass { type UniformOffset = MemberOffset; fn bind_texture<'a>( - descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, - binding: &TextureBinding, texture: &Self::InputTexture, device: &Self::DeviceContext) { + descriptors: &mut Self::DescriptorSet<'a>, + samplers: &Self::SamplerSet, + binding: &TextureBinding, + texture: &Self::InputTexture, + device: &Self::DeviceContext, + ) { let sampler = samplers.get(texture.wrap_mode, texture.filter_mode, texture.mip_filter); let image_info = [vk::DescriptorImageInfo::builder() .sampler(sampler.handle) @@ -244,16 +250,14 @@ impl FilterPass { source, &self.uniform_bindings, &self.reflection.meta.texture_meta, - parent.output_inputs[0..pass_index].iter() + parent.output_inputs[0..pass_index] + .iter() .map(|o| o.as_ref()), - parent.feedback_inputs.iter() - .map(|o| o.as_ref()), - parent.history_textures.iter() - .map(|o| o.as_ref()), - parent.luts.iter() - .map(|(u, i)| (*u, i.as_ref())), + parent.feedback_inputs.iter().map(|o| o.as_ref()), + parent.history_textures.iter().map(|o| o.as_ref()), + parent.luts.iter().map(|(u, i)| (*u, i.as_ref())), &self.source.parameters, - &parent.config.parameters + &parent.config.parameters, ); } } diff --git a/librashader-runtime-vk/src/framebuffer.rs b/librashader-runtime-vk/src/framebuffer.rs index 572263c..324ffa9 100644 --- a/librashader-runtime-vk/src/framebuffer.rs +++ b/librashader-runtime-vk/src/framebuffer.rs @@ -1,9 +1,9 @@ -use std::sync::Arc; use crate::filter_chain::VulkanObjects; use crate::texture::VulkanImage; use crate::{error, util}; use ash::vk; use librashader_common::Size; +use std::sync::Arc; #[derive(Clone)] pub(crate) struct OutputImage { diff --git a/librashader-runtime-vk/src/hello_triangle/command.rs b/librashader-runtime-vk/src/hello_triangle/command.rs index 5abd052..a637e11 100644 --- a/librashader-runtime-vk/src/hello_triangle/command.rs +++ b/librashader-runtime-vk/src/hello_triangle/command.rs @@ -1,8 +1,8 @@ -use std::sync::Arc; use crate::hello_triangle::physicaldevice::find_queue_family; use crate::hello_triangle::vulkan_base::VulkanBase; use ash::prelude::VkResult; use ash::vk; +use std::sync::Arc; pub struct VulkanCommandPool { pool: vk::CommandPool, diff --git a/librashader-runtime-vk/src/hello_triangle/mod.rs b/librashader-runtime-vk/src/hello_triangle/mod.rs index 26452c7..afec805 100644 --- a/librashader-runtime-vk/src/hello_triangle/mod.rs +++ b/librashader-runtime-vk/src/hello_triangle/mod.rs @@ -20,11 +20,11 @@ use crate::texture::VulkanImage; use crate::util; use ash::vk; use ash::vk::{Handle, RenderingInfo}; +use librashader_common::Viewport; use std::ffi::CString; use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder}; use winit::platform::windows::EventLoopBuilderExtWindows; -use librashader_common::Viewport; // Constants const WINDOW_TITLE: &'static str = "librashader Vulkan"; @@ -210,7 +210,7 @@ impl VulkanWindow { // vk::QUEUE_FAMILY_IGNORED // ); - filter + filter .frame( &VulkanImage { size: vulkan.swapchain.extent.into(), diff --git a/librashader-runtime-vk/src/hello_triangle/swapchain.rs b/librashader-runtime-vk/src/hello_triangle/swapchain.rs index a7d6237..00bc67d 100644 --- a/librashader-runtime-vk/src/hello_triangle/swapchain.rs +++ b/librashader-runtime-vk/src/hello_triangle/swapchain.rs @@ -109,11 +109,14 @@ impl VulkanSwapchain { let alloc_info = vk::MemoryAllocateInfo::builder() .allocation_size(mem_reqs.size) - .memory_type_index(find_vulkan_memory_type( - &base.mem_props, - mem_reqs.memory_type_bits, - vk::MemoryPropertyFlags::DEVICE_LOCAL, - ).unwrap()) + .memory_type_index( + find_vulkan_memory_type( + &base.mem_props, + mem_reqs.memory_type_bits, + vk::MemoryPropertyFlags::DEVICE_LOCAL, + ) + .unwrap(), + ) .build(); // todo: optimize by reusing existing memory. diff --git a/librashader-runtime-vk/src/lib.rs b/librashader-runtime-vk/src/lib.rs index 5859971..ff4bb91 100644 --- a/librashader-runtime-vk/src/lib.rs +++ b/librashader-runtime-vk/src/lib.rs @@ -20,8 +20,8 @@ mod vulkan_primitives; mod vulkan_state; pub use filter_chain::FilterChainVulkan; -pub use filter_chain::VulkanObjects; pub use filter_chain::VulkanInstance; +pub use filter_chain::VulkanObjects; pub use texture::VulkanImage; pub mod error; diff --git a/librashader-runtime-vk/src/luts.rs b/librashader-runtime-vk/src/luts.rs index 2f5d58d..837b6b6 100644 --- a/librashader-runtime-vk/src/luts.rs +++ b/librashader-runtime-vk/src/luts.rs @@ -254,4 +254,4 @@ impl AsRef for LutTexture { fn as_ref(&self) -> &InputImage { &self.image } -} \ No newline at end of file +} diff --git a/librashader-runtime-vk/src/options.rs b/librashader-runtime-vk/src/options.rs index 8d9db85..9d1e6bc 100644 --- a/librashader-runtime-vk/src/options.rs +++ b/librashader-runtime-vk/src/options.rs @@ -19,4 +19,3 @@ pub struct FilterChainOptionsVulkan { /// Whether or not to explicitly disable mipmap generation regardless of shader preset settings. pub force_no_mipmaps: bool, } - diff --git a/librashader-runtime-vk/src/samplers.rs b/librashader-runtime-vk/src/samplers.rs index b2f0b52..7be35f8 100644 --- a/librashader-runtime-vk/src/samplers.rs +++ b/librashader-runtime-vk/src/samplers.rs @@ -1,8 +1,8 @@ -use std::sync::Arc; use crate::error; use ash::vk; use librashader_common::{FilterMode, WrapMode}; use rustc_hash::FxHashMap; +use std::sync::Arc; pub struct VulkanSampler { pub handle: vk::Sampler, diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index b8d76c2..e266b72 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -1,9 +1,9 @@ -use std::sync::Arc; use crate::filter_chain::VulkanObjects; use crate::util::find_vulkan_memory_type; use crate::vulkan_primitives::VulkanImageMemory; use crate::{error, util}; use ash::vk; +use std::sync::Arc; use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_presets::Scale2D; @@ -532,4 +532,4 @@ impl AsRef for InputImage { fn as_ref(&self) -> &InputImage { &self } -} \ No newline at end of file +} diff --git a/librashader-runtime-vk/src/ubo_ring.rs b/librashader-runtime-vk/src/ubo_ring.rs index 91ccbd1..ab8b412 100644 --- a/librashader-runtime-vk/src/ubo_ring.rs +++ b/librashader-runtime-vk/src/ubo_ring.rs @@ -1,9 +1,9 @@ -use std::sync::Arc; use crate::error; use crate::vulkan_primitives::VulkanBuffer; use ash::vk; use librashader_runtime::ringbuffer::{BoxRingBuffer, RingBuffer}; use librashader_runtime::uniforms::UniformStorageAccess; +use std::sync::Arc; pub struct VkUboRing { ring: BoxRingBuffer, diff --git a/librashader-runtime-vk/src/util.rs b/librashader-runtime-vk/src/util.rs index 0d66d30..f3f2f96 100644 --- a/librashader-runtime-vk/src/util.rs +++ b/librashader-runtime-vk/src/util.rs @@ -1,8 +1,8 @@ use ash::vk; -use librashader_reflect::reflect::semantics::BindingStage; use crate::error; use crate::error::FilterChainError; +use librashader_reflect::reflect::semantics::BindingStage; pub fn binding_stage_to_vulkan_stage(stage_mask: BindingStage) -> vk::ShaderStageFlags { let mut mask = vk::ShaderStageFlags::default(); @@ -33,7 +33,11 @@ pub fn find_vulkan_memory_type( if host_reqs == vk::MemoryPropertyFlags::empty() { Err(FilterChainError::VulkanMemoryError(device_reqs)) } else { - Ok(find_vulkan_memory_type(props, device_reqs, vk::MemoryPropertyFlags::empty())?) + Ok(find_vulkan_memory_type( + props, + device_reqs, + vk::MemoryPropertyFlags::empty(), + )?) } } diff --git a/librashader-runtime/src/binding.rs b/librashader-runtime/src/binding.rs index 5d23003..305f01d 100644 --- a/librashader-runtime/src/binding.rs +++ b/librashader-runtime/src/binding.rs @@ -1,9 +1,11 @@ -use std::collections::HashMap; -use std::hash::BuildHasher; +use crate::uniforms::{BindUniform, NoUniformBinder, UniformStorage}; use librashader_common::Size; use librashader_preprocess::ShaderParameter; -use librashader_reflect::reflect::semantics::{MemberOffset, Semantic, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics}; -use crate::uniforms::{BindUniform, NoUniformBinder, UniformStorage}; +use librashader_reflect::reflect::semantics::{ + MemberOffset, Semantic, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, +}; +use std::collections::HashMap; +use std::hash::BuildHasher; /// Trait for input textures used during uniform binding, pub trait TextureInput { @@ -13,12 +15,12 @@ pub trait TextureInput { /// A uniform member offset with context that needs to be resolved. pub trait ContextOffset - where - H: BindUniform, - H: BindUniform, - H: BindUniform, - H: for<'a> BindUniform, - H: for<'a> BindUniform, +where + H: BindUniform, + H: BindUniform, + H: BindUniform, + H: for<'a> BindUniform, + H: for<'a> BindUniform, { /// Gets the `MemberOffset` part of the offset. fn offset(&self) -> MemberOffset; @@ -28,12 +30,12 @@ pub trait ContextOffset } impl ContextOffset> for MemberOffset - where - H: BindUniform, f32>, - H: BindUniform, u32>, - H: BindUniform, i32>, - H: for<'a> BindUniform, &'a [f32; 4]>, - H: for<'a> BindUniform, &'a [f32; 16]>, +where + H: BindUniform, f32>, + H: BindUniform, u32>, + H: BindUniform, i32>, + H: for<'a> BindUniform, &'a [f32; 4]>, + H: for<'a> BindUniform, &'a [f32; 16]>, { fn offset(&self) -> MemberOffset { *self @@ -45,13 +47,13 @@ impl ContextOffset> for MemberOffset } /// Trait that abstracts binding of semantics to shader uniforms. -pub trait BindSemantics> - where - H: BindUniform, - H: BindUniform, - H: BindUniform, - H: for<'b> BindUniform, - H: for<'b> BindUniform +pub trait BindSemantics> +where + H: BindUniform, + H: BindUniform, + H: BindUniform, + H: for<'b> BindUniform, + H: for<'b> BindUniform, { /// The type of the input texture used for semantic binding. type InputTexture: TextureInput; @@ -68,14 +70,13 @@ pub trait BindSemantics> /// The type of uniform offsets to use. type UniformOffset: ContextOffset; - /// Bind a texture to the input descriptor set fn bind_texture<'a>( descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, binding: &TextureBinding, texture: &Self::InputTexture, - device: &Self::DeviceContext + device: &Self::DeviceContext, ); #[clippy::allow(too_many_arguments)] @@ -100,8 +101,7 @@ pub trait BindSemantics> lookup_textures: impl Iterator)>, parameter_defaults: &[ShaderParameter], runtime_parameters: &HashMap, - ) - { + ) { // Bind MVP if let Some(offset) = uniform_bindings.get(&UniqueSemantics::MVP.into()) { uniform_storage.bind_mat4(offset.offset(), mvp, offset.context()); @@ -113,90 +113,53 @@ pub trait BindSemantics> } // bind FinalViewportSize - if let Some(offset) = uniform_bindings - .get(&UniqueSemantics::FinalViewport.into()) - { + if let Some(offset) = uniform_bindings.get(&UniqueSemantics::FinalViewport.into()) { uniform_storage.bind_vec4(offset.offset(), viewport_size, offset.context()); } // bind FrameCount - if let Some(offset) = uniform_bindings - .get(&UniqueSemantics::FrameCount.into()) - { + if let Some(offset) = uniform_bindings.get(&UniqueSemantics::FrameCount.into()) { uniform_storage.bind_scalar(offset.offset(), frame_count, offset.context()); } // bind FrameDirection - if let Some(offset) = uniform_bindings - .get(&UniqueSemantics::FrameDirection.into()) - { - uniform_storage - .bind_scalar(offset.offset(), frame_direction, offset.context()); + if let Some(offset) = uniform_bindings.get(&UniqueSemantics::FrameDirection.into()) { + uniform_storage.bind_scalar(offset.offset(), frame_direction, offset.context()); } // bind Original sampler - if let Some(binding) = texture_meta - .get(&TextureSemantics::Original.semantics(0)) - { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - original, - device - ); + if let Some(binding) = texture_meta.get(&TextureSemantics::Original.semantics(0)) { + Self::bind_texture(descriptor_set, sampler_set, binding, original, device); } // bind OriginalSize - if let Some(offset) = uniform_bindings - .get(&TextureSemantics::Original.semantics(0).into()) + if let Some(offset) = uniform_bindings.get(&TextureSemantics::Original.semantics(0).into()) { - uniform_storage - .bind_vec4(offset.offset(), original.size(), offset.context()); + uniform_storage.bind_vec4(offset.offset(), original.size(), offset.context()); } // bind Source sampler - if let Some(binding) = texture_meta - .get(&TextureSemantics::Source.semantics(0)) - { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - source, - device - ); + if let Some(binding) = texture_meta.get(&TextureSemantics::Source.semantics(0)) { + Self::bind_texture(descriptor_set, sampler_set, binding, source, device); } // bind SourcelSize - if let Some(offset) = uniform_bindings - .get(&TextureSemantics::Source.semantics(0).into()) - { - uniform_storage - .bind_vec4(offset.offset(), source.size(), offset.context()); + if let Some(offset) = uniform_bindings.get(&TextureSemantics::Source.semantics(0).into()) { + uniform_storage.bind_vec4(offset.offset(), source.size(), offset.context()); } // OriginalHistory0 aliases OriginalHistory // bind OriginalHistory0 sampler - if let Some(binding) = texture_meta - .get(&TextureSemantics::OriginalHistory.semantics(0)) - { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - original, - device - ); + if let Some(binding) = texture_meta.get(&TextureSemantics::OriginalHistory.semantics(0)) { + Self::bind_texture(descriptor_set, sampler_set, binding, original, device); } // bind OriginalHistory0Size - if let Some(offset) = uniform_bindings - .get(&TextureSemantics::OriginalHistory.semantics(0).into()) + if let Some(offset) = + uniform_bindings.get(&TextureSemantics::OriginalHistory.semantics(0).into()) { - uniform_storage - .bind_vec4(offset.offset(), original.size(), offset.context()); + uniform_storage.bind_vec4(offset.offset(), original.size(), offset.context()); } // bind OriginalHistory1-.. @@ -207,16 +170,10 @@ pub trait BindSemantics> let history = history.as_ref(); - if let Some(binding) = texture_meta - .get(&TextureSemantics::OriginalHistory.semantics(index + 1)) + if let Some(binding) = + texture_meta.get(&TextureSemantics::OriginalHistory.semantics(index + 1)) { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - history, - device - ); + Self::bind_texture(descriptor_set, sampler_set, binding, history, device); } if let Some(offset) = uniform_bindings.get( @@ -224,8 +181,7 @@ pub trait BindSemantics> .semantics(index + 1) .into(), ) { - uniform_storage - .bind_vec4(offset.offset(), history.size(), offset.context()); + uniform_storage.bind_vec4(offset.offset(), history.size(), offset.context()); } } @@ -239,25 +195,15 @@ pub trait BindSemantics> let output = output.as_ref(); - if let Some(binding) = texture_meta - .get(&TextureSemantics::PassOutput.semantics(index)) + if let Some(binding) = texture_meta.get(&TextureSemantics::PassOutput.semantics(index)) { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - output, - device - ); + Self::bind_texture(descriptor_set, sampler_set, binding, output, device); } - if let Some(offset) = uniform_bindings.get( - &TextureSemantics::PassOutput - .semantics(index) - .into(), - ) { - uniform_storage - .bind_vec4(offset.offset(), output.size(), offset.context()); + if let Some(offset) = + uniform_bindings.get(&TextureSemantics::PassOutput.semantics(index).into()) + { + uniform_storage.bind_vec4(offset.offset(), output.size(), offset.context()); } } @@ -269,31 +215,21 @@ pub trait BindSemantics> let feedback = output.as_ref(); - if let Some(binding) = texture_meta - .get(&TextureSemantics::PassFeedback.semantics(index)) + if let Some(binding) = + texture_meta.get(&TextureSemantics::PassFeedback.semantics(index)) { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - feedback, - device - ); + Self::bind_texture(descriptor_set, sampler_set, binding, feedback, device); } - if let Some(offset) = uniform_bindings.get( - &TextureSemantics::PassFeedback - .semantics(index) - .into(), - ) { - uniform_storage - .bind_vec4(offset.offset(), feedback.size(), offset.context()); + if let Some(offset) = + uniform_bindings.get(&TextureSemantics::PassFeedback.semantics(index).into()) + { + uniform_storage.bind_vec4(offset.offset(), feedback.size(), offset.context()); } } // bind User parameters - for (id, offset) in - uniform_bindings + for (id, offset) in uniform_bindings .iter() .filter_map(|(binding, value)| match binding { UniformBinding::Parameter(id) => Some((id, value)), @@ -302,7 +238,8 @@ pub trait BindSemantics> { let id = id.as_str(); - let default = parameter_defaults.iter() + let default = parameter_defaults + .iter() .find(|&p| p.id == id) .map(|f| f.initial) .unwrap_or(0f32); @@ -315,24 +252,15 @@ pub trait BindSemantics> // bind luts for (index, lut) in lookup_textures { let lut = lut.as_ref(); - if let Some(binding) = texture_meta - .get(&TextureSemantics::User.semantics(index)) - { - Self::bind_texture( - descriptor_set, - sampler_set, - binding, - lut, - device - ); + if let Some(binding) = texture_meta.get(&TextureSemantics::User.semantics(index)) { + Self::bind_texture(descriptor_set, sampler_set, binding, lut, device); } - if let Some(offset) = uniform_bindings - .get(&TextureSemantics::User.semantics(index).into()) + if let Some(offset) = + uniform_bindings.get(&TextureSemantics::User.semantics(index).into()) { - uniform_storage - .bind_vec4(offset.offset(), lut.size(), offset.context()); + uniform_storage.bind_vec4(offset.offset(), lut.size(), offset.context()); } } } -} \ No newline at end of file +} diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index bb20a53..291032a 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -69,9 +69,9 @@ pub mod preprocess { pub mod reflect { /// Supported shader compiler targets. pub mod targets { - pub use librashader_reflect::back::targets::SPIRV; pub use librashader_reflect::back::targets::GLSL; pub use librashader_reflect::back::targets::HLSL; + pub use librashader_reflect::back::targets::SPIRV; } pub use librashader_reflect::error::*; @@ -94,8 +94,8 @@ pub mod reflect { /// Shader runtimes to execute a filter chain on a GPU surface. #[cfg(feature = "runtime")] pub mod runtime { + pub use librashader_common::{Size, Viewport}; pub use librashader_runtime::parameters::FilterChainParameters; - pub use librashader_common::{Viewport, Size}; #[cfg(feature = "gl")] /// Shader runtime for OpenGL 3.3+. @@ -104,13 +104,9 @@ pub mod runtime { /// initialized with [`gl::load_with`](https://docs.rs/gl/0.14.0/gl/fn.load_with.html). pub mod gl { pub use librashader_runtime_gl::{ - options::{ - FilterChainOptionsGL as FilterChainOptions, - FrameOptionsGL as FrameOptions, - }, - FilterChainGL as FilterChain, - Framebuffer, GLImage, - error + error, + options::{FilterChainOptionsGL as FilterChainOptions, FrameOptionsGL as FrameOptions}, + FilterChainGL as FilterChain, Framebuffer, GLImage, }; #[doc(hidden)] @@ -126,13 +122,11 @@ pub mod runtime { /// Shader runtime for Direct3D 11. pub mod d3d11 { pub use librashader_runtime_d3d11::{ + error, options::{ - FilterChainOptionsD3D11 as FilterChainOptions, - FrameOptionsD3D11 as FrameOptions, + FilterChainOptionsD3D11 as FilterChainOptions, FrameOptionsD3D11 as FrameOptions, }, - FilterChainD3D11 as FilterChain, - D3D11InputView, D3D11OutputView, - error + D3D11InputView, D3D11OutputView, FilterChainD3D11 as FilterChain, }; #[doc(hidden)] @@ -148,13 +142,11 @@ pub mod runtime { /// Shader runtime for Vulkan 1.3+. pub mod vk { pub use librashader_runtime_vk::{ + error, options::{ - FilterChainOptionsVulkan as FilterChainOptions, - FrameOptionsVulkan as FrameOptions, + FilterChainOptionsVulkan as FilterChainOptions, FrameOptionsVulkan as FrameOptions, }, - FilterChainVulkan as FilterChain, - VulkanImage, VulkanObjects, VulkanInstance, - error + FilterChainVulkan as FilterChain, VulkanImage, VulkanInstance, VulkanObjects, }; #[doc(hidden)]