diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
commit | 4510dc5c7516f7bcd70bb1f21fbc309592767cb5 (patch) | |
tree | d891efd36ca4424d33be220d41eedae8e227ffa9 /stockton-render | |
parent | c92ddd37d04ebc7fb5582edd399f607c542e5501 (diff) |
refactor(draw): reformat
Diffstat (limited to 'stockton-render')
-rw-r--r-- | stockton-render/src/draw/context.rs | 34 | ||||
-rw-r--r-- | stockton-render/src/draw/queue_negotiator.rs | 44 | ||||
-rw-r--r-- | stockton-render/src/draw/texture/mod.rs | 2 | ||||
-rw-r--r-- | stockton-render/src/draw/texture/repo.rs | 2 |
4 files changed, 50 insertions, 32 deletions
diff --git a/stockton-render/src/draw/context.rs b/stockton-render/src/draw/context.rs index 5448357..4231a2e 100644 --- a/stockton-render/src/draw/context.rs +++ b/stockton-render/src/draw/context.rs @@ -19,7 +19,7 @@ use super::{ buffer::ModifiableBuffer, draw_buffers::{DrawBuffers, UvPoint}, pipeline::CompletePipeline, - queue_negotiator::{QueueNegotiator, DrawQueue}, + queue_negotiator::{DrawQueue, QueueNegotiator}, render::do_render, target::{SwapchainProperties, TargetChain}, texture::{resolver::FsResolver, TexLoadQueue, TextureLoadConfig, TextureRepo}, @@ -107,28 +107,26 @@ impl<'a, M: 'static + MinBspFeatures<VulkanSystem>> RenderingContext<'a, M> { let (mut queue_negotiator, surface) = { let dq: DrawQueue = DrawQueue { surface }; - let qn = QueueNegotiator::find(&adapter, &[ - &dq, - &TexLoadQueue, - ]) - .context("Error creating draw queue negotiator")?; + let qn = QueueNegotiator::find(&adapter, &[&dq, &TexLoadQueue]) + .context("Error creating draw queue negotiator")?; (qn, dq.surface) }; // Device & Queue groups let (device_lock, mut queue_groups) = { - let (df, dqs) = queue_negotiator.family_spec::<DrawQueue>(&adapter.queue_families, 1).ok_or(EnvironmentError::NoSuitableFamilies)?; - let (tf, tqs) = queue_negotiator.family_spec::<TexLoadQueue>(&adapter.queue_families, 2).ok_or(EnvironmentError::NoSuitableFamilies)?; + let (df, dqs) = queue_negotiator + .family_spec::<DrawQueue>(&adapter.queue_families, 1) + .ok_or(EnvironmentError::NoSuitableFamilies)?; + let (tf, tqs) = queue_negotiator + .family_spec::<TexLoadQueue>(&adapter.queue_families, 2) + .ok_or(EnvironmentError::NoSuitableFamilies)?; let gpu = unsafe { adapter .physical_device .open( - &[ - (df, dqs.as_slice()), - (tf, tqs.as_slice()), - ], + &[(df, dqs.as_slice()), (tf, tqs.as_slice())], hal::Features::empty(), ) .context("Error opening logical device")? @@ -151,7 +149,9 @@ impl<'a, M: 'static + MinBspFeatures<VulkanSystem>> RenderingContext<'a, M> { // Command pool let mut cmd_pool = unsafe { device.create_command_pool( - queue_negotiator.family::<DrawQueue>().ok_or(EnvironmentError::NoSuitableFamilies)?, + queue_negotiator + .family::<DrawQueue>() + .ok_or(EnvironmentError::NoSuitableFamilies)?, CommandPoolCreateFlags::RESET_INDIVIDUAL, ) } @@ -172,7 +172,9 @@ impl<'a, M: 'static + MinBspFeatures<VulkanSystem>> RenderingContext<'a, M> { debug!("Creating 3D Texture Repo"); let tex_repo = TextureRepo::new( device_lock.clone(), - queue_negotiator.family::<TexLoadQueue>().ok_or(EnvironmentError::NoQueues)?, + queue_negotiator + .family::<TexLoadQueue>() + .ok_or(EnvironmentError::NoQueues)?, queue_negotiator .get_queue::<TexLoadQueue>(&mut queue_groups) .ok_or(EnvironmentError::NoQueues) @@ -189,7 +191,9 @@ impl<'a, M: 'static + MinBspFeatures<VulkanSystem>> RenderingContext<'a, M> { debug!("Creating UI Texture Repo"); let ui_tex_repo = TextureRepo::new( device_lock.clone(), - queue_negotiator.family::<TexLoadQueue>().ok_or(EnvironmentError::NoQueues)?, + queue_negotiator + .family::<TexLoadQueue>() + .ok_or(EnvironmentError::NoQueues)?, queue_negotiator .get_queue::<TexLoadQueue>(&mut queue_groups) .ok_or(EnvironmentError::NoQueues) diff --git a/stockton-render/src/draw/queue_negotiator.rs b/stockton-render/src/draw/queue_negotiator.rs index 4f00c9e..c5d751b 100644 --- a/stockton-render/src/draw/queue_negotiator.rs +++ b/stockton-render/src/draw/queue_negotiator.rs @@ -1,9 +1,9 @@ use crate::{error::EnvironmentError, types::*}; -use anyhow::{Result, Error}; +use anyhow::{Error, Result}; use hal::queue::family::QueueFamilyId; -use std::sync::{Arc, RwLock}; -use std::collections::HashMap; use std::any::TypeId; +use std::collections::HashMap; +use std::sync::{Arc, RwLock}; pub struct QueueNegotiator { family_ids: HashMap<TypeId, QueueFamilyId>, @@ -12,12 +12,15 @@ pub struct QueueNegotiator { pub trait QueueFamilySelector: 'static { fn is_suitable(&self, family: &QueueFamilyT) -> bool; - - fn get_type_id_self(&self) -> TypeId{ + + fn get_type_id_self(&self) -> TypeId { TypeId::of::<Self>() } - fn get_type_id() -> TypeId where Self: Sized { + fn get_type_id() -> TypeId + where + Self: Sized, + { TypeId::of::<Self>() } } @@ -31,15 +34,19 @@ impl QueueNegotiator { .iter() .filter(|x| filter.is_suitable(*x)) .collect(); - + if candidates.len() == 0 { return Err(Error::new(EnvironmentError::NoSuitableFamilies)); } // Prefer using unique families - let family = match candidates.iter().filter(|x| !families.values().any(|y| *y == x.id())).next() { + let family = match candidates + .iter() + .filter(|x| !families.values().any(|y| *y == x.id())) + .next() + { Some(x) => *x, - None => candidates[0] + None => candidates[0], }; families.insert(filter.get_type_id_self(), family.id()); @@ -51,7 +58,10 @@ impl QueueNegotiator { }) } - pub fn get_queue<T: QueueFamilySelector>(&mut self, groups: &mut Vec<QueueGroup>) -> Option<Arc<RwLock<QueueT>>> { + pub fn get_queue<T: QueueFamilySelector>( + &mut self, + groups: &mut Vec<QueueGroup>, + ) -> Option<Arc<RwLock<QueueT>>> { let tid = T::get_type_id(); let family_id = self.family_ids.get(&tid)?; @@ -76,8 +86,8 @@ impl QueueNegotiator { Some(queue) } - None => None - } + None => None, + }, } } @@ -90,14 +100,18 @@ impl QueueNegotiator { match self.already_allocated.get_mut(&tid) { None => { self.already_allocated.insert(tid, (vec![queue], 0)); - }, + } Some(x) => { x.0.push(queue); } } } - pub fn family_spec<'a, T: QueueFamilySelector>(&self, queue_families: &'a Vec<QueueFamilyT>, count: usize) -> Option<(&'a QueueFamilyT, Vec<f32>)> { + pub fn family_spec<'a, T: QueueFamilySelector>( + &self, + queue_families: &'a Vec<QueueFamilyT>, + count: usize, + ) -> Option<(&'a QueueFamilyT, Vec<f32>)> { let qf_id = self.family::<T>()?; let qf = queue_families.iter().find(|x| x.id() == qf_id)?; @@ -108,7 +122,7 @@ impl QueueNegotiator { } pub struct DrawQueue { - pub surface: SurfaceT + pub surface: SurfaceT, } impl QueueFamilySelector for DrawQueue { fn is_suitable(&self, family: &QueueFamilyT) -> bool { diff --git a/stockton-render/src/draw/texture/mod.rs b/stockton-render/src/draw/texture/mod.rs index 5720349..aef1b03 100644 --- a/stockton-render/src/draw/texture/mod.rs +++ b/stockton-render/src/draw/texture/mod.rs @@ -12,7 +12,7 @@ pub use self::block::TexturesBlock; pub use self::image::LoadableImage; pub use self::load::TextureLoadConfig; pub use self::loader::BlockRef; -pub use self::repo::{TextureRepo, TexLoadQueue}; +pub use self::repo::{TexLoadQueue, TextureRepo}; /// The size of each pixel in an image pub const PIXEL_SIZE: usize = std::mem::size_of::<u8>() * 4; diff --git a/stockton-render/src/draw/texture/repo.rs b/stockton-render/src/draw/texture/repo.rs index d2aa9f2..2df7bd3 100644 --- a/stockton-render/src/draw/texture/repo.rs +++ b/stockton-render/src/draw/texture/repo.rs @@ -202,4 +202,4 @@ impl QueueFamilySelector for TexLoadQueue { fn is_suitable(&self, family: &QueueFamilyT) -> bool { family.queue_type().supports_transfer() && family.max_queues() >= NUM_SIMULTANEOUS_CMDS } -}
\ No newline at end of file +} |