Skip to content

Commit

Permalink
build and clippy fixes, command buffer cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 10, 2021
1 parent 3172377 commit 006f8ab
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
17 changes: 7 additions & 10 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
});
}

if let Some(ref label) = base.label {
unsafe {
raw.begin_debug_marker(label);
}
}

let (_, mut token) = hub.render_bundles.read(&mut token);
let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token);
let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token);
Expand All @@ -315,6 +309,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut string_offset = 0;
let mut active_query = None;

let hal_desc = hal::ComputePassDescriptor { label: base.label };
unsafe {
raw.begin_compute_pass(&hal_desc);
}

for command in base.commands {
match *command {
ComputeCommand::SetBindGroup {
Expand Down Expand Up @@ -659,10 +658,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}

if let Some(_) = base.label {
unsafe {
raw.end_debug_marker();
}
unsafe {
raw.end_compute_pass();
}
cmd_buf.status = CommandEncoderStatus::Recording;

Expand Down
3 changes: 1 addition & 2 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl<A: HalApi> CommandBuffer<A> {
#[cfg(feature = "trace")] enable_tracing: bool,
#[cfg(debug_assertions)] label: &Label,
) -> Self {
use crate::LabelHelpers as _;
CommandBuffer {
raw: vec![raw],
status: CommandEncoderStatus::Recording,
Expand All @@ -89,7 +88,7 @@ impl<A: HalApi> CommandBuffer<A> {
None
},
#[cfg(debug_assertions)]
label: label.borrow_or_default().to_string(),
label: crate::LabelHelpers::borrow_or_default(label).to_string(),
}
}

Expand Down
5 changes: 3 additions & 2 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3448,6 +3448,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device.features,
#[cfg(feature = "trace")]
device.trace.is_some(),
#[cfg(debug_assertions)]
&desc.label,
);

Expand Down Expand Up @@ -4412,14 +4413,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
#[cfg(feature = "trace")]
if let Some(ref trace) = device.trace {
let mut trace = trace.lock();
let size = sub_range.size_to(buffer.size);
let size = range.end - range.start;
let data = trace.make_binary("bin", unsafe {
std::slice::from_raw_parts(ptr.as_ptr(), size as usize)
});
trace.add(trace::Action::WriteBuffer {
id: buffer_id,
data,
range: sub_range.offset..sub_range.offset + size,
range: range.clone(),
queued: false,
});
}
Expand Down
5 changes: 3 additions & 2 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ impl<A: hal::Api> PendingWrites<A> {
}

pub fn dispose(self, device: &A::Device) {
if let Some(raw) = self.command_buffer {
if let Some(cmd_buf) = self.command_buffer {
unsafe {
device.destroy_command_buffer(raw);
device.destroy_command_buffer(cmd_buf);
}
}
for resource in self.temp_resources {
Expand All @@ -91,6 +91,7 @@ impl<A: hal::Api> PendingWrites<A> {

fn consume(&mut self, stage: StagingData<A>) {
self.temp_resources.push(TempResource::Buffer(stage.buffer));
assert!(self.command_buffer.is_none());
self.command_buffer = Some(stage.cmdbuf);
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn new_render_bundle_encoder_descriptor<'a>(
label,
color_formats: Cow::Borrowed(&context.attachments.colors),
depth_stencil_format: context.attachments.depth_stencil,
sample_count: context.sample_count as u32,
sample_count: context.sample_count,
}
}

Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/swap_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.take()
.ok_or(SwapChainError::AlreadyAcquired)?;
let (view_maybe, _) = hub.texture_views.unregister(view_id.value.0, &mut token);
drop(view_id); // contains the ref count
let view = view_maybe.ok_or(SwapChainError::Invalid)?;
if view.life_guard.ref_count.unwrap().load() != 1 {
return Err(SwapChainError::StillReferenced);
Expand Down
8 changes: 2 additions & 6 deletions wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl super::CommandBuffer {
self.blit.as_ref().unwrap()
}

fn leave_blit(&mut self) {
pub(super) fn leave_blit(&mut self) {
if let Some(encoder) = self.blit.take() {
encoder.end_encoding();
}
Expand All @@ -22,11 +22,7 @@ impl super::CommandBuffer {
} else if let Some(ref encoder) = self.compute {
encoder
} else {
if self.blit.is_none() {
debug_assert!(self.render.is_none() && self.compute.is_none());
self.blit = Some(self.raw.new_blit_command_encoder().to_owned());
}
self.blit.as_ref().unwrap()
self.enter_blit()
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ impl crate::Device<super::Api> for super::Device {
disabilities: self.shared.disabilities.clone(),
})
}
unsafe fn destroy_command_buffer(&self, _cmd_buf: super::CommandBuffer) {}
unsafe fn destroy_command_buffer(&self, mut cmd_buf: super::CommandBuffer) {
cmd_buf.leave_blit();
}

unsafe fn create_bind_group_layout(
&self,
Expand Down

0 comments on commit 006f8ab

Please sign in to comment.