Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarumych committed Oct 27, 2021
1 parent b72ee62 commit 7316a16
Show file tree
Hide file tree
Showing 26 changed files with 226 additions and 254 deletions.
10 changes: 4 additions & 6 deletions proc/src/descriptors/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{find_unique, get_unique};
#[derive(Clone)]
pub struct Buffer {
pub kind: Kind,
pub ty: syn::Type,
pub ty: Box<syn::Type>,
}

impl Buffer {
Expand All @@ -21,7 +21,7 @@ pub enum Kind {

enum Argument {
Kind(Kind),
Type(syn::Type),
Type(Box<syn::Type>),
}

pub(super) fn parse_buffer_attr(attr: &syn::Attribute) -> syn::Result<Option<Buffer>> {
Expand All @@ -43,11 +43,9 @@ pub(super) fn parse_buffer_attr(attr: &syn::Attribute) -> syn::Result<Option<Buf
let _eq = stream.parse::<syn::Token![=]>()?;
let ty = stream.parse::<syn::Type>()?;

Ok(Argument::Type(ty))
}
_ => {
return Err(stream.error("Unrecognized argument"));
Ok(Argument::Type(Box::new(ty)))
}
_ => Err(stream.error("Unrecognized argument")),
}
})?;

Expand Down
4 changes: 2 additions & 2 deletions proc/src/descriptors/combined_image_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub(super) fn parse_combined_image_sampler_attr(
})?;

let sampler = get_unique(
args.iter().filter_map(|arg| match arg {
AttributeArgument::SeparateSampler { member } => Some(member.clone()),
args.iter().map(|arg| match arg {
AttributeArgument::SeparateSampler { member } => member.clone(),
}),
attr,
"Argument with sampler member must be specified",
Expand Down
4 changes: 2 additions & 2 deletions proc/src/descriptors/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn generate(input: &Input) -> TokenStream {
let update_descriptor_statements: TokenStream = input
.descriptors
.iter()
.filter_map(|input| {
.map(|input| {
let field = &input.member;

let descriptor_field = quote::format_ident!("descriptor_{}", input.member);
Expand All @@ -52,7 +52,7 @@ pub(super) fn generate(input: &Input) -> TokenStream {
}
);

Some(stream)
stream
})
.collect();

Expand Down
1 change: 0 additions & 1 deletion proc/src/descriptors/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub(super) fn generate(input: &Input) -> TokenStream {
}
}
)
.into()
}

fn generate_layout_binding(descriptor: &Descriptor, binding: u32) -> TokenStream {
Expand Down
27 changes: 12 additions & 15 deletions proc/src/pass/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub struct Input {

#[derive(Clone)]
pub enum Layout {
Expr(syn::Expr),
Member(syn::Member),
Expr(Box<syn::Expr>),
Member(Box<syn::Member>),
}

#[derive(Clone)]
pub enum ClearValue {
Expr(syn::Expr),
Member(syn::Member),
Expr(Box<syn::Expr>),
Member(Box<syn::Member>),
}

#[derive(Clone)]
Expand Down Expand Up @@ -53,11 +53,8 @@ impl Attachment {
}
_ => {}
}
match &self.store_op {
StoreOp::Store(Layout::Member(layout)) => {
validate_member(layout, item_struct)?;
}
_ => {}
if let StoreOp::Store(Layout::Member(layout)) = &self.store_op {
validate_member(layout, item_struct)?;
}
Ok(())
}
Expand Down Expand Up @@ -313,10 +310,10 @@ fn parse_attachment_attr(attr: &syn::Attribute) -> syn::Result<Option<Attachment
let value = if value.peek(syn::Token![const]) {
let _const = value.parse::<syn::Token![const]>()?;
let expr = value.parse::<syn::Expr>()?;
ClearValue::Expr(expr)
ClearValue::Expr(Box::new(expr))
} else {
let member = value.parse::<syn::Member>()?;
ClearValue::Member(member)
ClearValue::Member(Box::new(member))
};

Ok(AttachmentAttributeArgument::LoadOp(LoadOp::Clear(value)))
Expand All @@ -328,10 +325,10 @@ fn parse_attachment_attr(attr: &syn::Attribute) -> syn::Result<Option<Attachment
let layout = if value.peek(syn::Token![const]) {
let _const = value.parse::<syn::Token![const]>()?;
let expr = value.parse::<syn::Expr>()?;
Layout::Expr(expr)
Layout::Expr(Box::new(expr))
} else {
let member = value.parse::<syn::Member>()?;
Layout::Member(member)
Layout::Member(Box::new(member))
};

Ok(AttachmentAttributeArgument::LoadOp(LoadOp::Load(layout)))
Expand All @@ -343,10 +340,10 @@ fn parse_attachment_attr(attr: &syn::Attribute) -> syn::Result<Option<Attachment
let layout = if value.peek(syn::Token![const]) {
let _const = value.parse::<syn::Token![const]>()?;
let expr = value.parse::<syn::Expr>()?;
Layout::Expr(expr)
Layout::Expr(Box::new(expr))
} else {
let member = value.parse::<syn::Member>()?;
Layout::Member(member)
Layout::Member(Box::new(member))
};

Ok(AttachmentAttributeArgument::StoreOp(StoreOp::Store(layout)))
Expand Down
3 changes: 1 addition & 2 deletions proc/src/pipeline/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(super) fn generate(input: &Input) -> TokenStream {
D: ::sierra::UpdatedPipelineDescriptors<Self>,
{
let raw: &_ = encoder.scope().to_scope(::std::clone::Clone::clone(::sierra::UpdatedDescriptors::raw(updated_descriptors)));

encoder.bind_ray_tracing_descriptor_sets(
&self.pipeline_layout,
D::N,
Expand Down Expand Up @@ -186,5 +186,4 @@ pub(super) fn generate(input: &Input) -> TokenStream {
#pipeline_descriptors

)
.into()
}
File renamed without changes.
4 changes: 2 additions & 2 deletions proc/src/repr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod generate;
mod parse;
mod repr;

use proc_macro2::TokenStream;

Expand All @@ -8,7 +8,7 @@ pub fn shader_repr(attr: proc_macro::TokenStream, item: proc_macro::TokenStream)
Ok(input) => {
let struct_item = &input.item_struct;
std::iter::once(quote::quote!(#struct_item))
.chain(Some(repr::generate_repr(&input)))
.chain(Some(generate::generate_repr(&input)))
// .chain(Some(generate_glsl_type(&input)))
.collect::<TokenStream>()
}
Expand Down
54 changes: 25 additions & 29 deletions src/backend/vulkan/device.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ordered_float::OrderedFloat;

use {
super::{
access::supported_access,
Expand Down Expand Up @@ -401,7 +403,7 @@ impl Device {
address,
buffer_index,
block,
memory_usage.unwrap_or(MemoryUsage::empty()),
memory_usage.unwrap_or_else(MemoryUsage::empty),
))
}

Expand Down Expand Up @@ -878,7 +880,7 @@ impl Device {
.create_graphics_pipelines(None, &[builder], None)
}
.result()
.map_err(|err| oom_error_from_erupt(err))?;
.map_err(oom_error_from_erupt)?;

debug_assert_eq!(pipelines.len(), 1);

Expand Down Expand Up @@ -923,7 +925,7 @@ impl Device {
)
}
.result()
.map_err(|err| oom_error_from_erupt(err))?;
.map_err(oom_error_from_erupt)?;

debug_assert_eq!(pipelines.len(), 1);

Expand Down Expand Up @@ -1027,7 +1029,7 @@ impl Device {
self.inner
.allocator
.lock()
.dealloc(EruptMemoryDevice::wrap(&self.logical()), block);
.dealloc(EruptMemoryDevice::wrap(self.logical()), block);

let handle = self.inner.images.lock().remove(index);
self.inner.logical.destroy_image(Some(handle), None);
Expand Down Expand Up @@ -1280,14 +1282,13 @@ impl Device {
} else {
None
}
.and_then(|c| c.try_into().ok())
.ok_or_else(|| {
.ok_or(
CreateRenderPassError::ColorAttachmentReferenceOutOfBound {
subpass: si,
index: ci,
attachment: c,
}
})?)
)?)
.layout(cl.to_erupt())
)
})
Expand All @@ -1304,13 +1305,12 @@ impl Device {
} else {
None
}
.and_then(|d| d.try_into().ok())
.ok_or_else(|| {
.ok_or(
CreateRenderPassError::DepthAttachmentReferenceOutOfBound {
subpass: si,
attachment: d,
}
})?,
},
)?,
)
.layout(dl.to_erupt()),
);
Expand Down Expand Up @@ -1354,16 +1354,8 @@ impl Device {
.iter()
.map(|d| {
vk1_0::SubpassDependencyBuilder::new()
.src_subpass(
d.src
.map(|s| s.try_into().expect("Subpass index out of bound"))
.unwrap_or(vk1_0::SUBPASS_EXTERNAL),
)
.dst_subpass(
d.dst
.map(|s| s.try_into().expect("Subpass index out of bound"))
.unwrap_or(vk1_0::SUBPASS_EXTERNAL),
)
.src_subpass(d.src.unwrap_or(vk1_0::SUBPASS_EXTERNAL))
.dst_subpass(d.dst.unwrap_or(vk1_0::SUBPASS_EXTERNAL))
.src_stage_mask(d.src_stages.to_erupt())
.dst_stage_mask(d.dst_stages.to_erupt())
.src_access_mask(supported_access(d.src_stages.to_erupt()))
Expand Down Expand Up @@ -1499,7 +1491,7 @@ impl Device {
}
};

if code.len() == 0 {
if code.is_empty() {
return Err(CreateShaderModuleError::InvalidShader {
source: InvalidShader::EmptySource,
});
Expand Down Expand Up @@ -1582,7 +1574,7 @@ impl Device {
/// Only one swapchain may be associated with one surface.
#[tracing::instrument]
pub fn create_swapchain(&self, surface: &mut Surface) -> Result<Swapchain, SurfaceError> {
Ok(Swapchain::new(surface, self)?)
Swapchain::new(surface, self)
}

pub(super) fn insert_swapchain(&self, swapchain: vksw::SwapchainKHR) -> usize {
Expand Down Expand Up @@ -2166,10 +2158,10 @@ impl Device {
.bindings(&bindings)
.flags(info.flags.to_erupt());

let mut flags = vk1_2::DescriptorSetLayoutBindingFlagsCreateInfoBuilder::new()
let flags = vk1_2::DescriptorSetLayoutBindingFlagsCreateInfoBuilder::new()
.binding_flags(&flags);

create_info = create_info.extend_from(&mut flags);
create_info = create_info.extend_from(&flags);

self.inner
.logical
Expand Down Expand Up @@ -2228,7 +2220,7 @@ impl Device {
EruptDescriptorDevice::wrap(&self.inner.logical),
&info.layout.handle(),
flags,
&info.layout.total_count(),
info.layout.total_count(),
1,
)
}
Expand Down Expand Up @@ -2510,8 +2502,8 @@ impl Device {

*acc_structure_write =
vkacc::WriteDescriptorSetAccelerationStructureKHRBuilder::new()
.acceleration_structures(&acceleration_structures[range.clone()]);
write.extend_from(&mut *acc_structure_write)
.acceleration_structures(&acceleration_structures[range]);
write.extend_from(&*acc_structure_write)
}
}
})
Expand All @@ -2536,7 +2528,11 @@ impl Device {
.address_mode_w(info.address_mode_w.to_erupt())
.mip_lod_bias(info.mip_lod_bias.into_inner())
.anisotropy_enable(info.max_anisotropy.is_some())
.max_anisotropy(info.max_anisotropy.unwrap_or(0.0.into()).into_inner())
.max_anisotropy(
info.max_anisotropy
.unwrap_or(OrderedFloat(0.0))
.into_inner(),
)
.compare_enable(info.compare_op.is_some())
.compare_op(match info.compare_op {
Some(compare_op) => compare_op.to_erupt(),
Expand Down
Loading

0 comments on commit 7316a16

Please sign in to comment.