diff --git a/Changelog.md b/Changelog.md index f64a5ccde..c299cbe1b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Removed unused lifetime from `vk::AllocationCallbacks` structure (#968) +- Removed `ash::prelude` and `ash::vk::prelude` in favour of capturing all contents directly in their parent module. (#972) ## [0.38.0] - 2024-04-01 diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index cc0a5e2ae..f5ff391d2 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -5,8 +5,7 @@ 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, Entry, Instance, + vk, Entry, Instance, VkResult, }; use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; diff --git a/ash/src/device.rs b/ash/src/device.rs index c772d6fd1..630914146 100644 --- a/ash/src/device.rs +++ b/ash/src/device.rs @@ -1,7 +1,8 @@ #![allow(clippy::trivially_copy_pass_by_ref)] -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::ffi; use core::mem; diff --git a/ash/src/entry.rs b/ash/src/entry.rs index c4621b6df..15296509e 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -1,9 +1,10 @@ -use crate::instance::Instance; +use super::Instance; #[cfg(doc)] use crate::khr; -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::ffi; use core::fmt; diff --git a/ash/src/extensions/amd/shader_info.rs b/ash/src/extensions/amd/shader_info.rs index 47d0cd7a0..0436d6fef 100644 --- a/ash/src/extensions/amd/shader_info.rs +++ b/ash/src/extensions/amd/shader_info.rs @@ -1,7 +1,8 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; +use crate::VkResult; use alloc::vec::Vec; use core::mem; use core::mem::size_of_val; // TODO: Remove when bumping MSRV to 1.80 diff --git a/ash/src/extensions/amdx/shader_enqueue.rs b/ash/src/extensions/amdx/shader_enqueue.rs index dae300a3f..6e13dd4fb 100644 --- a/ash/src/extensions/amdx/shader_enqueue.rs +++ b/ash/src/extensions/amdx/shader_enqueue.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; 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 d94deb3d2..225659fdc 100644 --- a/ash/src/extensions/android/external_memory_android_hardware_buffer.rs +++ b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::android::external_memory_android_hardware_buffer::Device { diff --git a/ash/src/extensions/ext/acquire_drm_display.rs b/ash/src/extensions/ext/acquire_drm_display.rs index 9ed928f73..402401a59 100644 --- a/ash/src/extensions/ext/acquire_drm_display.rs +++ b/ash/src/extensions/ext/acquire_drm_display.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::ext::acquire_drm_display::Instance { diff --git a/ash/src/extensions/ext/calibrated_timestamps.rs b/ash/src/extensions/ext/calibrated_timestamps.rs index 3005d3b63..416949e72 100644 --- a/ash/src/extensions/ext/calibrated_timestamps.rs +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -1,7 +1,8 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/ext/debug_marker.rs b/ash/src/extensions/ext/debug_marker.rs index 0e584fe2d..b25e0aaef 100755 --- a/ash/src/extensions/ext/debug_marker.rs +++ b/ash/src/extensions/ext/debug_marker.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; impl crate::ext::debug_marker::Device { /// diff --git a/ash/src/extensions/ext/debug_report.rs b/ash/src/extensions/ext/debug_report.rs index 3588bff7a..d212ae014 100755 --- a/ash/src/extensions/ext/debug_report.rs +++ b/ash/src/extensions/ext/debug_report.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::ext::debug_report::Instance { diff --git a/ash/src/extensions/ext/debug_utils.rs b/ash/src/extensions/ext/debug_utils.rs index 77e562fb8..191802baa 100755 --- a/ash/src/extensions/ext/debug_utils.rs +++ b/ash/src/extensions/ext/debug_utils.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::ext::debug_utils::Device { diff --git a/ash/src/extensions/ext/descriptor_buffer.rs b/ash/src/extensions/ext/descriptor_buffer.rs index a5e9ab857..b703c600e 100644 --- a/ash/src/extensions/ext/descriptor_buffer.rs +++ b/ash/src/extensions/ext/descriptor_buffer.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::ext::descriptor_buffer::Device { diff --git a/ash/src/extensions/ext/full_screen_exclusive.rs b/ash/src/extensions/ext/full_screen_exclusive.rs index f2b9791f7..77e86b37a 100644 --- a/ash/src/extensions/ext/full_screen_exclusive.rs +++ b/ash/src/extensions/ext/full_screen_exclusive.rs @@ -1,7 +1,8 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/ext/headless_surface.rs b/ash/src/extensions/ext/headless_surface.rs index 57a2efada..a1b8fd417 100644 --- a/ash/src/extensions/ext/headless_surface.rs +++ b/ash/src/extensions/ext/headless_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::ext::headless_surface::Instance { diff --git a/ash/src/extensions/ext/host_image_copy.rs b/ash/src/extensions/ext/host_image_copy.rs index 204896407..ed6e38390 100644 --- a/ash/src/extensions/ext/host_image_copy.rs +++ b/ash/src/extensions/ext/host_image_copy.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; #[cfg(doc)] use crate::{ext, khr}; diff --git a/ash/src/extensions/ext/image_drm_format_modifier.rs b/ash/src/extensions/ext/image_drm_format_modifier.rs index c07e14719..601b3e384 100644 --- a/ash/src/extensions/ext/image_drm_format_modifier.rs +++ b/ash/src/extensions/ext/image_drm_format_modifier.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; impl crate::ext::image_drm_format_modifier::Device { /// diff --git a/ash/src/extensions/ext/metal_surface.rs b/ash/src/extensions/ext/metal_surface.rs index adf8f7294..f4c3c0a9a 100644 --- a/ash/src/extensions/ext/metal_surface.rs +++ b/ash/src/extensions/ext/metal_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::ext::metal_surface::Instance { diff --git a/ash/src/extensions/ext/pipeline_properties.rs b/ash/src/extensions/ext/pipeline_properties.rs index 3ef7d4065..5e66e3ea1 100644 --- a/ash/src/extensions/ext/pipeline_properties.rs +++ b/ash/src/extensions/ext/pipeline_properties.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; impl crate::ext::pipeline_properties::Device { /// diff --git a/ash/src/extensions/ext/private_data.rs b/ash/src/extensions/ext/private_data.rs index 1874ae842..aa333d826 100644 --- a/ash/src/extensions/ext/private_data.rs +++ b/ash/src/extensions/ext/private_data.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::ext::private_data::Device { diff --git a/ash/src/extensions/ext/shader_object.rs b/ash/src/extensions/ext/shader_object.rs index f08e57ff0..244fb266e 100644 --- a/ash/src/extensions/ext/shader_object.rs +++ b/ash/src/extensions/ext/shader_object.rs @@ -1,8 +1,9 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::ptr; diff --git a/ash/src/extensions/ext/swapchain_maintenance1.rs b/ash/src/extensions/ext/swapchain_maintenance1.rs index 531474226..58a1c59a1 100644 --- a/ash/src/extensions/ext/swapchain_maintenance1.rs +++ b/ash/src/extensions/ext/swapchain_maintenance1.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; impl crate::ext::swapchain_maintenance1::Device { /// diff --git a/ash/src/extensions/ext/tooling_info.rs b/ash/src/extensions/ext/tooling_info.rs index e756b6276..5ba24dc98 100644 --- a/ash/src/extensions/ext/tooling_info.rs +++ b/ash/src/extensions/ext/tooling_info.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/google/display_timing.rs b/ash/src/extensions/google/display_timing.rs index 06de20926..1a0f11368 100644 --- a/ash/src/extensions/google/display_timing.rs +++ b/ash/src/extensions/google/display_timing.rs @@ -1,7 +1,8 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/acceleration_structure.rs b/ash/src/extensions/khr/acceleration_structure.rs index e47d66bb7..f257c0d74 100644 --- a/ash/src/extensions/khr/acceleration_structure.rs +++ b/ash/src/extensions/khr/acceleration_structure.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/android_surface.rs b/ash/src/extensions/khr/android_surface.rs index 8ecf56b01..c5a7b3874 100755 --- a/ash/src/extensions/khr/android_surface.rs +++ b/ash/src/extensions/khr/android_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::android_surface::Instance { diff --git a/ash/src/extensions/khr/calibrated_timestamps.rs b/ash/src/extensions/khr/calibrated_timestamps.rs index 2ed93a45c..bc8cacc72 100644 --- a/ash/src/extensions/khr/calibrated_timestamps.rs +++ b/ash/src/extensions/khr/calibrated_timestamps.rs @@ -1,7 +1,8 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/cooperative_matrix.rs b/ash/src/extensions/khr/cooperative_matrix.rs index 1a15eda34..2ed80327d 100644 --- a/ash/src/extensions/khr/cooperative_matrix.rs +++ b/ash/src/extensions/khr/cooperative_matrix.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/create_renderpass2.rs b/ash/src/extensions/khr/create_renderpass2.rs index 2228af7fd..2482dccca 100644 --- a/ash/src/extensions/khr/create_renderpass2.rs +++ b/ash/src/extensions/khr/create_renderpass2.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::create_renderpass2::Device { diff --git a/ash/src/extensions/khr/deferred_host_operations.rs b/ash/src/extensions/khr/deferred_host_operations.rs index 0eb89b199..3410b893c 100644 --- a/ash/src/extensions/khr/deferred_host_operations.rs +++ b/ash/src/extensions/khr/deferred_host_operations.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::deferred_host_operations::Device { diff --git a/ash/src/extensions/khr/device_group.rs b/ash/src/extensions/khr/device_group.rs index 44e807d20..6ce3b2696 100644 --- a/ash/src/extensions/khr/device_group.rs +++ b/ash/src/extensions/khr/device_group.rs @@ -2,8 +2,9 @@ #[cfg(doc)] use crate::khr; -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/device_group_creation.rs b/ash/src/extensions/khr/device_group_creation.rs index ad85ee079..1bd8e1f12 100644 --- a/ash/src/extensions/khr/device_group_creation.rs +++ b/ash/src/extensions/khr/device_group_creation.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/display.rs b/ash/src/extensions/khr/display.rs index 5cdce187e..211ce5ba6 100755 --- a/ash/src/extensions/khr/display.rs +++ b/ash/src/extensions/khr/display.rs @@ -1,8 +1,9 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/display_swapchain.rs b/ash/src/extensions/khr/display_swapchain.rs index 75f039715..3a6164ccd 100755 --- a/ash/src/extensions/khr/display_swapchain.rs +++ b/ash/src/extensions/khr/display_swapchain.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; impl crate::khr::display_swapchain::Device { diff --git a/ash/src/extensions/khr/external_fence_fd.rs b/ash/src/extensions/khr/external_fence_fd.rs index 8b7334acc..f772d29e5 100644 --- a/ash/src/extensions/khr/external_fence_fd.rs +++ b/ash/src/extensions/khr/external_fence_fd.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::external_fence_fd::Device { diff --git a/ash/src/extensions/khr/external_fence_win32.rs b/ash/src/extensions/khr/external_fence_win32.rs index e2c2e058d..7a45a9c86 100644 --- a/ash/src/extensions/khr/external_fence_win32.rs +++ b/ash/src/extensions/khr/external_fence_win32.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::external_fence_win32::Device { diff --git a/ash/src/extensions/khr/external_memory_fd.rs b/ash/src/extensions/khr/external_memory_fd.rs index f77e382cc..bee6f104a 100644 --- a/ash/src/extensions/khr/external_memory_fd.rs +++ b/ash/src/extensions/khr/external_memory_fd.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::external_memory_fd::Device { diff --git a/ash/src/extensions/khr/external_memory_win32.rs b/ash/src/extensions/khr/external_memory_win32.rs index 4bf2fc1f8..8af008ad2 100644 --- a/ash/src/extensions/khr/external_memory_win32.rs +++ b/ash/src/extensions/khr/external_memory_win32.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::external_memory_win32::Device { diff --git a/ash/src/extensions/khr/external_semaphore_fd.rs b/ash/src/extensions/khr/external_semaphore_fd.rs index 181ea3613..1b2997681 100644 --- a/ash/src/extensions/khr/external_semaphore_fd.rs +++ b/ash/src/extensions/khr/external_semaphore_fd.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::external_semaphore_fd::Device { diff --git a/ash/src/extensions/khr/external_semaphore_win32.rs b/ash/src/extensions/khr/external_semaphore_win32.rs index 889887e1b..5ef53ace3 100644 --- a/ash/src/extensions/khr/external_semaphore_win32.rs +++ b/ash/src/extensions/khr/external_semaphore_win32.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::external_semaphore_win32::Device { diff --git a/ash/src/extensions/khr/get_display_properties2.rs b/ash/src/extensions/khr/get_display_properties2.rs index 061269f8d..7cb6a5ce8 100644 --- a/ash/src/extensions/khr/get_display_properties2.rs +++ b/ash/src/extensions/khr/get_display_properties2.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/get_physical_device_properties2.rs b/ash/src/extensions/khr/get_physical_device_properties2.rs index 3c0e88d64..5d3375390 100644 --- a/ash/src/extensions/khr/get_physical_device_properties2.rs +++ b/ash/src/extensions/khr/get_physical_device_properties2.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/get_surface_capabilities2.rs b/ash/src/extensions/khr/get_surface_capabilities2.rs index 135334c10..9c238e950 100644 --- a/ash/src/extensions/khr/get_surface_capabilities2.rs +++ b/ash/src/extensions/khr/get_surface_capabilities2.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/performance_query.rs b/ash/src/extensions/khr/performance_query.rs index f5bcbc0ad..27785df08 100644 --- a/ash/src/extensions/khr/performance_query.rs +++ b/ash/src/extensions/khr/performance_query.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/pipeline_executable_properties.rs b/ash/src/extensions/khr/pipeline_executable_properties.rs index a42f7baf7..500744c66 100644 --- a/ash/src/extensions/khr/pipeline_executable_properties.rs +++ b/ash/src/extensions/khr/pipeline_executable_properties.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/khr/present_wait.rs b/ash/src/extensions/khr/present_wait.rs index 7ade6fbdf..4cba3ac9f 100644 --- a/ash/src/extensions/khr/present_wait.rs +++ b/ash/src/extensions/khr/present_wait.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; impl crate::khr::present_wait::Device { /// diff --git a/ash/src/extensions/khr/ray_tracing_pipeline.rs b/ash/src/extensions/khr/ray_tracing_pipeline.rs index 3d2189756..709d48270 100644 --- a/ash/src/extensions/khr/ray_tracing_pipeline.rs +++ b/ash/src/extensions/khr/ray_tracing_pipeline.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; impl crate::khr::ray_tracing_pipeline::Device { diff --git a/ash/src/extensions/khr/sampler_ycbcr_conversion.rs b/ash/src/extensions/khr/sampler_ycbcr_conversion.rs index d8cbad1cf..fbf0af66c 100644 --- a/ash/src/extensions/khr/sampler_ycbcr_conversion.rs +++ b/ash/src/extensions/khr/sampler_ycbcr_conversion.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::sampler_ycbcr_conversion::Device { diff --git a/ash/src/extensions/khr/surface.rs b/ash/src/extensions/khr/surface.rs index 972d1ac40..1d701fefd 100755 --- a/ash/src/extensions/khr/surface.rs +++ b/ash/src/extensions/khr/surface.rs @@ -1,8 +1,9 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/swapchain.rs b/ash/src/extensions/khr/swapchain.rs index bec3f8de2..f10e828f6 100755 --- a/ash/src/extensions/khr/swapchain.rs +++ b/ash/src/extensions/khr/swapchain.rs @@ -2,9 +2,10 @@ #[cfg(doc)] use crate::khr; -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/khr/synchronization2.rs b/ash/src/extensions/khr/synchronization2.rs index 2cfeef7a7..8da8177dd 100644 --- a/ash/src/extensions/khr/synchronization2.rs +++ b/ash/src/extensions/khr/synchronization2.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; impl crate::khr::synchronization2::Device { /// diff --git a/ash/src/extensions/khr/timeline_semaphore.rs b/ash/src/extensions/khr/timeline_semaphore.rs index 01af37554..d0a2d2517 100644 --- a/ash/src/extensions/khr/timeline_semaphore.rs +++ b/ash/src/extensions/khr/timeline_semaphore.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; impl crate::khr::timeline_semaphore::Device { diff --git a/ash/src/extensions/khr/wayland_surface.rs b/ash/src/extensions/khr/wayland_surface.rs index 2aa74480a..32c907286 100755 --- a/ash/src/extensions/khr/wayland_surface.rs +++ b/ash/src/extensions/khr/wayland_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::wayland_surface::Instance { diff --git a/ash/src/extensions/khr/win32_surface.rs b/ash/src/extensions/khr/win32_surface.rs index 149487d09..5908db512 100755 --- a/ash/src/extensions/khr/win32_surface.rs +++ b/ash/src/extensions/khr/win32_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::win32_surface::Instance { diff --git a/ash/src/extensions/khr/xcb_surface.rs b/ash/src/extensions/khr/xcb_surface.rs index c7a1c55a7..dbc458a77 100755 --- a/ash/src/extensions/khr/xcb_surface.rs +++ b/ash/src/extensions/khr/xcb_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::xcb_surface::Instance { diff --git a/ash/src/extensions/khr/xlib_surface.rs b/ash/src/extensions/khr/xlib_surface.rs index ac79f6d4d..e7e14b047 100755 --- a/ash/src/extensions/khr/xlib_surface.rs +++ b/ash/src/extensions/khr/xlib_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::khr::xlib_surface::Instance { diff --git a/ash/src/extensions/mvk/ios_surface.rs b/ash/src/extensions/mvk/ios_surface.rs index 2b0624d42..ca5da8477 100755 --- a/ash/src/extensions/mvk/ios_surface.rs +++ b/ash/src/extensions/mvk/ios_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::mvk::ios_surface::Instance { diff --git a/ash/src/extensions/mvk/macos_surface.rs b/ash/src/extensions/mvk/macos_surface.rs index b55adac7a..728a9ca6b 100755 --- a/ash/src/extensions/mvk/macos_surface.rs +++ b/ash/src/extensions/mvk/macos_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::mvk::macos_surface::Instance { diff --git a/ash/src/extensions/nn/vi_surface.rs b/ash/src/extensions/nn/vi_surface.rs index 4699aeafc..3a6772ace 100644 --- a/ash/src/extensions/nn/vi_surface.rs +++ b/ash/src/extensions/nn/vi_surface.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use core::mem; impl crate::nn::vi_surface::Instance { diff --git a/ash/src/extensions/nv/coverage_reduction_mode.rs b/ash/src/extensions/nv/coverage_reduction_mode.rs index 61161ef54..b8a4f8223 100644 --- a/ash/src/extensions/nv/coverage_reduction_mode.rs +++ b/ash/src/extensions/nv/coverage_reduction_mode.rs @@ -1,7 +1,7 @@ //! -use crate::prelude::*; use crate::vk; +use crate::VkResult; use core::mem; use core::ptr; diff --git a/ash/src/extensions/nv/cuda_kernel_launch.rs b/ash/src/extensions/nv/cuda_kernel_launch.rs index 3a32f72ae..9b907c07a 100644 --- a/ash/src/extensions/nv/cuda_kernel_launch.rs +++ b/ash/src/extensions/nv/cuda_kernel_launch.rs @@ -1,8 +1,9 @@ //! -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; diff --git a/ash/src/extensions/nv/low_latency2.rs b/ash/src/extensions/nv/low_latency2.rs index f20f1c8da..84beec4c8 100644 --- a/ash/src/extensions/nv/low_latency2.rs +++ b/ash/src/extensions/nv/low_latency2.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; impl crate::nv::low_latency2::Device { /// diff --git a/ash/src/extensions/nv/ray_tracing.rs b/ash/src/extensions/nv/ray_tracing.rs index c072e17a7..4d37a513c 100755 --- a/ash/src/extensions/nv/ray_tracing.rs +++ b/ash/src/extensions/nv/ray_tracing.rs @@ -1,8 +1,8 @@ //! -use crate::prelude::*; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::mem; use core::mem::size_of_val; // TODO: Remove when bumping MSRV to 1.80 diff --git a/ash/src/instance.rs b/ash/src/instance.rs index f84bca476..1cb9f2036 100644 --- a/ash/src/instance.rs +++ b/ash/src/instance.rs @@ -1,9 +1,10 @@ +use super::Device; #[cfg(doc)] use super::Entry; -use crate::device::Device; -use crate::prelude::*; +use crate::read_into_uninitialized_vector; use crate::vk; use crate::RawPtr; +use crate::VkResult; use alloc::vec::Vec; use core::ffi; use core::mem; diff --git a/ash/src/lib.rs b/ash/src/lib.rs index 05dd68a6a..bbdc88e97 100644 --- a/ash/src/lib.rs +++ b/ash/src/lib.rs @@ -55,6 +55,11 @@ extern crate alloc; +use alloc::vec::Vec; +use core::convert::TryInto; +use core::mem; +use core::ptr; + pub use crate::device::Device; pub use crate::entry::Entry; #[cfg(feature = "loaded")] @@ -67,7 +72,6 @@ mod device; mod entry; mod extensions_generated; mod instance; -pub mod prelude; mod tables; pub mod util; /// Raw Vulkan bindings and types, generated from `vk.xml` @@ -192,26 +196,62 @@ macro_rules! match_in_struct { }; } -#[cfg(test)] -mod tests { - use super::vk; - use alloc::vec::Vec; - #[test] - fn test_ptr_chains() { - let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::default(); - let mut corner = vk::PhysicalDeviceCornerSampledImageFeaturesNV::default(); - let chain = alloc::vec![ - <*mut _>::cast(&mut variable_pointers), - <*mut _>::cast(&mut corner), - ]; - let mut device_create_info = vk::DeviceCreateInfo::default() - .push(&mut corner) - .push(&mut variable_pointers); - let chain2: Vec<*mut vk::BaseOutStructure<'_>> = unsafe { - vk::ptr_chain_iter(&mut device_create_info) - .skip(1) - .collect() - }; - assert_eq!(chain, chain2); +pub type VkResult = Result; + +impl vk::Result { + #[inline] + pub fn result(self) -> VkResult<()> { + self.result_with_success(()) + } + + #[inline] + pub fn result_with_success(self, v: T) -> VkResult { + match self { + Self::SUCCESS => Ok(v), + _ => Err(self), + } + } + + #[inline] + pub unsafe fn assume_init_on_success(self, v: mem::MaybeUninit) -> VkResult { + self.result().map(move |()| v.assume_init()) + } + + #[inline] + pub unsafe fn set_vec_len_on_success(self, mut v: Vec, len: usize) -> VkResult> { + self.result().map(move |()| { + v.set_len(len); + v + }) + } +} + +/// Repeatedly calls `f` until it does not return [`vk::Result::INCOMPLETE`] anymore, ensuring all +/// available data has been read into the vector. +/// +/// See for example [`vkEnumerateInstanceExtensionProperties`]: the number of available items may +/// change between calls; [`vk::Result::INCOMPLETE`] is returned when the count increased (and the +/// vector is not large enough after querying the initial size), requiring Ash to try again. +/// +/// [`vkEnumerateInstanceExtensionProperties`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceExtensionProperties.html +pub(crate) unsafe fn read_into_uninitialized_vector, T>( + f: impl Fn(&mut N, *mut T) -> vk::Result, +) -> VkResult> +where + >::Error: core::fmt::Debug, +{ + loop { + let mut count = N::default(); + f(&mut count, ptr::null_mut()).result()?; + let mut data = + Vec::with_capacity(count.try_into().expect("`N` failed to convert to `usize`")); + + let err_code = f(&mut count, data.as_mut_ptr()); + if err_code != vk::Result::INCOMPLETE { + break err_code.set_vec_len_on_success( + data, + count.try_into().expect("`N` failed to convert to `usize`"), + ); + } } } diff --git a/ash/src/prelude.rs b/ash/src/prelude.rs deleted file mode 100644 index 74aa3f186..000000000 --- a/ash/src/prelude.rs +++ /dev/null @@ -1,93 +0,0 @@ -use alloc::vec::Vec; -use core::convert::TryInto; -use core::mem; -use core::ptr; - -use crate::vk; -pub type VkResult = Result; - -impl vk::Result { - #[inline] - pub fn result(self) -> VkResult<()> { - self.result_with_success(()) - } - - #[inline] - pub fn result_with_success(self, v: T) -> VkResult { - match self { - Self::SUCCESS => Ok(v), - _ => Err(self), - } - } - - #[inline] - pub unsafe fn assume_init_on_success(self, v: mem::MaybeUninit) -> VkResult { - self.result().map(move |()| v.assume_init()) - } - - #[inline] - pub unsafe fn set_vec_len_on_success(self, mut v: Vec, len: usize) -> VkResult> { - self.result().map(move |()| { - v.set_len(len); - v - }) - } -} - -/// Repeatedly calls `f` until it does not return [`vk::Result::INCOMPLETE`] anymore, ensuring all -/// available data has been read into the vector. -/// -/// See for example [`vkEnumerateInstanceExtensionProperties`]: the number of available items may -/// change between calls; [`vk::Result::INCOMPLETE`] is returned when the count increased (and the -/// vector is not large enough after querying the initial size), requiring Ash to try again. -/// -/// [`vkEnumerateInstanceExtensionProperties`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceExtensionProperties.html -pub(crate) unsafe fn read_into_uninitialized_vector, T>( - f: impl Fn(&mut N, *mut T) -> vk::Result, -) -> VkResult> -where - >::Error: core::fmt::Debug, -{ - loop { - let mut count = N::default(); - f(&mut count, ptr::null_mut()).result()?; - let mut data = - Vec::with_capacity(count.try_into().expect("`N` failed to convert to `usize`")); - - let err_code = f(&mut count, data.as_mut_ptr()); - if err_code != vk::Result::INCOMPLETE { - break err_code.set_vec_len_on_success( - data, - count.try_into().expect("`N` failed to convert to `usize`"), - ); - } - } -} - -#[cfg(feature = "debug")] -pub(crate) fn debug_flags + Copy>( - f: &mut core::fmt::Formatter<'_>, - known: &[(Value, &'static str)], - value: Value, -) -> core::fmt::Result { - let mut first = true; - let mut accum = value.into(); - for &(bit, name) in known { - let bit = bit.into(); - if bit != 0 && accum & bit == bit { - if !first { - f.write_str(" | ")?; - } - f.write_str(name)?; - first = false; - accum &= !bit; - } - } - if accum != 0 { - if !first { - f.write_str(" | ")?; - } - write!(f, "{accum:b}")?; - } - Ok(()) -} diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 312741709..5a424171a 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -4,6 +4,7 @@ clippy::wrong_self_convention, unused_qualifications )] + #[macro_use] mod macros; mod aliases; @@ -23,13 +24,38 @@ pub use extensions::*; mod feature_extensions; mod features; pub use features::*; -mod prelude; -pub use prelude::*; /// Native bindings from Vulkan headers, generated by bindgen #[allow(clippy::useless_transmute, nonstandard_style)] pub mod native; mod platform_types; pub use platform_types::*; + +pub trait Handle: Sized { + const TYPE: ObjectType; + fn as_raw(self) -> u64; + fn from_raw(_: u64) -> Self; + + /// Returns whether the handle is a `NULL` value. + /// + /// # Example + /// + /// ``` + /// # use ash::vk::{Handle, Instance}; + /// let instance = Instance::null(); + /// assert!(instance.is_null()); + /// ``` + fn is_null(self) -> bool { + self.as_raw() == 0 + } +} + +/// Structures implementing this trait are layout-compatible with [`BaseInStructure`] and +/// [`BaseOutStructure`]. Such structures have an `s_type` field indicating its type, which +/// must always match the value of [`TaggedStructure::STRUCTURE_TYPE`]. +pub unsafe trait TaggedStructure { + const STRUCTURE_TYPE: StructureType; +} + /// Iterates through the pointer chain. Includes the item that is passed into the function. /// Stops at the last [`BaseOutStructure`] that has a null [`BaseOutStructure::p_next`] field. pub(crate) unsafe fn ptr_chain_iter( @@ -46,21 +72,169 @@ pub(crate) unsafe fn ptr_chain_iter( Some(old) }) } -pub trait Handle: Sized { - const TYPE: ObjectType; - fn as_raw(self) -> u64; - fn from_raw(_: u64) -> Self; - /// Returns whether the handle is a `NULL` value. - /// - /// # Example - /// - /// ``` - /// # use ash::vk::{Handle, Instance}; - /// let instance = Instance::null(); - /// assert!(instance.is_null()); - /// ``` - fn is_null(self) -> bool { - self.as_raw() == 0 +/// Holds 24 bits in the least significant bits of memory, +/// and 8 bytes in the most significant bits of that memory, +/// occupying a single [`u32`] in total. This is commonly used in +/// [acceleration structure instances] such as +/// [`AccelerationStructureInstanceKHR`], +/// [`AccelerationStructureSRTMotionInstanceNV`] and +/// [`AccelerationStructureMatrixMotionInstanceNV`]. +/// +/// [acceleration structure instances]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkAccelerationStructureInstanceKHR.html#_description +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] +#[repr(transparent)] +pub struct Packed24_8(u32); + +impl Packed24_8 { + pub fn new(low_24: u32, high_8: u8) -> Self { + Self((low_24 & 0x00ff_ffff) | (u32::from(high_8) << 24)) + } + + /// Extracts the least-significant 24 bits (3 bytes) of this integer + pub fn low_24(&self) -> u32 { + self.0 & 0xffffff + } + + /// Extracts the most significant 8 bits (single byte) of this integer + pub fn high_8(&self) -> u8 { + (self.0 >> 24) as u8 + } +} + +impl ColorComponentFlags { + /// Contraction of [`R`][Self::R] | [`G`][Self::G] | [`B`][Self::B] | [`A`][Self::A] + pub const RGBA: Self = Self(Self::R.0 | Self::G.0 | Self::B.0 | Self::A.0); +} + +impl From for Extent3D { + fn from(value: Extent2D) -> Self { + Self { + width: value.width, + height: value.height, + depth: 1, + } + } +} + +impl From for Rect2D { + fn from(extent: Extent2D) -> Self { + Self { + offset: Default::default(), + extent, + } + } +} + +#[inline] +pub(crate) fn wrap_c_str_slice_until_nul( + str: &[core::ffi::c_char], +) -> core::result::Result<&core::ffi::CStr, core::ffi::FromBytesUntilNulError> { + // SAFETY: The cast from c_char to u8 is ok because a c_char is always one byte. + let bytes = unsafe { core::slice::from_raw_parts(str.as_ptr().cast(), str.len()) }; + core::ffi::CStr::from_bytes_until_nul(bytes) +} + +#[derive(Debug)] +pub struct CStrTooLargeForStaticArray { + pub static_array_size: usize, + pub c_str_size: usize, +} +#[cfg(feature = "std")] +impl std::error::Error for CStrTooLargeForStaticArray {} +impl core::fmt::Display for CStrTooLargeForStaticArray { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!( + f, + "static `c_char` target array of length `{}` is too small to write a `CStr` (with `NUL`-terminator) of length `{}`", + self.static_array_size, self.c_str_size + ) + } +} + +#[inline] +pub(crate) fn write_c_str_slice_with_nul( + target: &mut [core::ffi::c_char], + str: &core::ffi::CStr, +) -> core::result::Result<(), CStrTooLargeForStaticArray> { + let bytes = str.to_bytes_with_nul(); + // SAFETY: The cast from c_char to u8 is ok because a c_char is always one byte. + let bytes = unsafe { core::slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) }; + let static_array_size = target.len(); + target + .get_mut(..bytes.len()) + .ok_or(CStrTooLargeForStaticArray { + static_array_size, + c_str_size: bytes.len(), + })? + .copy_from_slice(bytes); + Ok(()) +} + +#[cfg(feature = "debug")] +pub(crate) fn debug_flags + Copy>( + f: &mut core::fmt::Formatter<'_>, + known: &[(Value, &'static str)], + value: Value, +) -> core::fmt::Result { + let mut first = true; + let mut accum = value.into(); + for &(bit, name) in known { + let bit = bit.into(); + if bit != 0 && accum & bit == bit { + if !first { + f.write_str(" | ")?; + } + f.write_str(name)?; + first = false; + accum &= !bit; + } + } + if accum != 0 { + if !first { + f.write_str(" | ")?; + } + write!(f, "{accum:b}")?; + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use crate::vk; + use alloc::vec::Vec; + #[test] + fn test_ptr_chains() { + let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::default(); + let mut corner = vk::PhysicalDeviceCornerSampledImageFeaturesNV::default(); + let chain = alloc::vec![ + <*mut _>::cast(&mut variable_pointers), + <*mut _>::cast(&mut corner), + ]; + let mut device_create_info = vk::DeviceCreateInfo::default() + .push(&mut corner) + .push(&mut variable_pointers); + let chain2: Vec<*mut vk::BaseOutStructure<'_>> = unsafe { + vk::ptr_chain_iter(&mut device_create_info) + .skip(1) + .collect() + }; + assert_eq!(chain, chain2); + } + + #[test] + fn test_debug_flags() { + assert_eq!( + format!( + "{:?}", + vk::AccessFlags::INDIRECT_COMMAND_READ | vk::AccessFlags::VERTEX_ATTRIBUTE_READ + ), + "INDIRECT_COMMAND_READ | VERTEX_ATTRIBUTE_READ" + ); + } + + #[test] + fn test_debug_enum() { + assert_eq!(format!("{:?}", vk::ChromaLocation::MIDPOINT), "MIDPOINT"); } } diff --git a/ash/src/vk/aliases.rs b/ash/src/vk/aliases.rs index f049d0087..5f172454f 100644 --- a/ash/src/vk/aliases.rs +++ b/ash/src/vk/aliases.rs @@ -1,6 +1,6 @@ -use crate::vk::bitflags::*; -use crate::vk::definitions::*; -use crate::vk::enums::*; +use super::bitflags::*; +use super::definitions::*; +use super::enums::*; pub type GeometryFlagsNV = GeometryFlagsKHR; pub type GeometryInstanceFlagsNV = GeometryInstanceFlagsKHR; pub type BuildAccelerationStructureFlagsNV = BuildAccelerationStructureFlagsKHR; diff --git a/ash/src/vk/bitflags.rs b/ash/src/vk/bitflags.rs index c2f24094a..3809cfff1 100644 --- a/ash/src/vk/bitflags.rs +++ b/ash/src/vk/bitflags.rs @@ -1,4 +1,4 @@ -use crate::vk::definitions::*; +use super::definitions::*; #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[doc = ""] diff --git a/ash/src/vk/const_debugs.rs b/ash/src/vk/const_debugs.rs index b0d032397..5f638518d 100644 --- a/ash/src/vk/const_debugs.rs +++ b/ash/src/vk/const_debugs.rs @@ -1,7 +1,7 @@ -use crate::prelude::debug_flags; -use crate::vk::bitflags::*; -use crate::vk::definitions::*; -use crate::vk::enums::*; +use super::bitflags::*; +use super::debug_flags; +use super::definitions::*; +use super::enums::*; use core::fmt; impl fmt::Debug for AccelerationStructureBuildTypeKHR { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/ash/src/vk/constants.rs b/ash/src/vk/constants.rs index 7abea7fa6..a46e34f8e 100644 --- a/ash/src/vk/constants.rs +++ b/ash/src/vk/constants.rs @@ -1,4 +1,4 @@ -use crate::vk::definitions::*; +use super::definitions::*; pub const MAX_PHYSICAL_DEVICE_NAME_SIZE: usize = 256; pub const UUID_SIZE: usize = 16; pub const LUID_SIZE: usize = 8; diff --git a/ash/src/vk/definitions.rs b/ash/src/vk/definitions.rs index 928bceea5..b0f3dbcd4 100644 --- a/ash/src/vk/definitions.rs +++ b/ash/src/vk/definitions.rs @@ -1,12 +1,14 @@ #![allow(clippy::needless_lifetimes)] -use crate::vk::aliases::*; -use crate::vk::bitflags::*; -use crate::vk::constants::*; -use crate::vk::enums::*; -use crate::vk::native::*; -use crate::vk::platform_types::*; -use crate::vk::prelude::*; -use crate::vk::{ptr_chain_iter, Handle}; +use super::aliases::*; +use super::bitflags::*; +use super::constants::*; +use super::enums::*; +use super::native::*; +use super::platform_types::*; +use super::{ + ptr_chain_iter, wrap_c_str_slice_until_nul, write_c_str_slice_with_nul, + CStrTooLargeForStaticArray, Handle, Packed24_8, TaggedStructure, +}; use core::ffi::*; use core::fmt; use core::marker::PhantomData; diff --git a/ash/src/vk/extensions.rs b/ash/src/vk/extensions.rs index b3710a439..d3ecf1d0a 100644 --- a/ash/src/vk/extensions.rs +++ b/ash/src/vk/extensions.rs @@ -1,9 +1,9 @@ #![allow(unused_qualifications)] -use crate::vk::aliases::*; -use crate::vk::bitflags::*; -use crate::vk::definitions::*; -use crate::vk::enums::*; -use crate::vk::platform_types::*; +use super::aliases::*; +use super::bitflags::*; +use super::definitions::*; +use super::enums::*; +use super::platform_types::*; use core::ffi::*; #[doc = "Generated from 'VK_KHR_surface'"] impl ObjectType { diff --git a/ash/src/vk/feature_extensions.rs b/ash/src/vk/feature_extensions.rs index 4b1820c9a..f82b567bc 100644 --- a/ash/src/vk/feature_extensions.rs +++ b/ash/src/vk/feature_extensions.rs @@ -1,5 +1,5 @@ -use crate::vk::bitflags::*; -use crate::vk::enums::*; +use super::bitflags::*; +use super::enums::*; #[doc = "Generated from 'VK_VERSION_1_1'"] impl BufferCreateFlags { #[doc = "Buffer requires protected memory"] diff --git a/ash/src/vk/features.rs b/ash/src/vk/features.rs index 94150ed00..73e9a3346 100644 --- a/ash/src/vk/features.rs +++ b/ash/src/vk/features.rs @@ -1,6 +1,6 @@ -use crate::vk::bitflags::*; -use crate::vk::definitions::*; -use crate::vk::enums::*; +use super::bitflags::*; +use super::definitions::*; +use super::enums::*; use core::ffi::*; #[allow(non_camel_case_types)] pub type PFN_vkGetInstanceProcAddr = unsafe extern "system" fn( diff --git a/ash/src/vk/prelude.rs b/ash/src/vk/prelude.rs deleted file mode 100644 index 5f77f1472..000000000 --- a/ash/src/vk/prelude.rs +++ /dev/null @@ -1,109 +0,0 @@ -use core::ffi::c_char; -use core::fmt; - -use crate::vk; - -/// Holds 24 bits in the least significant bits of memory, -/// and 8 bytes in the most significant bits of that memory, -/// occupying a single [`u32`] in total. This is commonly used in -/// [acceleration structure instances] such as -/// [`vk::AccelerationStructureInstanceKHR`], -/// [`vk::AccelerationStructureSRTMotionInstanceNV`] and -/// [`vk::AccelerationStructureMatrixMotionInstanceNV`]. -/// -/// [acceleration structure instances]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkAccelerationStructureInstanceKHR.html#_description -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] -#[repr(transparent)] -pub struct Packed24_8(u32); - -impl Packed24_8 { - pub fn new(low_24: u32, high_8: u8) -> Self { - Self((low_24 & 0x00ff_ffff) | (u32::from(high_8) << 24)) - } - - /// Extracts the least-significant 24 bits (3 bytes) of this integer - pub fn low_24(&self) -> u32 { - self.0 & 0xffffff - } - - /// Extracts the most significant 8 bits (single byte) of this integer - pub fn high_8(&self) -> u8 { - (self.0 >> 24) as u8 - } -} - -impl vk::ColorComponentFlags { - /// Contraction of [`R`][Self::R] | [`G`][Self::G] | [`B`][Self::B] | [`A`][Self::A] - pub const RGBA: Self = Self(Self::R.0 | Self::G.0 | Self::B.0 | Self::A.0); -} - -impl From for vk::Extent3D { - fn from(value: vk::Extent2D) -> Self { - Self { - width: value.width, - height: value.height, - depth: 1, - } - } -} - -impl From for vk::Rect2D { - fn from(extent: vk::Extent2D) -> Self { - Self { - offset: Default::default(), - extent, - } - } -} - -/// Structures implementing this trait are layout-compatible with [`vk::BaseInStructure`] and -/// [`vk::BaseOutStructure`]. Such structures have an `s_type` field indicating its type, which -/// must always match the value of [`TaggedStructure::STRUCTURE_TYPE`]. -pub unsafe trait TaggedStructure { - const STRUCTURE_TYPE: vk::StructureType; -} - -#[inline] -pub(crate) fn wrap_c_str_slice_until_nul( - str: &[c_char], -) -> Result<&core::ffi::CStr, core::ffi::FromBytesUntilNulError> { - // SAFETY: The cast from c_char to u8 is ok because a c_char is always one byte. - let bytes = unsafe { core::slice::from_raw_parts(str.as_ptr().cast(), str.len()) }; - core::ffi::CStr::from_bytes_until_nul(bytes) -} - -#[derive(Debug)] -pub struct CStrTooLargeForStaticArray { - pub static_array_size: usize, - pub c_str_size: usize, -} -#[cfg(feature = "std")] -impl std::error::Error for CStrTooLargeForStaticArray {} -impl fmt::Display for CStrTooLargeForStaticArray { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "static `c_char` target array of length `{}` is too small to write a `CStr` (with `NUL`-terminator) of length `{}`", - self.static_array_size, self.c_str_size - ) - } -} - -#[inline] -pub(crate) fn write_c_str_slice_with_nul( - target: &mut [c_char], - str: &core::ffi::CStr, -) -> Result<(), CStrTooLargeForStaticArray> { - let bytes = str.to_bytes_with_nul(); - // SAFETY: The cast from c_char to u8 is ok because a c_char is always one byte. - let bytes = unsafe { core::slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) }; - let static_array_size = target.len(); - target - .get_mut(..bytes.len()) - .ok_or(CStrTooLargeForStaticArray { - static_array_size, - c_str_size: bytes.len(), - })? - .copy_from_slice(bytes); - Ok(()) -} diff --git a/ash/tests/display.rs b/ash/tests/display.rs deleted file mode 100644 index f4131fdc7..000000000 --- a/ash/tests/display.rs +++ /dev/null @@ -1,17 +0,0 @@ -use ash::vk; - -#[test] -fn debug_flags() { - assert_eq!( - format!( - "{:?}", - vk::AccessFlags::INDIRECT_COMMAND_READ | vk::AccessFlags::VERTEX_ATTRIBUTE_READ - ), - "INDIRECT_COMMAND_READ | VERTEX_ATTRIBUTE_READ" - ); -} - -#[test] -fn debug_enum() { - assert_eq!(format!("{:?}", vk::ChromaLocation::MIDPOINT), "MIDPOINT"); -} diff --git a/generator/src/lib.rs b/generator/src/lib.rs index b56eb458a..b73692d02 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -3415,26 +3415,28 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { let feature_code = quote! { use core::ffi::*; - use crate::vk::bitflags::*; - use crate::vk::definitions::*; - use crate::vk::enums::*; + use super::bitflags::*; + use super::definitions::*; + use super::enums::*; #(#feature_fp_code)* }; let definition_code = quote! { #![allow(clippy::needless_lifetimes)] // Omitting these correctly in the generator is complex - use core::marker::PhantomData; - use core::fmt; + use super::aliases::*; + use super::bitflags::*; + use super::constants::*; + use super::enums::*; + use super::native::*; + use super::platform_types::*; + use super::{ + ptr_chain_iter, wrap_c_str_slice_until_nul, write_c_str_slice_with_nul, + CStrTooLargeForStaticArray, Handle, Packed24_8, TaggedStructure, + }; use core::ffi::*; - use crate::vk::{Handle, ptr_chain_iter}; - use crate::vk::aliases::*; - use crate::vk::bitflags::*; - use crate::vk::constants::*; - use crate::vk::enums::*; - use crate::vk::native::*; - use crate::vk::platform_types::*; - use crate::vk::prelude::*; + use core::fmt; + use core::marker::PhantomData; #(#definition_code)* }; @@ -3445,47 +3447,47 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { }; let bitflags_code = quote! { - use crate::vk::definitions::*; + use super::definitions::*; #(#bitflags_code)* }; let constants_code = quote! { - use crate::vk::definitions::*; + use super::definitions::*; #(#constants_code)* }; let extension_code = quote! { #![allow(unused_qualifications)] // For simplicity, we always generate absolute paths for `Device`/`Instance` + use super::platform_types::*; + use super::aliases::*; + use super::bitflags::*; + use super::definitions::*; + use super::enums::*; use core::ffi::*; - use crate::vk::platform_types::*; - use crate::vk::aliases::*; - use crate::vk::bitflags::*; - use crate::vk::definitions::*; - use crate::vk::enums::*; #(#extension_constants)* #(#extension_cmds)* }; let feature_extensions_code = quote! { - use crate::vk::bitflags::*; - use crate::vk::enums::*; + use super::bitflags::*; + use super::enums::*; #feature_extensions_code }; let const_debugs = quote! { + use super::debug_flags; + use super::bitflags::*; + use super::definitions::*; + use super::enums::*; use core::fmt; - use crate::vk::bitflags::*; - use crate::vk::definitions::*; - use crate::vk::enums::*; - use crate::prelude::debug_flags; #const_debugs }; let aliases = quote! { - use crate::vk::bitflags::*; - use crate::vk::definitions::*; - use crate::vk::enums::*; + use super::bitflags::*; + use super::definitions::*; + use super::enums::*; #(#aliases)* };