diff --git a/Changelog.md b/Changelog.md index 553026ead..16429a16b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Inlined struct setters (#602) - Bumped MSRV from 1.59 to 1.60 (#709) - Replaced `const fn name()` with associated `NAME` constants (#715) -- Separate low-level `*Fn` structs an high-level extension wrappers between instance and device functions, for the following extensions: (#TODO) +- Separate low-level `*Fn` structs an high-level extension wrappers between instance and device functions, for the following extensions: (#734) - `VK_KHR_swapchain` - `VK_KHR_video_queue` - `VK_KHR_device_group` diff --git a/ash/src/extensions/ext/calibrated_timestamps.rs b/ash/src/extensions/ext/calibrated_timestamps.rs index 670eddf0d..6432e3206 100644 --- a/ash/src/extensions/ext/calibrated_timestamps.rs +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -1,52 +1,38 @@ use crate::prelude::*; use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct CalibratedTimestamps { - handle: vk::Instance, - fp: vk::ExtCalibratedTimestampsFn, +pub struct CalibratedTimestampsDevice { + handle: vk::Device, + fp: vk::ExtCalibratedTimestampsDeviceFn, } -impl CalibratedTimestamps { - pub fn new(entry: &Entry, instance: &Instance) -> Self { - let handle = instance.handle(); - let fp = vk::ExtCalibratedTimestampsFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) +impl CalibratedTimestampsDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::ExtCalibratedTimestampsDeviceFn::load(|name| unsafe { + 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, Vec)> { let mut timestamps = vec![0u64; info.len()]; let mut max_deviation = vec![0u64; info.len()]; (self.fp.get_calibrated_timestamps_ext)( - device, + self.handle, info.len() as u32, info.as_ptr(), timestamps.as_mut_ptr(), @@ -55,15 +41,54 @@ impl CalibratedTimestamps { .result_with_success((timestamps, max_deviation)) } - pub const NAME: &'static CStr = vk::ExtCalibratedTimestampsFn::NAME; + pub const NAME: &'static CStr = vk::ExtCalibratedTimestampsDeviceFn::NAME; #[inline] - pub fn fp(&self) -> &vk::ExtCalibratedTimestampsFn { + pub fn fp(&self) -> &vk::ExtCalibratedTimestampsDeviceFn { &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::ExtCalibratedTimestampsInstanceFn, +} + +impl CalibratedTimestampsInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ExtCalibratedTimestampsInstanceFn::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, + ) + }) + } + + pub const NAME: &'static CStr = vk::ExtCalibratedTimestampsInstanceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::ExtCalibratedTimestampsInstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/ext/debug_utils.rs b/ash/src/extensions/ext/debug_utils.rs index 21e87177b..814f0cf38 100755 --- a/ash/src/extensions/ext/debug_utils.rs +++ b/ash/src/extensions/ext/debug_utils.rs @@ -1,20 +1,22 @@ use crate::prelude::*; use crate::{vk, RawPtr}; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct DebugUtils { - handle: vk::Instance, - fp: vk::ExtDebugUtilsFn, +pub struct DebugUtilsDevice { + handle: vk::Device, + fp: vk::ExtDebugUtilsDeviceFn, } -impl DebugUtils { - pub fn new(entry: &Entry, instance: &Instance) -> Self { - let handle = instance.handle(); - let fp = vk::ExtDebugUtilsFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) +impl DebugUtilsDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::ExtDebugUtilsDeviceFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } } @@ -23,20 +25,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 +91,36 @@ impl DebugUtils { (self.fp.queue_insert_debug_utils_label_ext)(queue, label); } + pub const NAME: &'static CStr = vk::ExtDebugUtilsDeviceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::ExtDebugUtilsDeviceFn { + &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::ExtDebugUtilsInstanceFn, +} + +impl DebugUtilsInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ExtDebugUtilsInstanceFn::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,10 +164,10 @@ impl DebugUtils { ); } - pub const NAME: &'static CStr = vk::ExtDebugUtilsFn::NAME; + pub const NAME: &'static CStr = vk::ExtDebugUtilsInstanceFn::NAME; #[inline] - pub fn fp(&self) -> &vk::ExtDebugUtilsFn { + pub fn fp(&self) -> &vk::ExtDebugUtilsInstanceFn { &self.fp } diff --git a/ash/src/extensions/ext/full_screen_exclusive.rs b/ash/src/extensions/ext/full_screen_exclusive.rs index 7a5760be2..a0c7f43ea 100644 --- a/ash/src/extensions/ext/full_screen_exclusive.rs +++ b/ash/src/extensions/ext/full_screen_exclusive.rs @@ -1,19 +1,21 @@ use crate::prelude::*; use crate::vk; -use crate::{Device, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct FullScreenExclusive { +pub struct FullScreenExclusiveDevice { handle: vk::Device, - fp: vk::ExtFullScreenExclusiveFn, + fp: vk::ExtFullScreenExclusiveDeviceFn, } -impl FullScreenExclusive { +impl FullScreenExclusiveDevice { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); - let fp = vk::ExtFullScreenExclusiveFn::load(|name| unsafe { + let fp = vk::ExtFullScreenExclusiveDeviceFn::load(|name| unsafe { mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } @@ -28,23 +30,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,10 +54,10 @@ impl FullScreenExclusive { .result_with_success(present_modes) } - pub const NAME: &'static CStr = vk::ExtFullScreenExclusiveFn::NAME; + pub const NAME: &'static CStr = vk::ExtFullScreenExclusiveDeviceFn::NAME; #[inline] - pub fn fp(&self) -> &vk::ExtFullScreenExclusiveFn { + pub fn fp(&self) -> &vk::ExtFullScreenExclusiveDeviceFn { &self.fp } @@ -81,3 +66,44 @@ impl FullScreenExclusive { self.handle } } + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct FullScreenExclusiveInstance { + fp: vk::ExtFullScreenExclusiveInstanceFn, +} + +impl FullScreenExclusiveInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ExtFullScreenExclusiveInstanceFn::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, + ) + }) + } + + pub const NAME: &'static CStr = vk::ExtFullScreenExclusiveInstanceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::ExtFullScreenExclusiveInstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/ext/mod.rs b/ash/src/extensions/ext/mod.rs index 761919f56..39bfcad0b 100644 --- a/ash/src/extensions/ext/mod.rs +++ b/ash/src/extensions/ext/mod.rs @@ -1,23 +1,23 @@ 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::image_compression_control::ImageCompressionControl; pub use self::image_drm_format_modifier::ImageDrmFormatModifier; pub use self::mesh_shader::MeshShader; pub use self::metal_surface::MetalSurface; 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::tooling_info::ToolingInfo; diff --git a/ash/src/extensions/ext/sample_locations.rs b/ash/src/extensions/ext/sample_locations.rs index c910fb53c..d07511859 100644 --- a/ash/src/extensions/ext/sample_locations.rs +++ b/ash/src/extensions/ext/sample_locations.rs @@ -1,17 +1,51 @@ use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +/// High-level device function wrapper for /// #[derive(Clone)] -pub struct SampleLocations { - fp: vk::ExtSampleLocationsFn, +pub struct SampleLocationsDevice { + fp: vk::ExtSampleLocationsDeviceFn, } -impl SampleLocations { +impl SampleLocationsDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let fp = vk::ExtSampleLocationsDeviceFn::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::ExtSampleLocationsDeviceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::ExtSampleLocationsDeviceFn { + &self.fp + } +} + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct SampleLocationsInstance { + fp: vk::ExtSampleLocationsInstanceFn, +} + +impl SampleLocationsInstance { pub fn new(entry: &Entry, instance: &Instance) -> Self { - let fp = vk::ExtSampleLocationsFn::load(|name| unsafe { + let fp = vk::ExtSampleLocationsInstanceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); Self { fp } @@ -32,20 +66,10 @@ 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::ExtSampleLocationsFn::NAME; + pub const NAME: &'static CStr = vk::ExtSampleLocationsInstanceFn::NAME; #[inline] - pub fn fp(&self) -> &vk::ExtSampleLocationsFn { + pub fn fp(&self) -> &vk::ExtSampleLocationsInstanceFn { &self.fp } } diff --git a/ash/src/extensions/khr/device_group.rs b/ash/src/extensions/khr/device_group.rs index 32f20fe2d..5bda4eea8 100644 --- a/ash/src/extensions/khr/device_group.rs +++ b/ash/src/extensions/khr/device_group.rs @@ -2,21 +2,22 @@ use super::Swapchain; use crate::prelude::*; use crate::vk; -use crate::{Device, Instance}; +use crate::{Device, Entry, Instance}; use std::ffi::CStr; use std::mem; +/// High-level device function wrapper for /// #[derive(Clone)] -pub struct DeviceGroup { +pub struct DeviceGroupDevice { handle: vk::Device, - fp: vk::KhrDeviceGroupFn, + fp: vk::KhrDeviceGroupDeviceFn, } -impl DeviceGroup { +impl DeviceGroupDevice { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); - let fp = vk::KhrDeviceGroupFn::load(|name| unsafe { + let fp = vk::KhrDeviceGroupDeviceFn::load(|name| unsafe { mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } @@ -104,30 +105,6 @@ 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. @@ -152,10 +129,10 @@ impl DeviceGroup { } } - pub const NAME: &'static CStr = vk::KhrDeviceGroupFn::NAME; + pub const NAME: &'static CStr = vk::KhrDeviceGroupDeviceFn::NAME; #[inline] - pub fn fp(&self) -> &vk::KhrDeviceGroupFn { + pub fn fp(&self) -> &vk::KhrDeviceGroupDeviceFn { &self.fp } @@ -164,3 +141,51 @@ impl DeviceGroup { self.handle } } + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct DeviceGroupInstance { + fp: vk::KhrDeviceGroupInstanceFn, +} + +impl DeviceGroupInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::KhrDeviceGroupInstanceFn::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 [`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, + ) + }) + } + + pub const NAME: &'static CStr = vk::KhrDeviceGroupInstanceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::KhrDeviceGroupInstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index ff84d0dbf..21efd118f 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -4,7 +4,7 @@ pub use self::buffer_device_address::BufferDeviceAddress; 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; @@ -22,14 +22,14 @@ pub use self::get_surface_capabilities2::GetSurfaceCapabilities2; pub use self::maintenance1::Maintenance1; pub use self::maintenance3::Maintenance3; pub use self::maintenance4::Maintenance4; -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; pub use self::ray_tracing_maintenance1::RayTracingMaintenance1; pub use self::ray_tracing_pipeline::RayTracingPipeline; 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 54cfd2f24..6386eb0c8 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; +/// High-level device function wrapper for /// #[derive(Clone)] -pub struct PerformanceQuery { - handle: vk::Instance, - fp: vk::KhrPerformanceQueryFn, +pub struct PerformanceQueryDevice { + handle: vk::Device, + fp: vk::KhrPerformanceQueryDeviceFn, } -impl PerformanceQuery { - pub fn new(entry: &Entry, instance: &Instance) -> Self { - let handle = instance.handle(); - let fp = vk::KhrPerformanceQueryFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) +impl PerformanceQueryDevice { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::KhrPerformanceQueryDeviceFn::load(|name| unsafe { + 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) + } + + pub const NAME: &'static CStr = vk::KhrPerformanceQueryDeviceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::KhrPerformanceQueryDeviceFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} + +/// High-level instance function wrapper for +/// +#[derive(Clone)] +pub struct PerformanceQueryInstance { + fp: vk::KhrPerformanceQueryInstanceFn, +} + +impl PerformanceQueryInstance { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let fp = vk::KhrPerformanceQueryInstanceFn::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,10 @@ 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() - } + pub const NAME: &'static CStr = vk::KhrPerformanceQueryInstanceFn::NAME; - /// #[inline] - pub unsafe fn release_profiling_lock(&self, device: vk::Device) { - (self.fp.release_profiling_lock_khr)(device) - } - - pub const NAME: &'static CStr = vk::KhrPerformanceQueryFn::NAME; - - #[inline] - pub fn fp(&self) -> &vk::KhrPerformanceQueryFn { + pub fn fp(&self) -> &vk::KhrPerformanceQueryInstanceFn { &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 a4a99d53c..bd7c939a8 100755 --- a/ash/src/extensions/khr/swapchain.rs +++ b/ash/src/extensions/khr/swapchain.rs @@ -1,22 +1,24 @@ #[cfg(doc)] -use super::DeviceGroup; +use super::DeviceGroupDevice; 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; +/// High-level device function wrapper for +/// #[derive(Clone)] -pub struct Swapchain { +pub struct SwapchainDevice { handle: vk::Device, - fp: vk::KhrSwapchainFn, + fp: vk::KhrSwapchainDeviceFn, } -impl Swapchain { +impl SwapchainDevice { pub fn new(instance: &Instance, device: &Device) -> Self { let handle = device.handle(); - let fp = vk::KhrSwapchainFn::load(|name| unsafe { + let fp = vk::KhrSwapchainDeviceFn::load(|name| unsafe { mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) }); Self { handle, fp } @@ -144,31 +146,6 @@ impl Swapchain { .result_with_success(modes) } - /// Only available since [Vulkan 1.1]. - /// - /// Also available as [`DeviceGroup::get_physical_device_present_rectangles()`] - /// when [`VK_KHR_surface`] is enabled. - /// - /// - /// - /// [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. /// /// Only available since [Vulkan 1.1]. @@ -194,10 +171,10 @@ impl Swapchain { } } - pub const NAME: &'static CStr = vk::KhrSwapchainFn::NAME; + pub const NAME: &'static CStr = vk::KhrSwapchainDeviceFn::NAME; #[inline] - pub fn fp(&self) -> &vk::KhrSwapchainFn { + pub fn fp(&self) -> &vk::KhrSwapchainDeviceFn { &self.fp } @@ -206,3 +183,51 @@ impl Swapchain { 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 [`DeviceGroup::get_physical_device_present_rectangles()`] + /// when [`VK_KHR_surface`] is enabled. + /// + /// + /// + /// [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, + ) + }) + } + + pub const NAME: &'static CStr = vk::KhrSwapchainInstanceFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::KhrSwapchainInstanceFn { + &self.fp + } +} 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)