From 2450217c2916dac86ae997527cc407a0c5c8c770 Mon Sep 17 00:00:00 2001 From: chyyran Date: Tue, 6 Feb 2024 01:32:08 -0500 Subject: [PATCH] fmt: cargo fmt --- librashader-cache/src/compilation.rs | 2 +- librashader-common/src/wgpu.rs | 6 +- librashader-presets/src/extract_if.rs | 89 +++++++-------- librashader-presets/src/lib.rs | 2 +- librashader-presets/src/parse/preset.rs | 2 +- librashader-reflect/src/reflect/cross.rs | 4 +- librashader-reflect/src/reflect/naga.rs | 37 +++---- librashader-runtime-gl/src/gl/mod.rs | 2 +- librashader-runtime-vk/src/filter_pass.rs | 4 +- .../src/graphics_pipeline.rs | 12 +- librashader-runtime-vk/tests/triangle.rs | 2 +- librashader-runtime-wgpu/src/buffer.rs | 2 +- librashader-runtime-wgpu/src/filter_chain.rs | 43 +++++--- librashader-runtime-wgpu/src/framebuffer.rs | 2 - .../tests/hello_triangle.rs | 103 +++++++++--------- librashader-runtime/src/array_chunks_mut.rs | 9 +- librashader-runtime/src/image.rs | 2 +- 17 files changed, 163 insertions(+), 160 deletions(-) diff --git a/librashader-cache/src/compilation.rs b/librashader-cache/src/compilation.rs index 3f25ad5..b0bddb1 100644 --- a/librashader-cache/src/compilation.rs +++ b/librashader-cache/src/compilation.rs @@ -1,8 +1,8 @@ //! Cache helpers for `ShaderCompilation` objects to cache compiled SPIRV. use librashader_preprocess::ShaderSource; -use librashader_reflect::back::targets::{GLSL, HLSL, SPIRV}; #[cfg(all(target_os = "windows", feature = "d3d"))] use librashader_reflect::back::targets::DXIL; +use librashader_reflect::back::targets::{GLSL, HLSL, SPIRV}; use librashader_reflect::back::{CompilerBackend, FromCompilation}; use librashader_reflect::error::{ShaderCompileError, ShaderReflectError}; diff --git a/librashader-common/src/wgpu.rs b/librashader-common/src/wgpu.rs index a9c9637..3a7398e 100644 --- a/librashader-common/src/wgpu.rs +++ b/librashader-common/src/wgpu.rs @@ -71,7 +71,7 @@ impl From for ImageFormat { wgpu_types::TextureFormat::Rgba32Uint => ImageFormat::R32G32B32A32Uint, wgpu_types::TextureFormat::Rgba32Sint => ImageFormat::R32G32B32A32Sint, wgpu_types::TextureFormat::Rgba32Float => ImageFormat::R32G32B32A32Sfloat, - _ => ImageFormat::Unknown + _ => ImageFormat::Unknown, } } } @@ -155,8 +155,6 @@ impl From for wgpu_types::FilterMode { } } - - impl From for wgpu_types::AddressMode { fn from(value: WrapMode) -> Self { match value { @@ -176,4 +174,4 @@ impl From> for wgpu_types::Extent3d { depth_or_array_layers: 1, } } -} \ No newline at end of file +} diff --git a/librashader-presets/src/extract_if.rs b/librashader-presets/src/extract_if.rs index 5cc403d..7f38dc4 100644 --- a/librashader-presets/src/extract_if.rs +++ b/librashader-presets/src/extract_if.rs @@ -5,7 +5,6 @@ use core::slice; /// Polyfill trait for [`Vec::extract_if`](https://github.com/rust-lang/rust/issues/43244). pub(crate) trait MakeExtractIf { - /// Creates an iterator which uses a closure to determine if an element should be removed. /// /// If the closure returns true, then the element is removed and yielded. @@ -33,14 +32,14 @@ pub(crate) trait MakeExtractIf { /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); /// ``` fn extract_if(&mut self, filter: F) -> ExtractIf - where - F: FnMut(&mut T) -> bool; + where + F: FnMut(&mut T) -> bool; } impl MakeExtractIf for Vec { fn extract_if(&mut self, filter: F) -> ExtractIf - where - F: FnMut(&mut T) -> bool, + where + F: FnMut(&mut T) -> bool, { let old_len = self.len(); @@ -74,8 +73,8 @@ impl MakeExtractIf for Vec { #[derive(Debug)] #[must_use = "iterators are lazy and do nothing unless consumed"] pub struct ExtractIf<'a, T, F> - where - F: FnMut(&mut T) -> bool, +where + F: FnMut(&mut T) -> bool, { vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -89,8 +88,8 @@ pub struct ExtractIf<'a, T, F> } impl Iterator for ExtractIf<'_, T, F> - where - F: FnMut(&mut T) -> bool, +where + F: FnMut(&mut T) -> bool, { type Item = T; @@ -124,8 +123,8 @@ impl Iterator for ExtractIf<'_, T, F> } impl Drop for ExtractIf<'_, T, F> - where - F: FnMut(&mut T) -> bool, +where + F: FnMut(&mut T) -> bool, { fn drop(&mut self) { unsafe { @@ -235,35 +234,30 @@ mod test { #[test] fn drain_filter_complex() { - - { // [+xxx++++++xxxxx++++x+x++] - let mut vec = vec![1, - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36, - 37, 39]; + { + // [+xxx++++++xxxxx++++x+x++] + let mut vec = vec![ + 1, 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, + 37, 39, + ]; let removed = vec.extract_if(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); assert_eq!(removed, vec![2, 4, 6, 18, 20, 22, 24, 26, 34, 36]); assert_eq!(vec.len(), 14); - assert_eq!(vec, vec![1, 7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39]); + assert_eq!( + vec, + vec![1, 7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39] + ); } - { // [xxx++++++xxxxx++++x+x++] - let mut vec = vec![2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36, - 37, 39]; + { + // [xxx++++++xxxxx++++x+x++] + let mut vec = vec![ + 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, + 39, + ]; let removed = vec.extract_if(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -273,14 +267,11 @@ mod test { assert_eq!(vec, vec![7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39]); } - { // [xxx++++++xxxxx++++x+x] - let mut vec = vec![2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36]; + { + // [xxx++++++xxxxx++++x+x] + let mut vec = vec![ + 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, + ]; let removed = vec.extract_if(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -290,9 +281,11 @@ mod test { assert_eq!(vec, vec![7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35]); } - { // [xxxxxxxxxx+++++++++++] - let mut vec = vec![2, 4, 6, 8, 10, 12, 14, 16, 18, 20, - 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]; + { + // [xxxxxxxxxx+++++++++++] + let mut vec = vec![ + 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, + ]; let removed = vec.extract_if(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -302,9 +295,11 @@ mod test { assert_eq!(vec, vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19]); } - { // [+++++++++++xxxxxxxxxx] - let mut vec = vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19, - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]; + { + // [+++++++++++xxxxxxxxxx] + let mut vec = vec![ + 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, + ]; let removed = vec.extract_if(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -314,4 +309,4 @@ mod test { assert_eq!(vec, vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19]); } } -} \ No newline at end of file +} diff --git a/librashader-presets/src/lib.rs b/librashader-presets/src/lib.rs index ac19c5f..3200ffd 100644 --- a/librashader-presets/src/lib.rs +++ b/librashader-presets/src/lib.rs @@ -11,9 +11,9 @@ #![allow(unstable_name_collisions)] mod error; +mod extract_if; mod parse; mod preset; -mod extract_if; pub use error::*; pub use preset::*; diff --git a/librashader-presets/src/parse/preset.rs b/librashader-presets/src/parse/preset.rs index cb904d0..58efa21 100644 --- a/librashader-presets/src/parse/preset.rs +++ b/librashader-presets/src/parse/preset.rs @@ -1,7 +1,7 @@ +use crate::extract_if::MakeExtractIf; use crate::parse::remove_if; use crate::parse::value::Value; use crate::{ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPreset, TextureConfig}; -use crate::extract_if::MakeExtractIf; pub fn resolve_values(mut values: Vec) -> ShaderPreset { let textures: Vec = values diff --git a/librashader-reflect/src/reflect/cross.rs b/librashader-reflect/src/reflect/cross.rs index 88b6146..51e4a21 100644 --- a/librashader-reflect/src/reflect/cross.rs +++ b/librashader-reflect/src/reflect/cross.rs @@ -1,8 +1,8 @@ use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError}; use crate::front::GlslangCompilation; use crate::reflect::semantics::{ - BindingMeta, BindingStage, MemberOffset, ShaderReflection, ShaderSemantics, - TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, BufferReflection, + BindingMeta, BindingStage, BufferReflection, MemberOffset, ShaderReflection, ShaderSemantics, + TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UniformMemberBlock, UniqueSemanticMap, UniqueSemantics, ValidateTypeSemantics, VariableMeta, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, }; diff --git a/librashader-reflect/src/reflect/naga.rs b/librashader-reflect/src/reflect/naga.rs index 5ed99e0..97e6834 100644 --- a/librashader-reflect/src/reflect/naga.rs +++ b/librashader-reflect/src/reflect/naga.rs @@ -1,13 +1,16 @@ use crate::error::{SemanticsErrorKind, ShaderReflectError}; -use naga::{AddressSpace, Binding, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, Scalar, ScalarKind, TypeInner, VectorSize}; +use naga::{ + AddressSpace, Binding, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, Scalar, + ScalarKind, TypeInner, VectorSize, +}; use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; use crate::reflect::semantics::{ - BindingMeta, BindingStage, MemberOffset, ShaderSemantics, TextureBinding, - TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, BufferReflection, - UniformMemberBlock, UniqueSemanticMap, UniqueSemantics, ValidateTypeSemantics, VariableMeta, - MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, + BindingMeta, BindingStage, BufferReflection, MemberOffset, ShaderSemantics, TextureBinding, + TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UniformMemberBlock, + UniqueSemanticMap, UniqueSemantics, ValidateTypeSemantics, VariableMeta, MAX_BINDINGS_COUNT, + MAX_PUSH_BUFFER_SIZE, }; use crate::reflect::{align_uniform_size, ReflectShader, ShaderReflection}; @@ -82,7 +85,11 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics { impl ValidateTypeSemantics<&TypeInner> for TextureSemantics { fn validate_type(&self, ty: &&TypeInner) -> Option { - let TypeInner::Vector { scalar: Scalar { width, kind }, size } = ty else { + let TypeInner::Vector { + scalar: Scalar { width, kind }, + size, + } = ty + else { return None; }; @@ -185,10 +192,9 @@ impl NagaReflect { }) } - fn get_next_binding(&self, bind_group: u32) -> u32{ + fn get_next_binding(&self, bind_group: u32) -> u32 { let mut max_bind = 0; - for (_, gv) in self.vertex - .global_variables.iter() { + for (_, gv) in self.vertex.global_variables.iter() { let Some(binding) = &gv.binding else { continue; }; @@ -198,8 +204,7 @@ impl NagaReflect { max_bind = std::cmp::max(max_bind, binding.binding); } - for (_, gv) in self.fragment - .global_variables.iter() { + for (_, gv) in self.fragment.global_variables.iter() { let Some(binding) = &gv.binding else { continue; }; @@ -234,18 +239,12 @@ impl NagaReflect { // Reassign to UBO later if we want during compilation. if let Some(vertex_pcb) = vertex_pcb { let ubo = &mut self.vertex.global_variables[vertex_pcb]; - ubo.binding = Some(ResourceBinding { - group: 0, - binding, - }); + ubo.binding = Some(ResourceBinding { group: 0, binding }); } if let Some(fragment_pcb) = fragment_pcb { let ubo = &mut self.fragment.global_variables[fragment_pcb]; - ubo.binding = Some(ResourceBinding { - group: 0, - binding, - }); + ubo.binding = Some(ResourceBinding { group: 0, binding }); }; match (vertex_pcb, fragment_pcb) { diff --git a/librashader-runtime-gl/src/gl/mod.rs b/librashader-runtime-gl/src/gl/mod.rs index 6336bab..6d17a79 100644 --- a/librashader-runtime-gl/src/gl/mod.rs +++ b/librashader-runtime-gl/src/gl/mod.rs @@ -13,7 +13,7 @@ use librashader_common::{ImageFormat, Size}; use librashader_presets::{Scale2D, TextureConfig}; use librashader_reflect::back::cross::CrossGlslContext; use librashader_reflect::back::ShaderCompilerOutput; -use librashader_reflect::reflect::semantics::{TextureBinding, BufferReflection}; +use librashader_reflect::reflect::semantics::{BufferReflection, TextureBinding}; use librashader_runtime::uniforms::UniformStorageAccess; use rustc_hash::FxHashMap; diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index 50a085b..7516c3c 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -124,9 +124,7 @@ impl FilterPass { output.output.begin_pass(cmd); - let residual = self - .graphics_pipeline - .begin_rendering(output, cmd)?; + let residual = self.graphics_pipeline.begin_rendering(output, cmd)?; unsafe { parent.device.cmd_bind_pipeline( diff --git a/librashader-runtime-vk/src/graphics_pipeline.rs b/librashader-runtime-vk/src/graphics_pipeline.rs index 6ffb54a..d29067e 100644 --- a/librashader-runtime-vk/src/graphics_pipeline.rs +++ b/librashader-runtime-vk/src/graphics_pipeline.rs @@ -7,7 +7,7 @@ use crate::render_pass::VulkanRenderPass; use ash::vk::PushConstantRange; use librashader_cache::cache_pipeline; use librashader_reflect::back::ShaderCompilerOutput; -use librashader_reflect::reflect::semantics::{TextureBinding, BufferReflection}; +use librashader_reflect::reflect::semantics::{BufferReflection, TextureBinding}; use librashader_reflect::reflect::ShaderReflection; use librashader_runtime::render_target::RenderTarget; use std::ffi::CStr; @@ -31,7 +31,9 @@ impl PipelineDescriptors { } pub fn add_ubo_binding(&mut self, ubo_meta: Option<&BufferReflection>) { - if let Some(ubo_meta) = ubo_meta && !ubo_meta.stage_mask.is_empty() { + if let Some(ubo_meta) = ubo_meta + && !ubo_meta.stage_mask.is_empty() + { let ubo_mask = util::binding_stage_to_vulkan_stage(ubo_meta.stage_mask); self.layout_bindings.push(vk::DescriptorSetLayoutBinding { @@ -417,7 +419,11 @@ impl VulkanGraphicsPipeline { extent: output.output.size.into(), }); unsafe { - self.device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE); + self.device.cmd_begin_render_pass( + cmd, + &render_pass_info, + vk::SubpassContents::INLINE, + ); } Ok(Some(framebuffer)) } else { diff --git a/librashader-runtime-vk/tests/triangle.rs b/librashader-runtime-vk/tests/triangle.rs index 69af0c7..7b48be2 100644 --- a/librashader-runtime-vk/tests/triangle.rs +++ b/librashader-runtime-vk/tests/triangle.rs @@ -23,7 +23,7 @@ fn triangle_vk() { disable_cache: false, }), ) - .unwrap(); + .unwrap(); hello_triangle::main(base, filter) } diff --git a/librashader-runtime-wgpu/src/buffer.rs b/librashader-runtime-wgpu/src/buffer.rs index 486aa79..ae129f3 100644 --- a/librashader-runtime-wgpu/src/buffer.rs +++ b/librashader-runtime-wgpu/src/buffer.rs @@ -1,6 +1,6 @@ +use parking_lot::RwLock; use std::ops::{Deref, DerefMut}; use std::sync::Arc; -use parking_lot::RwLock; pub struct WgpuStagedBuffer { buffer: wgpu::Buffer, diff --git a/librashader-runtime-wgpu/src/filter_chain.rs b/librashader-runtime-wgpu/src/filter_chain.rs index 1062db4..2e3cbe8 100644 --- a/librashader-runtime-wgpu/src/filter_chain.rs +++ b/librashader-runtime-wgpu/src/filter_chain.rs @@ -16,15 +16,13 @@ use std::sync::Arc; use crate::buffer::WgpuStagedBuffer; use crate::draw_quad::DrawQuad; -use librashader_common::{ImageFormat, Size, Viewport}; +use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; use librashader_reflect::back::wgsl::WgslCompileOptions; use librashader_runtime::framebuffer::FramebufferInit; use librashader_runtime::render_target::RenderTarget; use librashader_runtime::scaling::ScaleFramebuffer; use rayon::prelude::*; -use wgpu::{ - Device, TextureFormat, -}; +use wgpu::{Device, TextureFormat}; use crate::error; use crate::error::FilterChainError; @@ -32,6 +30,7 @@ use crate::filter_pass::FilterPass; use crate::framebuffer::OutputView; use crate::graphics_pipeline::WgpuGraphicsPipeline; use crate::luts::LutTexture; +use crate::mipmap::MipmapGen; use crate::options::FrameOptionsWGPU; use crate::samplers::SamplerSet; use crate::texture::{Handle, InputImage, OwnedImage}; @@ -56,6 +55,7 @@ pub struct FilterChainWGPU { history_framebuffers: VecDeque, disable_mipmaps: bool, // residuals: Box<[FrameResiduals]>, + mipmapper: MipmapGen, } pub struct FilterMutable { @@ -73,7 +73,7 @@ pub(crate) struct FilterCommon { pub internal_frame_count: i32, pub(crate) draw_quad: DrawQuad, device: Arc, - pub(crate) queue: Arc + pub(crate) queue: Arc, } impl FilterChainWGPU { @@ -86,7 +86,7 @@ impl FilterChainWGPU { /// graphics queue. The command buffer must be completely executed before calling [`frame`](Self::frame). pub fn load_from_preset_deferred( device: Arc, - queue: Arc, + queue: Arc, cmd: &mut wgpu::CommandEncoder, preset: ShaderPreset, ) -> error::Result { @@ -94,9 +94,17 @@ impl FilterChainWGPU { // // initialize passes let filters = Self::init_passes(Arc::clone(&device), passes, &semantics)?; - // - let luts = FilterChainWGPU::load_luts(&device, &queue, cmd, &preset.textures)?; + let samplers = SamplerSet::new(&device); + let mut mipmapper = MipmapGen::new(Arc::clone(&device)); + let luts = FilterChainWGPU::load_luts( + &device, + &queue, + cmd, + &mut mipmapper, + &samplers, + &preset.textures, + )?; // let framebuffer_gen = || { Ok::<_, error::FilterChainError>(OwnedImage::new( @@ -123,11 +131,6 @@ impl FilterChainWGPU { // // initialize history let (history_framebuffers, history_textures) = framebuffer_init.init_history()?; - // - // let mut intermediates = Vec::new(); - // intermediates.resize_with(frames_in_flight as usize, || { - // FrameResiduals::new(&device.device) - // }); let draw_quad = DrawQuad::new(&device); @@ -156,6 +159,7 @@ impl FilterChainWGPU { feedback_framebuffers, history_framebuffers, disable_mipmaps: false, // todo: force no mipmaps, + mipmapper, }) } @@ -163,6 +167,8 @@ impl FilterChainWGPU { device: &wgpu::Device, queue: &wgpu::Queue, cmd: &mut wgpu::CommandEncoder, + mipmapper: &mut MipmapGen, + sampler_set: &SamplerSet, textures: &[TextureConfig], ) -> error::Result> { let mut luts = FxHashMap::default(); @@ -171,7 +177,8 @@ impl FilterChainWGPU { .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) .collect::, ImageError>>()?; for (index, (texture, image)) in textures.iter().zip(images).enumerate() { - let texture = LutTexture::new(device, queue, cmd, image, texture); + let texture = + LutTexture::new(device, queue, cmd, image, texture, mipmapper, sampler_set); luts.insert(index, texture); } Ok(luts) @@ -375,7 +382,13 @@ impl FilterChainWGPU { )?; if target.max_miplevels > 1 && !self.disable_mipmaps { - target.generate_mipmaps(cmd); + let sampler = self.common.samplers.get( + WrapMode::ClampToEdge, + FilterMode::Linear, + FilterMode::Nearest, + ); + + target.generate_mipmaps(cmd, &mut self.mipmapper, &sampler); } source = self.common.output_textures[index].clone().unwrap(); diff --git a/librashader-runtime-wgpu/src/framebuffer.rs b/librashader-runtime-wgpu/src/framebuffer.rs index fc96e13..30cef5d 100644 --- a/librashader-runtime-wgpu/src/framebuffer.rs +++ b/librashader-runtime-wgpu/src/framebuffer.rs @@ -16,5 +16,3 @@ impl<'a> OutputView<'a> { } } } - - diff --git a/librashader-runtime-wgpu/tests/hello_triangle.rs b/librashader-runtime-wgpu/tests/hello_triangle.rs index 51f4fe2..7654048 100644 --- a/librashader-runtime-wgpu/tests/hello_triangle.rs +++ b/librashader-runtime-wgpu/tests/hello_triangle.rs @@ -6,13 +6,13 @@ use winit::{ window::{Window, WindowBuilder}, }; +use librashader_common::Viewport; use librashader_presets::ShaderPreset; use librashader_runtime_wgpu::FilterChainWGPU; use wgpu::util::DeviceExt; use winit::event_loop::EventLoopBuilder; use winit::keyboard::{Key, KeyCode, PhysicalKey}; use winit::platform::windows::EventLoopBuilderExtWindows; -use librashader_common::Viewport; #[cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*; @@ -75,7 +75,7 @@ struct State<'a> { vertex_buffer: wgpu::Buffer, num_vertices: u32, chain: FilterChainWGPU, - frame_count: usize + frame_count: usize, } impl<'a> State<'a> { async fn new(window: &'a Window) -> Self { @@ -228,44 +228,37 @@ impl<'a> State<'a> { fn render(&mut self) -> Result<(), wgpu::SurfaceError> { let output = self.surface.get_current_texture()?; - let render_output = Arc::new(self.device.create_texture( - &wgpu::TextureDescriptor { - label: Some("rendertexture"), - size: output.texture.size(), - mip_level_count: output.texture.mip_level_count(), - sample_count: output.texture.sample_count(), - dimension: output.texture.dimension(), - format: output.texture.format(), - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::RENDER_ATTACHMENT - | wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::COPY_SRC, - view_formats: &[output.texture.format()], - } - )); + let render_output = Arc::new(self.device.create_texture(&wgpu::TextureDescriptor { + label: Some("rendertexture"), + size: output.texture.size(), + mip_level_count: output.texture.mip_level_count(), + sample_count: output.texture.sample_count(), + dimension: output.texture.dimension(), + format: output.texture.format(), + usage: wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::RENDER_ATTACHMENT + | wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC, + view_formats: &[output.texture.format()], + })); - let filter_output = Arc::new(self.device.create_texture( - &wgpu::TextureDescriptor { - label: Some("filteroutput"), - size: output.texture.size(), - mip_level_count: output.texture.mip_level_count(), - sample_count: output.texture.sample_count(), - dimension: output.texture.dimension(), - format: output.texture.format(), - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::RENDER_ATTACHMENT - | wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::COPY_SRC, - view_formats: &[output.texture.format()], - } - )); + let filter_output = Arc::new(self.device.create_texture(&wgpu::TextureDescriptor { + label: Some("filteroutput"), + size: output.texture.size(), + mip_level_count: output.texture.mip_level_count(), + sample_count: output.texture.sample_count(), + dimension: output.texture.dimension(), + format: output.texture.format(), + usage: wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::RENDER_ATTACHMENT + | wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC, + view_formats: &[output.texture.format()], + })); + let view = render_output.create_view(&wgpu::TextureViewDescriptor::default()); - let view = render_output - .create_view(&wgpu::TextureViewDescriptor::default()); - - let filter_view = filter_output - .create_view(&wgpu::TextureViewDescriptor::default()); + let filter_view = filter_output.create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -274,8 +267,7 @@ impl<'a> State<'a> { }); { - let mut render_pass = - encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: &view, @@ -295,25 +287,28 @@ impl<'a> State<'a> { } self.chain - .frame(Arc::clone(&render_output), - &Viewport { - x: 0.0, - y: 0.0, - mvp: None, - output: librashader_runtime_wgpu::OutputView { - size: filter_output.size().into(), - view: &filter_view, - format: filter_output.format(), - }, - }, - &mut encoder, - self.frame_count, None - ).expect("failed to draw frame"); + .frame( + Arc::clone(&render_output), + &Viewport { + x: 0.0, + y: 0.0, + mvp: None, + output: librashader_runtime_wgpu::OutputView { + size: filter_output.size().into(), + view: &filter_view, + format: filter_output.format(), + }, + }, + &mut encoder, + self.frame_count, + None, + ) + .expect("failed to draw frame"); encoder.copy_texture_to_texture( filter_output.as_image_copy(), output.texture.as_image_copy(), - output.texture.size() + output.texture.size(), ); self.queue.submit(std::iter::once(encoder.finish())); diff --git a/librashader-runtime/src/array_chunks_mut.rs b/librashader-runtime/src/array_chunks_mut.rs index 4e111ab..453d386 100644 --- a/librashader-runtime/src/array_chunks_mut.rs +++ b/librashader-runtime/src/array_chunks_mut.rs @@ -21,7 +21,9 @@ impl<'a, T, const N: usize> ArrayChunksMut<'a, T, N> { #[inline] pub(super) fn new(slice: &'a mut [T]) -> Self { let (array_slice, _rem) = as_chunks_mut(slice); - Self { iter: array_slice.iter_mut() } + Self { + iter: array_slice.iter_mut(), + } } } @@ -54,7 +56,6 @@ impl<'a, T, const N: usize> Iterator for ArrayChunksMut<'a, T, N> { } } - /// Splits the slice into a slice of `N`-element arrays, /// starting at the beginning of the slice, /// and a remainder slice with length strictly less than `N`. @@ -69,7 +70,7 @@ impl<'a, T, const N: usize> Iterator for ArrayChunksMut<'a, T, N> { fn as_chunks_mut(slice: &mut [T]) -> (&mut [[T; N]], &mut [T]) { unsafe fn as_chunks_unchecked_mut(slice: &mut [T]) -> &mut [[T; N]] { // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length - let new_len = slice.len() / N; + let new_len = slice.len() / N; // SAFETY: We cast a slice of `new_len * N` elements into // a slice of `new_len` many `N` elements chunks. @@ -83,4 +84,4 @@ fn as_chunks_mut(slice: &mut [T]) -> (&mut [[T; N]], &mut [T] // that the length of the subslice is a multiple of N. let array_slice = unsafe { as_chunks_unchecked_mut(multiple_of_n) }; (array_slice, remainder) -} \ No newline at end of file +} diff --git a/librashader-runtime/src/image.rs b/librashader-runtime/src/image.rs index 98e4eab..df2e8fd 100644 --- a/librashader-runtime/src/image.rs +++ b/librashader-runtime/src/image.rs @@ -2,8 +2,8 @@ pub use image::ImageError; use librashader_common::Size; use std::marker::PhantomData; -use std::path::Path; use crate::array_chunks_mut::ArrayChunksMut; +use std::path::Path; /// An uncompressed raw image ready to upload to GPU buffers. pub struct Image {