Skip to content

Commit

Permalink
Rustfmt stable pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Apr 6, 2020
1 parent 384606f commit a3aefe2
Show file tree
Hide file tree
Showing 29 changed files with 875 additions and 1,066 deletions.
4 changes: 0 additions & 4 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
newline_style = "Native"
blank_lines_upper_bound = 2
spaces_around_ranges = true
imports_layout = "HorizontalVertical"
39 changes: 28 additions & 11 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@

use crate::{
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId},
track::{DUMMY_SELECTOR, TrackerSet},
FastHashMap,
LifeGuard,
RefCount,
Stored,
track::{TrackerSet, DUMMY_SELECTOR},
FastHashMap, LifeGuard, RefCount, Stored,
};

use wgt::{BufferAddress, TextureComponentType};
use arrayvec::ArrayVec;
use gfx_descriptor::{DescriptorCounts, DescriptorSet};
use wgt::{BufferAddress, TextureComponentType};

#[cfg(feature = "serde")]
use serde_crate::{Deserialize, Serialize};
use std::borrow::Borrow;

#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
pub enum BindingType {
UniformBuffer = 0,
StorageBuffer = 1,
Expand All @@ -35,7 +36,11 @@ pub enum BindingType {

#[repr(C)]
#[derive(Clone, Debug, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
pub struct BindGroupLayoutEntry {
pub binding: u32,
pub visibility: wgt::ShaderStage,
Expand Down Expand Up @@ -80,7 +85,11 @@ pub struct PipelineLayout<B: hal::Backend> {

#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
pub struct BufferBinding {
pub buffer: BufferId,
pub offset: BufferAddress,
Expand All @@ -89,7 +98,11 @@ pub struct BufferBinding {

#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
pub enum BindingResource {
Buffer(BufferBinding),
Sampler(SamplerId),
Expand All @@ -98,7 +111,11 @@ pub enum BindingResource {

#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
pub struct BindGroupEntry {
pub binding: u32,
pub resource: BindingResource,
Expand Down
20 changes: 10 additions & 10 deletions wgpu-core/src/command/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

use super::CommandBuffer;
use crate::{
hub::GfxBackend,
id::DeviceId,
track::TrackerSet,
Features,
LifeGuard,
Stored,
SubmissionIndex,
hub::GfxBackend, id::DeviceId, track::TrackerSet, Features, LifeGuard, Stored, SubmissionIndex,
};

use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _};
Expand All @@ -27,7 +21,7 @@ struct CommandPool<B: hal::Backend> {

impl<B: hal::Backend> CommandPool<B> {
fn maintain(&mut self, lowest_active_index: SubmissionIndex) {
for i in (0 .. self.pending.len()).rev() {
for i in (0..self.pending.len()).rev() {
let index = self.pending[i]
.life_guard
.submission_index
Expand Down Expand Up @@ -55,7 +49,10 @@ impl<B: hal::Backend> CommandPool<B> {

fn allocate(&mut self) -> B::CommandBuffer {
if self.available.is_empty() {
unsafe { self.raw.allocate(20, hal::command::Level::Primary, &mut self.available) };
unsafe {
self.raw
.allocate(20, hal::command::Level::Primary, &mut self.available)
};
}
self.available.pop().unwrap()
}
Expand Down Expand Up @@ -131,7 +128,10 @@ impl<B: hal::Backend> CommandAllocator<B> {
let pool = inner.pools.get_mut(&cmd_buf.recorded_thread_id).unwrap();

if pool.available.is_empty() {
unsafe { pool.raw.allocate(20, hal::command::Level::Primary, &mut pool.available) };
unsafe {
pool.raw
.allocate(20, hal::command::Level::Primary, &mut pool.available)
};
}

pool.available.pop().unwrap()
Expand Down
15 changes: 5 additions & 10 deletions wgpu-core/src/command/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
};

use smallvec::{smallvec, SmallVec};
use wgt::DynamicOffset;
use std::slice;
use wgt::DynamicOffset;

pub const DEFAULT_BIND_GROUPS: usize = 4;
type BindGroupMask = u8;
Expand Down Expand Up @@ -44,12 +44,7 @@ impl<'a> Iterator for FollowUpIter<'a> {
fn next(&mut self) -> Option<Self::Item> {
self.iter
.next()
.and_then(|entry| {
Some((
entry.actual_value()?,
entry.dynamic_offsets.as_slice(),
))
})
.and_then(|entry| Some((entry.actual_value()?, entry.dynamic_offsets.as_slice())))
}
}

Expand Down Expand Up @@ -151,7 +146,7 @@ impl Binder {
}

pub(crate) fn reset_expectations(&mut self, length: usize) {
for entry in self.entries[length ..].iter_mut() {
for entry in self.entries[length..].iter_mut() {
entry.expected_layout_id = None;
}
}
Expand Down Expand Up @@ -185,8 +180,8 @@ impl Binder {
Some((
self.pipeline_layout_id?,
FollowUpIter {
iter: self.entries[index + 1 .. end].iter(),
}
iter: self.entries[index + 1..end].iter(),
},
))
} else {
log::trace!("\t\tskipping above compatible {}", compatible_count);
Expand Down
80 changes: 42 additions & 38 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
use crate::{
command::{
bind::{Binder, LayoutChange},
CommandBuffer,
PhantomSlice,
CommandBuffer, PhantomSlice,
},
device::all_buffer_stages,
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
id,
};

use wgt::{BufferAddress, BufferUsage, DynamicOffset, BIND_BUFFER_ALIGNMENT};
use hal::command::CommandBuffer as _;
use peek_poke::{Peek, PeekPoke, Poke};
use wgt::{BufferAddress, BufferUsage, DynamicOffset, BIND_BUFFER_ALIGNMENT};

use std::iter;

Expand Down Expand Up @@ -90,17 +89,24 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut pipeline_state = PipelineState::Required;

let mut peeker = raw_data.as_ptr();
let raw_data_end = unsafe {
raw_data.as_ptr().add(raw_data.len())
};
let raw_data_end = unsafe { raw_data.as_ptr().add(raw_data.len()) };
let mut command = ComputeCommand::Dispatch([0; 3]); // dummy
loop {
assert!(unsafe { peeker.add(ComputeCommand::max_size()) } <= raw_data_end);
peeker = unsafe { ComputeCommand::peek_from(peeker, &mut command) };
match command {
ComputeCommand::SetBindGroup { index, num_dynamic_offsets, bind_group_id, phantom_offsets } => {
ComputeCommand::SetBindGroup {
index,
num_dynamic_offsets,
bind_group_id,
phantom_offsets,
} => {
let (new_peeker, offsets) = unsafe {
phantom_offsets.decode_unaligned(peeker, num_dynamic_offsets as usize, raw_data_end)
phantom_offsets.decode_unaligned(
peeker,
num_dynamic_offsets as usize,
raw_data_end,
)
};
peeker = new_peeker;

Expand Down Expand Up @@ -136,11 +142,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&*texture_guard,
);

if let Some((pipeline_layout_id, follow_ups)) = binder
.provide_entry(index as usize, bind_group_id, bind_group, offsets)
if let Some((pipeline_layout_id, follow_ups)) =
binder.provide_entry(index as usize, bind_group_id, bind_group, offsets)
{
let bind_groups = iter::once(bind_group.raw.raw())
.chain(follow_ups.clone().map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()));
let bind_groups = iter::once(bind_group.raw.raw()).chain(
follow_ups
.clone()
.map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()),
);
unsafe {
raw.bind_compute_descriptor_sets(
&pipeline_layout_guard[pipeline_layout_id].raw,
Expand All @@ -156,7 +165,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
ComputeCommand::SetPipeline(pipeline_id) => {
pipeline_state = PipelineState::Set;
let pipeline = cmb.trackers
let pipeline = cmb
.trackers
.compute_pipes
.use_extend(&*pipeline_guard, pipeline_id, (), ())
.unwrap();
Expand All @@ -169,8 +179,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if binder.pipeline_layout_id != Some(pipeline.layout_id) {
let pipeline_layout = &pipeline_layout_guard[pipeline.layout_id];
binder.pipeline_layout_id = Some(pipeline.layout_id);
binder
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
binder.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
let mut is_compatible = true;

for (index, (entry, &bgl_id)) in binder
Expand Down Expand Up @@ -200,13 +209,21 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
ComputeCommand::Dispatch(groups) => {
assert_eq!(pipeline_state, PipelineState::Set, "Dispatch error: Pipeline is missing");
assert_eq!(
pipeline_state,
PipelineState::Set,
"Dispatch error: Pipeline is missing"
);
unsafe {
raw.dispatch(groups);
}
}
ComputeCommand::DispatchIndirect { buffer_id, offset } => {
assert_eq!(pipeline_state, PipelineState::Set, "Dispatch error: Pipeline is missing");
assert_eq!(
pipeline_state,
PipelineState::Set,
"Dispatch error: Pipeline is missing"
);
let (src_buffer, src_pending) = cmb.trackers.buffers.use_replace(
&*buffer_guard,
buffer_id,
Expand All @@ -219,7 +236,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

unsafe {
raw.pipeline_barrier(
all_buffer_stages() .. all_buffer_stages(),
all_buffer_stages()..all_buffer_stages(),
hal::memory::Dependencies::empty(),
barriers,
);
Expand All @@ -234,15 +251,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

pub mod compute_ffi {
use super::{
ComputeCommand,
super::{PhantomSlice, RawPass},
ComputeCommand,
};
use crate::{
id,
RawString,
};
use wgt::{BufferAddress, DynamicOffset};
use crate::{id, RawString};
use std::{convert::TryInto, slice};
use wgt::{BufferAddress, DynamicOffset};

/// # Safety
///
Expand All @@ -264,9 +278,7 @@ use wgt::{BufferAddress, DynamicOffset};
bind_group_id,
phantom_offsets: PhantomSlice::default(),
});
pass.encode_slice(
slice::from_raw_parts(offsets, offset_length),
);
pass.encode_slice(slice::from_raw_parts(offsets, offset_length));
}

#[no_mangle]
Expand All @@ -293,24 +305,16 @@ use wgt::{BufferAddress, DynamicOffset};
buffer_id: id::BufferId,
offset: BufferAddress,
) {
pass.encode(&ComputeCommand::DispatchIndirect {
buffer_id,
offset,
});
pass.encode(&ComputeCommand::DispatchIndirect { buffer_id, offset });
}

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_push_debug_group(
_pass: &mut RawPass,
_label: RawString,
) {
pub extern "C" fn wgpu_compute_pass_push_debug_group(_pass: &mut RawPass, _label: RawString) {
//TODO
}

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_pop_debug_group(
_pass: &mut RawPass,
) {
pub extern "C" fn wgpu_compute_pass_pop_debug_group(_pass: &mut RawPass) {
//TODO
}

Expand Down
Loading

0 comments on commit a3aefe2

Please sign in to comment.