From 0b343b71a611bcbb90db55991455733e1962af90 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 19 Nov 2021 11:08:47 +0100 Subject: [PATCH] Use device in pipeline_executable_properties and timeline_semaphore Of all the extensions calling get_instance_proc_addr only these two remain that should use the "optimized" device-specific function pointers, since all functions take the device as argument (a child of the device such as a command buffer or queue is also possible, but not applicable here) and may otherwise have to go through a dispatch function [1]. Only VK_EXT_debug_utils remains where all but three of the functions are device (or device-child) specific. This however requires the autogenerated loader to be separated out into two stages (and debug utils are generally initialized before creating a logical device), making it worth to accept the dispatch function unless this extension struct is split, too. [1]: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceProcAddr.html --- .../khr/pipeline_executable_properties.rs | 23 +++++++------- ash/src/extensions/khr/timeline_semaphore.rs | 31 +++++++------------ 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/ash/src/extensions/khr/pipeline_executable_properties.rs b/ash/src/extensions/khr/pipeline_executable_properties.rs index 3662f6f..5dbd060 100644 --- a/ash/src/extensions/khr/pipeline_executable_properties.rs +++ b/ash/src/extensions/khr/pipeline_executable_properties.rs @@ -1,23 +1,23 @@ use crate::prelude::*; use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Instance}; use std::ffi::CStr; use std::mem; #[derive(Clone)] pub struct PipelineExecutableProperties { - handle: vk::Instance, + handle: vk::Device, pipeline_executable_properties_fn: vk::KhrPipelineExecutablePropertiesFn, } impl PipelineExecutableProperties { - pub fn new(entry: &Entry, instance: &Instance) -> Self { + pub fn new(instance: &Instance, device: &Device) -> Self { let pipeline_executable_properties_fn = vk::KhrPipelineExecutablePropertiesFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }); Self { - handle: instance.handle(), + handle: device.handle(), pipeline_executable_properties_fn, } } @@ -29,13 +29,12 @@ impl PipelineExecutableProperties { #[doc = ""] pub unsafe fn get_pipeline_executable_internal_representations( &self, - device: vk::Device, executable_info: &vk::PipelineExecutableInfoKHR, ) -> VkResult> { read_into_defaulted_vector(|count, data| { self.pipeline_executable_properties_fn .get_pipeline_executable_internal_representations_khr( - device, + self.handle, executable_info, count, data, @@ -46,24 +45,24 @@ impl PipelineExecutableProperties { #[doc = ""] pub unsafe fn get_pipeline_executable_properties( &self, - device: vk::Device, + pipeline_info: &vk::PipelineInfoKHR, ) -> VkResult> { read_into_defaulted_vector(|count, data| { self.pipeline_executable_properties_fn - .get_pipeline_executable_properties_khr(device, pipeline_info, count, data) + .get_pipeline_executable_properties_khr(self.handle, pipeline_info, count, data) }) } #[doc = ""] pub unsafe fn get_pipeline_executable_statistics( &self, - device: vk::Device, + executable_info: &vk::PipelineExecutableInfoKHR, ) -> VkResult> { read_into_defaulted_vector(|count, data| { self.pipeline_executable_properties_fn - .get_pipeline_executable_statistics_khr(device, executable_info, count, data) + .get_pipeline_executable_statistics_khr(self.handle, executable_info, count, data) }) } @@ -71,7 +70,7 @@ impl PipelineExecutableProperties { &self.pipeline_executable_properties_fn } - pub fn instance(&self) -> vk::Instance { + pub fn device(&self) -> vk::Device { self.handle } } diff --git a/ash/src/extensions/khr/timeline_semaphore.rs b/ash/src/extensions/khr/timeline_semaphore.rs index 4de9c3f..2bb11b2 100644 --- a/ash/src/extensions/khr/timeline_semaphore.rs +++ b/ash/src/extensions/khr/timeline_semaphore.rs @@ -1,22 +1,22 @@ use crate::prelude::*; use crate::vk; -use crate::{Entry, Instance}; +use crate::{Device, Instance}; use std::ffi::CStr; use std::mem; #[derive(Clone)] pub struct TimelineSemaphore { - handle: vk::Instance, + handle: vk::Device, timeline_semaphore_fn: vk::KhrTimelineSemaphoreFn, } impl TimelineSemaphore { - pub fn new(entry: &Entry, instance: &Instance) -> Self { + pub fn new(instance: &Instance, device: &Device) -> Self { let timeline_semaphore_fn = vk::KhrTimelineSemaphoreFn::load(|name| unsafe { - mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }); Self { - handle: instance.handle(), + handle: device.handle(), timeline_semaphore_fn, } } @@ -26,37 +26,28 @@ impl TimelineSemaphore { } #[doc = ""] - pub unsafe fn get_semaphore_counter_value( - &self, - device: vk::Device, - semaphore: vk::Semaphore, - ) -> VkResult { + pub unsafe fn get_semaphore_counter_value(&self, semaphore: vk::Semaphore) -> VkResult { let mut value = 0; self.timeline_semaphore_fn - .get_semaphore_counter_value_khr(device, semaphore, &mut value) + .get_semaphore_counter_value_khr(self.handle, semaphore, &mut value) .result_with_success(value) } #[doc = ""] pub unsafe fn wait_semaphores( &self, - device: vk::Device, wait_info: &vk::SemaphoreWaitInfo, timeout: u64, ) -> VkResult<()> { self.timeline_semaphore_fn - .wait_semaphores_khr(device, wait_info, timeout) + .wait_semaphores_khr(self.handle, wait_info, timeout) .result() } #[doc = ""] - pub unsafe fn signal_semaphore( - &self, - device: vk::Device, - signal_info: &vk::SemaphoreSignalInfo, - ) -> VkResult<()> { + pub unsafe fn signal_semaphore(&self, signal_info: &vk::SemaphoreSignalInfo) -> VkResult<()> { self.timeline_semaphore_fn - .signal_semaphore_khr(device, signal_info) + .signal_semaphore_khr(self.handle, signal_info) .result() } @@ -64,7 +55,7 @@ impl TimelineSemaphore { &self.timeline_semaphore_fn } - pub fn instance(&self) -> vk::Instance { + pub fn device(&self) -> vk::Device { self.handle } }