vulkayes_core/lib.rs
1//! This crate provides core components for the vulkayes project.
2//!
3//! ## Crate features:
4//!
5//! ### `host_allocator` and `rust_host_allocator`
6//!
7//! `host_allocator` adds `Custom` variant to `HostMemoryAllocator`. This makes the type sized, but enables the use of custom host memory allocators.
8//!
9//! `rust_host_allocator` adds `Rust()` constructor to `HostMemoryAllocator` that uses Rusts `std::alloc` methods. Requires `host_allocator` feature.
10//!
11//! ### `naive_device_allocator`
12//!
13//! Adds a simple memory allocator `NaiveDeviceMemoryAllocator` that allocates memory for each resource separately.
14//! It should not be used in production applications.
15//!
16//! ### `multi_thread`
17//!
18//! Enables multi thread support by using `Arc<T>` and `Mutex<T>` (dubbed as `Vrc` and `Vutex`) instead of `Rc<T>` and `RefCell<T>` (wrapped to have compatible API).
19//!
20//! ### `parking_lot_vutex`
21//!
22//! Uses `Mutex` from `parking_lot` crate instead of the standard library. Requires `multi_thread` feature.
23//!
24//! ### `insecure_hash`
25//!
26//! Uses `rustc_hash::{FxHashMap, FxHashSet}` instead of `std::collections::{HashMap, HashSet}` (dubbed as `VHashMap` and `VHashSet`).
27//!
28//! ### `runtime_implicit_validations`
29//!
30//! Some implicit validations cannot be checked statically. This feature enables runtime checks of those validations.
31//! Note that in some circumstances, such as Instance creation and extension name checking, the validation is part of the input
32//! argument transformation and turning it off would not bring any advantages.
33//!
34//! These validations might not be cheap. It is recommended to only enabled them when debugging, not in release/production builds.
35//!
36//! ### `vulkan1_1` and `vulkan1_2`
37//!
38//! `vulkan1_1` enables methods that will panic on Vulkan 1.0
39//!
40//! `vulkan1_2` enables methods that will panic on Vulkan 1.0 and 1.1. Requires `vulkan1_1` feature.
41//!
42//! ### `log_max_level_*` and `log_release_max_level_*`
43//!
44//! These features directly correspond to the features on the `log` crate.
45
46// Export `ash` because all other component will use it.
47pub use ash;
48// Export `log` so that `log_*` features can be applied to all vulkayes crates
49pub use log;
50// Export `seq_macro` because `lock_and_deref` macro requires it.
51pub use seq_macro;
52
53/// Non zero `1u32` constant to avoid unnecessary unsafe blocks in constant contexts.
54pub const NONZEROU32_ONE: std::num::NonZeroU32 = unsafe { std::num::NonZeroU32::new_unchecked(1) };
55
56// Macros used inside and outside of the crate.
57#[macro_use]
58pub mod util;
59
60pub mod command;
61pub mod descriptor;
62pub mod device;
63pub mod entry;
64pub mod framebuffer;
65pub mod instance;
66pub mod memory;
67pub mod physical_device;
68pub mod pipeline;
69pub mod prelude;
70pub mod queue;
71pub mod render_pass;
72pub mod resource;
73pub mod shader;
74pub mod surface;
75pub mod swapchain;
76pub mod sync;
77
78#[cfg(test)]
79mod test {
80 pub fn setup_testing_logger() {
81 static LOGGER_INITIALIZED: std::sync::atomic::AtomicBool =
82 std::sync::atomic::AtomicBool::new(false);
83
84 if LOGGER_INITIALIZED.compare_and_swap(false, true, std::sync::atomic::Ordering::SeqCst)
85 == false
86 {
87 let logger = edwardium_logger::Logger::new(
88 [edwardium_logger::targets::stderr::StderrTarget::new(
89 log::Level::Trace
90 )],
91 std::time::Instant::now()
92 );
93 logger.init_boxed().expect("Could not initialize logger");
94 }
95 }
96
97 #[test]
98 // Debug test for testing small thing during development
99 fn debug() {
100 setup_testing_logger();
101
102 fn print_size<T>(name: &str) {
103 log::info!(
104 "{} size: {} align: {}",
105 name,
106 std::mem::size_of::<T>(),
107 std::mem::align_of::<T>()
108 );
109 }
110
111 print_size::<crate::memory::host::HostMemoryAllocator>("HostMemoryAllocator");
112
113 print_size::<ash::Instance>("ash::Instance");
114 print_size::<ash::Device>("ash::Instance");
115
116 print_size::<crate::instance::Instance>("Instance");
117 print_size::<crate::device::Device>("Device");
118 }
119}