Attribute Macro auto_deviceinfo_impl

Source
#[auto_deviceinfo_impl]
Expand description

Derive the implementation of the vulkan_layer::DeviceInfo trait from the implementation of the vulkan_layer::DeviceHooks trait.

This attribute macro should be used over an implementation item of the vulkan_layer::DeviceHooks trait, and will implement the vulkan_layer::DeviceInfo trait for the type:

  • DeviceInfo::hooked_commands returns a list of the overridden methods that appear in the implementation item.
  • DeviceInfo::HooksType and DeviceInfo::HooksRefType are defined as Self and &Self.
  • DeviceInfo::hooks returns self.

ยงExamples

use ash::vk;
use vulkan_layer::{
    auto_deviceinfo_impl, DeviceHooks, DeviceInfo, LayerResult, LayerVulkanCommand,
};

#[derive(Default)]
struct MyDeviceHooks;

#[auto_deviceinfo_impl]
impl DeviceHooks for MyDeviceHooks {
    fn create_image(
        &self,
        _p_create_info: &vk::ImageCreateInfo,
        _p_allocator: Option<&vk::AllocationCallbacks>,
    ) -> LayerResult<ash::prelude::VkResult<vk::Image>> {
        LayerResult::Unhandled
    }
}

let my_device_hooks: MyDeviceHooks = Default::default();
assert!(std::ptr::eq(my_device_hooks.hooks(), &my_device_hooks));
assert_eq!(
    MyDeviceHooks::hooked_commands(),
    [LayerVulkanCommand::CreateImage]
);