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