From 689548b967ae898758bbd55c18970f1b40f91fa7 Mon Sep 17 00:00:00 2001 From: ilyas-taouaou Date: Wed, 30 Oct 2024 00:07:22 +0100 Subject: [PATCH] check feature macro --- engine/src/rendering_context.rs | 49 ++++++++++++++------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/engine/src/rendering_context.rs b/engine/src/rendering_context.rs index 78ee114..5869dbe 100644 --- a/engine/src/rendering_context.rs +++ b/engine/src/rendering_context.rs @@ -97,6 +97,17 @@ pub mod queue_family_picker { } } +macro_rules! check_feature { + ($features:expr, $feature_name:ident) => { + if $features.$feature_name == vk::FALSE { + return Err(anyhow::anyhow!(concat!( + "Physical device does not support ", + stringify!($feature_name) + ))); + } + }; +} + impl RenderingContext { pub fn new(attributes: RenderingContextAttributes) -> Result { unsafe { @@ -174,35 +185,15 @@ impl RenderingContext { let (physical_device, queue_families) = (attributes.queue_family_picker)(physical_devices)?; - if physical_device.vulkan12_features.buffer_device_address == vk::FALSE { - return Err(anyhow::anyhow!( - "Physical device does not support buffer device address" - )); - } - - if physical_device.vulkan12_features.descriptor_indexing == vk::FALSE { - return Err(anyhow::anyhow!( - "Physical device does not support descriptor indexing" - )); - } - - if physical_device.vulkan12_features.scalar_block_layout == vk::FALSE { - return Err(anyhow::anyhow!( - "Physical device does not support scalar block layout" - )); - } - - if physical_device.vulkan13_features.dynamic_rendering == vk::FALSE { - return Err(anyhow::anyhow!( - "Physical device does not support dynamic rendering" - )); - } - - if physical_device.vulkan13_features.synchronization2 == vk::FALSE { - return Err(anyhow::anyhow!( - "Physical device does not support synchronization2" - )); - } + let features12 = physical_device.vulkan12_features; + let features13 = physical_device.vulkan13_features; + + check_feature!(features12, buffer_device_address); + check_feature!(features12, buffer_device_address_capture_replay); + check_feature!(features12, descriptor_indexing); + check_feature!(features12, scalar_block_layout); + check_feature!(features13, dynamic_rendering); + check_feature!(features13, synchronization2); let queue_family_indices = HashSet::from([ queue_families.graphics,