diff --git a/librashader-build-script/src/main.rs b/librashader-build-script/src/main.rs index e013fa2..ef183d3 100644 --- a/librashader-build-script/src/main.rs +++ b/librashader-build-script/src/main.rs @@ -120,5 +120,5 @@ pub fn main() -> ExitCode { } } - return ExitCode::SUCCESS; + ExitCode::SUCCESS } diff --git a/librashader-cache/src/cache.rs b/librashader-cache/src/cache.rs index dae430c..2a4904a 100644 --- a/librashader-cache/src/cache.rs +++ b/librashader-cache/src/cache.rs @@ -46,7 +46,7 @@ pub(crate) mod internal { pub(crate) fn get_cache() -> Result> { let cache_dir = get_cache_dir()?; match Persy::open_or_create_with( - &cache_dir.join("librashader.db.1"), + cache_dir.join("librashader.db.1"), Config::new(), |persy| { let tx = persy.begin()?; @@ -110,13 +110,13 @@ where T: Cacheable, { if bypass_cache { - return Ok(load(factory(keys)?)?); + return load(factory(keys)?); } let cache = internal::get_cache(); let Ok(cache) = cache else { - return Ok(load(factory(keys)?)?); + return load(factory(keys)?); }; let hashkey = { @@ -124,8 +124,8 @@ where for subkeys in keys { hasher.update(subkeys.hash_bytes()); } - let hash = hasher.finalize(); - hash + + hasher.finalize() }; 'attempt: { @@ -145,7 +145,7 @@ where if let Some(slice) = T::to_bytes(&blob) { let _ = internal::set_blob(&cache, index, hashkey.as_bytes(), &slice); } - Ok(load(blob)?) + load(blob) } /// Cache a pipeline state object. @@ -166,13 +166,13 @@ where T: Cacheable, { if bypass_cache { - return Ok(restore_pipeline(None)?); + return restore_pipeline(None); } let cache = internal::get_cache(); let Ok(cache) = cache else { - return Ok(restore_pipeline(None)?); + return restore_pipeline(None); }; let hashkey = { @@ -180,18 +180,15 @@ where for subkeys in keys { hasher.update(subkeys.hash_bytes()); } - let hash = hasher.finalize(); - hash + + hasher.finalize() }; let pipeline = 'attempt: { if let Ok(Some(blob)) = internal::get_blob(&cache, index, hashkey.as_bytes()) { let cached = restore_pipeline(Some(blob)); - match cached { - Ok(res) => { - break 'attempt res; - } - _ => (), + if let Ok(res) = cached { + break 'attempt res; } } diff --git a/librashader-cache/src/compilation.rs b/librashader-cache/src/compilation.rs index 6e1191c..8fd324c 100644 --- a/librashader-cache/src/compilation.rs +++ b/librashader-cache/src/compilation.rs @@ -36,8 +36,8 @@ where let mut hasher = blake3::Hasher::new(); hasher.update(source.vertex.as_bytes()); hasher.update(source.fragment.as_bytes()); - let hash = hasher.finalize(); - hash + + hasher.finalize() }; let compilation = 'cached: { diff --git a/librashader-cache/src/key.rs b/librashader-cache/src/key.rs index e2a6021..632f9c2 100644 --- a/librashader-cache/src/key.rs +++ b/librashader-cache/src/key.rs @@ -7,13 +7,13 @@ pub trait CacheKey { impl CacheKey for u32 { fn hash_bytes(&self) -> &[u8] { - &bytemuck::bytes_of(&*self) + bytemuck::bytes_of(self) } } impl CacheKey for i32 { fn hash_bytes(&self) -> &[u8] { - &bytemuck::bytes_of(&*self) + bytemuck::bytes_of(self) } } @@ -25,13 +25,13 @@ impl CacheKey for &[u8] { impl CacheKey for Vec { fn hash_bytes(&self) -> &[u8] { - &self + self } } impl CacheKey for Vec { fn hash_bytes(&self) -> &[u8] { - bytemuck::cast_slice(&self) + bytemuck::cast_slice(self) } } diff --git a/librashader-presets/src/context.rs b/librashader-presets/src/context.rs index 1d35875..1e652bb 100644 --- a/librashader-presets/src/context.rs +++ b/librashader-presets/src/context.rs @@ -275,6 +275,12 @@ impl Display for ContextItem { #[derive(Debug, Clone)] pub struct WildcardContext(VecDeque); +impl Default for WildcardContext { + fn default() -> Self { + Self::new() + } +} + impl WildcardContext { /// Create a new wildcard context. pub fn new() -> Self { @@ -391,12 +397,12 @@ pub(crate) fn apply_context(path: &mut PathBuf, context: &FastHashMap new_path.push(component), } diff --git a/librashader-presets/src/parse/value.rs b/librashader-presets/src/parse/value.rs index 333fe4e..7dcb46b 100644 --- a/librashader-presets/src/parse/value.rs +++ b/librashader-presets/src/parse/value.rs @@ -23,6 +23,7 @@ use crate::extract_if::MakeExtractIf; #[derive(Debug)] pub enum Value { ShaderCount(i32), + #[allow(dead_code)] FeedbackPass(i32), Shader(i32, PathBuf), ScaleX(i32, ScaleFactor), @@ -376,8 +377,7 @@ pub fn parse_values( && t.key.ends_with(*texture) && t.key.len() == "filter_".len() + texture.len() }) - // NOPANIC: infallible - .map_or(None, |(_, v)| Some(FilterMode::from_str(&v.value).unwrap())); + .map(|(_, v)| FilterMode::from_str(&v.value).unwrap()); values.push(Value::Texture { name: texture.to_string(), diff --git a/librashader-presets/tests/parse_all.rs b/librashader-presets/tests/parse_all.rs index 8a65be9..1ec76b6 100644 --- a/librashader-presets/tests/parse_all.rs +++ b/librashader-presets/tests/parse_all.rs @@ -16,7 +16,7 @@ fn parses_all_slang_presets() { #[test] fn parses_problematic() { let path = "../test/Mega_Bezel_Packs/Duimon-Mega-Bezel/Presets/Advanced/Nintendo_NDS_DREZ/NDS-[DREZ]-[Native]-[ADV]-[Guest]-[Night].slangp"; - ShaderPreset::try_parse(path).expect(&format!("Failed to parse {}", path)); + ShaderPreset::try_parse(path).unwrap_or_else(|_| panic!("Failed to parse {}", path)); } #[test] @@ -30,5 +30,5 @@ fn parses_wildcard() { context.append_item(ContextItem::CoreName(String::from("image display"))); ShaderPreset::try_parse_with_context(path, context) - .expect(&format!("Failed to parse {}", path)); + .unwrap_or_else(|_| panic!("Failed to parse {}", path)); } diff --git a/librashader-reflect/src/back/hlsl.rs b/librashader-reflect/src/back/hlsl.rs index c5c7e0a..75d0ce7 100644 --- a/librashader-reflect/src/back/hlsl.rs +++ b/librashader-reflect/src/back/hlsl.rs @@ -47,7 +47,7 @@ impl HlslBufferAssignments { { return true; } - return false; + false } // Check if the mangled name matches. @@ -87,7 +87,7 @@ impl HlslBufferAssignments { } } - return false; + false } } diff --git a/librashader-reflect/src/front/spirv_passes/link_input_outputs.rs b/librashader-reflect/src/front/spirv_passes/link_input_outputs.rs index 770fe04..378e02c 100644 --- a/librashader-reflect/src/front/spirv_passes/link_input_outputs.rs +++ b/librashader-reflect/src/front/spirv_passes/link_input_outputs.rs @@ -18,7 +18,7 @@ impl<'a> LinkInputs<'a> { return None; }; - let Some(&Operand::IdRef(target)) = op.operands.get(0) else { + let Some(&Operand::IdRef(target)) = op.operands.first() else { return None; }; @@ -29,7 +29,7 @@ impl<'a> LinkInputs<'a> { let Some(&Operand::LiteralBit32(binding)) = op.operands.get(2) else { return None; }; - return Some(binding); + Some(binding) }) } @@ -62,7 +62,7 @@ impl<'a> LinkInputs<'a> { if let Some(frag_ref) = bindings.get(&location) { // if something is bound to the same location in the vertex shader, // we're good. - inputs.remove(&frag_ref); + inputs.remove(frag_ref); } } } @@ -112,7 +112,7 @@ impl<'a> LinkInputs<'a> { } } } - return true; + true }); self.frag_builder.module_mut().annotations.retain(|instr| { @@ -123,7 +123,7 @@ impl<'a> LinkInputs<'a> { } } } - return true; + true }); for entry_point in self.frag_builder.module_mut().entry_points.iter_mut() { @@ -133,7 +133,7 @@ impl<'a> LinkInputs<'a> { return false; } } - return true; + true }) } diff --git a/librashader-reflect/src/front/spirv_passes/lower_samplers.rs b/librashader-reflect/src/front/spirv_passes/lower_samplers.rs index fb0504b..8ef574e 100644 --- a/librashader-reflect/src/front/spirv_passes/lower_samplers.rs +++ b/librashader-reflect/src/front/spirv_passes/lower_samplers.rs @@ -33,12 +33,12 @@ struct OpAccessChain<'a> { impl<'a> LowerCombinedImageSamplerPass<'a> { pub fn new(builder: &'a mut Builder) -> Self { - let val = Self { + + + Self { builder, seen_functions: FxHashSet::default(), - }; - - val + } } pub(crate) fn do_pass(&mut self) { @@ -109,7 +109,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { return None; } - let Some(&Operand::IdRef(target)) = &i.operands.get(0) else { + let Some(&Operand::IdRef(target)) = &i.operands.first() else { return None; }; @@ -121,7 +121,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { return None; }; - return Some(format!("_{string}_sampler")); + Some(format!("_{string}_sampler")) }) } @@ -130,7 +130,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { return None; } - let Some(&Operand::IdRef(referand)) = inst.operands.get(0) else { + let Some(&Operand::IdRef(referand)) = inst.operands.first() else { return None; }; @@ -183,7 +183,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { self.builder.decorate( sampler_uniform, decoration_type, - decoration.operands[2..].iter().map(|f| f.clone()), + decoration.operands[2..].iter().cloned(), ) } @@ -264,7 +264,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { } if uniform_type.class.opcode == spirv::Op::TypeArray { - let Some(&Operand::IdRef(array_base_type)) = uniform_type.operands.get(0) + let Some(&Operand::IdRef(array_base_type)) = uniform_type.operands.first() else { continue; }; @@ -402,7 +402,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { } // This doesn't affect array loads because array loads load the result of the OpAccessChain which can be done in a separate pass. - let Some(Operand::IdRef(op_variable_id)) = &instr.operands.get(0) else { + let Some(Operand::IdRef(op_variable_id)) = &instr.operands.first() else { instructions.push(instr); continue; }; @@ -474,7 +474,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { } // This doesn't affect array loads because array loads load the result of the OpAccessChain which can be done in a separate pass. - let Some(Operand::IdRef(op_variable)) = &instr.operands.get(0) else { + let Some(Operand::IdRef(op_variable)) = &instr.operands.first() else { instructions.push(instr); continue; }; @@ -565,7 +565,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { continue; } - let Some(Operand::IdRef(op_variable)) = &instr.operands.get(0) else { + let Some(Operand::IdRef(op_variable)) = &instr.operands.first() else { instructions.push(instr); continue; }; @@ -656,7 +656,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { continue; } - let Some(&Operand::IdRef(function_id)) = instr.operands.get(0) else { + let Some(&Operand::IdRef(function_id)) = instr.operands.first() else { continue; }; @@ -729,7 +729,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { continue; } - let Some(&Operand::IdRef(function_id)) = instr.operands.get(0) else { + let Some(&Operand::IdRef(function_id)) = instr.operands.first() else { instructions.push(instr); continue; }; @@ -742,7 +742,7 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { return false; }; - op_access_chains.contains_key(&op_ref_id) + op_access_chains.contains_key(op_ref_id) }) .collect::>(); @@ -861,9 +861,9 @@ impl<'a> LowerCombinedImageSamplerPass<'a> { seen_functions } - fn rewrite_functions_definitions<'b>( + fn rewrite_functions_definitions( &mut self, - mappings: &FxHashMap>>, + mappings: &FxHashMap>>, ) -> FxHashMap { let mut sampled_refs = FxHashMap::default(); let mut functions = self.builder.module_ref().functions.clone(); diff --git a/librashader-reflect/src/front/spirv_passes/mod.rs b/librashader-reflect/src/front/spirv_passes/mod.rs index 2c64871..8294fe7 100644 --- a/librashader-reflect/src/front/spirv_passes/mod.rs +++ b/librashader-reflect/src/front/spirv_passes/mod.rs @@ -5,6 +5,6 @@ pub mod lower_samplers; pub(crate) fn load_module(words: &[u32]) -> rspirv::dr::Module { let mut loader = rspirv::dr::Loader::new(); rspirv::binary::parse_words(words, &mut loader).unwrap(); - let module = loader.module(); - module + + loader.module() } diff --git a/librashader-reflect/src/reflect/naga/mod.rs b/librashader-reflect/src/reflect/naga/mod.rs index bfb5838..4f96766 100644 --- a/librashader-reflect/src/reflect/naga/mod.rs +++ b/librashader-reflect/src/reflect/naga/mod.rs @@ -205,7 +205,7 @@ impl ValidateTypeSemantics<&TypeInner> for UniqueSemantics { } }; - return None; + None } } @@ -426,13 +426,13 @@ impl NagaReflect { // Verify types if self.vertex.global_variables.iter().any(|(_, gv)| { let ty = &self.vertex.types[gv.ty]; - match ty.inner { + !matches!( + ty.inner, TypeInner::Scalar { .. } - | TypeInner::Vector { .. } - | TypeInner::Matrix { .. } - | TypeInner::Struct { .. } => false, - _ => true, - } + | TypeInner::Vector { .. } + | TypeInner::Matrix { .. } + | TypeInner::Struct { .. } + ) }) { return Err(ShaderReflectError::VertexSemanticError( SemanticsErrorKind::InvalidResourceType, @@ -483,7 +483,7 @@ impl NagaReflect { SemanticsErrorKind::InvalidInputCount(vert_inputs), )); } - for input in &vertex_entry_point.function.arguments { + if let Some(input) = &vertex_entry_point.function.arguments.first() { let &Some(Binding::Location { location, .. }) = &input.binding else { return Err(ShaderReflectError::VertexSemanticError( SemanticsErrorKind::MissingBinding, @@ -644,7 +644,7 @@ impl NagaReflect { offset_type: UniformMemberBlock, blame: SemanticErrorBlame, ) -> Result<(), ShaderReflectError> { - let reachable = Self::collect_uniform_names(&module, resource, blame)?; + let reachable = Self::collect_uniform_names(module, resource, blame)?; let resource = &module.global_variables[resource]; @@ -824,7 +824,7 @@ impl NagaReflect { Ok(TextureData { // id: texture.id, // descriptor_set, - name: &name, + name, binding: binding.binding, }) } @@ -1002,44 +1002,3 @@ impl ReflectShader for NagaReflect { }) } } - -#[cfg(test)] -mod test { - use crate::reflect::semantics::{Semantic, TextureSemantics, UniformSemantic}; - use librashader_common::map::FastHashMap; - use librashader_preprocess::ShaderSource; - use librashader_presets::ShaderPreset; - - // #[test] - // pub fn test_into() { - // let result = ShaderSource::load("../test/slang-shaders/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap(); - // let compilation = crate::front::GlslangCompilation::try_from(&result).unwrap(); - // - // let mut loader = rspirv::dr::Loader::new(); - // rspirv::binary::parse_words(compilation.vertex.as_binary(), &mut loader).unwrap(); - // let module = loader.module(); - // - // let outputs: Vec<&Instruction> = module - // .types_global_values - // .iter() - // .filter(|i| i.class.opcode == Op::Variable) - // .collect(); - // - // println!("{outputs:#?}"); - // } - - // #[test] - // pub fn mega_bezel_reflect() { - // let preset = ShaderPreset::try_parse( - // "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", - // ) - // .unwrap(); - // - // let mut uniform_semantics: FastHashMap = Default::default(); - // let mut texture_semantics: FastHashMap> = Default::default(); - // - // - // - // - // } -} diff --git a/librashader-reflect/src/reflect/naga/msl.rs b/librashader-reflect/src/reflect/naga/msl.rs index 74300c4..82e0404 100644 --- a/librashader-reflect/src/reflect/naga/msl.rs +++ b/librashader-reflect/src/reflect/naga/msl.rs @@ -53,7 +53,7 @@ impl CompileShader for NagaReflect { ) -> Result<(String, TranslationInfo), ShaderCompileError> { let mut valid = naga::valid::Validator::new(ValidationFlags::all(), Capabilities::empty()); - let info = valid.validate(&module)?; + let info = valid.validate(module)?; let pipeline_options = PipelineOptions { allow_and_force_point_size: false, @@ -61,7 +61,7 @@ impl CompileShader for NagaReflect { vertex_buffer_mappings: vec![], }; - let msl = naga::back::msl::write_string(&module, &info, &options, &pipeline_options)?; + let msl = naga::back::msl::write_string(module, &info, &options, &pipeline_options)?; Ok(msl) } diff --git a/librashader-reflect/src/reflect/naga/spirv.rs b/librashader-reflect/src/reflect/naga/spirv.rs index 7d95041..9bacf21 100644 --- a/librashader-reflect/src/reflect/naga/spirv.rs +++ b/librashader-reflect/src/reflect/naga/spirv.rs @@ -22,12 +22,14 @@ impl CompileShader for NagaReflect { ) -> Result, ShaderCompileError> { let mut valid = naga::valid::Validator::new(ValidationFlags::all(), Capabilities::empty()); - let info = valid.validate(&module)?; - let mut options = naga::back::spv::Options::default(); - options.lang_version = version; + let info = valid.validate(module)?; + let options = naga::back::spv::Options { + lang_version: version, + ..Default::default() + }; let spv = naga::back::spv::write_vec( - &module, + module, &info, &options, Some(&PipelineOptions { diff --git a/librashader-reflect/src/reflect/naga/wgsl.rs b/librashader-reflect/src/reflect/naga/wgsl.rs index 388ba3f..61b1961 100644 --- a/librashader-reflect/src/reflect/naga/wgsl.rs +++ b/librashader-reflect/src/reflect/naga/wgsl.rs @@ -16,7 +16,7 @@ impl CompileShader for NagaReflect { options: Self::Options, ) -> Result, ShaderCompileError> { fn write_wgsl(module: &Module, info: &ModuleInfo) -> Result { - let wgsl = naga::back::wgsl::write_string(&module, &info, WriterFlags::empty())?; + let wgsl = naga::back::wgsl::write_string(module, info, WriterFlags::empty())?; Ok(wgsl) } diff --git a/librashader-runtime/src/binding.rs b/librashader-runtime/src/binding.rs index ee31e32..1661d66 100644 --- a/librashader-runtime/src/binding.rs +++ b/librashader-runtime/src/binding.rs @@ -95,8 +95,8 @@ where type UniformOffset: ContextOffset; /// Bind a texture to the input descriptor set - fn bind_texture<'a>( - descriptors: &mut Self::DescriptorSet<'a>, + fn bind_texture( + descriptors: &mut Self::DescriptorSet<'_>, samplers: &Self::SamplerSet, binding: &TextureBinding, texture: &Self::InputTexture, @@ -105,11 +105,11 @@ where #[allow(clippy::too_many_arguments)] /// Write uniform and texture semantics to the provided storages. - fn bind_semantics<'a>( + fn bind_semantics( device: &Self::DeviceContext, sampler_set: &Self::SamplerSet, uniform_storage: &mut UniformStorage, - descriptor_set: &mut Self::DescriptorSet<'a>, + descriptor_set: &mut Self::DescriptorSet<'_>, uniform_inputs: UniformInputs<'_>, original: &Self::InputTexture, source: &Self::InputTexture, diff --git a/librashader-runtime/src/framebuffer.rs b/librashader-runtime/src/framebuffer.rs index 674e8ed..55fc3b1 100644 --- a/librashader-runtime/src/framebuffer.rs +++ b/librashader-runtime/src/framebuffer.rs @@ -14,7 +14,7 @@ impl<'a, F, I, E> FramebufferInit<'a, F, I, E> { /// Create a new framebuffer initializer with the given /// closures to create owned framebuffers and image views. pub fn new( - filters: impl Iterator + ExactSizeIterator, + filters: impl ExactSizeIterator, owned_generator: &'a dyn Fn() -> Result, input_generator: &'a dyn Fn() -> I, ) -> Self { diff --git a/librashader-runtime/src/parameters.rs b/librashader-runtime/src/parameters.rs index 1ba9add..74b672d 100644 --- a/librashader-runtime/src/parameters.rs +++ b/librashader-runtime/src/parameters.rs @@ -7,8 +7,8 @@ pub trait FilterChainParameters { fn set_enabled_pass_count(&mut self, count: usize); /// Enumerates the active parameters as well as their values in the current filter chain. - fn enumerate_parameters<'a>( - &'a self, + fn enumerate_parameters( + &self, ) -> ::librashader_common::map::halfbrown::Iter; /// Get the value of the given parameter if present. diff --git a/librashader-runtime/src/ringbuffer.rs b/librashader-runtime/src/ringbuffer.rs index 7fd5635..32b4d4a 100644 --- a/librashader-runtime/src/ringbuffer.rs +++ b/librashader-runtime/src/ringbuffer.rs @@ -39,6 +39,16 @@ pub struct InlineRingBuffer { index: usize, } +impl Default for InlineRingBuffer +where + T: Copy, + T: Default, + { + fn default() -> Self { + Self::new() + } +} + impl InlineRingBuffer where T: Copy,