vulkan_lib/vulkan-rs/src/deferred_operation.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

2023-01-14 12:03:01 +00:00
use crate::prelude::*;
use anyhow::Result;
use std::sync::Arc;
pub enum DeferredOperationResult {
Success,
Pending,
OperationResult(VkResult),
}
pub struct DeferredOperation {
device: Arc<Device>,
deferred_operation: VkDeferredOperationKHR,
}
impl DeferredOperation {
pub fn new(device: Arc<Device>) -> Result<Arc<Self>> {
let deferred_operation = device.create_deferred_operation(None)?;
Ok(Arc::new(DeferredOperation {
device,
deferred_operation,
}))
}
pub fn max_concurrency(&self) -> u32 {
self.device
.get_deferred_operation_max_concurrency(self.deferred_operation)
}
pub fn result(&self) -> DeferredOperationResult {
let result = self
.device
.get_deferred_operation_result(self.deferred_operation);
match result {
VK_SUCCESS => DeferredOperationResult::Success,
VK_NOT_READY => DeferredOperationResult::Pending,
_ => DeferredOperationResult::OperationResult(result),
}
}
pub fn join(&self) -> DeferredOperationResult {
let result = self.device.deferred_operation_join(self.deferred_operation);
match result {
VK_SUCCESS => DeferredOperationResult::Success,
VK_THREAD_IDLE_KHR | VK_THREAD_DONE_KHR => DeferredOperationResult::Pending,
_ => DeferredOperationResult::OperationResult(result),
}
}
}
impl Drop for DeferredOperation {
fn drop(&mut self) {
self.device
.destroy_deferred_operation(self.deferred_operation, None);
}
}