diff --git a/crates/renderer/src/instance.rs b/crates/renderer/src/instance.rs index 16bbd51..6e3fabf 100644 --- a/crates/renderer/src/instance.rs +++ b/crates/renderer/src/instance.rs @@ -2,7 +2,11 @@ use crate::error::RendererError; use ash::{Entry, Instance, ext, vk}; -use std::ffi::{CStr, c_char}; +use std::ffi::c_char; +// `CStr` and the tracing macros are used only by the debug-build validation callback. +#[cfg(debug_assertions)] +use std::ffi::CStr; +#[cfg(debug_assertions)] use tracing::{debug, error, info, warn}; /// Creates a Vulkan instance and optionally a debug messenger. @@ -21,7 +25,22 @@ pub fn create_instance( ), RendererError, > { + // The validation extension and layer are pushed only in debug builds, so in release builds these vectors are never mutated after initialization. + #[cfg_attr( + not(debug_assertions), + expect( + unused_mut, + reason = "the debug-only block below mutates these vectors" + ) + )] let mut extensions = required_extensions.to_vec(); + #[cfg_attr( + not(debug_assertions), + expect( + unused_mut, + reason = "the debug-only block below mutates these vectors" + ) + )] let mut layers = Vec::new(); #[cfg(debug_assertions)] @@ -70,6 +89,7 @@ pub fn create_instance( /// # Safety /// /// Invoked by the Vulkan loader, which must pass a valid `p_callback_data` pointer whose `p_message` is either null or a valid NUL-terminated C string. Not to be called directly. +#[cfg(debug_assertions)] unsafe extern "system" fn vulkan_debug_callback( message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, _message_type: vk::DebugUtilsMessageTypeFlagsEXT,