move command encoder/buffer creation in a new device method

This commit is contained in:
teoxoy 2024-06-19 11:19:34 +02:00 committed by Teodor Tanasoaia
parent 4b5666ceff
commit 0b7a5b054b
2 changed files with 25 additions and 19 deletions

View File

@ -1313,26 +1313,11 @@ impl Global {
Ok(device) => device,
Err(_) => break 'error DeviceError::InvalidDeviceId,
};
if !device.is_valid() {
break 'error DeviceError::Lost;
}
let Some(queue) = device.get_queue() else {
break 'error DeviceError::InvalidQueueId;
let command_buffer = match device.create_command_encoder(&desc.label) {
Ok(command_buffer) => command_buffer,
Err(e) => break 'error e,
};
let encoder = match device
.command_allocator
.acquire_encoder(device.raw(), queue.raw.as_ref().unwrap())
{
Ok(raw) => raw,
Err(_) => break 'error DeviceError::OutOfMemory,
};
let command_buffer = command::CommandBuffer::new(
encoder,
&device,
#[cfg(feature = "trace")]
device.trace.lock().is_some(),
desc.label.to_hal(device.instance_flags).map(str::to_owned),
);
let (id, _) = fid.assign(Arc::new(command_buffer));
api_log!("Device::create_command_encoder -> {id:?}");

View File

@ -1596,6 +1596,27 @@ impl<A: HalApi> Device<A> {
})
}
pub(crate) fn create_command_encoder(
self: &Arc<Self>,
label: &crate::Label,
) -> Result<command::CommandBuffer<A>, DeviceError> {
self.check_is_valid()?;
let queue = self.get_queue().unwrap();
let encoder = self
.command_allocator
.acquire_encoder(self.raw(), queue.raw.as_ref().unwrap())?;
Ok(command::CommandBuffer::new(
encoder,
self,
#[cfg(feature = "trace")]
self.trace.lock().is_some(),
label.to_hal(self.instance_flags).map(str::to_owned),
))
}
/// Generate information about late-validated buffer bindings for pipelines.
//TODO: should this be combined with `get_introspection_bind_group_layouts` in some way?
pub(crate) fn make_late_sized_buffer_groups(