mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
[rs] Fix all the clippy lints and add clippy/fmt CI
This commit is contained in:
parent
aa45e7668b
commit
162fe18e7d
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@ -43,3 +43,23 @@ jobs:
|
||||
- name: cargo doc
|
||||
run: cargo --version; cargo doc --lib --no-deps
|
||||
continue-on-error: true
|
||||
|
||||
lint:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- run: rustup component add clippy
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: -- -D warnings
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: -- --check
|
||||
|
@ -155,7 +155,7 @@ async fn create_png(
|
||||
// from the padded_buffer we write just the unpadded bytes into the image
|
||||
for chunk in padded_buffer.chunks(buffer_dimensions.padded_bytes_per_row) {
|
||||
png_writer
|
||||
.write(&chunk[..buffer_dimensions.unpadded_bytes_per_row])
|
||||
.write_all(&chunk[..buffer_dimensions.unpadded_bytes_per_row])
|
||||
.unwrap();
|
||||
}
|
||||
png_writer.finish().unwrap();
|
||||
|
@ -6,7 +6,7 @@ use winit::{
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
};
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#[rustfmt::skip]
|
||||
#[allow(unused)]
|
||||
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
|
@ -101,7 +101,7 @@ impl Example {
|
||||
let multisampled_frame_descriptor = &wgpu::TextureDescriptor {
|
||||
size: multisampled_texture_extent,
|
||||
mip_level_count: 1,
|
||||
sample_count: sample_count,
|
||||
sample_count,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: sc_desc.format,
|
||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||
@ -192,6 +192,7 @@ impl framework::Example for Example {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||
match event {
|
||||
winit::event::WindowEvent::KeyboardInput { input, .. } => {
|
||||
|
@ -294,7 +294,7 @@ impl framework::Example for Example {
|
||||
use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3};
|
||||
|
||||
let transform = Decomposed {
|
||||
disp: cube.offset.clone(),
|
||||
disp: cube.offset,
|
||||
rot: Quaternion::from_axis_angle(cube.offset.normalize(), Deg(cube.angle)),
|
||||
scale: cube.scale,
|
||||
};
|
||||
|
@ -363,6 +363,7 @@ impl framework::Example for Skybox {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||
match event {
|
||||
winit::event::WindowEvent::CursorMoved { position, .. } => {
|
||||
@ -443,7 +444,7 @@ impl framework::Example for Skybox {
|
||||
}
|
||||
|
||||
rpass.set_pipeline(&self.sky_pipeline);
|
||||
rpass.draw(0..3 as u32, 0..1);
|
||||
rpass.draw(0..3, 0..1);
|
||||
}
|
||||
|
||||
queue.submit(std::iter::once(encoder.finish()));
|
||||
|
@ -662,6 +662,7 @@ impl framework::Example for Example {
|
||||
self.reflect_view = reflect_view;
|
||||
}
|
||||
|
||||
#[allow(clippy::eq_op)]
|
||||
fn render(
|
||||
&mut self,
|
||||
frame: &wgpu::SwapChainTexture,
|
||||
|
@ -30,7 +30,7 @@ const S45: f32 = std::f32::consts::FRAC_1_SQRT_2;
|
||||
///
|
||||
const C45: f32 = S45;
|
||||
|
||||
const SQRT_3: f32 = 1.73205080757;
|
||||
const SQRT_3: f32 = 1.7320508;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)]
|
||||
|
@ -78,15 +78,12 @@ impl Context {
|
||||
let sink = sink_mutex.lock();
|
||||
let mut source_opt: Option<&(dyn Error + 'static)> = Some(&error);
|
||||
while let Some(source) = source_opt {
|
||||
if let Some(device_error) = source.downcast_ref::<wgc::device::DeviceError>() {
|
||||
match device_error {
|
||||
wgc::device::DeviceError::OutOfMemory => {
|
||||
return sink.handle_error(crate::Error::OutOfMemoryError {
|
||||
source: Box::new(error),
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Some(wgc::device::DeviceError::OutOfMemory) =
|
||||
source.downcast_ref::<wgc::device::DeviceError>()
|
||||
{
|
||||
return sink.handle_error(crate::Error::OutOfMemoryError {
|
||||
source: Box::new(error),
|
||||
});
|
||||
}
|
||||
source_opt = source.source();
|
||||
}
|
||||
@ -156,14 +153,14 @@ mod pass_impl {
|
||||
fn insert_debug_marker(&mut self, label: &str) {
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(label).unwrap();
|
||||
wgpu_compute_pass_insert_debug_marker(self, label.as_ptr().into(), 0);
|
||||
wgpu_compute_pass_insert_debug_marker(self, label.as_ptr(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn push_debug_group(&mut self, group_label: &str) {
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(group_label).unwrap();
|
||||
wgpu_compute_pass_push_debug_group(self, label.as_ptr().into(), 0);
|
||||
wgpu_compute_pass_push_debug_group(self, label.as_ptr(), 0);
|
||||
}
|
||||
}
|
||||
fn pop_debug_group(&mut self) {
|
||||
@ -362,14 +359,14 @@ mod pass_impl {
|
||||
fn insert_debug_marker(&mut self, label: &str) {
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(label).unwrap();
|
||||
wgpu_render_pass_insert_debug_marker(self, label.as_ptr().into(), 0);
|
||||
wgpu_render_pass_insert_debug_marker(self, label.as_ptr(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn push_debug_group(&mut self, group_label: &str) {
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(group_label).unwrap();
|
||||
wgpu_render_pass_push_debug_group(self, label.as_ptr().into(), 0);
|
||||
wgpu_render_pass_push_debug_group(self, label.as_ptr(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -637,6 +634,7 @@ impl crate::Context for Context {
|
||||
type SwapChainOutputDetail = SwapChainOutputDetail;
|
||||
|
||||
type RequestAdapterFuture = Ready<Option<Self::AdapterId>>;
|
||||
#[allow(clippy::type_complexity)]
|
||||
type RequestDeviceFuture =
|
||||
Ready<Result<(Self::DeviceId, Self::QueueId), crate::RequestDeviceError>>;
|
||||
type MapAsyncFuture = native_gpu_future::GpuFuture<Result<(), crate::BufferAsyncError>>;
|
||||
@ -853,11 +851,8 @@ impl crate::Context for Context {
|
||||
{
|
||||
// gather all the array view IDs first
|
||||
for entry in desc.entries.iter() {
|
||||
match entry.resource {
|
||||
BindingResource::TextureViewArray(array) => {
|
||||
arrayed_texture_views.extend(array.iter().map(|view| view.id));
|
||||
}
|
||||
_ => {}
|
||||
if let BindingResource::TextureViewArray(array) = entry.resource {
|
||||
arrayed_texture_views.extend(array.iter().map(|view| view.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1290,7 +1285,7 @@ impl crate::Context for Context {
|
||||
MapMode::Write => wgc::device::HostMap::Write,
|
||||
},
|
||||
callback: buffer_map_future_wrapper,
|
||||
user_data: completion.to_raw() as _,
|
||||
user_data: completion.into_raw() as _,
|
||||
};
|
||||
|
||||
let global = &self.0;
|
||||
|
@ -163,12 +163,9 @@ impl PrettyError for wgc::binding_model::CreatePipelineLayoutError {
|
||||
fn fmt_pretty(&self, context: &super::Context) -> String {
|
||||
let global = context.global();
|
||||
let mut ret = format_error_line(self);
|
||||
match *self {
|
||||
Self::InvalidBindGroupLayout(id) => {
|
||||
let name = wgc::gfx_select!(id => global.bind_group_layout_label(id));
|
||||
ret.push_str(&format_label_line("bind group layout", &name));
|
||||
}
|
||||
_ => {}
|
||||
if let Self::InvalidBindGroupLayout(id) = *self {
|
||||
let name = wgc::gfx_select!(id => global.bind_group_layout_label(id));
|
||||
ret.push_str(&format_label_line("bind group layout", &name));
|
||||
};
|
||||
ret
|
||||
}
|
||||
@ -192,12 +189,9 @@ impl PrettyError for wgc::command::RenderPassErrorInner {
|
||||
fn fmt_pretty(&self, context: &super::Context) -> String {
|
||||
let global = context.global();
|
||||
let mut ret = format_error_line(self);
|
||||
match *self {
|
||||
Self::InvalidAttachment(id) => {
|
||||
let name = wgc::gfx_select!(id => global.texture_view_label(id));
|
||||
ret.push_str(&format_label_line("attachment", &name));
|
||||
}
|
||||
_ => {}
|
||||
if let Self::InvalidAttachment(id) = *self {
|
||||
let name = wgc::gfx_select!(id => global.texture_view_label(id));
|
||||
ret.push_str(&format_label_line("attachment", &name));
|
||||
};
|
||||
ret
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl<T> GpuFutureCompletion<T> {
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) fn to_raw(self) -> *mut OpaqueData {
|
||||
pub(crate) fn into_raw(self) -> *mut OpaqueData {
|
||||
Arc::into_raw(self.data) as _
|
||||
}
|
||||
|
||||
|
@ -2853,7 +2853,7 @@ impl SwapChain {
|
||||
let output = view_id.map(|id| SwapChainTexture {
|
||||
view: TextureView {
|
||||
context: Arc::clone(&self.context),
|
||||
id: id,
|
||||
id,
|
||||
owned: false,
|
||||
},
|
||||
detail,
|
||||
|
@ -42,7 +42,8 @@ impl DeviceExt for crate::Device {
|
||||
// 2. buffer size must be greater than 0.
|
||||
// Therefore we round the value up to the nearest multiple, and ensure it's at least COPY_BUFFER_ALIGNMENT.
|
||||
let align_mask = crate::COPY_BUFFER_ALIGNMENT - 1;
|
||||
let padded_size = ((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT);
|
||||
let padded_size =
|
||||
((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT);
|
||||
|
||||
let wgt_descriptor = crate::BufferDescriptor {
|
||||
label: descriptor.label,
|
||||
|
@ -24,7 +24,7 @@ pub use encoder::RenderEncoder;
|
||||
/// - Input length isn't multiple of 4
|
||||
/// - Input is longer than [`usize::max_value`]
|
||||
/// - SPIR-V magic number is missing from beginning of stream
|
||||
pub fn make_spirv<'a>(data: &'a [u8]) -> super::ShaderSource<'a> {
|
||||
pub fn make_spirv(data: &[u8]) -> super::ShaderSource {
|
||||
const MAGIC_NUMBER: u32 = 0x0723_0203;
|
||||
|
||||
assert_eq!(
|
||||
|
Loading…
Reference in New Issue
Block a user