update code that opens and closes the encoder to

go through `CommandEncoder`'s methods

So that `CommandEncoder.is_open` is always accurate.
This commit is contained in:
teoxoy authored and Teodor Tanasoaia committed 2024-12-20 15:44:15 +01:00
1 parent 53f40794f2
commit 38e09d02cc
2 files changed
+42 -21

No files matched your search

+26 -2
View File
@@ -313,6 +313,26 @@ impl CommandEncoder {
Ok(())
}
/// Finish the current command buffer and insert it at the beginning
/// of [`self.list`][l].
///
/// On return, the underlying hal encoder is closed.
///
/// # Panics
///
/// - If the encoder is not open.
///
/// [l]: CommandEncoder::list
pub(crate) fn close_and_push_front(&mut self, device: &Device) -> Result<(), DeviceError> {
assert!(self.is_open);
self.is_open = false;
let new = unsafe { self.raw.end_encoding() }.map_err(|e| device.handle_hal_error(e))?;
self.list.insert(0, new);
Ok(())
}
/// Finish the current command buffer, if any, and add it to the
/// end of [`self.list`][l].
///
@@ -323,7 +343,7 @@ impl CommandEncoder {
/// On return, the underlying hal encoder is closed.
///
/// [l]: CommandEncoder::list
fn close(&mut self, device: &Device) -> Result<(), DeviceError> {
pub(crate) fn close(&mut self, device: &Device) -> Result<(), DeviceError> {
if self.is_open {
self.is_open = false;
let cmd_buf =
@@ -355,7 +375,11 @@ impl CommandEncoder {
/// its own label.
///
/// The underlying hal encoder is put in the "recording" state.
fn open_pass(&mut self, hal_label: Option<&str>, device: &Device) -> Result<(), DeviceError> {
pub(crate) fn open_pass(
&mut self,
hal_label: Option<&str>,
device: &Device,
) -> Result<(), DeviceError> {
self.is_open = true;
unsafe { self.raw.begin_encoding(hal_label) }.map_err(|e| device.handle_hal_error(e))?;
+16 -19
View File
@@ -1165,14 +1165,10 @@ impl Queue {
};
// execute resource transitions
if let Err(e) = unsafe {
baked.encoder.raw.begin_encoding(hal_label(
Some("(wgpu internal) Transit"),
self.device.instance_flags,
))
}
.map_err(|e| self.device.handle_hal_error(e))
{
if let Err(e) = baked.encoder.open_pass(
hal_label(Some("(wgpu internal) Transit"), self.device.instance_flags),
&self.device,
) {
break 'error Err(e.into());
}
@@ -1199,21 +1195,21 @@ impl Queue {
&snatch_guard,
);
let transit = unsafe { baked.encoder.raw.end_encoding().unwrap() };
baked.encoder.list.insert(0, transit);
if let Err(e) = baked.encoder.close_and_push_front(&self.device) {
break 'error Err(e.into());
}
// 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.raw.begin_encoding(hal_label(
if let Err(e) = baked.encoder.open_pass(
hal_label(
Some("(wgpu internal) Present"),
self.device.instance_flags,
))
}
.map_err(|e| self.device.handle_hal_error(e))
{
),
&self.device,
) {
break 'error Err(e.into());
}
let texture_barriers = trackers
@@ -1223,11 +1219,12 @@ impl Queue {
&snatch_guard,
)
.collect::<Vec<_>>();
let present = unsafe {
unsafe {
baked.encoder.raw.transition_textures(&texture_barriers);
baked.encoder.raw.end_encoding().unwrap()
};
baked.encoder.list.push(present);
if let Err(e) = baked.encoder.close(&self.device) {
break 'error Err(e.into());
}
used_surface_textures = track::TextureUsageScope::default();
}