expose vulkan physical device capabilities, enabled device extensions (#2688)

This commit is contained in:
i509VCB 2022-06-10 14:32:52 -05:00 committed by GitHub
parent f94f25f355
commit e0327b1db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 20 deletions

View File

@ -608,7 +608,11 @@ unsafe impl Send for PhysicalDeviceCapabilities {}
unsafe impl Sync for PhysicalDeviceCapabilities {}
impl PhysicalDeviceCapabilities {
fn supports_extension(&self, extension: &CStr) -> bool {
pub fn properties(&self) -> vk::PhysicalDeviceProperties {
self.properties
}
pub fn supports_extension(&self, extension: &CStr) -> bool {
self.supported_extensions
.iter()
.any(|ep| unsafe { CStr::from_ptr(ep.extension_name.as_ptr()) } == extension)
@ -1125,6 +1129,14 @@ impl super::Adapter {
self.raw
}
pub fn physical_device_capabilities(&self) -> &PhysicalDeviceCapabilities {
&self.phd_capabilities
}
pub fn shared_instance(&self) -> &super::InstanceShared {
&self.instance
}
pub fn required_device_extensions(&self, features: wgt::Features) -> Vec<&'static CStr> {
let (supported_extensions, unsupported_extensions) = self
.phd_capabilities
@ -1299,6 +1311,8 @@ impl super::Adapter {
raw: raw_device,
handle_is_owned,
instance: Arc::clone(&self.instance),
physical_device: self.raw,
enabled_extensions: enabled_extensions.into(),
extension_fns: super::DeviceExtensionFunctions {
draw_indirect_count: indirect_count_fn,
timeline_semaphore: timeline_semaphore_fn,

View File

@ -8,7 +8,7 @@ use parking_lot::Mutex;
use std::{
borrow::Cow,
collections::{hash_map::Entry, BTreeMap},
ffi::CString,
ffi::{CStr, CString},
num::NonZeroU32,
ptr,
sync::Arc,
@ -21,8 +21,6 @@ impl super::DeviceShared {
object: impl vk::Handle,
name: &str,
) {
use std::ffi::CStr;
let extension = match self.instance.debug_utils {
Some(ref debug_utils) => &debug_utils.extension,
None => return,
@ -699,6 +697,18 @@ impl super::Device {
pub fn raw_device(&self) -> &ash::Device {
&self.shared.raw
}
pub fn raw_physical_device(&self) -> ash::vk::PhysicalDevice {
self.shared.physical_device
}
pub fn enabled_device_extensions(&self) -> &[&'static CStr] {
&self.shared.enabled_extensions
}
pub fn shared_instance(&self) -> &super::InstanceShared {
&self.shared.instance
}
}
impl crate::Device<super::Api> for super::Device {

View File

@ -132,22 +132,28 @@ impl super::Swapchain {
}
}
impl super::Instance {
impl super::InstanceShared {
pub fn entry(&self) -> &ash::Entry {
&self.shared.entry
&self.entry
}
pub fn raw_instance(&self) -> &ash::Instance {
&self.shared.raw
&self.raw
}
pub fn driver_api_version(&self) -> u32 {
self.shared.driver_api_version
self.driver_api_version
}
pub fn extensions(&self) -> &[&'static CStr] {
&self.extensions[..]
}
}
impl super::Instance {
pub fn shared_instance(&self) -> &super::InstanceShared {
&self.shared
}
pub fn required_extensions(
entry: &ash::Entry,
@ -279,6 +285,7 @@ impl super::Instance {
Ok(Self {
shared: Arc::new(super::InstanceShared {
raw: raw_instance,
extensions,
drop_guard,
flags,
debug_utils,
@ -288,7 +295,6 @@ impl super::Instance {
driver_api_version,
android_sdk_version,
}),
extensions,
})
}
@ -298,7 +304,7 @@ impl super::Instance {
dpy: *mut vk::Display,
window: vk::Window,
) -> super::Surface {
if !self.extensions.contains(&khr::XlibSurface::name()) {
if !self.shared.extensions.contains(&khr::XlibSurface::name()) {
panic!("Vulkan driver does not support VK_KHR_XLIB_SURFACE");
}
@ -322,7 +328,7 @@ impl super::Instance {
connection: *mut vk::xcb_connection_t,
window: vk::xcb_window_t,
) -> super::Surface {
if !self.extensions.contains(&khr::XcbSurface::name()) {
if !self.shared.extensions.contains(&khr::XcbSurface::name()) {
panic!("Vulkan driver does not support VK_KHR_XCB_SURFACE");
}
@ -346,7 +352,11 @@ impl super::Instance {
display: *mut c_void,
surface: *mut c_void,
) -> super::Surface {
if !self.extensions.contains(&khr::WaylandSurface::name()) {
if !self
.shared
.extensions
.contains(&khr::WaylandSurface::name())
{
panic!("Vulkan driver does not support VK_KHR_WAYLAND_SURFACE");
}
@ -383,7 +393,7 @@ impl super::Instance {
hinstance: *mut c_void,
hwnd: *mut c_void,
) -> super::Surface {
if !self.extensions.contains(&khr::Win32Surface::name()) {
if !self.shared.extensions.contains(&khr::Win32Surface::name()) {
panic!("Vulkan driver does not support VK_KHR_WIN32_SURFACE");
}
@ -625,16 +635,21 @@ impl crate::Instance<super::Api> for super::Instance {
match has_handle.raw_window_handle() {
RawWindowHandle::Wayland(handle)
if self.extensions.contains(&khr::WaylandSurface::name()) =>
if self
.shared
.extensions
.contains(&khr::WaylandSurface::name()) =>
{
Ok(self.create_surface_from_wayland(handle.display, handle.surface))
}
RawWindowHandle::Xlib(handle)
if self.extensions.contains(&khr::XlibSurface::name()) =>
if self.shared.extensions.contains(&khr::XlibSurface::name()) =>
{
Ok(self.create_surface_from_xlib(handle.display as *mut _, handle.window))
}
RawWindowHandle::Xcb(handle) if self.extensions.contains(&khr::XcbSurface::name()) => {
RawWindowHandle::Xcb(handle)
if self.shared.extensions.contains(&khr::XcbSurface::name()) =>
{
Ok(self.create_surface_from_xcb(handle.connection, handle.window))
}
RawWindowHandle::AndroidNdk(handle) => {
@ -649,13 +664,13 @@ impl crate::Instance<super::Api> for super::Instance {
}
#[cfg(target_os = "macos")]
RawWindowHandle::AppKit(handle)
if self.extensions.contains(&ext::MetalSurface::name()) =>
if self.shared.extensions.contains(&ext::MetalSurface::name()) =>
{
Ok(self.create_surface_from_view(handle.ns_view))
}
#[cfg(target_os = "ios")]
RawWindowHandle::UiKit(handle)
if self.extensions.contains(&ext::MetalSurface::name()) =>
if self.shared.extensions.contains(&ext::MetalSurface::name()) =>
{
Ok(self.create_surface_from_view(handle.ui_view))
}

View File

@ -79,8 +79,9 @@ struct DebugUtils {
messenger: vk::DebugUtilsMessengerEXT,
}
struct InstanceShared {
pub struct InstanceShared {
raw: ash::Instance,
extensions: Vec<&'static CStr>,
drop_guard: Option<DropGuard>,
flags: crate::InstanceFlags,
debug_utils: Option<DebugUtils>,
@ -93,7 +94,6 @@ struct InstanceShared {
pub struct Instance {
shared: Arc<InstanceShared>,
extensions: Vec<&'static CStr>,
}
struct Swapchain {
@ -314,6 +314,8 @@ struct DeviceShared {
raw: ash::Device,
handle_is_owned: bool,
instance: Arc<InstanceShared>,
physical_device: ash::vk::PhysicalDevice,
enabled_extensions: Vec<&'static CStr>,
extension_fns: DeviceExtensionFunctions,
vendor_id: u32,
timestamp_period: f32,