vulkano/instance/layers.rs
1use crate::Version;
2
3/// Properties of a layer.
4#[derive(Clone)]
5pub struct LayerProperties {
6 pub(crate) props: ash::vk::LayerProperties,
7}
8
9impl LayerProperties {
10 /// Returns the name of the layer.
11 ///
12 /// If you want to enable this layer on an instance, you need to pass this value to
13 /// `Instance::new`.
14 ///
15 /// # Examples
16 ///
17 /// ```no_run
18 /// use vulkano::VulkanLibrary;
19 ///
20 /// let library = VulkanLibrary::new().unwrap();
21 ///
22 /// for layer in library.layer_properties().unwrap() {
23 /// println!("Layer name: {}", layer.name());
24 /// }
25 /// ```
26 #[inline]
27 pub fn name(&self) -> &str {
28 self.props.layer_name_as_c_str().unwrap().to_str().unwrap()
29 }
30
31 /// Returns a description of the layer.
32 ///
33 /// This description is chosen by the layer itself.
34 ///
35 /// # Examples
36 ///
37 /// ```no_run
38 /// use vulkano::VulkanLibrary;
39 ///
40 /// let library = VulkanLibrary::new().unwrap();
41 ///
42 /// for layer in library.layer_properties().unwrap() {
43 /// println!("Layer description: {}", layer.description());
44 /// }
45 /// ```
46 #[inline]
47 pub fn description(&self) -> &str {
48 self.props.description_as_c_str().unwrap().to_str().unwrap()
49 }
50
51 /// Returns the version of Vulkan supported by this layer.
52 ///
53 /// # Examples
54 ///
55 /// ```no_run
56 /// use vulkano::{Version, VulkanLibrary};
57 ///
58 /// let library = VulkanLibrary::new().unwrap();
59 ///
60 /// for layer in library.layer_properties().unwrap() {
61 /// if layer.vulkan_version() >= Version::major_minor(2, 0) {
62 /// println!("Layer {} requires Vulkan 2.0", layer.name());
63 /// }
64 /// }
65 /// ```
66 #[inline]
67 pub fn vulkan_version(&self) -> Version {
68 Version::from(self.props.spec_version)
69 }
70
71 /// Returns an implementation-specific version number for this layer.
72 ///
73 /// The number is chosen by the layer itself. It can be used for bug reports for example.
74 ///
75 /// # Examples
76 ///
77 /// ```no_run
78 /// use vulkano::VulkanLibrary;
79 ///
80 /// let library = VulkanLibrary::new().unwrap();
81 ///
82 /// for layer in library.layer_properties().unwrap() {
83 /// println!(
84 /// "Layer {} - Version: {}",
85 /// layer.name(),
86 /// layer.implementation_version(),
87 /// );
88 /// }
89 /// ```
90 #[inline]
91 pub fn implementation_version(&self) -> u32 {
92 self.props.implementation_version
93 }
94}
95
96#[cfg(test)]
97mod tests {
98 use crate::VulkanLibrary;
99
100 #[test]
101 fn layers_list() {
102 let library = match VulkanLibrary::new() {
103 Ok(x) => x,
104 Err(_) => return,
105 };
106
107 let list = match library.layer_properties() {
108 Ok(l) => l,
109 Err(_) => return,
110 };
111
112 for _ in list {}
113 }
114}