From d6f47f83caa45a405f242449d7f6b4bc9ab4723b Mon Sep 17 00:00:00 2001 From: chyyran Date: Mon, 31 Oct 2022 20:29:25 -0400 Subject: [PATCH] fmt: run clippy --- librashader-reflect/src/front/naga.rs | 10 +++--- librashader-reflect/src/front/shaderc.rs | 4 +-- librashader-reflect/src/reflect/cross.rs | 32 ++++++++++---------- librashader-reflect/src/reflect/mod.rs | 2 +- librashader-reflect/src/reflect/naga.rs | 8 ++--- librashader-reflect/src/reflect/rspirv.rs | 2 +- librashader-reflect/src/reflect/semantics.rs | 3 +- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/librashader-reflect/src/front/naga.rs b/librashader-reflect/src/front/naga.rs index 049ef1b..cfd308a 100644 --- a/librashader-reflect/src/front/naga.rs +++ b/librashader-reflect/src/front/naga.rs @@ -23,7 +23,7 @@ mod test { use naga::back::spv::{Capability, WriterFlags}; use naga::front::glsl::{Options, Parser}; use naga::front::spv::Options as SpvOptions; - use naga::valid::{Capabilities, ModuleInfo, ValidationFlags}; + use naga::valid::{Capabilities, ValidationFlags}; use naga::{FastHashSet, ShaderStage}; use rspirv::binary::Disassemble; #[test] @@ -36,7 +36,7 @@ mod test { let fragment_source = result.fragment; let mut parser = Parser::default(); println!("{fragment_source}"); - let fragment = parser + let _fragment = parser .parse(&Options::from(ShaderStage::Fragment), &fragment_source) .unwrap(); } @@ -48,7 +48,7 @@ mod test { ) .unwrap(); let spirv = compile_spirv(&result).unwrap(); - eprintln!("{:?}", spirv) + eprintln!("{spirv:?}") } #[test] @@ -132,8 +132,8 @@ mod test { let mut ast = spirv_cross::spirv::Ast::::parse(&loaded).unwrap(); println!("{:#}", ast.compile().unwrap()); println!("--- naga glsl---"); - println!("{:#}", glsl_out); + println!("{glsl_out:#}"); println!("--- naga wgsl---"); - println!("{:#}", wgsl) + println!("{wgsl:#}") } } diff --git a/librashader-reflect/src/front/shaderc.rs b/librashader-reflect/src/front/shaderc.rs index f58ffeb..70cd878 100644 --- a/librashader-reflect/src/front/shaderc.rs +++ b/librashader-reflect/src/front/shaderc.rs @@ -1,6 +1,6 @@ use crate::error::ShaderCompileError; use librashader::ShaderSource; -use shaderc::{CompilationArtifact, CompileOptions, GlslProfile, Limit, ShaderKind}; +use shaderc::{CompilationArtifact, CompileOptions, Limit, ShaderKind}; pub struct GlslangCompilation { pub(crate) vertex: CompilationArtifact, @@ -127,6 +127,6 @@ mod test { #[test] pub fn compile_shader() { let result = librashader_preprocess::load_shader_source("../test/basic.slang").unwrap(); - let spirv = compile_spirv(&result).unwrap(); + let _spirv = compile_spirv(&result).unwrap(); } } diff --git a/librashader-reflect/src/reflect/cross.rs b/librashader-reflect/src/reflect/cross.rs index ccd2d1c..17085f9 100644 --- a/librashader-reflect/src/reflect/cross.rs +++ b/librashader-reflect/src/reflect/cross.rs @@ -10,7 +10,7 @@ use rustc_hash::FxHashMap; use spirv_cross::hlsl::{CompilerOptions, ShaderModel}; use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type}; use spirv_cross::{hlsl, ErrorCode}; -use std::fmt::Debug; + use std::str::FromStr; pub struct CrossReflect @@ -153,7 +153,7 @@ where )); } - let mut vert_mask = vertex_res.stage_inputs.iter().try_fold(0, |mask, input| { + let vert_mask = vertex_res.stage_inputs.iter().try_fold(0, |mask, input| { Ok::( mask | 1 << self.vertex.get_decoration(input.id, Decoration::Location)?, ) @@ -219,10 +219,10 @@ enum SemanticErrorBlame { impl SemanticErrorBlame { fn error(self, kind: SemanticsErrorKind) -> ShaderReflectError { - return match self { + match self { SemanticErrorBlame::Vertex => ShaderReflectError::VertexSemanticError(kind), SemanticErrorBlame::Fragment => ShaderReflectError::FragmentSemanticError(kind), - }; + } } } @@ -291,7 +291,7 @@ impl TextureSemanticMap for FxHashMap }); } } - return None; + None } Some(UniformSemantic::Variable(_)) => None, Some(UniformSemantic::Texture(texture)) => Some(*texture), @@ -321,7 +321,7 @@ impl TextureSemanticMap for FxHashMap Some(*texture), } @@ -377,7 +377,7 @@ where blame: SemanticErrorBlame, ) -> Result<(), ShaderReflectError> { let ranges = ast.get_active_buffer_ranges(resource.id)?; - eprintln!("{:?}", ranges); + eprintln!("{ranges:?}"); for range in ranges { let name = ast.get_member_name(resource.base_type_id, range.index)?; let ubo_type = ast.get_type(resource.base_type_id)?; @@ -483,7 +483,7 @@ where }); } else { meta.texture_size_meta.insert( - texture.clone(), + texture, TextureSizeMeta { offset, // todo: fix this. @@ -661,13 +661,13 @@ where let fragment_res = self.fragment.get_shader_resources()?; self.validate(&vertex_res, &fragment_res)?; - let vertex_ubo = vertex_res.uniform_buffers.first().map(|f| f); - let fragment_ubo = fragment_res.uniform_buffers.first().map(|f| f); + let vertex_ubo = vertex_res.uniform_buffers.first(); + let fragment_ubo = fragment_res.uniform_buffers.first(); let ubo = self.reflect_ubos(vertex_ubo, fragment_ubo)?; - let vertex_push = vertex_res.push_constant_buffers.first().map(|f| f); - let fragment_push = fragment_res.push_constant_buffers.first().map(|f| f); + let vertex_push = vertex_res.push_constant_buffers.first(); + let fragment_push = fragment_res.push_constant_buffers.first(); let push_constant = self.reflect_push_constant_buffer(vertex_push, fragment_push)?; @@ -728,7 +728,7 @@ where if ubo_bindings & (1 << texture_data.binding) != 0 { return Err(ShaderReflectError::BindingInUse(texture_data.binding)); } - ubo_bindings |= (1 << texture_data.binding); + ubo_bindings |= 1 << texture_data.binding; self.reflect_texture_metas(texture_data, options, &mut meta)?; } @@ -747,8 +747,8 @@ where mod test { use crate::reflect::cross::CrossReflect; use crate::reflect::{ReflectOptions, ReflectShader}; - use rspirv::binary::Disassemble; - use spirv_cross::{glsl, hlsl}; + + use spirv_cross::{hlsl}; #[test] pub fn test_into() { @@ -763,7 +763,7 @@ mod test { non_uniform_semantics: Default::default(), }) .unwrap(); - eprintln!("{:#?}", huh); + eprintln!("{huh:#?}"); eprintln!("{:#}", reflect.fragment.compile().unwrap()) // let mut loader = rspirv::dr::Loader::new(); // rspirv::binary::parse_words(spirv.fragment.as_binary(), &mut loader).unwrap(); diff --git a/librashader-reflect/src/reflect/mod.rs b/librashader-reflect/src/reflect/mod.rs index b8302ed..7de0c86 100644 --- a/librashader-reflect/src/reflect/mod.rs +++ b/librashader-reflect/src/reflect/mod.rs @@ -1,4 +1,4 @@ -use crate::error::{SemanticsErrorKind, ShaderReflectError}; +use crate::error::{ShaderReflectError}; use crate::reflect::semantics::{ SemanticMap, ShaderReflection, TextureImage, TextureSemantics, TextureSizeMeta, VariableMeta, VariableSemantics, diff --git a/librashader-reflect/src/reflect/naga.rs b/librashader-reflect/src/reflect/naga.rs index 9209686..46d3f50 100644 --- a/librashader-reflect/src/reflect/naga.rs +++ b/librashader-reflect/src/reflect/naga.rs @@ -38,13 +38,13 @@ impl TryFrom for NagaReflect { #[cfg(test)] mod test { - use crate::reflect::naga::NagaReflect; - use naga::front::spv::Options; - use rspirv::binary::Disassemble; + + + #[test] pub fn test_into() { let result = librashader_preprocess::load_shader_source("../test/basic.slang").unwrap(); - let spirv = crate::front::shaderc::compile_spirv(&result).unwrap(); + let _spirv = crate::front::shaderc::compile_spirv(&result).unwrap(); } } diff --git a/librashader-reflect/src/reflect/rspirv.rs b/librashader-reflect/src/reflect/rspirv.rs index 4c0c643..062cbb1 100644 --- a/librashader-reflect/src/reflect/rspirv.rs +++ b/librashader-reflect/src/reflect/rspirv.rs @@ -32,7 +32,7 @@ mod test { pub fn test_into() { let result = librashader_preprocess::load_shader_source("../test/basic.slang").unwrap(); let spirv = crate::front::shaderc::compile_spirv(&result).unwrap(); - let mut reflect = RspirvReflect::try_from(spirv).unwrap(); + let reflect = RspirvReflect::try_from(spirv).unwrap(); // let pcr = reflect.fragment.get_push_constant_range().unwrap() // .unwrap(); println!("{:?}", reflect.fragment.get_descriptor_sets()); diff --git a/librashader-reflect/src/reflect/semantics.rs b/librashader-reflect/src/reflect/semantics.rs index 6b5727f..79f6126 100644 --- a/librashader-reflect/src/reflect/semantics.rs +++ b/librashader-reflect/src/reflect/semantics.rs @@ -1,4 +1,4 @@ -use crate::error::ShaderReflectError; + use crate::reflect::ReflectMeta; use bitflags::bitflags; @@ -143,3 +143,4 @@ pub struct ShaderReflection { pub push_constant: Option, pub meta: ReflectMeta, } +