From 19e8da7d854efa5c2575b7381e8ff52de7138395 Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 15 Jan 2023 11:08:13 -0500 Subject: [PATCH] chore: general cleanup --- librashader-capi/src/error.rs | 18 ++++----- librashader-capi/src/ffi.rs | 10 ++--- .../src/runtime/d3d11/filter_chain.rs | 6 +-- .../src/runtime/gl/filter_chain.rs | 2 +- .../src/runtime/vk/filter_chain.rs | 2 +- librashader-presets/src/preset.rs | 2 +- librashader-runtime-d3d11/src/filter_pass.rs | 16 +------- .../src/filter_chain/mod.rs | 2 +- librashader-runtime-gl/src/filter_pass.rs | 4 +- .../src/gl/gl3/hello_triangle.rs | 3 +- .../src/gl/gl46/hello_triangle.rs | 3 +- librashader-runtime-gl/src/texture.rs | 4 +- librashader-runtime-vk/src/filter_chain.rs | 8 ++-- librashader-runtime-vk/src/filter_pass.rs | 40 ++++--------------- librashader-runtime-vk/src/framebuffer.rs | 2 +- .../src/hello_triangle/command.rs | 2 +- .../src/hello_triangle/framebuffer.rs | 2 +- .../src/hello_triangle/mod.rs | 10 ++--- .../src/hello_triangle/physicaldevice.rs | 8 ++-- .../src/hello_triangle/pipeline.rs | 6 +-- .../src/hello_triangle/surface.rs | 4 +- .../src/hello_triangle/swapchain.rs | 6 +-- .../src/hello_triangle/vulkan_base.rs | 24 +++++------ librashader-runtime-vk/src/lib.rs | 4 +- librashader-runtime-vk/src/luts.rs | 4 +- librashader-runtime-vk/src/queue_selection.rs | 2 +- librashader-runtime-vk/src/texture.rs | 8 ++-- librashader-runtime-vk/src/util.rs | 2 +- .../src/vulkan_primitives.rs | 4 +- librashader-runtime-vk/src/vulkan_state.rs | 18 ++++----- librashader-runtime/src/binding.rs | 2 +- 31 files changed, 93 insertions(+), 135 deletions(-) diff --git a/librashader-capi/src/error.rs b/librashader-capi/src/error.rs index b3e7631..25f5ccb 100644 --- a/librashader-capi/src/error.rs +++ b/librashader-capi/src/error.rs @@ -61,7 +61,7 @@ pub type PFN_libra_error_errno = extern "C" fn(error: libra_error_t) -> LIBRA_ER /// /// ## Safety /// - `error` must be valid and initialized. -pub extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO { +pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO { let Some(error) = error else { return LIBRA_ERRNO::UNKNOWN_ERROR }; @@ -77,7 +77,7 @@ pub type PFN_libra_error_print = extern "C" fn(error: libra_error_t) -> i32; /// If `error` is null, this function does nothing and returns 1. Otherwise, this function returns 0. /// ## Safety /// - `error` must be a valid and initialized instance of `libra_error_t`. -pub extern "C" fn libra_error_print(error: libra_error_t) -> i32 { +pub unsafe extern "C" fn libra_error_print(error: libra_error_t) -> i32 { let Some(error) = error else { return 1 }; @@ -85,7 +85,7 @@ pub extern "C" fn libra_error_print(error: libra_error_t) -> i32 { let error = error.as_ref(); println!("{error:?}: {error}"); } - return 0; + 0 } /// Function pointer definition for libra_error_free @@ -97,7 +97,7 @@ pub type PFN_libra_error_free = extern "C" fn(error: *mut libra_error_t) -> i32; /// The resulting error object becomes null. /// ## Safety /// - `error` must be null or a pointer to a valid and initialized instance of `libra_error_t`. -pub extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 { +pub unsafe extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 { if error.is_null() { return 1; } @@ -109,7 +109,7 @@ pub extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 { }; unsafe { drop(Box::from_raw(error.as_ptr())) } - return 0; + 0 } /// Function pointer definition for libra_error_write @@ -122,7 +122,7 @@ pub type PFN_libra_error_write = /// ## Safety /// - `error` must be a valid and initialized instance of `libra_error_t`. /// - `out` must be a non-null pointer. The resulting string must not be modified. -pub extern "C" fn libra_error_write( +pub unsafe extern "C" fn libra_error_write( error: libra_error_t, out: *mut MaybeUninit<*mut c_char>, ) -> i32 { @@ -141,7 +141,7 @@ pub extern "C" fn libra_error_write( out.write(MaybeUninit::new(cstring.into_raw())) } - return 0; + 0 } /// Function pointer definition for libra_error_free_string @@ -154,7 +154,7 @@ pub type PFN_libra_error_free_string = extern "C" fn(out: *mut *mut c_char) -> i /// - If `libra_error_write` is not null, it must point to a string previously returned by `libra_error_write`. /// Attempting to free anything else, including strings or objects from other librashader functions, is immediate /// Undefined Behaviour. -pub extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 { +pub unsafe extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 { if out.is_null() { return 1; } @@ -164,7 +164,7 @@ pub extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 { *out = std::ptr::null_mut(); drop(CString::from_raw(ptr)) } - return 0; + 0 } impl LibrashaderError { diff --git a/librashader-capi/src/ffi.rs b/librashader-capi/src/ffi.rs index e22349a..49c379a 100644 --- a/librashader-capi/src/ffi.rs +++ b/librashader-capi/src/ffi.rs @@ -67,7 +67,7 @@ macro_rules! extern_fn { #[no_mangle] $(#[$($attrss)*])* - pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { + pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { $crate::ffi::ffi_body!($body) } }; @@ -81,7 +81,7 @@ macro_rules! extern_fn { #[no_mangle] $(#[$($attrss)*])* - pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { + pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { $body } }; @@ -95,7 +95,7 @@ macro_rules! extern_fn { #[no_mangle] $(#[$($attrss)*])* - pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { + pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { $crate::ffi::ffi_body!(|$($ref_capture),*|; mut |$($mut_capture),*| $body) } }; @@ -109,7 +109,7 @@ macro_rules! extern_fn { #[no_mangle] $(#[$($attrss)*])* - pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { + pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { $crate::ffi::ffi_body!(mut |$($mut_capture),*| $body) } }; @@ -122,7 +122,7 @@ macro_rules! extern_fn { #[no_mangle] $(#[$($attrss)*])* - pub extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { + pub unsafe extern "C" fn $func_name($($arg_name: $arg_ty,)*) -> $crate::ctypes::libra_error_t { $crate::ffi::ffi_body!(|$($ref_capture),*| $body) } }; diff --git a/librashader-capi/src/runtime/d3d11/filter_chain.rs b/librashader-capi/src/runtime/d3d11/filter_chain.rs index 2f8447d..8a00717 100644 --- a/librashader-capi/src/runtime/d3d11/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d11/filter_chain.rs @@ -35,7 +35,7 @@ impl TryFrom for D3D11InputView { assert_non_null!(noexport handle); Ok(D3D11InputView { - handle: unsafe { (&*handle).clone() }, + handle: unsafe { (*handle).clone() }, size: Size::new(value.width, value.height), }) } @@ -124,7 +124,7 @@ extern_fn! { y: viewport.y, output: D3D11OutputView { size: Size::new(viewport.width, viewport.height), - handle: unsafe { (&*out).clone() }, + handle: unsafe { (*out).clone() }, }, mvp, }; @@ -152,7 +152,7 @@ extern_fn! { let name = CStr::from_ptr(param_name); let name = name.to_str()?; - if let None = chain.set_parameter(name, value) { + if chain.set_parameter(name, value).is_none() { return LibrashaderError::UnknownShaderParameter(param_name).export() } } diff --git a/librashader-capi/src/runtime/gl/filter_chain.rs b/librashader-capi/src/runtime/gl/filter_chain.rs index 1af1bfc..a6e1897 100644 --- a/librashader-capi/src/runtime/gl/filter_chain.rs +++ b/librashader-capi/src/runtime/gl/filter_chain.rs @@ -170,7 +170,7 @@ extern_fn! { let name = CStr::from_ptr(param_name); let name = name.to_str()?; - if let None = chain.set_parameter(name, value) { + if chain.set_parameter(name, value).is_none() { return LibrashaderError::UnknownShaderParameter(param_name).export() } } diff --git a/librashader-capi/src/runtime/vk/filter_chain.rs b/librashader-capi/src/runtime/vk/filter_chain.rs index 190f19b..488e10b 100644 --- a/librashader-capi/src/runtime/vk/filter_chain.rs +++ b/librashader-capi/src/runtime/vk/filter_chain.rs @@ -181,7 +181,7 @@ extern_fn! { let name = CStr::from_ptr(param_name); let name = name.to_str()?; - if let None = chain.set_parameter(name, value) { + if chain.set_parameter(name, value).is_none() { return LibrashaderError::UnknownShaderParameter(param_name).export() } } diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index b1dfc02..c409ca5 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -38,7 +38,7 @@ impl ShaderPassConfig { } else if self.float_framebuffer { return Some(ImageFormat::R16G16B16A16Sfloat); } - return None; + None } } diff --git a/librashader-runtime-d3d11/src/filter_pass.rs b/librashader-runtime-d3d11/src/filter_pass.rs index b556eed..c8c21a0 100644 --- a/librashader-runtime-d3d11/src/filter_pass.rs +++ b/librashader-runtime-d3d11/src/filter_pass.rs @@ -6,7 +6,7 @@ use librashader_presets::ShaderPassConfig; use librashader_reflect::back::cross::CrossHlslContext; use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::reflect::semantics::{ - BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, + BindingStage, MemberOffset, TextureBinding, UniformBinding, }; use librashader_reflect::reflect::ShaderReflection; use rustc_hash::FxHashMap; @@ -94,18 +94,6 @@ impl FilterPass { } } - fn bind_texture( - samplers: &SamplerSet, - texture_binding: &mut [Option; 16], - sampler_binding: &mut [Option; 16], - binding: &TextureBinding, - texture: &InputTexture, - ) { - texture_binding[binding.binding as usize] = Some(texture.view.handle.clone()); - sampler_binding[binding.binding as usize] = - Some(samplers.get(texture.wrap_mode, texture.filter).clone()); - } - // framecount should be pre-modded fn build_semantics<'a>( &mut self, @@ -175,7 +163,7 @@ impl FilterPass { let mut textures: [Option; 16] = std::array::from_fn(|_| None); let mut samplers: [Option; 16] = std::array::from_fn(|_| None); - let mut descriptors = (&mut textures, &mut samplers); + let descriptors = (&mut textures, &mut samplers); self.build_semantics( pass_index, diff --git a/librashader-runtime-gl/src/filter_chain/mod.rs b/librashader-runtime-gl/src/filter_chain/mod.rs index 97b5ee8..c87c69b 100644 --- a/librashader-runtime-gl/src/filter_chain/mod.rs +++ b/librashader-runtime-gl/src/filter_chain/mod.rs @@ -39,7 +39,7 @@ impl FilterChainGL { }) }); match result { - Err(_) => return Err(FilterChainError::GLLoadError), + Err(_) => Err(FilterChainError::GLLoadError), Ok(res) => res, } } diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index 06c6c32..16a4bf7 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -7,7 +7,7 @@ use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{ - MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, + MemberOffset, TextureBinding, UniformBinding, }; use librashader_runtime::binding::{BindSemantics, ContextOffset, TextureInput}; use rustc_hash::FxHashMap; @@ -74,7 +74,7 @@ impl BindSemantics> for texture: &Self::InputTexture, _device: &Self::DeviceContext, ) { - T::BindTexture::bind_texture(&samplers, binding, texture); + T::BindTexture::bind_texture(samplers, binding, texture); } } diff --git a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs index 9834383..480c4e2 100644 --- a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs @@ -9,8 +9,7 @@ use librashader_common::{Size, Viewport}; use crate::filter_chain::FilterChainGL; use crate::framebuffer::GLImage; -use crate::gl::gl3::CompatibilityGL; -use crate::gl::{FramebufferInterface, GLInterface}; + use crate::Framebuffer; const WIDTH: u32 = 800; diff --git a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs index f0418bf..df09d02 100644 --- a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs @@ -9,8 +9,7 @@ use librashader_common::{Size, Viewport}; use crate::filter_chain::FilterChainGL; use crate::framebuffer::GLImage; -use crate::gl::gl46::DirectStateAccessGL; -use crate::gl::{FramebufferInterface, GLInterface}; + use crate::Framebuffer; const WIDTH: u32 = 800; diff --git a/librashader-runtime-gl/src/texture.rs b/librashader-runtime-gl/src/texture.rs index 798a4ed..959cade 100644 --- a/librashader-runtime-gl/src/texture.rs +++ b/librashader-runtime-gl/src/texture.rs @@ -1,5 +1,5 @@ use crate::framebuffer::GLImage; -use gl::types::GLuint; + use librashader_common::{FilterMode, WrapMode}; #[derive(Default, Debug, Copy, Clone)] @@ -18,7 +18,7 @@ impl InputTexture { /// Returns a reference to itself if the texture is bound. pub fn bound(&self) -> Option<&Self> { if self.is_bound() { - Some(&self) + Some(self) } else { None } diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 0ffbae0..a97419a 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -505,7 +505,7 @@ impl FilterChainVulkan { // eprintln!("[history] using frame history with {required_images} images"); let mut images = Vec::with_capacity(required_images); images.resize_with(required_images, || { - OwnedImage::new(&vulkan, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, 1) + OwnedImage::new(vulkan, Size::new(1, 1), ImageFormat::R8G8B8A8Unorm, 1) }); let images: error::Result> = images.into_iter().collect(); @@ -553,7 +553,7 @@ impl FilterChainVulkan { vk::QUEUE_FAMILY_IGNORED, ); - back.copy_from(cmd, &input, vk::ImageLayout::TRANSFER_SRC_OPTIMAL); + back.copy_from(cmd, input, vk::ImageLayout::TRANSFER_SRC_OPTIMAL); util::vulkan_image_layout_transition_levels( &self.vulkan.device, @@ -729,7 +729,7 @@ impl FilterChainVulkan { frame_direction, viewport, &original, - &source, + source, &out, )?; @@ -739,7 +739,7 @@ impl FilterChainVulkan { out.output.end_pass(cmd); } - source = &self.common.output_inputs[index].as_ref().unwrap(); + source = self.common.output_inputs[index].as_ref().unwrap(); intermediates.dispose_outputs(out.output); } diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index 24c1773..20d926b 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -10,12 +10,12 @@ use librashader_common::{ImageFormat, Size, Viewport}; use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{ - BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, + BindingStage, MemberOffset, TextureBinding, UniformBinding, }; use librashader_reflect::reflect::ShaderReflection; use librashader_runtime::binding::{BindSemantics, TextureInput}; use librashader_runtime::uniforms::{ - BindUniform, NoUniformBinder, UniformStorage, UniformStorageAccess, + UniformStorage, UniformStorageAccess, }; use rustc_hash::FxHashMap; use std::sync::Arc; @@ -46,6 +46,7 @@ impl BindSemantics for FilterPass { type DeviceContext = Arc; type UniformOffset = MemberOffset; + #[inline(always)] fn bind_texture<'a>( descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, @@ -74,33 +75,6 @@ impl BindSemantics for FilterPass { } impl FilterPass { - #[inline(always)] - fn bind_texture( - device: &ash::Device, - samplers: &SamplerSet, - descriptor_set: vk::DescriptorSet, - binding: &TextureBinding, - texture: &InputImage, - ) { - let sampler = samplers.get(texture.wrap_mode, texture.filter_mode, texture.mip_filter); - let image_info = [vk::DescriptorImageInfo::builder() - .sampler(sampler.handle) - .image_view(texture.image_view) - .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) - .build()]; - - let write_desc = [vk::WriteDescriptorSet::builder() - .dst_set(descriptor_set) - .dst_binding(binding.binding) - .dst_array_element(0) - .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(&image_info) - .build()]; - unsafe { - device.update_descriptor_sets(&write_desc, &[]); - } - } - pub fn get_format(&self) -> ImageFormat { let fb_format = self.source.format; if let Some(format) = self.config.get_format_override() { @@ -124,13 +98,13 @@ impl FilterPass { source: &InputImage, output: &RenderTarget, ) -> error::Result<()> { - let mut descriptor = *&self.graphics_pipeline.layout.descriptor_sets + let mut descriptor = self.graphics_pipeline.layout.descriptor_sets [(frame_count % self.frames_in_flight) as usize]; self.build_semantics( pass_index, parent, - &output.mvp, + output.mvp, frame_count, frame_direction, output.output.size, @@ -231,7 +205,7 @@ impl FilterPass { frame_direction: i32, fb_size: Size, viewport_size: Size, - mut descriptor_set: &mut vk::DescriptorSet, + descriptor_set: &mut vk::DescriptorSet, original: &InputImage, source: &InputImage, ) { @@ -239,7 +213,7 @@ impl FilterPass { &self.device, &parent.samplers, &mut self.uniform_storage, - &mut descriptor_set, + descriptor_set, mvp, frame_count, frame_direction, diff --git a/librashader-runtime-vk/src/framebuffer.rs b/librashader-runtime-vk/src/framebuffer.rs index 2f049e9..0c89e56 100644 --- a/librashader-runtime-vk/src/framebuffer.rs +++ b/librashader-runtime-vk/src/framebuffer.rs @@ -33,7 +33,7 @@ impl OutputImage { let view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(image.format) - .image(image.image.clone()) + .image(image.image) .subresource_range(image_subresource) .components(swizzle_components) .build(); diff --git a/librashader-runtime-vk/src/hello_triangle/command.rs b/librashader-runtime-vk/src/hello_triangle/command.rs index a637e11..f34ad97 100644 --- a/librashader-runtime-vk/src/hello_triangle/command.rs +++ b/librashader-runtime-vk/src/hello_triangle/command.rs @@ -12,7 +12,7 @@ pub struct VulkanCommandPool { impl VulkanCommandPool { pub fn new(base: &VulkanBase, frames_in_flight: u32) -> VkResult { - let indices = find_queue_family(&base.instance, base.physical_device.clone()); + let indices = find_queue_family(&base.instance, base.physical_device); let create_info = vk::CommandPoolCreateInfo::builder() .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) diff --git a/librashader-runtime-vk/src/hello_triangle/framebuffer.rs b/librashader-runtime-vk/src/hello_triangle/framebuffer.rs index 95d3b83..33a8082 100644 --- a/librashader-runtime-vk/src/hello_triangle/framebuffer.rs +++ b/librashader-runtime-vk/src/hello_triangle/framebuffer.rs @@ -1,4 +1,4 @@ -use crate::hello_triangle::swapchain::VulkanSwapchain; + use ash::prelude::VkResult; use ash::vk; diff --git a/librashader-runtime-vk/src/hello_triangle/mod.rs b/librashader-runtime-vk/src/hello_triangle/mod.rs index afec805..4aa27b2 100644 --- a/librashader-runtime-vk/src/hello_triangle/mod.rs +++ b/librashader-runtime-vk/src/hello_triangle/mod.rs @@ -8,7 +8,7 @@ mod swapchain; mod syncobjects; pub mod vulkan_base; -use crate::filter_chain::{FilterChainVulkan, VulkanObjects}; +use crate::filter_chain::{FilterChainVulkan}; use crate::hello_triangle::command::VulkanCommandPool; use crate::hello_triangle::framebuffer::VulkanFramebuffer; use crate::hello_triangle::pipeline::VulkanPipeline; @@ -19,15 +19,15 @@ use crate::hello_triangle::vulkan_base::VulkanBase; 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; // Constants -const WINDOW_TITLE: &'static str = "librashader Vulkan"; +const WINDOW_TITLE: &str = "librashader Vulkan"; const WINDOW_WIDTH: u32 = 800; const WINDOW_HEIGHT: u32 = 600; const MAX_FRAMES_IN_FLIGHT: usize = 3; @@ -384,7 +384,7 @@ pub fn main(vulkan: VulkanBase, filter_chain: FilterChainVulkan) { let pipeline = unsafe { VulkanPipeline::new(&vulkan, &swapchain) }.unwrap(); let mut render_framebuffers = vec![]; - for (index, image) in swapchain.render_image_views.iter().enumerate() { + for (_index, image) in swapchain.render_image_views.iter().enumerate() { render_framebuffers.push( VulkanFramebuffer::new( &vulkan.device, diff --git a/librashader-runtime-vk/src/hello_triangle/physicaldevice.rs b/librashader-runtime-vk/src/hello_triangle/physicaldevice.rs index 93ac62d..77b8428 100644 --- a/librashader-runtime-vk/src/hello_triangle/physicaldevice.rs +++ b/librashader-runtime-vk/src/hello_triangle/physicaldevice.rs @@ -24,10 +24,8 @@ pub(crate) fn pick_physical_device(instance: &ash::Instance) -> vk::PhysicalDevi let mut result = None; for &physical_device in physical_devices.iter() { - if is_physical_device_suitable(instance, physical_device) { - if result.is_none() { - result = Some(physical_device) - } + if is_physical_device_suitable(instance, physical_device) && result.is_none() { + result = Some(physical_device) } } @@ -113,7 +111,7 @@ fn is_physical_device_suitable( let indices = find_queue_family(instance, physical_device); - return indices.is_complete(); + indices.is_complete() } pub fn find_queue_family( diff --git a/librashader-runtime-vk/src/hello_triangle/pipeline.rs b/librashader-runtime-vk/src/hello_triangle/pipeline.rs index f7b0403..5895a7e 100644 --- a/librashader-runtime-vk/src/hello_triangle/pipeline.rs +++ b/librashader-runtime-vk/src/hello_triangle/pipeline.rs @@ -1,15 +1,15 @@ use crate::hello_triangle::find_memorytype_index; -use crate::hello_triangle::surface::VulkanSurface; + use crate::hello_triangle::swapchain::VulkanSwapchain; use crate::hello_triangle::vulkan_base::VulkanBase; use ash::prelude::VkResult; use ash::util::{read_spv, Align}; use ash::vk; -use bytemuck::offset_of; + use std::ffi::CStr; use std::io::Cursor; use std::mem::align_of; -const ENTRY_POINT: &'static CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") }; +const ENTRY_POINT: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") }; #[derive(Default, Clone, Debug, Copy)] struct Vertex { diff --git a/librashader-runtime-vk/src/hello_triangle/surface.rs b/librashader-runtime-vk/src/hello_triangle/surface.rs index 0fe077e..7daac6b 100644 --- a/librashader-runtime-vk/src/hello_triangle/surface.rs +++ b/librashader-runtime-vk/src/hello_triangle/surface.rs @@ -65,11 +65,11 @@ impl VulkanSurface { if available_format.format == vk::Format::B8G8R8A8_SRGB && available_format.color_space == vk::ColorSpaceKHR::SRGB_NONLINEAR { - return Ok(available_format.clone()); + return Ok(*available_format); } } - return Ok(available_formats.first().unwrap().clone()); + return Ok(*available_formats.first().unwrap()); } } diff --git a/librashader-runtime-vk/src/hello_triangle/swapchain.rs b/librashader-runtime-vk/src/hello_triangle/swapchain.rs index 00bc67d..59cc849 100644 --- a/librashader-runtime-vk/src/hello_triangle/swapchain.rs +++ b/librashader-runtime-vk/src/hello_triangle/swapchain.rs @@ -4,8 +4,8 @@ use crate::util::find_vulkan_memory_type; use crate::vulkan_primitives::VulkanImageMemory; use ash::prelude::VkResult; use ash::vk; -use ash::vk::{Extent3D, Handle}; -use std::ffi::CStr; +use ash::vk::{Extent3D}; + use std::sync::Arc; pub struct VulkanSwapchain { @@ -93,7 +93,7 @@ impl VulkanSwapchain { unsafe { let image = base.device.create_image(&create_info, None)?; - let mem_reqs = unsafe { base.device.get_image_memory_requirements(image.clone()) }; + let mem_reqs = unsafe { base.device.get_image_memory_requirements(image) }; // base.debug // .loader diff --git a/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs b/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs index 6a35e21..2f1f9c4 100644 --- a/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs +++ b/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs @@ -1,18 +1,18 @@ use ash::vk; -use std::borrow::Cow; -use std::error::Error; + + use crate::error::FilterChainError; use crate::filter_chain::VulkanObjects; use crate::hello_triangle::debug::VulkanDebug; use crate::hello_triangle::physicaldevice::{find_queue_family, pick_physical_device}; -use crate::hello_triangle::surface::VulkanSurface; + use ash::prelude::VkResult; -use std::ffi::{CStr, CString}; +use std::ffi::{CStr}; use std::sync::Arc; -const WINDOW_TITLE: &'static [u8] = b"librashader Vulkan\0"; -const KHRONOS_VALIDATION: &'static [u8] = b"VK_LAYER_KHRONOS_validation\0"; +const WINDOW_TITLE: &[u8] = b"librashader Vulkan\0"; +const KHRONOS_VALIDATION: &[u8] = b"VK_LAYER_KHRONOS_validation\0"; pub struct VulkanBase { pub entry: ash::Entry, @@ -27,8 +27,8 @@ pub struct VulkanBase { impl VulkanBase { pub fn new(entry: ash::Entry) -> VkResult { let app_info = vk::ApplicationInfo::builder() - .application_name(unsafe { &CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) }) - .engine_name(unsafe { &CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) }) + .application_name(unsafe { CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) }) + .engine_name(unsafe { CStr::from_bytes_with_nul_unchecked(WINDOW_TITLE) }) .engine_version(0) .application_version(0) .api_version(vk::make_api_version(0, 1, 3, 0)) @@ -80,7 +80,7 @@ impl VulkanBase { ) -> VkResult<(ash::Device, vk::Queue)> { let debug = [unsafe { CStr::from_bytes_with_nul_unchecked(KHRONOS_VALIDATION).as_ptr() }]; - let indices = find_queue_family(&instance, *physical_device); + let indices = find_queue_family(instance, *physical_device); let queue_info = [vk::DeviceQueueCreateInfo::builder() .queue_family_index(indices.graphics_family()) .queue_priorities(&[1.0f32]) @@ -119,9 +119,9 @@ impl VulkanBase { } unsafe extern "system" fn vulkan_debug_callback( - message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, - message_type: vk::DebugUtilsMessageTypeFlagsEXT, - p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT, + _message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, + _message_type: vk::DebugUtilsMessageTypeFlagsEXT, + _p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT, _user_data: *mut std::os::raw::c_void, ) -> vk::Bool32 { // let callback_data = *p_callback_data; diff --git a/librashader-runtime-vk/src/lib.rs b/librashader-runtime-vk/src/lib.rs index ff4bb91..743330b 100644 --- a/librashader-runtime-vk/src/lib.rs +++ b/librashader-runtime-vk/src/lib.rs @@ -29,7 +29,7 @@ pub mod options; #[cfg(test)] mod tests { - use super::*; + use crate::filter_chain::FilterChainVulkan; use crate::hello_triangle::vulkan_base::VulkanBase; @@ -38,7 +38,7 @@ mod tests { let entry = unsafe { ash::Entry::load().unwrap() }; let base = VulkanBase::new(entry).unwrap(); dbg!("finished"); - let mut filter = FilterChainVulkan::load_from_path( + let filter = FilterChainVulkan::load_from_path( &base, // "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp", "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", diff --git a/librashader-runtime-vk/src/luts.rs b/librashader-runtime-vk/src/luts.rs index d219d5d..fd6cfa2 100644 --- a/librashader-runtime-vk/src/luts.rs +++ b/librashader-runtime-vk/src/luts.rs @@ -45,7 +45,7 @@ impl LutTexture { let texture = unsafe { vulkan.device.create_image(&image_info, None)? }; let memory = unsafe { - let mem_reqs = vulkan.device.get_image_memory_requirements(texture.clone()); + let mem_reqs = vulkan.device.get_image_memory_requirements(texture); let mem_type = util::find_vulkan_memory_type( &vulkan.memory_properties, mem_reqs.memory_type_bits, @@ -77,7 +77,7 @@ impl LutTexture { let view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(vk::Format::B8G8R8A8_UNORM) - .image(texture.clone()) + .image(texture) .subresource_range(image_subresource) .components(swizzle_components) .build(); diff --git a/librashader-runtime-vk/src/queue_selection.rs b/librashader-runtime-vk/src/queue_selection.rs index 924969a..9f2c2a7 100644 --- a/librashader-runtime-vk/src/queue_selection.rs +++ b/librashader-runtime-vk/src/queue_selection.rs @@ -15,7 +15,7 @@ fn find_graphics_queue_family( } } - return 0; + 0 } pub fn get_graphics_queue( diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index e266b72..f695714 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -59,7 +59,7 @@ impl OwnedImage { .build(); let image = unsafe { device.create_image(&image_create_info, None)? }; - let mem_reqs = unsafe { device.get_image_memory_requirements(image.clone()) }; + let mem_reqs = unsafe { device.get_image_memory_requirements(image) }; let alloc_info = vk::MemoryAllocateInfo::builder() .allocation_size(mem_reqs.size) @@ -92,7 +92,7 @@ impl OwnedImage { let view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(format.into()) - .image(image.clone()) + .image(image) .subresource_range(image_subresource) .components(swizzle_components) .build(); @@ -186,7 +186,7 @@ impl OwnedImage { pub(crate) fn as_input(&self, filter: FilterMode, wrap_mode: WrapMode) -> InputImage { InputImage { image: self.image.clone(), - image_view: self.image_view.clone(), + image_view: self.image_view, wrap_mode, filter_mode: filter, mip_filter: filter, @@ -530,6 +530,6 @@ pub struct InputImage { impl AsRef for InputImage { fn as_ref(&self) -> &InputImage { - &self + self } } diff --git a/librashader-runtime-vk/src/util.rs b/librashader-runtime-vk/src/util.rs index f3f2f96..2d7ccbe 100644 --- a/librashader-runtime-vk/src/util.rs +++ b/librashader-runtime-vk/src/util.rs @@ -66,7 +66,7 @@ pub unsafe fn vulkan_image_layout_transition_levels( barrier.new_layout = new_layout; barrier.src_queue_family_index = src_queue_family_index; barrier.dst_queue_family_index = dst_queue_family_index; - barrier.image = image.clone(); + barrier.image = image; barrier.subresource_range.aspect_mask = vk::ImageAspectFlags::COLOR; barrier.subresource_range.base_array_layer = 0; barrier.subresource_range.level_count = levels; diff --git a/librashader-runtime-vk/src/vulkan_primitives.rs b/librashader-runtime-vk/src/vulkan_primitives.rs index 70458ce..dfcc4f6 100644 --- a/librashader-runtime-vk/src/vulkan_primitives.rs +++ b/librashader-runtime-vk/src/vulkan_primitives.rs @@ -25,7 +25,7 @@ impl VulkanImageMemory { unsafe { Ok(self .device - .bind_image_memory(image.clone(), self.handle.clone(), 0)?) + .bind_image_memory(*image, self.handle, 0)?) } } } @@ -76,7 +76,7 @@ impl VulkanBuffer { .build(); let alloc = device.allocate_memory(&alloc_info, None)?; - device.bind_buffer_memory(buffer.clone(), alloc.clone(), 0)?; + device.bind_buffer_memory(buffer, alloc, 0)?; Ok(VulkanBuffer { handle: buffer, diff --git a/librashader-runtime-vk/src/vulkan_state.rs b/librashader-runtime-vk/src/vulkan_state.rs index 701a62c..55f3894 100644 --- a/librashader-runtime-vk/src/vulkan_state.rs +++ b/librashader-runtime-vk/src/vulkan_state.rs @@ -6,7 +6,7 @@ use librashader_reflect::reflect::semantics::{TextureBinding, UboReflection}; use librashader_reflect::reflect::ShaderReflection; use std::ffi::CStr; -const ENTRY_POINT: &'static CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") }; +const ENTRY_POINT: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") }; pub struct PipelineDescriptors { pub replicas: u32, @@ -138,12 +138,12 @@ impl PipelineLayoutObjects { let descriptor_sets: Vec = descriptor_sets.into_iter().flatten().collect(); - return Ok(PipelineLayoutObjects { + Ok(PipelineLayoutObjects { layout, descriptor_set_layout, descriptor_sets, pool, - }); + }) } } @@ -184,7 +184,7 @@ impl VulkanGraphicsPipeline { replicas: u32, ) -> error::Result { // shader_vulkan 1927 (init_pipeline_layout) - let pipeline_layout = PipelineLayoutObjects::new(&reflection, replicas, device)?; + let pipeline_layout = PipelineLayoutObjects::new(reflection, replicas, device)?; let input_assembly = vk::PipelineInputAssemblyStateCreateInfo::builder() .topology(vk::PrimitiveTopology::TRIANGLE_STRIP) @@ -271,13 +271,13 @@ impl VulkanGraphicsPipeline { let shader_stages = [ vk::PipelineShaderStageCreateInfo::builder() .stage(vk::ShaderStageFlags::VERTEX) - .name(&ENTRY_POINT) - .module(vertex_module.shader.clone()) + .name(ENTRY_POINT) + .module(vertex_module.shader) .build(), vk::PipelineShaderStageCreateInfo::builder() .stage(vk::ShaderStageFlags::FRAGMENT) - .name(&ENTRY_POINT) - .module(fragment_module.shader.clone()) + .name(ENTRY_POINT) + .module(fragment_module.shader) .build(), ]; @@ -297,7 +297,7 @@ impl VulkanGraphicsPipeline { let pipeline = unsafe { // panic_safety: if this is successful this should return 1 pipelines. device - .create_graphics_pipelines(cache.clone(), &[pipeline_info], None) + .create_graphics_pipelines(*cache, &[pipeline_info], None) .map_err(|e| e.1) .unwrap()[0] }; diff --git a/librashader-runtime/src/binding.rs b/librashader-runtime/src/binding.rs index 305f01d..f8522d0 100644 --- a/librashader-runtime/src/binding.rs +++ b/librashader-runtime/src/binding.rs @@ -79,7 +79,7 @@ where device: &Self::DeviceContext, ); - #[clippy::allow(too_many_arguments)] + #[allow(clippy::too_many_arguments)] /// Write uniform and texture semantics to the provided storages. fn bind_semantics<'a>( device: &Self::DeviceContext,