aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:23 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:23 +0100
commit13d1d5214d7d7043f22dee0837fd6600aaa50797 (patch)
treed2adedb0c5a0986bab28855b10aa54e8575357d8 /stockton-render/src
parent6ab13f2d0cb345795f761181a06777ade61ff09c (diff)
refactor(all): various cleanup
Diffstat (limited to 'stockton-render/src')
-rw-r--r--stockton-render/src/buffers/mod.rs2
-rw-r--r--stockton-render/src/builders/pipeline.rs4
-rw-r--r--stockton-render/src/context.rs2
-rw-r--r--stockton-render/src/draw_passes/util.rs2
-rw-r--r--stockton-render/src/error.rs1
-rw-r--r--stockton-render/src/queue_negotiator.rs24
-rw-r--r--stockton-render/src/texture/image.rs28
-rw-r--r--stockton-render/src/texture/loader.rs15
-rw-r--r--stockton-render/src/texture/repo.rs6
9 files changed, 43 insertions, 41 deletions
diff --git a/stockton-render/src/buffers/mod.rs b/stockton-render/src/buffers/mod.rs
index 82ca62a..74c5aab 100644
--- a/stockton-render/src/buffers/mod.rs
+++ b/stockton-render/src/buffers/mod.rs
@@ -59,5 +59,5 @@ pub trait ModifiableBuffer: IndexMut<usize> {
fn get_buffer(&mut self) -> &BufferT;
/// Record the command(s) required to commit changes to this buffer to the given command buffer.
- fn record_commit_cmds<'a>(&'a mut self, cmd_buffer: &mut CommandBufferT) -> Result<()>;
+ fn record_commit_cmds(&mut self, cmd_buffer: &mut CommandBufferT) -> Result<()>;
}
diff --git a/stockton-render/src/builders/pipeline.rs b/stockton-render/src/builders/pipeline.rs
index 25a4dc6..f68d9d6 100644
--- a/stockton-render/src/builders/pipeline.rs
+++ b/stockton-render/src/builders/pipeline.rs
@@ -275,10 +275,10 @@ impl CompletePipeline {
if let Some(x) = self.gm_module.take() {
device.destroy_shader_module(x)
}
- self.ts_module.take().map(|(a, b)| {
+ if let Some((a, b)) = self.ts_module.take() {
device.destroy_shader_module(a);
device.destroy_shader_module(b);
- });
+ }
device.destroy_graphics_pipeline(ManuallyDrop::into_inner(read(&self.pipeline)));
diff --git a/stockton-render/src/context.rs b/stockton-render/src/context.rs
index 3985c47..802b8ca 100644
--- a/stockton-render/src/context.rs
+++ b/stockton-render/src/context.rs
@@ -77,7 +77,7 @@ impl RenderingContext {
let (mut queue_negotiator, surface) = {
let dq: DrawQueue = DrawQueue { surface };
- let mut qn = QueueNegotiator::new();
+ let mut qn = QueueNegotiator::default();
// Draw Queue
qn.find(&adapter, &dq)
diff --git a/stockton-render/src/draw_passes/util.rs b/stockton-render/src/draw_passes/util.rs
index 5a4eb1a..7e82209 100644
--- a/stockton-render/src/draw_passes/util.rs
+++ b/stockton-render/src/draw_passes/util.rs
@@ -27,7 +27,7 @@ impl<T> TargetSpecificResources<T> {
}
/// Get the next resource, wrapping around if necessary.
- pub fn get_next<'a>(&'a mut self) -> &'a T {
+ pub fn get_next(&mut self) -> &T {
let el = &self.elements[self.next_idx];
self.next_idx = (self.next_idx + 1) % self.elements.len();
el
diff --git a/stockton-render/src/error.rs b/stockton-render/src/error.rs
index 6c895eb..1f57892 100644
--- a/stockton-render/src/error.rs
+++ b/stockton-render/src/error.rs
@@ -1,6 +1,5 @@
//! Error types
-use anyhow;
use thiserror::Error;
#[derive(Error, Debug)]
diff --git a/stockton-render/src/queue_negotiator.rs b/stockton-render/src/queue_negotiator.rs
index 65c7aa4..879a935 100644
--- a/stockton-render/src/queue_negotiator.rs
+++ b/stockton-render/src/queue_negotiator.rs
@@ -8,10 +8,12 @@ use std::{
sync::{Arc, RwLock},
};
+type SharedQueue = Arc<RwLock<QueueT>>;
+
/// Used to find appropriate queue families and share queues from them as needed.
pub struct QueueNegotiator {
family_ids: HashMap<TypeId, QueueFamilyId>,
- already_allocated: HashMap<TypeId, (Vec<Arc<RwLock<QueueT>>>, usize)>,
+ already_allocated: HashMap<TypeId, (Vec<SharedQueue>, usize)>,
all: Vec<QueueGroup>,
}
@@ -22,14 +24,6 @@ pub trait QueueFamilySelector: 'static {
}
impl QueueNegotiator {
- pub fn new() -> Self {
- QueueNegotiator {
- family_ids: HashMap::new(),
- already_allocated: HashMap::new(),
- all: vec![],
- }
- }
-
pub fn find<T: QueueFamilySelector>(&mut self, adapter: &Adapter, filter: &T) -> Result<()> {
if self.family_ids.contains_key(&TypeId::of::<T>()) {
return Ok(());
@@ -113,7 +107,7 @@ impl QueueNegotiator {
pub fn family_spec<'a, T: QueueFamilySelector>(
&self,
- queue_families: &'a Vec<QueueFamilyT>,
+ queue_families: &'a [QueueFamilyT],
count: usize,
) -> Option<(&'a QueueFamilyT, Vec<f32>)> {
let qf_id = self.family::<T>()?;
@@ -125,6 +119,16 @@ impl QueueNegotiator {
}
}
+impl Default for QueueNegotiator {
+ fn default() -> Self {
+ QueueNegotiator {
+ family_ids: HashMap::new(),
+ already_allocated: HashMap::new(),
+ all: vec![],
+ }
+ }
+}
+
pub struct DrawQueue {
pub surface: SurfaceT,
}
diff --git a/stockton-render/src/texture/image.rs b/stockton-render/src/texture/image.rs
index 0e272e9..f984b72 100644
--- a/stockton-render/src/texture/image.rs
+++ b/stockton-render/src/texture/image.rs
@@ -9,8 +9,19 @@ use image::RgbaImage;
pub trait LoadableImage {
fn width(&self) -> u32;
fn height(&self) -> u32;
- fn copy_row(&self, y: u32, ptr: *mut u8);
- unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize);
+
+ /// # Safety
+ /// Ensure the ptr is at least width() * PIXEL_SIZE bytes.
+ unsafe fn copy_row(&self, y: u32, ptr: *mut u8);
+
+ /// # Safety
+ /// Ensure the ptr is at least row_size * height() * PIXEL_SIZE bytes.
+ unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize) {
+ for y in 0..self.height() as usize {
+ let dest_base: isize = (y * row_size).try_into().unwrap();
+ self.copy_row(y as u32, ptr.offset(dest_base));
+ }
+ }
}
impl LoadableImage for RgbaImage {
@@ -22,20 +33,11 @@ impl LoadableImage for RgbaImage {
self.height()
}
- fn copy_row(&self, y: u32, ptr: *mut u8) {
+ unsafe fn copy_row(&self, y: u32, ptr: *mut u8) {
let row_size_bytes = self.width() as usize * PIXEL_SIZE;
let raw: &Vec<u8> = self.as_raw();
let row = &raw[y as usize * row_size_bytes..(y as usize + 1) * row_size_bytes];
- unsafe {
- copy_nonoverlapping(row.as_ptr(), ptr, row.len());
- }
- }
-
- unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize) {
- for y in 0..self.height() as usize {
- let dest_base: isize = (y * row_size).try_into().unwrap();
- self.copy_row(y as u32, ptr.offset(dest_base));
- }
+ copy_nonoverlapping(row.as_ptr(), ptr, row.len());
}
}
diff --git a/stockton-render/src/texture/loader.rs b/stockton-render/src/texture/loader.rs
index f9c643c..5c85fd3 100644
--- a/stockton-render/src/texture/loader.rs
+++ b/stockton-render/src/texture/loader.rs
@@ -184,11 +184,12 @@ impl<R: TextureResolver> TextureLoader<R> {
pub fn new(
adapter: &Adapter,
device_lock: Arc<RwLock<DeviceT>>,
- family: QueueFamilyId,
- queue_lock: Arc<RwLock<QueueT>>,
+ (family, queue_lock): (QueueFamilyId, Arc<RwLock<QueueT>>),
ds_layout: Arc<RwLock<DescriptorSetLayoutT>>,
- request_channel: Receiver<LoaderRequest>,
- return_channel: Sender<TexturesBlock<DynamicBlock>>,
+ (request_channel, return_channel): (
+ Receiver<LoaderRequest>,
+ Sender<TexturesBlock<DynamicBlock>>,
+ ),
config: TextureLoadConfig<R>,
) -> Result<Self> {
let mut device = device_lock
@@ -300,8 +301,7 @@ impl<R: TextureResolver> TextureLoader<R> {
&mut device,
&mut buffers[0].1,
&queue_lock,
- &mut staging_allocator,
- &mut tex_allocator,
+ (&mut staging_allocator, &mut tex_allocator),
staging_memory_type,
optimal_buffer_copy_pitch_alignment,
&config,
@@ -535,8 +535,7 @@ impl<R: TextureResolver> TextureLoader<R> {
device: &mut DeviceT,
buf: &mut CommandBufferT,
queue_lock: &Arc<RwLock<QueueT>>,
- staging_allocator: &mut DynamicAllocator,
- tex_allocator: &mut DynamicAllocator,
+ (staging_allocator, tex_allocator): (&mut DynamicAllocator, &mut DynamicAllocator),
staging_memory_type: MemoryTypeId,
obcpa: u64,
config: &TextureLoadConfig<R>,
diff --git a/stockton-render/src/texture/repo.rs b/stockton-render/src/texture/repo.rs
index e29625b..341d355 100644
--- a/stockton-render/src/texture/repo.rs
+++ b/stockton-render/src/texture/repo.rs
@@ -94,11 +94,9 @@ impl TextureRepo {
let loader = TextureLoader::new(
adapter,
device_lock.clone(),
- family,
- queue,
+ (family, queue),
ds_lock.clone(),
- req_recv,
- resp_send,
+ (req_recv, resp_send),
config,
)?;