diff --git a/ash/src/extensions/android/external_memory_android_hardware_buffer.rs b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs index 98cf1c88a..f2a19a11c 100644 --- a/ash/src/extensions/android/external_memory_android_hardware_buffer.rs +++ b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs @@ -14,9 +14,10 @@ pub struct ExternalMemoryAndroidHardwareBuffer { impl ExternalMemoryAndroidHardwareBuffer { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); - let fp = vk::android_external_memory_android_hardware_buffer::DeviceFn::load(|name| unsafe { - mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) - }); + let fp = + vk::android_external_memory_android_hardware_buffer::DeviceFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); Self { handle, fp } } @@ -42,7 +43,8 @@ impl ExternalMemoryAndroidHardwareBuffer { .result_with_success(buffer) } - pub const NAME: &'static CStr = vk::android_external_memory_android_hardware_buffer::DeviceFn::NAME; + pub const NAME: &'static CStr = + vk::android_external_memory_android_hardware_buffer::DeviceFn::NAME; #[inline] pub fn fp(&self) -> &vk::android_external_memory_android_hardware_buffer::DeviceFn { diff --git a/ash/src/extensions/ext/calibrated_timestamps.rs b/ash/src/extensions/ext/calibrated_timestamps.rs index 95d61470d..a902b1904 100644 --- a/ash/src/extensions/ext/calibrated_timestamps.rs +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -1,52 +1,40 @@ use crate::prelude::*; use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +pub const NAME: &CStr = vk::ext_calibrated_timestamps::InstanceFn::NAME; + +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct CalibratedTimestamps { - handle: vk::Instance, +pub struct CalibratedTimestampsDevice { + handle: vk::Device, fp: vk::ext_calibrated_timestamps::DeviceFn, } -impl CalibratedTimestamps { - pub fn new(entry: &Entry, instance: &Instance) -> Self { - let handle = instance.handle(); +impl CalibratedTimestampsDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); let fp = vk::ext_calibrated_timestamps::DeviceFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } } - /// - #[inline] - pub unsafe fn get_physical_device_calibrateable_time_domains( - &self, - physical_device: vk::PhysicalDevice, - ) -> VkResult> { - read_into_uninitialized_vector(|count, data| { - (self.fp.get_physical_device_calibrateable_time_domains_ext)( - physical_device, - count, - data, - ) - }) - } - /// /// /// Returns a tuple containing `(timestamps, max_deviation)` #[inline] pub unsafe fn get_calibrated_timestamps( &self, - device: vk::Device, info: &[vk::CalibratedTimestampInfoEXT], ) -> VkResult<(Vec, u64)> { let mut timestamps = vec![0u64; info.len()]; let mut max_deviation = 0u64; (self.fp.get_calibrated_timestamps_ext)( - device, + self.handle, info.len() as u32, info.as_ptr(), timestamps.as_mut_ptr(), @@ -55,15 +43,50 @@ impl CalibratedTimestamps { .result_with_success((timestamps, max_deviation)) } - pub const NAME: &'static CStr = vk::ext_calibrated_timestamps::DeviceFn::NAME; - #[inline] pub fn fp(&self) -> &vk::ext_calibrated_timestamps::DeviceFn { &self.fp } #[inline] - pub fn instance(&self) -> vk::Instance { + pub fn device(&self) -> vk::Device { self.handle } } + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct CalibratedTimestampsInstance { + fp: vk::ext_calibrated_timestamps::InstanceFn, +} + +impl CalibratedTimestampsInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ext_calibrated_timestamps::InstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { fp } + } + + /// + #[inline] + pub unsafe fn get_physical_device_calibrateable_time_domains( + &self, + physical_device: vk::PhysicalDevice, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data| { + (self.fp.get_physical_device_calibrateable_time_domains_ext)( + physical_device, + count, + data, + ) + }) + } + + #[inline] + pub fn fp(&self) -> &vk::ext_calibrated_timestamps::InstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/ext/debug_utils.rs b/ash/src/extensions/ext/debug_utils.rs index 6eff9b7be..3fba05545 100755 --- a/ash/src/extensions/ext/debug_utils.rs +++ b/ash/src/extensions/ext/debug_utils.rs @@ -1,20 +1,24 @@ use crate::prelude::*; use crate::{vk, RawPtr}; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +pub const NAME: &CStr = vk::ext_debug_utils::NAME; + +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct DebugUtils { - handle: vk::Instance, +pub struct DebugUtilsDevice { + handle: vk::Device, fp: vk::ext_debug_utils::DeviceFn, } -impl DebugUtils { - pub fn new(entry: &Entry, instance: &Instance) -> Self { - let handle = instance.handle(); +impl DebugUtilsDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); let fp = vk::ext_debug_utils::DeviceFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } } @@ -23,20 +27,18 @@ impl DebugUtils { #[inline] pub unsafe fn set_debug_utils_object_name( &self, - device: vk::Device, name_info: &vk::DebugUtilsObjectNameInfoEXT, ) -> VkResult<()> { - (self.fp.set_debug_utils_object_name_ext)(device, name_info).result() + (self.fp.set_debug_utils_object_name_ext)(self.handle, name_info).result() } /// #[inline] pub unsafe fn set_debug_utils_object_tag( &self, - device: vk::Device, tag_info: &vk::DebugUtilsObjectTagInfoEXT, ) -> VkResult<()> { - (self.fp.set_debug_utils_object_tag_ext)(device, tag_info).result() + (self.fp.set_debug_utils_object_tag_ext)(self.handle, tag_info).result() } /// @@ -91,6 +93,34 @@ impl DebugUtils { (self.fp.queue_insert_debug_utils_label_ext)(queue, label); } + #[inline] + pub fn fp(&self) -> &vk::ext_debug_utils::DeviceFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct DebugUtilsInstance { + handle: vk::Instance, + fp: vk::ext_debug_utils::InstanceFn, +} + +impl DebugUtilsInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ext_debug_utils::InstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + /// #[inline] pub unsafe fn create_debug_utils_messenger( @@ -134,8 +164,6 @@ impl DebugUtils { ); } - pub const NAME: &'static CStr = vk::ext_debug_utils::DeviceFn::NAME; - #[inline] pub fn fp(&self) -> &vk::ext_debug_utils::DeviceFn { &self.fp diff --git a/ash/src/extensions/ext/full_screen_exclusive.rs b/ash/src/extensions/ext/full_screen_exclusive.rs index 7f56d8b27..f7c643e5f 100644 --- a/ash/src/extensions/ext/full_screen_exclusive.rs +++ b/ash/src/extensions/ext/full_screen_exclusive.rs @@ -1,16 +1,20 @@ use crate::prelude::*; use crate::vk; -use crate::{Device, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +pub const NAME: &CStr = vk::ext_full_screen_exclusive::NAME; + +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct FullScreenExclusive { +pub struct FullScreenExclusiveDevice { handle: vk::Device, fp: vk::ext_full_screen_exclusive::DeviceFn, } -impl FullScreenExclusive { +impl FullScreenExclusiveDevice { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); let fp = vk::ext_full_screen_exclusive::DeviceFn::load(|name| unsafe { @@ -28,23 +32,6 @@ impl FullScreenExclusive { (self.fp.acquire_full_screen_exclusive_mode_ext)(self.handle, swapchain).result() } - /// - #[inline] - pub unsafe fn get_physical_device_surface_present_modes2( - &self, - physical_device: vk::PhysicalDevice, - surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR, - ) -> VkResult> { - read_into_uninitialized_vector(|count, data| { - (self.fp.get_physical_device_surface_present_modes2_ext)( - physical_device, - surface_info, - count, - data, - ) - }) - } - /// #[inline] pub unsafe fn release_full_screen_exclusive_mode( @@ -69,8 +56,6 @@ impl FullScreenExclusive { .result_with_success(present_modes) } - pub const NAME: &'static CStr = vk::ext_full_screen_exclusive::DeviceFn::NAME; - #[inline] pub fn fp(&self) -> &vk::ext_full_screen_exclusive::DeviceFn { &self.fp @@ -81,3 +66,42 @@ impl FullScreenExclusive { self.handle } } + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct FullScreenExclusiveInstance { + fp: vk::ext_full_screen_exclusive::InstanceFn, +} + +impl FullScreenExclusiveInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ext_full_screen_exclusive::InstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { fp } + } + + /// + #[inline] + pub unsafe fn get_physical_device_surface_present_modes2( + &self, + physical_device: vk::PhysicalDevice, + surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data| { + (self.fp.get_physical_device_surface_present_modes2_ext)( + physical_device, + surface_info, + count, + data, + ) + }) + } + + #[inline] + pub fn fp(&self) -> &vk::ext_full_screen_exclusive::InstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/ext/mod.rs b/ash/src/extensions/ext/mod.rs index 680a99761..c08a7d177 100644 --- a/ash/src/extensions/ext/mod.rs +++ b/ash/src/extensions/ext/mod.rs @@ -1,16 +1,16 @@ pub use self::acquire_drm_display::AcquireDrmDisplay; pub use self::buffer_device_address::BufferDeviceAddress; -pub use self::calibrated_timestamps::CalibratedTimestamps; +pub use self::calibrated_timestamps::{CalibratedTimestampsDevice, CalibratedTimestampsInstance}; #[allow(deprecated)] pub use self::debug_marker::DebugMarker; #[allow(deprecated)] pub use self::debug_report::DebugReport; -pub use self::debug_utils::DebugUtils; +pub use self::debug_utils::{DebugUtilsDevice, DebugUtilsInstance}; pub use self::descriptor_buffer::DescriptorBuffer; pub use self::extended_dynamic_state::ExtendedDynamicState; pub use self::extended_dynamic_state2::ExtendedDynamicState2; pub use self::extended_dynamic_state3::ExtendedDynamicState3; -pub use self::full_screen_exclusive::FullScreenExclusive; +pub use self::full_screen_exclusive::{FullScreenExclusiveDevice, FullScreenExclusiveInstance}; pub use self::headless_surface::HeadlessSurface; pub use self::host_image_copy::HostImageCopy; pub use self::image_compression_control::ImageCompressionControl; @@ -19,7 +19,7 @@ pub use self::mesh_shader::MeshShader; pub use self::metal_surface::MetalSurface; pub use self::pipeline_properties::PipelineProperties; pub use self::private_data::PrivateData; -pub use self::sample_locations::SampleLocations; +pub use self::sample_locations::{SampleLocationsDevice, SampleLocationsInstance}; pub use self::shader_object::ShaderObject; pub use self::swapchain_maintenance1::SwapchainMaintenance1; pub use self::tooling_info::ToolingInfo; diff --git a/ash/src/extensions/ext/sample_locations.rs b/ash/src/extensions/ext/sample_locations.rs index d0b63bf6a..25e0289e7 100644 --- a/ash/src/extensions/ext/sample_locations.rs +++ b/ash/src/extensions/ext/sample_locations.rs @@ -1,17 +1,53 @@ use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +pub const NAME: &CStr = vk::ext_sample_locations::NAME; + +/// High-level device function wrapper for /// #[derive(Clone)] -pub struct SampleLocations { +pub struct SampleLocationsDevice { fp: vk::ext_sample_locations::DeviceFn, } -impl SampleLocations { - pub fn new(entry: &Entry, instance: &Instance) -> Self { +impl SampleLocationsDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { let fp = vk::ext_sample_locations::DeviceFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) + }); + Self { fp } + } + + /// + #[inline] + pub unsafe fn cmd_set_sample_locations( + &self, + command_buffer: vk::CommandBuffer, + sample_locations_info: &vk::SampleLocationsInfoEXT, + ) { + (self.fp.cmd_set_sample_locations_ext)(command_buffer, sample_locations_info) + } + + pub const NAME: &'static CStr = vk::ext_sample_locations::DeviceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::ext_sample_locations::DeviceFn { + &self.fp + } +} + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct SampleLocationsInstance { + fp: vk::ext_sample_locations::InstanceFn, +} + +impl SampleLocationsInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let fp = vk::ext_sample_locations::InstanceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); Self { fp } @@ -32,20 +68,8 @@ impl SampleLocations { ) } - /// #[inline] - pub unsafe fn cmd_set_sample_locations( - &self, - command_buffer: vk::CommandBuffer, - sample_locations_info: &vk::SampleLocationsInfoEXT, - ) { - (self.fp.cmd_set_sample_locations_ext)(command_buffer, sample_locations_info) - } - - pub const NAME: &'static CStr = vk::ext_sample_locations::DeviceFn::NAME; - - #[inline] - pub fn fp(&self) -> &vk::ext_sample_locations::DeviceFn { + pub fn fp(&self) -> &vk::ext_sample_locations::InstanceFn { &self.fp } } diff --git a/ash/src/extensions/khr/device_group.rs b/ash/src/extensions/khr/device_group.rs index f6977272a..8552e9eac 100644 --- a/ash/src/extensions/khr/device_group.rs +++ b/ash/src/extensions/khr/device_group.rs @@ -1,19 +1,22 @@ #[cfg(doc)] -use super::Swapchain; +use super::{SwapchainDevice, SwapchainInstance}; use crate::prelude::*; use crate::vk; -use crate::{Device, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +pub const NAME: &CStr = vk::khr_device_group::NAME; + +/// High-level device function wrapper for /// #[derive(Clone)] -pub struct DeviceGroup { +pub struct DeviceGroupDevice { handle: vk::Device, fp: vk::khr_device_group::DeviceFn, } -impl DeviceGroup { +impl DeviceGroupDevice { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); let fp = vk::khr_device_group::DeviceFn::load(|name| unsafe { @@ -68,7 +71,7 @@ impl DeviceGroup { /// Requires [`VK_KHR_surface`] to be enabled. /// - /// Also available as [`Swapchain::get_device_group_present_capabilities()`] since [Vulkan 1.1]. + /// Also available as [`SwapchainDevice::get_device_group_present_capabilities()`] since [Vulkan 1.1]. /// /// /// @@ -88,7 +91,7 @@ impl DeviceGroup { /// Requires [`VK_KHR_surface`] to be enabled. /// - /// Also available as [`Swapchain::get_device_group_surface_present_modes()`] since [Vulkan 1.1]. + /// Also available as [`SwapchainDevice::get_device_group_surface_present_modes()`] since [Vulkan 1.1]. /// /// /// @@ -104,35 +107,11 @@ impl DeviceGroup { .result_with_success(modes) } - /// Requires [`VK_KHR_surface`] to be enabled. - /// - /// Also available as [`Swapchain::get_physical_device_present_rectangles()`] since [Vulkan 1.1]. - /// - /// - /// - /// [Vulkan 1.1]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html - /// [`VK_KHR_surface`]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html - #[inline] - pub unsafe fn get_physical_device_present_rectangles( - &self, - physical_device: vk::PhysicalDevice, - surface: vk::SurfaceKHR, - ) -> VkResult> { - read_into_uninitialized_vector(|count, data| { - (self.fp.get_physical_device_present_rectangles_khr)( - physical_device, - surface, - count, - data, - ) - }) - } - /// On success, returns the next image's index and whether the swapchain is suboptimal for the surface. /// /// Requires [`VK_KHR_swapchain`] to be enabled. /// - /// Also available as [`Swapchain::acquire_next_image2()`] since [Vulkan 1.1]. + /// Also available as [`SwapchainDevice::acquire_next_image2()`] since [Vulkan 1.1]. /// /// /// @@ -152,8 +131,6 @@ impl DeviceGroup { } } - pub const NAME: &'static CStr = vk::khr_device_group::DeviceFn::NAME; - #[inline] pub fn fp(&self) -> &vk::khr_device_group::DeviceFn { &self.fp @@ -164,3 +141,49 @@ impl DeviceGroup { self.handle } } + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct DeviceGroupInstance { + fp: vk::khr_device_group::InstanceFn, +} + +impl DeviceGroupInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::khr_device_group::InstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { fp } + } + + /// Requires [`VK_KHR_surface`] to be enabled. + /// + /// Also available as [`SwapchainInstance::get_physical_device_present_rectangles()`] since [Vulkan 1.1]. + /// + /// + /// + /// [Vulkan 1.1]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html + /// [`VK_KHR_surface`]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_surface.html + #[inline] + pub unsafe fn get_physical_device_present_rectangles( + &self, + physical_device: vk::PhysicalDevice, + surface: vk::SurfaceKHR, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data| { + (self.fp.get_physical_device_present_rectangles_khr)( + physical_device, + surface, + count, + data, + ) + }) + } + + #[inline] + pub fn fp(&self) -> &vk::khr_device_group::InstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index e62ad54ac..4e53402a8 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -5,7 +5,7 @@ pub use self::cooperative_matrix::CooperativeMatrix; pub use self::copy_commands2::CopyCommands2; pub use self::create_render_pass2::CreateRenderPass2; pub use self::deferred_host_operations::DeferredHostOperations; -pub use self::device_group::DeviceGroup; +pub use self::device_group::{DeviceGroupDevice, DeviceGroupInstance}; pub use self::device_group_creation::DeviceGroupCreation; pub use self::display::Display; pub use self::display_swapchain::DisplaySwapchain; @@ -24,7 +24,7 @@ pub use self::maintenance1::Maintenance1; pub use self::maintenance3::Maintenance3; pub use self::maintenance4::Maintenance4; pub use self::maintenance5::Maintenance5; -pub use self::performance_query::PerformanceQuery; +pub use self::performance_query::{PerformanceQueryDevice, PerformanceQueryInstance}; pub use self::pipeline_executable_properties::PipelineExecutableProperties; pub use self::present_wait::PresentWait; pub use self::push_descriptor::PushDescriptor; @@ -32,7 +32,7 @@ pub use self::ray_tracing_maintenance1::RayTracingMaintenance1; pub use self::ray_tracing_pipeline::RayTracingPipeline; pub use self::sampler_ycbcr_conversion::SamplerYcbcrConversion; pub use self::surface::Surface; -pub use self::swapchain::Swapchain; +pub use self::swapchain::{SwapchainDevice, SwapchainInstance}; pub use self::synchronization2::Synchronization2; pub use self::timeline_semaphore::TimelineSemaphore; pub use self::wayland_surface::WaylandSurface; diff --git a/ash/src/extensions/khr/performance_query.rs b/ash/src/extensions/khr/performance_query.rs index a813a3068..c5069b1e2 100644 --- a/ash/src/extensions/khr/performance_query.rs +++ b/ash/src/extensions/khr/performance_query.rs @@ -1,26 +1,70 @@ use crate::prelude::*; use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; use std::ptr; +pub const NAME: &'static CStr = vk::khr_performance_query::NAME; + +/// High-level device function wrapper for /// #[derive(Clone)] -pub struct PerformanceQuery { - handle: vk::Instance, +pub struct PerformanceQueryDevice { + handle: vk::Device, fp: vk::khr_performance_query::DeviceFn, } -impl PerformanceQuery { - pub fn new(entry: &Entry, instance: &Instance) -> Self { - let handle = instance.handle(); +impl PerformanceQueryDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); let fp = vk::khr_performance_query::DeviceFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } } + /// + #[inline] + pub unsafe fn acquire_profiling_lock( + &self, + info: &vk::AcquireProfilingLockInfoKHR, + ) -> VkResult<()> { + (self.fp.acquire_profiling_lock_khr)(self.handle, info).result() + } + + /// + #[inline] + pub unsafe fn release_profiling_lock(&self) { + (self.fp.release_profiling_lock_khr)(self.handle) + } + + #[inline] + pub fn fp(&self) -> &vk::khr_performance_query::DeviceFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct PerformanceQueryInstance { + fp: vk::khr_performance_query::InstanceFn, +} + +impl PerformanceQueryInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let fp = vk::khr_performance_query::InstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + }); + Self { fp } + } + /// Retrieve the number of elements to pass to [`enumerate_physical_device_queue_family_performance_query_counters()`][Self::enumerate_physical_device_queue_family_performance_query_counters()] #[inline] pub unsafe fn enumerate_physical_device_queue_family_performance_query_counters_len( @@ -88,31 +132,8 @@ impl PerformanceQuery { num_passes } - /// #[inline] - pub unsafe fn acquire_profiling_lock( - &self, - device: vk::Device, - info: &vk::AcquireProfilingLockInfoKHR, - ) -> VkResult<()> { - (self.fp.acquire_profiling_lock_khr)(device, info).result() - } - - /// - #[inline] - pub unsafe fn release_profiling_lock(&self, device: vk::Device) { - (self.fp.release_profiling_lock_khr)(device) - } - - pub const NAME: &'static CStr = vk::khr_performance_query::DeviceFn::NAME; - - #[inline] - pub fn fp(&self) -> &vk::khr_performance_query::DeviceFn { + pub fn fp(&self) -> &vk::khr_performance_query::InstanceFn { &self.fp } - - #[inline] - pub fn instance(&self) -> vk::Instance { - self.handle - } } diff --git a/ash/src/extensions/khr/swapchain.rs b/ash/src/extensions/khr/swapchain.rs index 01b64e937..5fd35eba5 100755 --- a/ash/src/extensions/khr/swapchain.rs +++ b/ash/src/extensions/khr/swapchain.rs @@ -1,19 +1,23 @@ #[cfg(doc)] -use super::DeviceGroup; +use super::{DeviceGroupDevice, DeviceGroupInstance}; use crate::prelude::*; use crate::vk; use crate::RawPtr; -use crate::{Device, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +pub const NAME: &CStr = vk::khr_swapchain::NAME; + +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct Swapchain { +pub struct SwapchainDevice { handle: vk::Device, fp: vk::khr_swapchain::DeviceFn, } -impl Swapchain { +impl SwapchainDevice { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); let fp = vk::khr_swapchain::DeviceFn::load(|name| unsafe { @@ -106,7 +110,7 @@ impl Swapchain { /// Only available since [Vulkan 1.1]. /// - /// Also available as [`DeviceGroup::get_device_group_present_capabilities()`] + /// Also available as [`DeviceGroupDevice::get_device_group_present_capabilities()`] /// when [`VK_KHR_surface`] is enabled. /// /// @@ -127,7 +131,7 @@ impl Swapchain { /// Only available since [Vulkan 1.1]. /// - /// Also available as [`DeviceGroup::get_device_group_surface_present_modes()`] + /// Also available as [`DeviceGroupDevice::get_device_group_surface_present_modes()`] /// when [`VK_KHR_surface`] is enabled. /// /// @@ -144,9 +148,60 @@ impl Swapchain { .result_with_success(modes) } + /// On success, returns the next image's index and whether the swapchain is suboptimal for the surface. + /// /// Only available since [Vulkan 1.1]. /// - /// Also available as [`DeviceGroup::get_physical_device_present_rectangles()`] + /// Also available as [`DeviceGroupDevice::acquire_next_image2()`] + /// when [`VK_KHR_swapchain`] is enabled. + /// + /// + /// + /// [Vulkan 1.1]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_VERSION_1_1.html + /// [`VK_KHR_swapchain`]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_swapchain.html + #[inline] + pub unsafe fn acquire_next_image2( + &self, + acquire_info: &vk::AcquireNextImageInfoKHR, + ) -> VkResult<(u32, bool)> { + let mut index = 0; + let err_code = (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, &mut index); + match err_code { + vk::Result::SUCCESS => Ok((index, false)), + vk::Result::SUBOPTIMAL_KHR => Ok((index, true)), + _ => Err(err_code), + } + } + + #[inline] + pub fn fp(&self) -> &vk::KhrSwapchainDeviceFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct SwapchainInstance { + fp: vk::KhrSwapchainInstanceFn, +} + +impl SwapchainInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let fp = vk::KhrSwapchainInstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + }); + Self { fp } + } + + /// Only available since [Vulkan 1.1]. + /// + /// Also available as [`DeviceGroupInstance::get_physical_device_present_rectangles()`] /// when [`VK_KHR_surface`] is enabled. /// /// @@ -194,15 +249,8 @@ impl Swapchain { } } - pub const NAME: &'static CStr = vk::khr_swapchain::DeviceFn::NAME; - #[inline] pub fn fp(&self) -> &vk::khr_swapchain::DeviceFn { &self.fp } - - #[inline] - pub fn device(&self) -> vk::Device { - self.handle - } } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index a2d5ef3b7..d23dd7f77 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -2,8 +2,8 @@ extern crate ash; extern crate winit; use ash::extensions::{ - ext::DebugUtils, - khr::{Surface, Swapchain}, + ext::DebugUtilsInstance, + khr::{Surface, SwapchainDevice}, }; use ash::{vk, Entry}; pub use ash::{Device, Instance}; @@ -141,8 +141,8 @@ pub struct ExampleBase { pub instance: Instance, pub device: Device, pub surface_loader: Surface, - pub swapchain_loader: Swapchain, - pub debug_utils_loader: DebugUtils, + pub swapchain_loader: SwapchainDevice, + pub debug_utils_loader: DebugUtilsInstance, pub window: winit::window::Window, pub event_loop: RefCell>, pub debug_call_back: vk::DebugUtilsMessengerEXT, @@ -228,7 +228,7 @@ impl ExampleBase { ash_window::enumerate_required_extensions(window.raw_display_handle()) .unwrap() .to_vec(); - extension_names.push(DebugUtils::NAME.as_ptr()); + extension_names.push(DebugUtilsInstance::NAME.as_ptr()); #[cfg(any(target_os = "macos", target_os = "ios"))] { @@ -273,7 +273,7 @@ impl ExampleBase { ) .pfn_user_callback(Some(vulkan_debug_callback)); - let debug_utils_loader = DebugUtils::new(&entry, &instance); + let debug_utils_loader = DebugUtilsInstance::new(&entry, &instance); let debug_call_back = debug_utils_loader .create_debug_utils_messenger(&debug_info, None) .unwrap(); @@ -316,7 +316,7 @@ impl ExampleBase { .expect("Couldn't find suitable device."); let queue_family_index = queue_family_index as u32; let device_extension_names_raw = [ - Swapchain::NAME.as_ptr(), + SwapchainDevice::NAME.as_ptr(), #[cfg(any(target_os = "macos", target_os = "ios"))] KhrPortabilitySubsetFn::NAME.as_ptr(), ]; @@ -377,7 +377,7 @@ impl ExampleBase { .cloned() .find(|&mode| mode == vk::PresentModeKHR::MAILBOX) .unwrap_or(vk::PresentModeKHR::FIFO); - let swapchain_loader = Swapchain::new(&instance, &device); + let swapchain_loader = SwapchainDevice::new(&instance, &device); let swapchain_create_info = vk::SwapchainCreateInfoKHR::default() .surface(surface)