Skip to content

Commit

Permalink
Isolate raw bindings from generated support code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Mar 29, 2024
1 parent c058497 commit bd54abb
Show file tree
Hide file tree
Showing 99 changed files with 28,850 additions and 27,455 deletions.
13 changes: 5 additions & 8 deletions ash-examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ use std::{
};

use ash::{
vk,
vk::{
ext::debug_utils,
khr::{surface, swapchain},
},
Device, Entry, Instance,
ext::debug_utils,
khr::{surface, swapchain},
vk, Device, Entry, Instance,
};
use winit::{
event::{ElementState, Event, KeyEvent, WindowEvent},
Expand Down Expand Up @@ -233,9 +230,9 @@ impl ExampleBase {

#[cfg(any(target_os = "macos", target_os = "ios"))]
{
extension_names.push(vk::khr::portability_enumeration::NAME.as_ptr());
extension_names.push(ash::khr::portability_enumeration::NAME.as_ptr());
// Enabling this extension is a requirement when using `VK_KHR_portability_subset`
extension_names.push(vk::khr::get_physical_device_properties2::NAME.as_ptr());
extension_names.push(ash::khr::get_physical_device_properties2::NAME.as_ptr());
}

let appinfo = vk::ApplicationInfo::default()
Expand Down
2 changes: 1 addition & 1 deletion ash-window/examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.build(&event_loop)?;

// Load the surface extensions
let surface_fn = vk::khr::surface::Instance::new(&entry, &instance);
let surface_fn = ash::khr::surface::Instance::new(&entry, &instance);
let mut surface = None;

let _ = event_loop.run(move |event, elwp| match event {
Expand Down
11 changes: 3 additions & 8 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
use std::os::raw::c_char;

use ash::{
ext::metal_surface,
khr::{android_surface, surface, wayland_surface, win32_surface, xcb_surface, xlib_surface},
prelude::*,
vk,
vk::{
ext::metal_surface,
khr::{
android_surface, surface, wayland_surface, win32_surface, xcb_surface, xlib_surface,
},
},
Entry, Instance,
vk, Entry, Instance,
};
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};

Expand Down
34 changes: 17 additions & 17 deletions ash/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use core::ptr;
pub struct Device {
pub(crate) handle: vk::Device,

pub(crate) device_fn_1_0: vk::DeviceFnV1_0,
pub(crate) device_fn_1_1: vk::DeviceFnV1_1,
pub(crate) device_fn_1_2: vk::DeviceFnV1_2,
pub(crate) device_fn_1_3: vk::DeviceFnV1_3,
pub(crate) device_fn_1_0: crate::DeviceFnV1_0,
pub(crate) device_fn_1_1: crate::DeviceFnV1_1,
pub(crate) device_fn_1_2: crate::DeviceFnV1_2,
pub(crate) device_fn_1_3: crate::DeviceFnV1_3,
}

impl Device {
pub unsafe fn load(instance_fn: &vk::InstanceFnV1_0, device: vk::Device) -> Self {
pub unsafe fn load(instance_fn: &crate::InstanceFnV1_0, device: vk::Device) -> Self {
Self::load_with(
|name| mem::transmute((instance_fn.get_device_proc_addr)(device, name.as_ptr())),
device,
Expand All @@ -32,20 +32,20 @@ impl Device {
) -> Self {
Self::from_parts_1_3(
device,
vk::DeviceFnV1_0::load(&mut load_fn),
vk::DeviceFnV1_1::load(&mut load_fn),
vk::DeviceFnV1_2::load(&mut load_fn),
vk::DeviceFnV1_3::load(&mut load_fn),
crate::DeviceFnV1_0::load(&mut load_fn),
crate::DeviceFnV1_1::load(&mut load_fn),
crate::DeviceFnV1_2::load(&mut load_fn),
crate::DeviceFnV1_3::load(&mut load_fn),
)
}

#[inline]
pub fn from_parts_1_3(
handle: vk::Device,
device_fn_1_0: vk::DeviceFnV1_0,
device_fn_1_1: vk::DeviceFnV1_1,
device_fn_1_2: vk::DeviceFnV1_2,
device_fn_1_3: vk::DeviceFnV1_3,
device_fn_1_0: crate::DeviceFnV1_0,
device_fn_1_1: crate::DeviceFnV1_1,
device_fn_1_2: crate::DeviceFnV1_2,
device_fn_1_3: crate::DeviceFnV1_3,
) -> Self {
Self {
handle,
Expand All @@ -66,7 +66,7 @@ impl Device {
/// Vulkan core 1.3
impl Device {
#[inline]
pub fn fp_v1_3(&self) -> &vk::DeviceFnV1_3 {
pub fn fp_v1_3(&self) -> &crate::DeviceFnV1_3 {
&self.device_fn_1_3
}

Expand Down Expand Up @@ -556,7 +556,7 @@ impl Device {
/// Vulkan core 1.2
impl Device {
#[inline]
pub fn fp_v1_2(&self) -> &vk::DeviceFnV1_2 {
pub fn fp_v1_2(&self) -> &crate::DeviceFnV1_2 {
&self.device_fn_1_2
}

Expand Down Expand Up @@ -736,7 +736,7 @@ impl Device {
/// Vulkan core 1.1
impl Device {
#[inline]
pub fn fp_v1_1(&self) -> &vk::DeviceFnV1_1 {
pub fn fp_v1_1(&self) -> &crate::DeviceFnV1_1 {
&self.device_fn_1_1
}

Expand Down Expand Up @@ -982,7 +982,7 @@ impl Device {
/// Vulkan core 1.0
impl Device {
#[inline]
pub fn fp_v1_0(&self) -> &vk::DeviceFnV1_0 {
pub fn fp_v1_0(&self) -> &crate::DeviceFnV1_0 {
&self.device_fn_1_0
}

Expand Down
36 changes: 19 additions & 17 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::instance::Instance;
#[cfg(doc)]
use crate::khr;
use crate::prelude::*;
use crate::vk;
use crate::RawPtr;
Expand All @@ -14,9 +16,9 @@ use libloading::Library;
/// Holds the Vulkan functions independent of a particular instance
#[derive(Clone)]
pub struct Entry {
static_fn: vk::StaticFn,
entry_fn_1_0: vk::EntryFnV1_0,
entry_fn_1_1: vk::EntryFnV1_1,
static_fn: crate::StaticFn,
entry_fn_1_0: crate::EntryFnV1_0,
entry_fn_1_1: crate::EntryFnV1_1,
#[cfg(feature = "loaded")]
_lib_guard: Option<alloc::sync::Arc<Library>>,
}
Expand Down Expand Up @@ -111,7 +113,7 @@ impl Entry {
// Sound because we're linking to Vulkan, which provides a vkGetInstanceProcAddr that has
// defined behavior in this use.
unsafe {
Self::from_static_fn(vk::StaticFn {
Self::from_static_fn(crate::StaticFn {
get_instance_proc_addr: vkGetInstanceProcAddr,
})
}
Expand All @@ -133,7 +135,7 @@ impl Entry {
.map_err(LoadingError::LibraryLoadFailure)
.map(alloc::sync::Arc::new)?;

let static_fn = vk::StaticFn::load_checked(|name| {
let static_fn = crate::StaticFn::load_checked(|name| {
lib.get(name.to_bytes_with_nul())
.map(|symbol| *symbol)
.unwrap_or(ptr::null_mut())
Expand All @@ -145,13 +147,13 @@ impl Entry {
})
}

/// Load entry points based on an already-loaded [`vk::StaticFn`]
/// Load entry points based on an already-loaded [`crate::StaticFn`]
///
/// # Safety
///
/// `static_fn` must contain valid function pointers that comply with the semantics specified
/// by Vulkan 1.0, which must remain valid for at least the lifetime of the returned [`Entry`].
pub unsafe fn from_static_fn(static_fn: vk::StaticFn) -> Self {
pub unsafe fn from_static_fn(static_fn: crate::StaticFn) -> Self {
let load_fn = move |name: &ffi::CStr| {
mem::transmute((static_fn.get_instance_proc_addr)(
vk::Instance::null(),
Expand All @@ -161,16 +163,16 @@ impl Entry {

Self::from_parts_1_1(
static_fn,
vk::EntryFnV1_0::load(load_fn),
vk::EntryFnV1_1::load(load_fn),
crate::EntryFnV1_0::load(load_fn),
crate::EntryFnV1_1::load(load_fn),
)
}

#[inline]
pub fn from_parts_1_1(
static_fn: vk::StaticFn,
entry_fn_1_0: vk::EntryFnV1_0,
entry_fn_1_1: vk::EntryFnV1_1,
static_fn: crate::StaticFn,
entry_fn_1_0: crate::EntryFnV1_0,
entry_fn_1_1: crate::EntryFnV1_1,
) -> Self {
Self {
static_fn,
Expand All @@ -182,12 +184,12 @@ impl Entry {
}

#[inline]
pub fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
pub fn fp_v1_0(&self) -> &crate::EntryFnV1_0 {
&self.entry_fn_1_0
}

#[inline]
pub fn static_fn(&self) -> &vk::StaticFn {
pub fn static_fn(&self) -> &crate::StaticFn {
&self.static_fn
}

Expand Down Expand Up @@ -235,7 +237,7 @@ impl Entry {
/// # Safety
///
/// The resulting [`Instance`] and any function-pointer objects (e.g. [`Device`][crate::Device]
/// and extensions like [`vk::khr::swapchain::Device`]) loaded from it may not be used after
/// and extensions like [`khr::swapchain::Device`]) loaded from it may not be used after
/// this [`Entry`] object is dropped, unless it was crated using [`Entry::linked()`] or
/// [`Entry::from_parts_1_1()`].
///
Expand Down Expand Up @@ -294,7 +296,7 @@ impl Entry {
/// Vulkan core 1.1
impl Entry {
#[inline]
pub fn fp_v1_1(&self) -> &vk::EntryFnV1_1 {
pub fn fp_v1_1(&self) -> &crate::EntryFnV1_1 {
&self.entry_fn_1_1
}

Expand All @@ -319,7 +321,7 @@ impl Default for Entry {
}
}

impl vk::StaticFn {
impl crate::StaticFn {
pub fn load_checked<F>(mut _f: F) -> Result<Self, MissingEntryPoint>
where
F: FnMut(&ffi::CStr) -> *const ffi::c_void,
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/amd/buffer_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::vk;

impl vk::amd::buffer_marker::Device {
impl crate::amd::buffer_marker::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdWriteBufferMarkerAMD.html>
#[inline]
pub unsafe fn cmd_write_buffer_marker(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/amd/shader_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::vk;
use alloc::vec::Vec;
use core::mem;

impl vk::amd::shader_info::Device {
impl crate::amd::shader_info::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetShaderInfoAMD.html>
#[inline]
pub unsafe fn get_shader_info(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/amdx/shader_enqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::RawPtr;
use alloc::vec::Vec;
use core::mem;

impl vk::amdx::shader_enqueue::Device {
impl crate::amdx::shader_enqueue::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateExecutionGraphPipelinesAMDX.html>
#[inline]
pub unsafe fn create_execution_graph_pipelines(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::prelude::*;
use crate::vk;
use core::mem;

impl vk::android::external_memory_android_hardware_buffer::Device {
impl crate::android::external_memory_android_hardware_buffer::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetAndroidHardwareBufferPropertiesANDROID.html>
#[inline]
pub unsafe fn get_android_hardware_buffer_properties(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/acquire_drm_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::prelude::*;
use crate::vk;
use core::mem;

impl vk::ext::acquire_drm_display::Instance {
impl crate::ext::acquire_drm_display::Instance {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkAcquireDrmDisplayEXT.html>
#[inline]
pub unsafe fn acquire_drm_display(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/buffer_device_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::vk;

impl vk::ext::buffer_device_address::Device {
impl crate::ext::buffer_device_address::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetBufferDeviceAddressEXT.html>
#[inline]
pub unsafe fn get_buffer_device_address(
Expand Down
4 changes: 2 additions & 2 deletions ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::vk;
use alloc::vec::Vec;
use core::mem;

impl vk::ext::calibrated_timestamps::Device {
impl crate::ext::calibrated_timestamps::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetCalibratedTimestampsEXT.html>
///
/// Returns a tuple containing `(timestamps, max_deviation)`
Expand All @@ -29,7 +29,7 @@ impl vk::ext::calibrated_timestamps::Device {
}
}

impl vk::ext::calibrated_timestamps::Instance {
impl crate::ext::calibrated_timestamps::Instance {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceCalibrateableTimeDomainsEXT.html>
#[inline]
pub unsafe fn get_physical_device_calibrateable_time_domains(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/debug_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::prelude::*;
use crate::vk;

impl vk::ext::debug_marker::Device {
impl crate::ext::debug_marker::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDebugMarkerSetObjectNameEXT.html>
#[inline]
pub unsafe fn debug_marker_set_object_name(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/debug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::vk;
use crate::RawPtr;
use core::mem;

impl vk::ext::debug_report::Instance {
impl crate::ext::debug_report::Instance {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyDebugReportCallbackEXT.html>
#[inline]
pub unsafe fn destroy_debug_report_callback(
Expand Down
4 changes: 2 additions & 2 deletions ash/src/extensions/ext/debug_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::vk;
use crate::RawPtr;
use core::mem;

impl vk::ext::debug_utils::Device {
impl crate::ext::debug_utils::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkSetDebugUtilsObjectNameEXT.html>
#[inline]
pub unsafe fn set_debug_utils_object_name(
Expand Down Expand Up @@ -77,7 +77,7 @@ impl vk::ext::debug_utils::Device {
}
}

impl vk::ext::debug_utils::Instance {
impl crate::ext::debug_utils::Instance {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateDebugUtilsMessengerEXT.html>
#[inline]
pub unsafe fn create_debug_utils_messenger(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/descriptor_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::prelude::*;
use crate::vk;
use core::mem;

impl vk::ext::descriptor_buffer::Device {
impl crate::ext::descriptor_buffer::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetDescriptorSetLayoutSizeEXT.html>
#[inline]
pub unsafe fn get_descriptor_set_layout_size(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/extended_dynamic_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::vk;
use core::ptr;

impl vk::ext::extended_dynamic_state::Device {
impl crate::ext::extended_dynamic_state::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetCullModeEXT.html>
#[inline]
pub unsafe fn cmd_set_cull_mode(
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/extended_dynamic_state2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::vk;

impl vk::ext::extended_dynamic_state2::Device {
impl crate::ext::extended_dynamic_state2::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetPatchControlPointsEXT.html>
#[inline]
pub unsafe fn cmd_set_patch_control_points(
Expand Down
Loading

0 comments on commit bd54abb

Please sign in to comment.