From 4f068467c4954fb79e6ce297ae1ac0fdd2bdf16a Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:24 +0100 Subject: WIP refactor(skeleton): type state for context also some api improvements closes #2 related: #7 --- stockton-skeleton/src/texture/loader.rs | 16 +++++----------- stockton-skeleton/src/texture/repo.rs | 8 ++------ 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'stockton-skeleton/src/texture') diff --git a/stockton-skeleton/src/texture/loader.rs b/stockton-skeleton/src/texture/loader.rs index 80d4a61..6de4a4d 100644 --- a/stockton-skeleton/src/texture/loader.rs +++ b/stockton-skeleton/src/texture/loader.rs @@ -12,7 +12,7 @@ use super::{ use crate::{ buffers::image::SampledImage, context::RenderingContext, - error::{EnvironmentError, LockPoisoned}, + error::LockPoisoned, mem::{MappableBlock, MemoryPool}, queue_negotiator::QueueFamilySelector, types::*, @@ -216,22 +216,16 @@ where config: TextureLoadConfig, ) -> Result { // Queue family & Lock - let family = context - .queue_negotiator_mut() - .family::() - .ok_or(EnvironmentError::NoSuitableFamilies)?; - let queue_lock = context.queue_negotiator_mut().get_queue::()?; + let family = context.get_queue_family::()?; + let queue_lock = context.get_queue::()?; // Memory pools let tex_mempool = context.memory_pool()?.clone(); let staging_mempool = context.memory_pool()?.clone(); // Lock device - let device_lock = context.device().clone(); - let mut device = device_lock - .write() - .map_err(|_| LockPoisoned::Device) - .context("Error getting device lock")?; + let device_lock = context.clone_device_lock(); + let mut device = context.lock_device().context("Error getting device lock")?; // Physical properties let device_props = context.physical_device_properties(); diff --git a/stockton-skeleton/src/texture/repo.rs b/stockton-skeleton/src/texture/repo.rs index 635eebb..4591f17 100644 --- a/stockton-skeleton/src/texture/repo.rs +++ b/stockton-skeleton/src/texture/repo.rs @@ -68,11 +68,7 @@ where // Create Channels let (req_send, req_recv) = channel(); let (resp_send, resp_recv) = channel(); - let device = context - .device() - .write() - .map_err(|_| LockPoisoned::Device) - .context("Error getting device lock")?; + let device = context.lock_device()?; // Create descriptor set layout let ds_lock = Arc::new(RwLock::new( @@ -193,7 +189,7 @@ where .unwrap(); // Only now can we lock device without deadlocking - let mut device = context.device().write().unwrap(); + let mut device = context.lock_device().unwrap(); // Return all the texture memory and descriptors. for (_, v) in self.blocks.drain() { -- cgit v1.2.3