You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
833B

  1. use crate::render::Device;
  2. use ash::{version::DeviceV1_0, vk};
  3. use std::rc::Rc;
  4. pub struct Semaphore {
  5. handle: vk::Semaphore,
  6. pub device: Rc<Device>,
  7. }
  8. impl Semaphore {
  9. pub fn create(device: Rc<Device>) -> Result<Rc<Self>, vk::Result> {
  10. let create_info = vk::SemaphoreCreateInfo::default();
  11. let handle = unsafe { device.create_semaphore(&create_info, None)? };
  12. Ok(Rc::new(Self { handle, device }))
  13. }
  14. pub fn create_all(
  15. device: Rc<Device>,
  16. num: usize,
  17. ) -> Result<Vec<Rc<Self>>, vk::Result> {
  18. (0..num).map(|_| Self::create(device.clone())).collect()
  19. }
  20. }
  21. impl Drop for Semaphore {
  22. fn drop(&mut self) {
  23. unsafe {
  24. self.device.destroy_semaphore(self.handle, None);
  25. }
  26. }
  27. }
  28. impl std::ops::Deref for Semaphore {
  29. type Target = vk::Semaphore;
  30. fn deref(&self) -> &Self::Target {
  31. &self.handle
  32. }
  33. }
  34. // EOF