Skip to content

Commit

Permalink
Formatting pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Oct 24, 2019
1 parent 41c433e commit 5099754
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 206 deletions.
10 changes: 9 additions & 1 deletion wgpu-native/src/command/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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

use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _};
use parking_lot::Mutex;
Expand Down
22 changes: 11 additions & 11 deletions wgpu-native/src/command/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ pub enum LayoutChange<'a> {
#[derive(Debug)]
pub enum Provision {
Unchanged,
Changed {
was_compatible: bool,
},
Changed { was_compatible: bool },
}

struct TakeSome<I> {
Expand Down Expand Up @@ -94,9 +92,7 @@ impl BindGroupEntry {
self.dynamic_offsets.clear();
self.dynamic_offsets.extend_from_slice(offsets);

Provision::Changed {
was_compatible,
}
Provision::Changed { was_compatible }
}

pub fn expect_layout(&mut self, bind_group_layout_id: BindGroupLayoutId) -> LayoutChange {
Expand All @@ -107,8 +103,9 @@ impl BindGroupEntry {
Some(BindGroupPair {
layout_id,
ref group_id,
}) if layout_id == bind_group_layout_id =>
LayoutChange::Match(group_id.value, &self.dynamic_offsets),
}) if layout_id == bind_group_layout_id => {
LayoutChange::Match(group_id.value, &self.dynamic_offsets)
}
Some(_) | None => LayoutChange::Mismatch,
}
} else {
Expand Down Expand Up @@ -147,7 +144,7 @@ impl Binder {
pub(crate) fn new(max_bind_groups: u32) -> Self {
Self {
pipeline_layout_id: None,
entries: smallvec![Default::default(); max_bind_groups as usize]
entries: smallvec![Default::default(); max_bind_groups as usize],
}
}

Expand Down Expand Up @@ -181,8 +178,11 @@ impl Binder {
Provision::Changed { was_compatible, .. } => {
let compatible_count = self.compatible_count();
if index < compatible_count {
let end = compatible_count
.min(if was_compatible { index + 1 } else { self.entries.len() });
let end = compatible_count.min(if was_compatible {
index + 1
} else {
self.entries.len()
});
log::trace!("\t\tbinding up to {}", end);
Some((
self.pipeline_layout_id?,
Expand Down
11 changes: 8 additions & 3 deletions wgpu-native/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ pub extern "C" fn wgpu_compute_pass_insert_debug_marker(

// Compute-specific routines

pub fn compute_pass_dispatch<B: GfxBackend>(global: &Global, pass_id: ComputePassId, x: u32, y: u32, z: u32) {
pub fn compute_pass_dispatch<B: GfxBackend>(
global: &Global,
pass_id: ComputePassId,
x: u32,
y: u32,
z: u32,
) {
let hub = B::hub(global);
let mut token = Token::root();
let (mut pass_guard, _) = hub.compute_passes.write(&mut token);
Expand Down Expand Up @@ -291,8 +297,7 @@ pub fn compute_pass_set_pipeline<B: GfxBackend>(
);
}
}
LayoutChange::Match(..) |
LayoutChange::Unchanged => {}
LayoutChange::Match(..) | LayoutChange::Unchanged => {}
LayoutChange::Mismatch => {
is_compatible = false;
}
Expand Down
164 changes: 84 additions & 80 deletions wgpu-native/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ use hal::{adapter::PhysicalDevice as _, command::CommandBuffer as _, device::Dev

#[cfg(feature = "local")]
use std::marker::PhantomData;
use std::{
borrow::Borrow,
collections::hash_map::Entry,
iter,
mem,
ptr,
slice,
thread::ThreadId,
};
use std::{borrow::Borrow, collections::hash_map::Entry, iter, mem, ptr, slice, thread::ThreadId};


pub struct RenderBundle<B: hal::Backend> {
Expand Down Expand Up @@ -292,17 +284,15 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
}
let texture_id = match view.inner {
TextureViewInner::Native { ref source_id, .. } => source_id.value,
TextureViewInner::SwapChain {..} =>
panic!("Unexpected depth/stencil use of swapchain image!"),
TextureViewInner::SwapChain { .. } => {
panic!("Unexpected depth/stencil use of swapchain image!")
}
};

let texture = &texture_guard[texture_id];
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));

let old_layout = match trackers
.textures
.query(texture_id, view.range.clone())
{
let old_layout = match trackers.textures.query(texture_id, view.range.clone()) {
Some(usage) => {
conv::map_texture_state(
usage,
Expand Down Expand Up @@ -355,40 +345,42 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
view.samples, sample_count,
"All attachments must have the same sample_count"
);
let first_use = trackers.views
.init(at.attachment, &view.life_guard.ref_count, (), ());
let first_use =
trackers
.views
.init(at.attachment, &view.life_guard.ref_count, (), ());

let layouts = match view.inner {
TextureViewInner::Native { ref source_id, .. } => {
let texture = &texture_guard[source_id.value];
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));

let old_layout = match trackers
.textures
.query(source_id.value, view.range.clone())
{
Some(usage) => conv::map_texture_state(usage, hal::format::Aspects::COLOR).1,
None => {
// Required sub-resources have inconsistent states, we need to
// issue individual barriers instead of relying on the render pass.
let pending = trackers.textures.change_replace(
source_id.value,
&texture.life_guard.ref_count,
view.range.clone(),
TextureUsage::OUTPUT_ATTACHMENT,
);
barriers.extend(pending.map(|pending| {
log::trace!("\tcolor {:?}", pending);
hal::memory::Barrier::Image {
states: pending.to_states(),
target: &texture.raw,
families: None,
range: pending.selector,
}
}));
hal::image::Layout::ColorAttachmentOptimal
}
};
let old_layout =
match trackers.textures.query(source_id.value, view.range.clone()) {
Some(usage) => {
conv::map_texture_state(usage, hal::format::Aspects::COLOR).1
}
None => {
// Required sub-resources have inconsistent states, we need to
// issue individual barriers instead of relying on the render pass.
let pending = trackers.textures.change_replace(
source_id.value,
&texture.life_guard.ref_count,
view.range.clone(),
TextureUsage::OUTPUT_ATTACHMENT,
);
barriers.extend(pending.map(|pending| {
log::trace!("\tcolor {:?}", pending);
hal::memory::Barrier::Image {
states: pending.to_states(),
target: &texture.raw,
families: None,
range: pending.selector,
}
}));
hal::image::Layout::ColorAttachmentOptimal
}
};
old_layout .. hal::image::Layout::ColorAttachmentOptimal
}
TextureViewInner::SwapChain { .. } => {
Expand All @@ -403,7 +395,11 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
}

let end = hal::image::Layout::Present;
let start = if first_use { hal::image::Layout::Undefined } else { end };
let start = if first_use {
hal::image::Layout::Undefined
} else {
end
};
start .. end
}
};
Expand All @@ -427,40 +423,42 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
view.samples, 1,
"All resolve_targets must have a sample_count of 1"
);
let first_use = trackers.views
.init(resolve_target, &view.life_guard.ref_count, (), ());
let first_use =
trackers
.views
.init(resolve_target, &view.life_guard.ref_count, (), ());

let layouts = match view.inner {
TextureViewInner::Native { ref source_id, .. } => {
let texture = &texture_guard[source_id.value];
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));

let old_layout = match trackers
.textures
.query(source_id.value, view.range.clone())
{
Some(usage) => conv::map_texture_state(usage, hal::format::Aspects::COLOR).1,
None => {
// Required sub-resources have inconsistent states, we need to
// issue individual barriers instead of relying on the render pass.
let pending = trackers.textures.change_replace(
source_id.value,
&texture.life_guard.ref_count,
view.range.clone(),
TextureUsage::OUTPUT_ATTACHMENT,
);
barriers.extend(pending.map(|pending| {
log::trace!("\tresolve {:?}", pending);
hal::memory::Barrier::Image {
states: pending.to_states(),
target: &texture.raw,
families: None,
range: pending.selector,
}
}));
hal::image::Layout::ColorAttachmentOptimal
}
};
let old_layout =
match trackers.textures.query(source_id.value, view.range.clone()) {
Some(usage) => {
conv::map_texture_state(usage, hal::format::Aspects::COLOR).1
}
None => {
// Required sub-resources have inconsistent states, we need to
// issue individual barriers instead of relying on the render pass.
let pending = trackers.textures.change_replace(
source_id.value,
&texture.life_guard.ref_count,
view.range.clone(),
TextureUsage::OUTPUT_ATTACHMENT,
);
barriers.extend(pending.map(|pending| {
log::trace!("\tresolve {:?}", pending);
hal::memory::Barrier::Image {
states: pending.to_states(),
target: &texture.raw,
families: None,
range: pending.selector,
}
}));
hal::image::Layout::ColorAttachmentOptimal
}
};
old_layout .. hal::image::Layout::ColorAttachmentOptimal
}
TextureViewInner::SwapChain { .. } => {
Expand All @@ -475,7 +473,11 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
}

let end = hal::image::Layout::Present;
let start = if first_use { hal::image::Layout::Undefined } else { end };
let start = if first_use {
hal::image::Layout::Undefined
} else {
end
};
start .. end
}
};
Expand Down Expand Up @@ -604,12 +606,16 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
let fb = {
let attachments = e.key().all().map(|&id| match view_guard[id].inner {
TextureViewInner::Native { ref raw, .. } => raw,
TextureViewInner::SwapChain { ref image, .. } => Borrow::borrow(image),
TextureViewInner::SwapChain { ref image, .. } => {
Borrow::borrow(image)
}
});
unsafe {
device
.raw
.create_framebuffer(&render_pass, attachments, extent.unwrap())
device.raw.create_framebuffer(
&render_pass,
attachments,
extent.unwrap(),
)
}
.unwrap()
};
Expand Down Expand Up @@ -655,9 +661,7 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
uint32: conv::map_color_u32(&at.clear_color),
},
};
Some(hal::command::ClearValue {
color: value,
})
Some(hal::command::ClearValue { color: value })
}
}
})
Expand Down
19 changes: 10 additions & 9 deletions wgpu-native/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use crate::{
Stored,
};
#[cfg(feature = "local")]
use crate::{gfx_select, RawString, RenderBundleId, hub::GLOBAL};
use crate::{gfx_select, hub::GLOBAL, RawString, RenderBundleId};

use hal::command::CommandBuffer as _;

use std::{iter, ops::Range};
#[cfg(feature = "local")]
use std::slice;
use std::{iter, ops::Range};

#[derive(Debug, PartialEq)]
enum OptionalState {
Expand Down Expand Up @@ -644,8 +644,7 @@ pub fn render_pass_set_pipeline<B: GfxBackend>(
);
}
}
LayoutChange::Match(..) |
LayoutChange::Unchanged => {}
LayoutChange::Match(..) | LayoutChange::Unchanged => {}
LayoutChange::Mismatch => {
is_compatible = false;
}
Expand Down Expand Up @@ -704,7 +703,9 @@ pub extern "C" fn wgpu_render_pass_set_pipeline(
}

pub fn render_pass_set_blend_color<B: GfxBackend>(
global: &Global, pass_id: RenderPassId, color: &Color
global: &Global,
pass_id: RenderPassId,
color: &Color,
) {
let hub = B::hub(global);
let mut token = Token::root();
Expand All @@ -725,7 +726,9 @@ pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color:
}

pub fn render_pass_set_stencil_reference<B: GfxBackend>(
global: &Global, pass_id: RenderPassId, value: u32
global: &Global,
pass_id: RenderPassId,
value: u32,
) {
let hub = B::hub(global);
let mut token = Token::root();
Expand All @@ -741,9 +744,7 @@ pub fn render_pass_set_stencil_reference<B: GfxBackend>(

#[cfg(feature = "local")]
#[no_mangle]
pub extern "C" fn wgpu_render_pass_set_stencil_reference(
pass_id: RenderPassId, value: u32
) {
pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: RenderPassId, value: u32) {
gfx_select!(pass_id => render_pass_set_stencil_reference(&*GLOBAL, pass_id, value))
}

Expand Down
Loading

0 comments on commit 5099754

Please sign in to comment.