1 // Copyright (c) 2016 The vulkano developers 2 // Licensed under the Apache License, Version 2.0 3 // <LICENSE-APACHE or 4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT 5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 6 // at your option. All files in the project carrying such 7 // notice may not be copied, modified, or distributed except 8 // according to those terms. 9 10 use crate::Version; 11 use std::ffi::CStr; 12 13 /// Properties of a layer. 14 #[derive(Clone)] 15 pub struct LayerProperties { 16 pub(crate) props: ash::vk::LayerProperties, 17 } 18 19 impl LayerProperties { 20 /// Returns the name of the layer. 21 /// 22 /// If you want to enable this layer on an instance, you need to pass this value to 23 /// `Instance::new`. 24 /// 25 /// # Examples 26 /// 27 /// ```no_run 28 /// use vulkano::VulkanLibrary; 29 /// 30 /// let library = VulkanLibrary::new().unwrap(); 31 /// 32 /// for layer in library.layer_properties().unwrap() { 33 /// println!("Layer name: {}", layer.name()); 34 /// } 35 /// ``` 36 #[inline] name(&self) -> &str37 pub fn name(&self) -> &str { 38 unsafe { 39 CStr::from_ptr(self.props.layer_name.as_ptr()) 40 .to_str() 41 .unwrap() 42 } 43 } 44 45 /// Returns a description of the layer. 46 /// 47 /// This description is chosen by the layer itself. 48 /// 49 /// # Examples 50 /// 51 /// ```no_run 52 /// use vulkano::VulkanLibrary; 53 /// 54 /// let library = VulkanLibrary::new().unwrap(); 55 /// 56 /// for layer in library.layer_properties().unwrap() { 57 /// println!("Layer description: {}", layer.description()); 58 /// } 59 /// ``` 60 #[inline] description(&self) -> &str61 pub fn description(&self) -> &str { 62 unsafe { 63 CStr::from_ptr(self.props.description.as_ptr()) 64 .to_str() 65 .unwrap() 66 } 67 } 68 69 /// Returns the version of Vulkan supported by this layer. 70 /// 71 /// # Examples 72 /// 73 /// ```no_run 74 /// use vulkano::{Version, VulkanLibrary}; 75 /// 76 /// let library = VulkanLibrary::new().unwrap(); 77 /// 78 /// for layer in library.layer_properties().unwrap() { 79 /// if layer.vulkan_version() >= Version::major_minor(2, 0) { 80 /// println!("Layer {} requires Vulkan 2.0", layer.name()); 81 /// } 82 /// } 83 /// ``` 84 #[inline] vulkan_version(&self) -> Version85 pub fn vulkan_version(&self) -> Version { 86 Version::from(self.props.spec_version) 87 } 88 89 /// Returns an implementation-specific version number for this layer. 90 /// 91 /// The number is chosen by the layer itself. It can be used for bug reports for example. 92 /// 93 /// # Examples 94 /// 95 /// ```no_run 96 /// use vulkano::VulkanLibrary; 97 /// 98 /// let library = VulkanLibrary::new().unwrap(); 99 /// 100 /// for layer in library.layer_properties().unwrap() { 101 /// println!("Layer {} - Version: {}", layer.name(), layer.implementation_version()); 102 /// } 103 /// ``` 104 #[inline] implementation_version(&self) -> u32105 pub fn implementation_version(&self) -> u32 { 106 self.props.implementation_version 107 } 108 } 109 110 #[cfg(test)] 111 mod tests { 112 use crate::VulkanLibrary; 113 114 #[test] layers_list()115 fn layers_list() { 116 let library = match VulkanLibrary::new() { 117 Ok(x) => x, 118 Err(_) => return, 119 }; 120 121 let list = match library.layer_properties() { 122 Ok(l) => l, 123 Err(_) => return, 124 }; 125 126 for _ in list {} 127 } 128 } 129