aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/draw
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:22 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:22 +0100
commit767b1c878532924775d5be7307e5aec10872e443 (patch)
treefcce38e88c3ffdb444095a1a90aee3c62c5afb68 /stockton-render/src/draw
parente8126750633fd9ed3e682a2c889740a1f51a86f7 (diff)
chore(all): fix lints
Diffstat (limited to 'stockton-render/src/draw')
-rw-r--r--stockton-render/src/draw/buffer.rs7
-rw-r--r--stockton-render/src/draw/context.rs39
-rw-r--r--stockton-render/src/draw/draw_buffers.rs5
-rw-r--r--stockton-render/src/draw/target.rs25
-rw-r--r--stockton-render/src/draw/texture/chunk.rs10
-rw-r--r--stockton-render/src/draw/texture/image.rs75
-rw-r--r--stockton-render/src/draw/texture/loader.rs16
-rw-r--r--stockton-render/src/draw/texture/mod.rs5
-rw-r--r--stockton-render/src/draw/texture/resolver.rs1
-rw-r--r--stockton-render/src/draw/ui/render.rs4
-rwxr-xr-xstockton-render/src/draw/ui/texture.rs41
-rw-r--r--stockton-render/src/draw/utils.rs18
12 files changed, 122 insertions, 124 deletions
diff --git a/stockton-render/src/draw/buffer.rs b/stockton-render/src/draw/buffer.rs
index 5d88e25..1485c44 100644
--- a/stockton-render/src/draw/buffer.rs
+++ b/stockton-render/src/draw/buffer.rs
@@ -21,12 +21,7 @@ use std::iter::once;
use std::ops::{Index, IndexMut};
use hal::prelude::*;
-use hal::{
- buffer::Usage,
- memory::Properties,
- queue::Submission,
- MemoryTypeId,
-};
+use hal::{buffer::Usage, memory::Properties, queue::Submission, MemoryTypeId};
use crate::error::CreationError;
use crate::types::*;
diff --git a/stockton-render/src/draw/context.rs b/stockton-render/src/draw/context.rs
index 8f4b549..139c59a 100644
--- a/stockton-render/src/draw/context.rs
+++ b/stockton-render/src/draw/context.rs
@@ -25,8 +25,8 @@ use arrayvec::ArrayVec;
use hal::{pool::CommandPoolCreateFlags, prelude::*};
use log::debug;
use na::Mat4;
-use winit::window::Window;
use rendy_memory::DynamicConfig;
+use winit::window::Window;
use super::{
buffer::ModifiableBuffer,
@@ -161,9 +161,9 @@ impl<'a> RenderingContext<'a> {
// Memory allocators
let mut texture_allocator = unsafe {
use hal::{
- memory::Properties,
- image::{Kind, Tiling, Usage, ViewCapabilities},
format::Format,
+ image::{Kind, Tiling, Usage, ViewCapabilities},
+ memory::Properties,
};
// We create an empty image with the same format as used for textures
@@ -175,29 +175,32 @@ impl<'a> RenderingContext<'a> {
// TODO: Way to tune these options
- let img = device.create_image(
- Kind::D2(16 as u32, 16 as u32, 1, 1),
- 1,
- Format::Rgba8Srgb,
- Tiling::Optimal,
- Usage::SAMPLED,
- ViewCapabilities::empty()
- ).map_err(|_| error::CreationError::OutOfMemoryError)?;
+ let img = device
+ .create_image(
+ Kind::D2(16, 16, 1, 1),
+ 1,
+ Format::Rgba8Srgb,
+ Tiling::Optimal,
+ Usage::SAMPLED,
+ ViewCapabilities::empty(),
+ )
+ .map_err(|_| error::CreationError::OutOfMemoryError)?;
let type_mask = device.get_image_requirements(&img).type_mask;
device.destroy_image(img);
let props = Properties::DEVICE_LOCAL;
-
+
DynamicAllocator::new(
- find_memory_type_id(&adapter, type_mask, props).ok_or(error::CreationError::OutOfMemoryError)?,
+ find_memory_type_id(&adapter, type_mask, props)
+ .ok_or(error::CreationError::OutOfMemoryError)?,
props,
DynamicConfig {
block_size_granularity: 4 * 32 * 32, // 32x32 image
max_chunk_size: u64::pow(2, 63),
min_device_allocation: 4 * 32 * 32,
- }
+ },
)
};
@@ -276,7 +279,7 @@ impl<'a> RenderingContext<'a> {
ui_draw_buffers: ManuallyDrop::new(ui_draw_buffers),
ui_texture_store: ManuallyDrop::new(ui_texture_store),
-
+
texture_allocator: ManuallyDrop::new(texture_allocator),
vp_matrix: Mat4::identity(),
@@ -433,8 +436,10 @@ impl<'a> core::ops::Drop for RenderingContext<'a> {
ManuallyDrop::into_inner(read(&self.draw_buffers)).deactivate(&mut self.device);
ManuallyDrop::into_inner(read(&self.ui_draw_buffers)).deactivate(&mut self.device);
- ManuallyDrop::into_inner(read(&self.texture_store)).deactivate(&mut self.device, &mut self.texture_allocator);
- ManuallyDrop::into_inner(read(&self.ui_texture_store)).deactivate(&mut self.device, &mut self.texture_allocator);
+ ManuallyDrop::into_inner(read(&self.texture_store))
+ .deactivate(&mut self.device, &mut self.texture_allocator);
+ ManuallyDrop::into_inner(read(&self.ui_texture_store))
+ .deactivate(&mut self.device, &mut self.texture_allocator);
ManuallyDrop::into_inner(read(&self.texture_allocator)).dispose();
diff --git a/stockton-render/src/draw/draw_buffers.rs b/stockton-render/src/draw/draw_buffers.rs
index 837356a..02625ad 100644
--- a/stockton-render/src/draw/draw_buffers.rs
+++ b/stockton-render/src/draw/draw_buffers.rs
@@ -37,7 +37,10 @@ pub struct DrawBuffers<'a, T: Sized> {
}
impl<'a, T> DrawBuffers<'a, T> {
- pub fn new(device: &mut Device, adapter: &Adapter) -> Result<DrawBuffers<'a, T>, CreationError> {
+ pub fn new(
+ device: &mut Device,
+ adapter: &Adapter,
+ ) -> Result<DrawBuffers<'a, T>, CreationError> {
let vert = StagedBuffer::new(device, &adapter, Usage::VERTEX, INITIAL_VERT_SIZE)?;
let index = StagedBuffer::new(device, &adapter, Usage::INDEX, INITIAL_INDEX_SIZE)?;
diff --git a/stockton-render/src/draw/target.rs b/stockton-render/src/draw/target.rs
index 02a7f84..2183a90 100644
--- a/stockton-render/src/draw/target.rs
+++ b/stockton-render/src/draw/target.rs
@@ -31,8 +31,11 @@ use hal::{
use na::Mat4;
use super::{
- buffer::ModifiableBuffer, draw_buffers::{DrawBuffers, UVPoint}, pipeline::CompletePipeline,
- texture::image::DedicatedLoadedImage, ui::{UIPipeline, UIPoint},
+ buffer::ModifiableBuffer,
+ draw_buffers::{DrawBuffers, UVPoint},
+ pipeline::CompletePipeline,
+ texture::image::DedicatedLoadedImage,
+ ui::{UIPipeline, UIPoint},
};
use crate::types::*;
@@ -53,8 +56,18 @@ pub struct SwapchainProperties {
pub extent: Extent,
}
+/// Indicates the given property has no acceptable values
+pub enum NoSupportedValuesError {
+ DepthFormat,
+ PresentMode,
+ CompositeAlphaMode,
+}
+
impl SwapchainProperties {
- pub fn find_best(adapter: &Adapter, surface: &Surface) -> Result<SwapchainProperties, ()> {
+ pub fn find_best(
+ adapter: &Adapter,
+ surface: &Surface,
+ ) -> Result<SwapchainProperties, NoSupportedValuesError> {
let caps = surface.capabilities(&adapter.physical_device);
let formats = surface.supported_formats(&adapter.physical_device);
@@ -83,7 +96,7 @@ impl SwapchainProperties {
.optimal_tiling
.contains(ImageFeature::DEPTH_STENCIL_ATTACHMENT)
})
- .ok_or(())?;
+ .ok_or(NoSupportedValuesError::DepthFormat)?;
let present_mode = {
[
@@ -95,7 +108,7 @@ impl SwapchainProperties {
.iter()
.cloned()
.find(|pm| caps.present_modes.contains(*pm))
- .ok_or(())?
+ .ok_or(NoSupportedValuesError::PresentMode)?
};
let composite_alpha_mode = {
[
@@ -107,7 +120,7 @@ impl SwapchainProperties {
.iter()
.cloned()
.find(|ca| caps.composite_alpha_modes.contains(*ca))
- .ok_or(())?
+ .ok_or(NoSupportedValuesError::CompositeAlphaMode)?
};
let extent = caps.extents.end().to_extent(); // Size
diff --git a/stockton-render/src/draw/texture/chunk.rs b/stockton-render/src/draw/texture/chunk.rs
index b95e863..0cb6737 100644
--- a/stockton-render/src/draw/texture/chunk.rs
+++ b/stockton-render/src/draw/texture/chunk.rs
@@ -101,7 +101,15 @@ impl TextureChunk {
for tex in textures {
if let Some(img) = resolver.resolve(tex) {
store
- .put_texture(img, local_idx, device, adapter, allocator, command_queue, command_pool)
+ .put_texture(
+ img,
+ local_idx,
+ device,
+ adapter,
+ allocator,
+ command_queue,
+ command_pool,
+ )
.unwrap();
} else {
// Texture not found. For now, tear everything down.
diff --git a/stockton-render/src/draw/texture/image.rs b/stockton-render/src/draw/texture/image.rs
index bd8058b..7cf84a7 100644
--- a/stockton-render/src/draw/texture/image.rs
+++ b/stockton-render/src/draw/texture/image.rs
@@ -29,8 +29,8 @@ use hal::{
MemoryTypeId,
};
use image::RgbaImage;
-use std::{convert::TryInto, iter::once};
use rendy_memory::{Allocator, Block};
+use std::{convert::TryInto, iter::once};
use crate::draw::buffer::create_buffer;
use crate::types::*;
@@ -42,7 +42,7 @@ const PIXEL_SIZE: usize = size_of::<u8>() * 4;
pub trait LoadableImage {
fn width(&self) -> u32;
fn height(&self) -> u32;
- fn copy_row(&self, y: u32, ptr: *mut u8) -> ();
+ fn copy_row(&self, y: u32, ptr: *mut u8);
}
impl LoadableImage for RgbaImage {
@@ -54,7 +54,7 @@ impl LoadableImage for RgbaImage {
self.height()
}
- fn copy_row(&self, y: u32, ptr: *mut u8) -> () {
+ 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];
@@ -113,12 +113,9 @@ pub fn create_image_view(
let (block, _) = unsafe {
let requirements = device.get_image_requirements(&image_ref);
- allocator.alloc(
- device,
- requirements.size,
- requirements.alignment
- )
- }.map_err(|_| "Out of memory")?;
+ allocator.alloc(device, requirements.size, requirements.alignment)
+ }
+ .map_err(|_| "Out of memory")?;
unsafe {
device
@@ -140,7 +137,8 @@ impl LoadedImage {
width: usize,
height: usize,
) -> Result<LoadedImage, &'static str> {
- let (memory, image_ref) = create_image_view(device, adapter, allocator, format, usage, width, height)?;
+ let (memory, image_ref) =
+ create_image_view(device, adapter, allocator, format, usage, width, height)?;
// Create ImageView and sampler
let image_view = unsafe {
@@ -161,7 +159,6 @@ impl LoadedImage {
img: T,
device: &mut Device,
adapter: &Adapter,
- allocator: &mut DynamicAllocator,
command_queue: &mut CommandQueue,
command_pool: &mut CommandPool,
) -> Result<(), &'static str> {
@@ -186,9 +183,11 @@ impl LoadedImage {
// Copy everything into it
unsafe {
- let mapped_memory: *mut u8 = std::mem::transmute(device
- .map_memory(&staging_memory, 0..total_size)
- .map_err(|_| "Couldn't map buffer memory")?);
+ let mapped_memory: *mut u8 = std::mem::transmute(
+ device
+ .map_memory(&staging_memory, 0..total_size)
+ .map_err(|_| "Couldn't map buffer memory")?,
+ );
for y in 0..img.height() as usize {
let dest_base: isize = (y * row_size).try_into().unwrap();
@@ -303,36 +302,6 @@ impl LoadedImage {
Ok(())
}
- /// Load the given image into a new buffer
- pub fn load_into_new<T: LoadableImage>(
- img: T,
- device: &mut Device,
- adapter: &Adapter,
- allocator: &mut DynamicAllocator,
- command_queue: &mut CommandQueue,
- command_pool: &mut CommandPool,
- format: Format,
- usage: ImgUsage,
- ) -> Result<LoadedImage, &'static str> {
- let mut loaded_image = Self::new(
- device,
- adapter,
- allocator,
- format,
- usage | ImgUsage::TRANSFER_DST,
- SubresourceRange {
- aspects: Aspects::COLOR,
- levels: 0..1,
- layers: 0..1,
- },
- img.width() as usize,
- img.height() as usize,
- )?;
- loaded_image.load(img, device, adapter, allocator, command_queue, command_pool)?;
-
- Ok(loaded_image)
- }
-
/// Properly frees/destroys all the objects in this struct
/// Dropping without doing this is a bad idea
pub fn deactivate(self, device: &mut Device, allocator: &mut DynamicAllocator) {
@@ -410,7 +379,7 @@ impl SampledImage {
)?;
sampled_image
.image
- .load(img, device, adapter, allocator, command_queue, command_pool)?;
+ .load(img, device, adapter, command_queue, command_pool)?;
Ok(sampled_image)
}
@@ -438,7 +407,6 @@ pub struct DedicatedLoadedImage {
memory: ManuallyDrop<Memory>,
}
-
impl DedicatedLoadedImage {
pub fn new(
device: &mut Device,
@@ -455,7 +423,8 @@ impl DedicatedLoadedImage {
let limits = adapter.physical_device.limits();
let row_alignment_mask = limits.optimal_buffer_copy_pitch_alignment as u32 - 1;
- let row_size = ((initial_row_size as u32 + row_alignment_mask) & !row_alignment_mask) as usize;
+ let row_size =
+ ((initial_row_size as u32 + row_alignment_mask) & !row_alignment_mask) as usize;
debug_assert!(row_size as usize >= initial_row_size);
// Make the image
@@ -474,7 +443,7 @@ impl DedicatedLoadedImage {
.map_err(|_| "Couldn't create image")?;
// Allocate memory
-
+
// Allocate memory
let memory = unsafe {
let requirements = device.get_image_requirements(&image_ref);
@@ -549,9 +518,11 @@ impl DedicatedLoadedImage {
// Copy everything into it
unsafe {
- let mapped_memory: *mut u8 = std::mem::transmute(device
- .map_memory(&staging_memory, 0..total_size)
- .map_err(|_| "Couldn't map buffer memory")?);
+ let mapped_memory: *mut u8 = std::mem::transmute(
+ device
+ .map_memory(&staging_memory, 0..total_size)
+ .map_err(|_| "Couldn't map buffer memory")?,
+ );
for y in 0..img.height() as usize {
let dest_base: isize = (y * row_size).try_into().unwrap();
@@ -705,4 +676,4 @@ impl DedicatedLoadedImage {
device.free_memory(ManuallyDrop::into_inner(read(&self.memory)));
}
}
-} \ No newline at end of file
+}
diff --git a/stockton-render/src/draw/texture/loader.rs b/stockton-render/src/draw/texture/loader.rs
index 9385d96..0cfe0c3 100644
--- a/stockton-render/src/draw/texture/loader.rs
+++ b/stockton-render/src/draw/texture/loader.rs
@@ -64,9 +64,7 @@ impl TextureStore {
// Descriptor pool, where we get our sets from
let mut descriptor_pool = unsafe {
- use hal::pso::{
- DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType,
- };
+ use hal::pso::{DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType};
device
.create_descriptor_pool(
@@ -91,9 +89,7 @@ impl TextureStore {
// Layout of our descriptor sets
let descriptor_set_layout = unsafe {
- use hal::pso::{
- DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags,
- };
+ use hal::pso::{DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags};
device.create_descriptor_set_layout(
&[
@@ -171,9 +167,7 @@ impl TextureStore {
// Descriptor pool, where we get our sets from
let mut descriptor_pool = unsafe {
- use hal::pso::{
- DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType,
- };
+ use hal::pso::{DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType};
device
.create_descriptor_pool(
@@ -198,9 +192,7 @@ impl TextureStore {
// Layout of our descriptor sets
let descriptor_set_layout = unsafe {
- use hal::pso::{
- DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags,
- };
+ use hal::pso::{DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags};
device.create_descriptor_set_layout(
&[
diff --git a/stockton-render/src/draw/texture/mod.rs b/stockton-render/src/draw/texture/mod.rs
index ec36502..3878472 100644
--- a/stockton-render/src/draw/texture/mod.rs
+++ b/stockton-render/src/draw/texture/mod.rs
@@ -17,11 +17,14 @@
//! Everything related to loading textures into GPU memory
+// Since this is in the process of being rewritten, we ignore this for now
+#![allow(clippy::too_many_arguments)]
+
mod chunk;
pub mod image;
pub mod loader;
mod resolver;
+pub use self::image::LoadableImage;
pub use self::image::{LoadedImage, SampledImage};
pub use self::loader::TextureStore;
-pub use self::image::LoadableImage; \ No newline at end of file
diff --git a/stockton-render/src/draw/texture/resolver.rs b/stockton-render/src/draw/texture/resolver.rs
index 610d43a..668ea32 100644
--- a/stockton-render/src/draw/texture/resolver.rs
+++ b/stockton-render/src/draw/texture/resolver.rs
@@ -26,7 +26,6 @@ use std::path::Path;
/// An object that can be used to resolve a texture from a BSP File
pub trait TextureResolver<T: LoadableImage> {
-
/// Get the given texture, or None if it's corrupt/not there.
fn resolve(&mut self, texture: &Texture) -> Option<T>;
}
diff --git a/stockton-render/src/draw/ui/render.rs b/stockton-render/src/draw/ui/render.rs
index ad23dfb..02135e5 100644
--- a/stockton-render/src/draw/ui/render.rs
+++ b/stockton-render/src/draw/ui/render.rs
@@ -17,7 +17,6 @@
use crate::draw::texture::TextureStore;
use arrayvec::ArrayVec;
-use egui::Pos2;
use hal::prelude::*;
use hal::pso::ShaderStageFlags;
@@ -26,7 +25,6 @@ use crate::draw::draw_buffers::DrawBuffers;
use crate::types::*;
use crate::UIState;
use std::convert::TryInto;
-use std::mem::transmute;
use stockton_types::Vector2;
pub fn do_render(
@@ -45,7 +43,7 @@ pub fn do_render(
&pipeline_layout,
ShaderStageFlags::VERTEX,
0,
- &[transmute(screen.x), transmute(screen.y)],
+ &[screen.x.to_bits(), screen.y.to_bits()],
);
}
diff --git a/stockton-render/src/draw/ui/texture.rs b/stockton-render/src/draw/ui/texture.rs
index 52580e5..98688de 100755
--- a/stockton-render/src/draw/ui/texture.rs
+++ b/stockton-render/src/draw/ui/texture.rs
@@ -14,10 +14,10 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use egui::Texture;
+use crate::draw::texture::{LoadableImage, TextureStore};
use crate::types::*;
-use crate::draw::texture::{TextureStore, LoadableImage};
use crate::UIState;
+use egui::Texture;
impl LoadableImage for &Texture {
fn width(&self) -> u32 {
@@ -26,30 +26,43 @@ impl LoadableImage for &Texture {
fn height(&self) -> u32 {
self.height as u32
}
- fn copy_row(&self, y: u32, ptr: *mut u8) -> () {
+ fn copy_row(&self, y: u32, ptr: *mut u8) {
let row_size = self.width();
let pixels = &self.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize];
- for (i,x) in pixels.iter().enumerate() {
+ for (i, x) in pixels.iter().enumerate() {
unsafe {
*ptr.offset(i as isize * 3) = *x;
*ptr.offset((i as isize * 3) + 1) = *x;
*ptr.offset((i as isize * 3) + 2) = *x;
}
- }
+ }
}
}
-pub fn ensure_textures(texture_store: &mut TextureStore, ui: &mut UIState,
- device: &mut Device,
- adapter: &mut Adapter,
- allocator: &mut DynamicAllocator,
- command_queue: &mut CommandQueue,
- command_pool: &mut CommandPool) {
+pub fn ensure_textures(
+ texture_store: &mut TextureStore,
+ ui: &mut UIState,
+ device: &mut Device,
+ adapter: &mut Adapter,
+ allocator: &mut DynamicAllocator,
+ command_queue: &mut CommandQueue,
+ command_pool: &mut CommandPool,
+) {
let tex = ui.ctx.texture();
if tex.version != ui.last_tex_ver {
- texture_store.put_texture(0, &*tex, device, adapter, allocator, command_queue, command_pool).unwrap(); // TODO
+ texture_store
+ .put_texture(
+ 0,
+ &*tex,
+ device,
+ adapter,
+ allocator,
+ command_queue,
+ command_pool,
+ )
+ .unwrap(); // TODO
ui.last_tex_ver = tex.version;
- }
-} \ No newline at end of file
+ }
+}
diff --git a/stockton-render/src/draw/utils.rs b/stockton-render/src/draw/utils.rs
index e175e47..97d303e 100644
--- a/stockton-render/src/draw/utils.rs
+++ b/stockton-render/src/draw/utils.rs
@@ -16,13 +16,13 @@
*/
use crate::types::*;
-use hal::{
- memory::{Properties as MemProperties},
- MemoryTypeId,
- prelude::*,
-};
+use hal::{memory::Properties as MemProperties, prelude::*, MemoryTypeId};
-pub fn find_memory_type_id(adapter: &Adapter, type_mask: u64, props: MemProperties) -> Option<MemoryTypeId> {
+pub fn find_memory_type_id(
+ adapter: &Adapter,
+ type_mask: u64,
+ props: MemProperties,
+) -> Option<MemoryTypeId> {
adapter
.physical_device
.memory_properties()
@@ -30,9 +30,7 @@ pub fn find_memory_type_id(adapter: &Adapter, type_mask: u64, props: MemProperti
.iter()
.enumerate()
.find(|&(id, memory_type)| {
- type_mask & (1 << id) != 0 &&
- memory_type.properties.contains(props)
+ type_mask & (1 << id) != 0 && memory_type.properties.contains(props)
})
.map(|(id, _)| MemoryTypeId(id))
-
-} \ No newline at end of file
+}