Skip to content

Commit

Permalink
Merge gfx-rs#847
Browse files Browse the repository at this point in the history
847: Gecko-requested refactor r=cwfitzgerald a=kvark



Co-authored-by: Dzmitry Malyshau <[email protected]>
  • Loading branch information
bors[bot] and kvark authored Jul 28, 2020
2 parents 5bd24d5 + bf862b7 commit 0dcd1e1
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 85 deletions.
63 changes: 52 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
&wgt::CommandEncoderDescriptor { label: ptr::null() },
comb_manager.alloc(device.backend()),
);
let comb = self.encode_commands::<B>(encoder, commands);
self.queue_submit::<B>(device, &[comb]).unwrap();
let cmdbuf = self.encode_commands::<B>(encoder, commands);
self.queue_submit::<B>(device, &[cmdbuf]).unwrap();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ package = "wgpu-types"
version = "0.5"

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { version = "0.5.4" }
gfx-backend-vulkan = { version = "0.5.9", optional = true }
gfx-backend-metal = { version = "0.5.6" }
gfx-backend-vulkan = { version = "0.5.11", optional = true }

[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.5.9" }
gfx-backend-vulkan = { version = "0.5.11" }

[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = { version = "0.5.8" }
gfx-backend-dx11 = { version = "0.5" }
gfx-backend-vulkan = { version = "0.5.9" }
gfx-backend-vulkan = { version = "0.5.11" }

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
battery = { version = "0.7", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/command/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<B: hal::Backend> CommandPool<B> {
if self.pending[i].1 <= last_done_index {
let (cmd_buf, index) = self.pending.swap_remove(i);
tracing::trace!(
"recycling comb submitted in {} when {} is last done",
"recycling cmdbuf submitted in {} when {} is last done",
index,
last_done_index,
);
Expand Down
22 changes: 11 additions & 11 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl RenderBundle {
/// a chance to go through the commands in `render_bundle_encoder_finish`.
pub(crate) unsafe fn execute<B: GfxBackend>(
&self,
comb: &mut B::CommandBuffer,
cmdbuf: &mut B::CommandBuffer,
pipeline_layout_guard: &Storage<
crate::binding_model::PipelineLayout<B>,
id::PipelineLayoutId,
Expand All @@ -149,7 +149,7 @@ impl RenderBundle {
bind_group_id,
} => {
let bind_group = &bind_group_guard[bind_group_id];
comb.bind_graphics_descriptor_sets(
cmdbuf.bind_graphics_descriptor_sets(
&pipeline_layout_guard[pipeline_layout_id.unwrap()].raw,
index as usize,
iter::once(bind_group.raw.raw()),
Expand All @@ -159,7 +159,7 @@ impl RenderBundle {
}
RenderCommand::SetPipeline(pipeline_id) => {
let pipeline = &pipeline_guard[pipeline_id];
comb.bind_graphics_pipeline(&pipeline.raw);
cmdbuf.bind_graphics_pipeline(&pipeline.raw);
index_type = conv::map_index_format(pipeline.index_format);
pipeline_layout_id = Some(pipeline.layout_id.value);
}
Expand All @@ -178,7 +178,7 @@ impl RenderBundle {
index_type,
};

comb.bind_index_buffer(view);
cmdbuf.bind_index_buffer(view);
}
RenderCommand::SetVertexBuffer {
slot,
Expand All @@ -191,7 +191,7 @@ impl RenderBundle {
offset,
size: size.map(|s| s.get()),
};
comb.bind_vertex_buffers(slot, iter::once((&buffer.raw, range)));
cmdbuf.bind_vertex_buffers(slot, iter::once((&buffer.raw, range)));
}
RenderCommand::SetPushConstant {
stages,
Expand All @@ -208,7 +208,7 @@ impl RenderBundle {
let data_slice = &self.base.push_constant_data
[(values_offset as usize)..values_end_offset];

comb.push_graphics_constants(
cmdbuf.push_graphics_constants(
&pipeline_layout.raw,
conv::map_shader_stage_flags(stages),
offset,
Expand All @@ -219,7 +219,7 @@ impl RenderBundle {
offset,
size_bytes,
|clear_offset, clear_data| {
comb.push_graphics_constants(
cmdbuf.push_graphics_constants(
&pipeline_layout.raw,
conv::map_shader_stage_flags(stages),
clear_offset,
Expand All @@ -235,7 +235,7 @@ impl RenderBundle {
first_vertex,
first_instance,
} => {
comb.draw(
cmdbuf.draw(
first_vertex..first_vertex + vertex_count,
first_instance..first_instance + instance_count,
);
Expand All @@ -247,7 +247,7 @@ impl RenderBundle {
base_vertex,
first_instance,
} => {
comb.draw_indexed(
cmdbuf.draw_indexed(
first_index..first_index + index_count,
base_vertex,
first_instance..first_instance + instance_count,
Expand All @@ -260,7 +260,7 @@ impl RenderBundle {
indexed: false,
} => {
let buffer = &buffer_guard[buffer_id];
comb.draw_indirect(&buffer.raw, offset, 1, 0);
cmdbuf.draw_indirect(&buffer.raw, offset, 1, 0);
}
RenderCommand::MultiDrawIndirect {
buffer_id,
Expand All @@ -269,7 +269,7 @@ impl RenderBundle {
indexed: true,
} => {
let buffer = &buffer_guard[buffer_id];
comb.draw_indexed_indirect(&buffer.raw, offset, 1, 0);
cmdbuf.draw_indexed_indirect(&buffer.raw, offset, 1, 0);
}
RenderCommand::MultiDrawIndirect { .. }
| RenderCommand::MultiDrawIndirectCount { .. } => unimplemented!(),
Expand Down
12 changes: 6 additions & 6 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (swap_chain_guard, mut token) = hub.swap_chains.read(&mut token);
//TODO: actually close the last recorded command buffer
let (mut comb_guard, _) = hub.command_buffers.write(&mut token);
let comb = &mut comb_guard[encoder_id];
if !comb.is_recording {
let cmdbuf = &mut comb_guard[encoder_id];
if !cmdbuf.is_recording {
return Err(CommandEncoderFinishError::NotRecording);
}
comb.is_recording = false;
cmdbuf.is_recording = false;
// stop tracking the swapchain image, if used
if let Some((ref sc_id, _)) = comb.used_swap_chain {
if let Some((ref sc_id, _)) = cmdbuf.used_swap_chain {
let view_id = swap_chain_guard[sc_id.value]
.acquired_view_id
.as_ref()
.expect("Used swap chain frame has already presented");
comb.trackers.views.remove(view_id.value);
cmdbuf.trackers.views.remove(view_id.value);
}
tracing::trace!("Command buffer {:?} {:#?}", encoder_id, comb.trackers);
tracing::trace!("Command buffer {:?} {:#?}", encoder_id, cmdbuf.trackers);
Ok(encoder_id)
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut trackers = TrackerSet::new(B::VARIANT);
let cmb = &mut cmb_guard[encoder_id];
let device = &device_guard[cmb.device_id.value];
let mut raw = device.com_allocator.extend(cmb);
let mut raw = device.cmd_allocator.extend(cmb);

#[cfg(feature = "trace")]
match cmb.commands {
Expand Down
28 changes: 14 additions & 14 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub struct Device<B: hal::Backend> {
pub(crate) raw: B::Device,
pub(crate) adapter_id: Stored<id::AdapterId>,
pub(crate) queue_group: hal::queue::QueueGroup<B>,
pub(crate) com_allocator: command::CommandAllocator<B>,
pub(crate) cmd_allocator: command::CommandAllocator<B>,
mem_allocator: Mutex<Heaps<B>>,
desc_allocator: Mutex<DescriptorAllocator<B>>,
//Note: The submission index here corresponds to the last submission that is done.
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<B: GfxBackend> Device<B> {
desc: &wgt::DeviceDescriptor,
trace_path: Option<&std::path::Path>,
) -> Self {
let com_allocator = command::CommandAllocator::new(queue_group.family, &raw);
let cmd_allocator = command::CommandAllocator::new(queue_group.family, &raw);
let heaps = unsafe {
Heaps::new(
&mem_props,
Expand All @@ -243,7 +243,7 @@ impl<B: GfxBackend> Device<B> {
Device {
raw,
adapter_id,
com_allocator,
cmd_allocator,
mem_allocator: Mutex::new(heaps),
desc_allocator: Mutex::new(descriptors),
queue_group,
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<B: GfxBackend> Device<B> {
self.life_guard
.submission_index
.store(last_done, Ordering::Release);
self.com_allocator.maintain(&self.raw, last_done);
self.cmd_allocator.maintain(&self.raw, last_done);
Ok(callbacks)
}

Expand Down Expand Up @@ -644,8 +644,8 @@ impl<B: hal::Backend> Device<B> {
let mut desc_alloc = self.desc_allocator.into_inner();
let mut mem_alloc = self.mem_allocator.into_inner();
self.pending_writes
.dispose(&self.raw, &self.com_allocator, &mut mem_alloc);
self.com_allocator.destroy(&self.raw);
.dispose(&self.raw, &self.cmd_allocator, &mut mem_alloc);
self.cmd_allocator.destroy(&self.raw);
unsafe {
desc_alloc.clear(&self.raw);
mem_alloc.clear(&self.raw);
Expand Down Expand Up @@ -2047,7 +2047,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
ref_count: device.life_guard.add_ref(),
};

let mut command_buffer = device.com_allocator.allocate(
let mut command_buffer = device.cmd_allocator.allocate(
dev_stored,
&device.raw,
device.limits.clone(),
Expand Down Expand Up @@ -2078,14 +2078,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut token = Token::root();

let (mut device_guard, mut token) = hub.devices.write(&mut token);
let comb = {
let cmdbuf = {
let (mut command_buffer_guard, _) = hub.command_buffers.write(&mut token);
command_buffer_guard.remove(command_encoder_id).unwrap()
};

let device = &mut device_guard[comb.device_id.value];
device.untrack::<G>(&hub, &comb.trackers, &mut token);
device.com_allocator.discard(comb);
let device = &mut device_guard[cmdbuf.device_id.value];
device.untrack::<G>(&hub, &cmdbuf.trackers, &mut token);
device.cmd_allocator.discard(cmdbuf);
}

pub fn command_buffer_destroy<B: GfxBackend>(&self, command_buffer_id: id::CommandBufferId) {
Expand Down Expand Up @@ -2987,14 +2987,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
families: None,
};
unsafe {
let comb = device.borrow_pending_writes();
comb.pipeline_barrier(
let cmdbuf = device.borrow_pending_writes();
cmdbuf.pipeline_barrier(
hal::pso::PipelineStage::HOST..hal::pso::PipelineStage::TRANSFER,
hal::memory::Dependencies::empty(),
iter::once(transition_src).chain(iter::once(transition_dst)),
);
if buffer.size > 0 {
comb.copy_buffer(&stage_buffer, &buffer.raw, iter::once(region));
cmdbuf.copy_buffer(&stage_buffer, &buffer.raw, iter::once(region));
}
}
device
Expand Down
Loading

0 comments on commit 0dcd1e1

Please sign in to comment.