From e98444ccc8592cedb807b636c1d6cb57e1cc7bb1 Mon Sep 17 00:00:00 2001 From: John Wells Date: Tue, 10 Oct 2023 22:20:45 -0400 Subject: [PATCH] Debug improvements --- src/driver/buffer.rs | 6 ++++++ src/driver/shader.rs | 4 ++-- src/driver/swapchain.rs | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/driver/buffer.rs b/src/driver/buffer.rs index 038de89..34f79d8 100644 --- a/src/driver/buffer.rs +++ b/src/driver/buffer.rs @@ -92,6 +92,8 @@ impl Buffer { trace!("create: {:?}", info); + debug_assert_ne!(info.size, 0, "Size must be non-zero"); + let device = Arc::clone(device); let buffer_info = vk::BufferCreateInfo::builder() .size(info.size) @@ -331,6 +333,8 @@ impl Buffer { /// # Ok(()) } /// ``` pub fn mapped_slice(this: &Self) -> &[u8] { + debug_assert!(this.info.can_map, "Buffer is not mappable - create using can_map flag"); + &this.allocation.as_ref().unwrap().mapped_slice().unwrap()[0..this.info.size as usize] } @@ -363,6 +367,8 @@ impl Buffer { /// # Ok(()) } /// ``` pub fn mapped_slice_mut(this: &mut Self) -> &mut [u8] { + debug_assert!(this.info.can_map, "Buffer is not mappable - create using can_map flag"); + &mut this .allocation .as_mut() diff --git a/src/driver/shader.rs b/src/driver/shader.rs index 232e40d..ab7ef9f 100644 --- a/src/driver/shader.rs +++ b/src/driver/shader.rs @@ -4,7 +4,7 @@ use { super::{device::Device, DescriptorSetLayout, DriverError, VertexInputState}, ash::vk, derive_builder::{Builder, UninitializedFieldError}, - log::{debug, error, info, trace, warn}, + log::{debug, error, trace, warn}, ordered_float::OrderedFloat, spirq::{ ty::{ScalarType, Type}, @@ -1062,7 +1062,7 @@ impl Shader { vertex_attribute_description.offset = offset; offset += stride; - info!( + debug!( "vertex attribute {}.{}: {:?} (offset={})", vertex_attribute_description.binding, vertex_attribute_description.location, diff --git a/src/driver/swapchain.rs b/src/driver/swapchain.rs index 6fd7702..d29863a 100644 --- a/src/driver/swapchain.rs +++ b/src/driver/swapchain.rs @@ -246,7 +246,7 @@ impl Swapchain { continue; } - if !Device::image_format_properties( + if Device::image_format_properties( &self.device, self.info.format.format, vk::ImageType::TYPE_2D, @@ -254,7 +254,7 @@ impl Swapchain { usage, vk::ImageCreateFlags::empty(), ) - .is_ok() + .is_err() { surface_capabilities.supported_usage_flags &= !usage; }