fix(renderer): silence release-build warnings from debug-only validation

This commit is contained in:
Serkyo 2026-07-16 03:01:02 +02:00
parent fd6ec10ce5
commit 8cfee29b53

View file

@ -2,7 +2,11 @@
use crate::error::RendererError; use crate::error::RendererError;
use ash::{Entry, Instance, ext, vk}; 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}; use tracing::{debug, error, info, warn};
/// Creates a Vulkan instance and optionally a debug messenger. /// Creates a Vulkan instance and optionally a debug messenger.
@ -21,7 +25,22 @@ pub fn create_instance(
), ),
RendererError, 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(); 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(); let mut layers = Vec::new();
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@ -70,6 +89,7 @@ pub fn create_instance(
/// # Safety /// # 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. /// 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( unsafe extern "system" fn vulkan_debug_callback(
message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
_message_type: vk::DebugUtilsMessageTypeFlagsEXT, _message_type: vk::DebugUtilsMessageTypeFlagsEXT,