use CommandEncoder for BakedCommands & EncoderInFlight

This commit is contained in:
teoxoy 2024-11-08 16:00:53 +01:00
parent 8d264843c5
commit 144c47680f
3 changed files with 28 additions and 28 deletions

View File

@ -216,7 +216,7 @@ impl BakedCommands {
let raw_buf = buffer.try_raw(snatch_guard)?;
unsafe {
self.encoder.transition_buffers(
self.encoder.raw.transition_buffers(
transition
.map(|pending| pending.into_hal(&buffer, snatch_guard))
.as_slice(),
@ -240,7 +240,7 @@ impl BakedCommands {
);
unsafe {
self.encoder.clear_buffer(raw_buf, range.clone());
self.encoder.raw.clear_buffer(raw_buf, range.clone());
}
}
}
@ -293,7 +293,7 @@ impl BakedCommands {
let clear_result = clear_texture(
&texture_use.texture,
range,
self.encoder.as_mut(),
self.encoder.raw.as_mut(),
&mut device_tracker.textures,
&device.alignments,
device.zero_buffer.as_ref(),

View File

@ -121,7 +121,7 @@ pub(crate) struct CommandEncoder {
///
/// [`CommandEncoder`]: hal::Api::CommandEncoder
/// [`CommandAllocator`]: crate::command::CommandAllocator
raw: Box<dyn hal::DynCommandEncoder>,
pub(crate) raw: Box<dyn hal::DynCommandEncoder>,
/// All the raw command buffers for our owning [`CommandBuffer`], in
/// submission order.
@ -134,7 +134,7 @@ pub(crate) struct CommandEncoder {
///
/// [CE::ra]: hal::CommandEncoder::reset_all
/// [`wgpu_hal::CommandEncoder`]: hal::CommandEncoder
list: Vec<Box<dyn hal::DynCommandBuffer>>,
pub(crate) list: Vec<Box<dyn hal::DynCommandBuffer>>,
/// True if `raw` is in the "recording" state.
///
@ -142,9 +142,9 @@ pub(crate) struct CommandEncoder {
/// details on the states `raw` can be in.
///
/// [`wgpu_hal::CommandEncoder`]: hal::CommandEncoder
is_open: bool,
pub(crate) is_open: bool,
hal_label: Option<String>,
pub(crate) hal_label: Option<String>,
}
//TODO: handle errors better
@ -247,8 +247,7 @@ impl CommandEncoder {
/// Look at the documentation for [`CommandBufferMutable`] for an explanation of
/// the fields in this struct. This is the "built" counterpart to that type.
pub(crate) struct BakedCommands {
pub(crate) encoder: Box<dyn hal::DynCommandEncoder>,
pub(crate) list: Vec<Box<dyn hal::DynCommandBuffer>>,
pub(crate) encoder: CommandEncoder,
pub(crate) trackers: Tracker,
buffer_memory_init_actions: Vec<BufferInitTrackerAction>,
texture_memory_actions: CommandBufferTextureMemoryActions,
@ -379,8 +378,7 @@ impl CommandBufferMutable {
pub(crate) fn into_baked_commands(self) -> BakedCommands {
BakedCommands {
encoder: self.encoder.raw,
list: self.encoder.list,
encoder: self.encoder,
trackers: self.trackers,
buffer_memory_init_actions: self.buffer_memory_init_actions,
texture_memory_actions: self.texture_memory_actions,

View File

@ -312,8 +312,7 @@ pub enum TempResource {
/// [`CommandBuffer`]: hal::Api::CommandBuffer
/// [`wgpu_hal::CommandEncoder`]: hal::CommandEncoder
pub(crate) struct EncoderInFlight {
raw: Box<dyn hal::DynCommandEncoder>,
cmd_buffers: Vec<Box<dyn hal::DynCommandBuffer>>,
inner: crate::command::CommandEncoder,
pub(crate) trackers: Tracker,
/// These are the buffers that have been tracked by `PendingWrites`.
@ -332,7 +331,7 @@ impl EncoderInFlight {
/// Return the command encoder, fully reset and ready to be
/// reused.
pub(crate) unsafe fn land(mut self) -> Box<dyn hal::DynCommandEncoder> {
unsafe { self.raw.reset_all(self.cmd_buffers) };
unsafe { self.inner.raw.reset_all(self.inner.list) };
{
// This involves actually decrementing the ref count of all command buffer
// resources, so can be _very_ expensive.
@ -343,7 +342,7 @@ impl EncoderInFlight {
drop(self.pending_blas_s);
drop(self.pending_tlas_s);
}
self.raw
self.inner.raw
}
}
@ -463,8 +462,12 @@ impl PendingWrites {
.map_err(|e| device.handle_hal_error(e))?;
let encoder = EncoderInFlight {
raw: mem::replace(&mut self.command_encoder, new_encoder),
cmd_buffers: vec![cmd_buf],
inner: crate::command::CommandEncoder {
raw: mem::replace(&mut self.command_encoder, new_encoder),
list: vec![cmd_buf],
is_open: false,
hal_label: None,
},
trackers: Tracker::new(),
pending_buffers,
pending_textures,
@ -1226,7 +1229,7 @@ impl Queue {
// execute resource transitions
if let Err(e) = unsafe {
baked.encoder.begin_encoding(hal_label(
baked.encoder.raw.begin_encoding(hal_label(
Some("(wgpu internal) Transit"),
self.device.instance_flags,
))
@ -1253,21 +1256,21 @@ impl Queue {
//Note: stateless trackers are not merged:
// device already knows these resources exist.
CommandBuffer::insert_barriers_from_device_tracker(
baked.encoder.as_mut(),
baked.encoder.raw.as_mut(),
&mut trackers,
&baked.trackers,
&snatch_guard,
);
let transit = unsafe { baked.encoder.end_encoding().unwrap() };
baked.list.insert(0, transit);
let transit = unsafe { baked.encoder.raw.end_encoding().unwrap() };
baked.encoder.list.insert(0, transit);
// Transition surface textures into `Present` state.
// Note: we could technically do it after all of the command buffers,
// but here we have a command encoder by hand, so it's easier to use it.
if !used_surface_textures.is_empty() {
if let Err(e) = unsafe {
baked.encoder.begin_encoding(hal_label(
baked.encoder.raw.begin_encoding(hal_label(
Some("(wgpu internal) Present"),
self.device.instance_flags,
))
@ -1284,17 +1287,16 @@ impl Queue {
)
.collect::<Vec<_>>();
let present = unsafe {
baked.encoder.transition_textures(&texture_barriers);
baked.encoder.end_encoding().unwrap()
baked.encoder.raw.transition_textures(&texture_barriers);
baked.encoder.raw.end_encoding().unwrap()
};
baked.list.push(present);
baked.encoder.list.push(present);
used_surface_textures = track::TextureUsageScope::default();
}
// done
active_executions.push(EncoderInFlight {
raw: baked.encoder,
cmd_buffers: baked.list,
inner: baked.encoder,
trackers: baked.trackers,
pending_buffers: FastHashMap::default(),
pending_textures: FastHashMap::default(),
@ -1358,7 +1360,7 @@ impl Queue {
}
let hal_command_buffers = active_executions
.iter()
.flat_map(|e| e.cmd_buffers.iter().map(|b| b.as_ref()))
.flat_map(|e| e.inner.list.iter().map(|b| b.as_ref()))
.collect::<Vec<_>>();
{