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
This commit is contained in:
Marijn Suijten 2021-11-19 11:08:47 +01:00 committed by Benjamin Saunders
parent 9e14786b83
commit 0b343b71a6
2 changed files with 22 additions and 32 deletions

View file

@ -1,23 +1,23 @@
use crate::prelude::*; use crate::prelude::*;
use crate::vk; use crate::vk;
use crate::{Entry, Instance}; use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
#[derive(Clone)] #[derive(Clone)]
pub struct PipelineExecutableProperties { pub struct PipelineExecutableProperties {
handle: vk::Instance, handle: vk::Device,
pipeline_executable_properties_fn: vk::KhrPipelineExecutablePropertiesFn, pipeline_executable_properties_fn: vk::KhrPipelineExecutablePropertiesFn,
} }
impl PipelineExecutableProperties { impl PipelineExecutableProperties {
pub fn new(entry: &Entry, instance: &Instance) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let pipeline_executable_properties_fn = let pipeline_executable_properties_fn =
vk::KhrPipelineExecutablePropertiesFn::load(|name| unsafe { 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 { Self {
handle: instance.handle(), handle: device.handle(),
pipeline_executable_properties_fn, pipeline_executable_properties_fn,
} }
} }
@ -29,13 +29,12 @@ impl PipelineExecutableProperties {
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableInternalRepresentationsKHR.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableInternalRepresentationsKHR.html>"]
pub unsafe fn get_pipeline_executable_internal_representations( pub unsafe fn get_pipeline_executable_internal_representations(
&self, &self,
device: vk::Device,
executable_info: &vk::PipelineExecutableInfoKHR, executable_info: &vk::PipelineExecutableInfoKHR,
) -> VkResult<Vec<vk::PipelineExecutableInternalRepresentationKHR>> { ) -> VkResult<Vec<vk::PipelineExecutableInternalRepresentationKHR>> {
read_into_defaulted_vector(|count, data| { read_into_defaulted_vector(|count, data| {
self.pipeline_executable_properties_fn self.pipeline_executable_properties_fn
.get_pipeline_executable_internal_representations_khr( .get_pipeline_executable_internal_representations_khr(
device, self.handle,
executable_info, executable_info,
count, count,
data, data,
@ -46,24 +45,24 @@ impl PipelineExecutableProperties {
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutablePropertiesKHR.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutablePropertiesKHR.html>"]
pub unsafe fn get_pipeline_executable_properties( pub unsafe fn get_pipeline_executable_properties(
&self, &self,
device: vk::Device,
pipeline_info: &vk::PipelineInfoKHR, pipeline_info: &vk::PipelineInfoKHR,
) -> VkResult<Vec<vk::PipelineExecutablePropertiesKHR>> { ) -> VkResult<Vec<vk::PipelineExecutablePropertiesKHR>> {
read_into_defaulted_vector(|count, data| { read_into_defaulted_vector(|count, data| {
self.pipeline_executable_properties_fn 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 = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableStatisticsKHR.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableStatisticsKHR.html>"]
pub unsafe fn get_pipeline_executable_statistics( pub unsafe fn get_pipeline_executable_statistics(
&self, &self,
device: vk::Device,
executable_info: &vk::PipelineExecutableInfoKHR, executable_info: &vk::PipelineExecutableInfoKHR,
) -> VkResult<Vec<vk::PipelineExecutableStatisticKHR>> { ) -> VkResult<Vec<vk::PipelineExecutableStatisticKHR>> {
read_into_defaulted_vector(|count, data| { read_into_defaulted_vector(|count, data| {
self.pipeline_executable_properties_fn 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 &self.pipeline_executable_properties_fn
} }
pub fn instance(&self) -> vk::Instance { pub fn device(&self) -> vk::Device {
self.handle self.handle
} }
} }

View file

@ -1,22 +1,22 @@
use crate::prelude::*; use crate::prelude::*;
use crate::vk; use crate::vk;
use crate::{Entry, Instance}; use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
#[derive(Clone)] #[derive(Clone)]
pub struct TimelineSemaphore { pub struct TimelineSemaphore {
handle: vk::Instance, handle: vk::Device,
timeline_semaphore_fn: vk::KhrTimelineSemaphoreFn, timeline_semaphore_fn: vk::KhrTimelineSemaphoreFn,
} }
impl TimelineSemaphore { 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 { 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 { Self {
handle: instance.handle(), handle: device.handle(),
timeline_semaphore_fn, timeline_semaphore_fn,
} }
} }
@ -26,37 +26,28 @@ impl TimelineSemaphore {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetSemaphoreCounterValue.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetSemaphoreCounterValue.html>"]
pub unsafe fn get_semaphore_counter_value( pub unsafe fn get_semaphore_counter_value(&self, semaphore: vk::Semaphore) -> VkResult<u64> {
&self,
device: vk::Device,
semaphore: vk::Semaphore,
) -> VkResult<u64> {
let mut value = 0; let mut value = 0;
self.timeline_semaphore_fn 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) .result_with_success(value)
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkWaitSemaphores.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkWaitSemaphores.html>"]
pub unsafe fn wait_semaphores( pub unsafe fn wait_semaphores(
&self, &self,
device: vk::Device,
wait_info: &vk::SemaphoreWaitInfo, wait_info: &vk::SemaphoreWaitInfo,
timeout: u64, timeout: u64,
) -> VkResult<()> { ) -> VkResult<()> {
self.timeline_semaphore_fn self.timeline_semaphore_fn
.wait_semaphores_khr(device, wait_info, timeout) .wait_semaphores_khr(self.handle, wait_info, timeout)
.result() .result()
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkSignalSemaphore.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkSignalSemaphore.html>"]
pub unsafe fn signal_semaphore( pub unsafe fn signal_semaphore(&self, signal_info: &vk::SemaphoreSignalInfo) -> VkResult<()> {
&self,
device: vk::Device,
signal_info: &vk::SemaphoreSignalInfo,
) -> VkResult<()> {
self.timeline_semaphore_fn self.timeline_semaphore_fn
.signal_semaphore_khr(device, signal_info) .signal_semaphore_khr(self.handle, signal_info)
.result() .result()
} }
@ -64,7 +55,7 @@ impl TimelineSemaphore {
&self.timeline_semaphore_fn &self.timeline_semaphore_fn
} }
pub fn instance(&self) -> vk::Instance { pub fn device(&self) -> vk::Device {
self.handle self.handle
} }
} }