-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::sync::Mutex; | ||
|
||
use slog::{o, Drain}; | ||
use smithay::backend::vulkan::{Instance, PhysicalDevice}; | ||
|
||
fn main() { | ||
let logger = slog::Logger::root(Mutex::new(slog_term::term_full().fuse()).fuse(), o!()); | ||
|
||
println!("Version: {}", Instance::max_instance_version().unwrap()); | ||
println!( | ||
"Available instance extensions: {:?}", | ||
Instance::enumerate_extensions().unwrap().collect::<Vec<_>>() | ||
); | ||
println!(); | ||
|
||
let instance = Instance::new(Version::VERSION_1_3, None, logger).unwrap(); | ||
|
||
for (idx, phy) in PhysicalDevice::enumerate(&instance).unwrap().enumerate() { | ||
println!( | ||
"Device #{}: {} v{}, {:?}", | ||
idx, | ||
phy.name(), | ||
phy.api_version(), | ||
phy.driver() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::{ | ||
ffi::{CStr, CString}, | ||
fmt, | ||
}; | ||
|
||
use ash::{extensions::ext::DebugUtils, vk}; | ||
use slog::Logger; | ||
|
||
use super::{version::Version, LoadError, LIBRARY}; | ||
|
||
pub struct InstanceInner { | ||
pub instance: ash::Instance, | ||
pub version: Version, | ||
pub debug_state: Option<DebugState>, | ||
|
||
/// Enabled instance extensions. | ||
pub enabled_extensions: Vec<&'static CStr>, | ||
} | ||
|
||
pub struct DebugState { | ||
pub debug_utils: DebugUtils, | ||
pub debug_messenger: vk::DebugUtilsMessengerEXT, | ||
pub logger_ptr: *mut Logger, | ||
} | ||
|
||
impl fmt::Debug for InstanceInner { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("InstanceInner") | ||
.field("instance", &self.instance.handle()) | ||
.finish_non_exhaustive() | ||
} | ||
} | ||
|
||
impl Drop for InstanceInner { | ||
fn drop(&mut self) { | ||
let logger = if let Some(debug) = &self.debug_state { | ||
unsafe { | ||
debug | ||
.debug_utils | ||
.destroy_debug_utils_messenger(debug.debug_messenger, None); | ||
} | ||
|
||
Some(unsafe { Box::from_raw(debug.logger_ptr as *mut slog::Logger) }) | ||
} else { | ||
None | ||
}; | ||
|
||
// Users of `Instance` are responsible for compliance with `VUID-vkDestroyInstance-instance-00629`. | ||
|
||
// SAFETY (Host Synchronization): InstanceInner is always stored in an Arc, therefore destruction is | ||
// synchronized (since the inner value of an Arc is always dropped on a single thread). | ||
unsafe { self.instance.destroy_instance(None) }; | ||
|
||
// Now that the instance has been destroyed, we can destroy the logger. | ||
drop(logger); | ||
} | ||
} | ||
|
||
impl super::Instance { | ||
pub(super) fn enumerate_layers() -> Result<impl Iterator<Item = CString>, LoadError> { | ||
let library = LIBRARY.as_ref().or(Err(LoadError))?; | ||
|
||
let layers = library | ||
.enumerate_instance_layer_properties() | ||
.or(Err(LoadError))? | ||
.into_iter() | ||
.map(|properties| { | ||
// SAFETY: Vulkan guarantees the string is null terminated. | ||
unsafe { CStr::from_ptr(&properties.layer_name as *const _) }.to_owned() | ||
}); | ||
|
||
Ok(layers) | ||
} | ||
} |
Oops, something went wrong.