• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(
2     clippy::too_many_arguments,
3     clippy::missing_safety_doc,
4     clippy::upper_case_acronyms
5 )]
6 //! # Vulkan API
7 //!
8 //! <https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/index.html>
9 //!
10 //! ## Examples
11 //!
12 //! ```no_run
13 //! use ash::{vk, Entry};
14 //! # fn main() -> Result<(), Box<dyn std::error::Error>> {
15 //! let entry = unsafe { Entry::new() }?;
16 //! let app_info = vk::ApplicationInfo {
17 //!     api_version: vk::make_api_version(0, 1, 0, 0),
18 //!     ..Default::default()
19 //! };
20 //! let create_info = vk::InstanceCreateInfo {
21 //!     p_application_info: &app_info,
22 //!     ..Default::default()
23 //! };
24 //! let instance = unsafe { entry.create_instance(&create_info, None)? };
25 //! # Ok(()) }
26 //! ```
27 //!
28 //! ## Getting started
29 //! Load the Vulkan library at the default location using [`Entry::new()`][EntryCustom<_>::new()],
30 //! or at a custom location using [`Entry::with_library("path/to/vulkan")`][EntryCustom<_>::with_library()].
31 //! These loaders use [`libloading`]. If you wish to perform function loading yourself
32 //! call [`EntryCustom::new_custom()`] with a closure turning function names
33 //! into function pointers.
34 
35 pub use crate::device::Device;
36 pub use crate::entry::{EntryCustom, InstanceError};
37 #[cfg(feature = "libloading")]
38 pub use crate::entry_libloading::{Entry, LoadingError};
39 pub use crate::instance::Instance;
40 
41 mod device;
42 mod entry;
43 #[cfg(feature = "libloading")]
44 mod entry_libloading;
45 mod instance;
46 pub mod prelude;
47 pub mod util;
48 /// Raw Vulkan bindings and types, generated from `vk.xml`
49 #[macro_use]
50 pub mod vk;
51 
52 // macros of vk need to be defined beforehand
53 /// Wrappers for Vulkan extensions
54 pub mod extensions;
55 
56 pub trait RawPtr<T> {
as_raw_ptr(&self) -> *const T57     fn as_raw_ptr(&self) -> *const T;
58 }
59 
60 impl<'r, T> RawPtr<T> for Option<&'r T> {
as_raw_ptr(&self) -> *const T61     fn as_raw_ptr(&self) -> *const T {
62         match *self {
63             Some(inner) => inner as *const T,
64 
65             _ => ::std::ptr::null(),
66         }
67     }
68 }
69 
70 #[cfg(test)]
71 mod tests {
72     use super::vk;
73     #[test]
test_ptr_chains()74     fn test_ptr_chains() {
75         let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::builder();
76         let mut corner = vk::PhysicalDeviceCornerSampledImageFeaturesNV::builder();
77         let chain = vec![
78             &variable_pointers as *const _ as usize,
79             &corner as *const _ as usize,
80         ];
81         let mut device_create_info = vk::DeviceCreateInfo::builder()
82             .push_next(&mut corner)
83             .push_next(&mut variable_pointers);
84         let chain2: Vec<usize> = unsafe {
85             vk::ptr_chain_iter(&mut device_create_info)
86                 .skip(1)
87                 .map(|ptr| ptr as usize)
88                 .collect()
89         };
90         assert_eq!(chain, chain2);
91     }
92 }
93