Skip to content

Commit

Permalink
Replace const fn name() with associated NAME constants
Browse files Browse the repository at this point in the history
`CStr::from_bytes_with_nul_unchecked` is `const`-stable since Rust 1.59
which is already required for `ash` so it is high time to finally turn
these inlined `name()` functions into associated constants (which is a
breaking change in itself that cannot be backported).
  • Loading branch information
MarijnS95 committed Mar 9, 2023
1 parent 197bc30 commit e288193
Show file tree
Hide file tree
Showing 71 changed files with 907 additions and 1,903 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Replaced builders with lifetimes/setters directly on Vulkan structs (#602)
- Inlined struct setters (#602)
- Bumped MSRV from 1.59 to 1.60 (#709)
- Replaced `const fn name()` with associated `NAME` constants (#715)

### Removed

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport};
#[cfg(all(unix, not(target_os = "android")))]
fn extension_names() -> Vec<*const i8> {
vec![
Surface::name().as_ptr(),
XlibSurface::name().as_ptr(),
DebugReport::name().as_ptr()
Surface::NAME.as_ptr(),
XlibSurface::NAME.as_ptr(),
DebugReport::NAME.as_ptr()
]
}
```
Expand Down
28 changes: 12 additions & 16 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,44 @@ pub fn enumerate_required_extensions(
let extensions = match display_handle {
RawDisplayHandle::Windows(_) => {
const WINDOWS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::Win32Surface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::Win32Surface::NAME.as_ptr(),
];
&WINDOWS_EXTS
}

RawDisplayHandle::Wayland(_) => {
const WAYLAND_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::WaylandSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::WaylandSurface::NAME.as_ptr(),
];
&WAYLAND_EXTS
}

RawDisplayHandle::Xlib(_) => {
const XLIB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::XlibSurface::name().as_ptr(),
];
const XLIB_EXTS: [*const c_char; 2] =
[khr::Surface::NAME.as_ptr(), khr::XlibSurface::NAME.as_ptr()];
&XLIB_EXTS
}

RawDisplayHandle::Xcb(_) => {
const XCB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::XcbSurface::name().as_ptr(),
];
const XCB_EXTS: [*const c_char; 2] =
[khr::Surface::NAME.as_ptr(), khr::XcbSurface::NAME.as_ptr()];
&XCB_EXTS
}

RawDisplayHandle::Android(_) => {
const ANDROID_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::AndroidSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::AndroidSurface::NAME.as_ptr(),
];
&ANDROID_EXTS
}

RawDisplayHandle::AppKit(_) | RawDisplayHandle::UiKit(_) => {
const METAL_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
ext::MetalSurface::NAME.as_ptr(),
];
&METAL_EXTS
}
Expand Down
17 changes: 6 additions & 11 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Entry {
impl Entry {
/// Load default Vulkan library for the current platform
///
/// Prefer this over [`linked`](Self::linked) when your application can gracefully handle
/// Prefer this over [`linked()`][Self::linked()] when your application can gracefully handle
/// environments that lack Vulkan support, and when the build environment might not have Vulkan
/// development packages installed (e.g. the Vulkan SDK, or Ubuntu's `libvulkan-dev`).
///
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Entry {

/// Load entry points from a Vulkan loader linked at compile time
///
/// Compared to [`load`](Self::load), this is infallible, but requires that the build
/// Compared to [`load()`][Self::load()], this is infallible, but requires that the build
/// environment have Vulkan development packages installed (e.g. the Vulkan SDK, or Ubuntu's
/// `libvulkan-dev`), and prevents the resulting binary from starting in environments that do not
/// support Vulkan.
Expand Down Expand Up @@ -197,9 +197,7 @@ impl Entry {
unsafe {
let mut api_version = 0;
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
let name = ::std::ffi::CStr::from_bytes_with_nul_unchecked(
b"vkEnumerateInstanceVersion\0",
);
let name = CStr::from_bytes_with_nul_unchecked(b"vkEnumerateInstanceVersion\0");
mem::transmute((self.static_fn.get_instance_proc_addr)(
vk::Instance::null(),
name.as_ptr(),
Expand All @@ -218,7 +216,7 @@ impl Entry {
///
/// # Safety
/// In order for the created [`Instance`] to be valid for the duration of its
/// usage, the [`Entry`](Self) this was called on must be dropped later than the
/// usage, the [`Entry`][Self] this was called on must be dropped later than the
/// resulting [`Instance`].
#[inline]
pub unsafe fn create_instance(
Expand Down Expand Up @@ -326,14 +324,11 @@ impl Default for Entry {
impl vk::StaticFn {
pub fn load_checked<F>(mut _f: F) -> Result<Self, MissingEntryPoint>
where
F: FnMut(&::std::ffi::CStr) -> *const c_void,
F: FnMut(&CStr) -> *const c_void,
{
// TODO: Make this a &'static CStr once CStr::from_bytes_with_nul_unchecked is const
static ENTRY_POINT: &[u8] = b"vkGetInstanceProcAddr\0";

Ok(Self {
get_instance_proc_addr: unsafe {
let cname = CStr::from_bytes_with_nul_unchecked(ENTRY_POINT);
let cname = CStr::from_bytes_with_nul_unchecked(b"vkGetInstanceProcAddr\0");
let val = _f(cname);
if val.is_null() {
return Err(MissingEntryPoint);
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/acquire_drm_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ impl AcquireDrmDisplay {
.assume_init_on_success(display)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtAcquireDrmDisplayFn::name()
}
pub const NAME: &'static CStr = vk::ExtAcquireDrmDisplayFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtAcquireDrmDisplayFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/buffer_device_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ impl BufferDeviceAddress {
(self.fp.get_buffer_device_address_ext)(self.handle, info)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtBufferDeviceAddressFn::name()
}
pub const NAME: &'static CStr = vk::ExtBufferDeviceAddressFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtBufferDeviceAddressFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ impl CalibratedTimestamps {
.result_with_success((timestamps, max_deviation))
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtCalibratedTimestampsFn::name()
}
pub const NAME: &'static CStr = vk::ExtCalibratedTimestampsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtCalibratedTimestampsFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/debug_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ impl DebugMarker {
(self.fp.cmd_debug_marker_insert_ext)(command_buffer, marker_info);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDebugMarkerFn::name()
}
pub const NAME: &'static CStr = vk::ExtDebugMarkerFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDebugMarkerFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/debug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ impl DebugReport {
.result_with_success(debug_cb)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDebugReportFn::name()
}
pub const NAME: &'static CStr = vk::ExtDebugReportFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDebugReportFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/debug_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ impl DebugUtils {
);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDebugUtilsFn::name()
}
pub const NAME: &'static CStr = vk::ExtDebugUtilsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDebugUtilsFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/descriptor_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ impl DescriptorBuffer {
.result()
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDescriptorBufferFn::name()
}
pub const NAME: &'static CStr = vk::ExtDescriptorBufferFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDescriptorBufferFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/extended_dynamic_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ impl ExtendedDynamicState {
)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicStateFn::name()
}
pub const NAME: &'static CStr = vk::ExtExtendedDynamicStateFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtExtendedDynamicStateFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/extended_dynamic_state2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ impl ExtendedDynamicState2 {
)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicState2Fn::name()
}
pub const NAME: &'static CStr = vk::ExtExtendedDynamicState2Fn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtExtendedDynamicState2Fn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/extended_dynamic_state3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ impl ExtendedDynamicState3 {
(self.fp.cmd_set_coverage_reduction_mode_nv)(command_buffer, coverage_reduction_mode)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicState3Fn::name()
}
pub const NAME: &'static CStr = vk::ExtExtendedDynamicState3Fn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtExtendedDynamicState3Fn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/full_screen_exclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl FullScreenExclusive {
.result_with_success(present_modes)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtFullScreenExclusiveFn::name()
}
pub const NAME: &'static CStr = vk::ExtFullScreenExclusiveFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtFullScreenExclusiveFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/headless_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ impl HeadlessSurface {
.result_with_success(surface)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtHeadlessSurfaceFn::name()
}
pub const NAME: &'static CStr = vk::ExtHeadlessSurfaceFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtHeadlessSurfaceFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/image_compression_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ impl ImageCompressionControl {
(self.fp.get_image_subresource_layout2_ext)(self.handle, image, subresource, layout)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtImageCompressionControlFn::name()
}
pub const NAME: &'static CStr = vk::ExtImageCompressionControlFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtImageCompressionControlFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/image_drm_format_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ impl ImageDrmFormatModifier {
.result()
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtImageDrmFormatModifierFn::name()
}
pub const NAME: &'static CStr = vk::ExtImageDrmFormatModifierFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtImageDrmFormatModifierFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/mesh_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ impl MeshShader {
);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtMeshShaderFn::name()
}
pub const NAME: &'static CStr = vk::ExtMeshShaderFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtMeshShaderFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/metal_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl MetalSurface {
.result_with_success(surface)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtMetalSurfaceFn::name()
}
pub const NAME: &'static CStr = vk::ExtMetalSurfaceFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtMetalSurfaceFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/physical_device_drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ impl PhysicalDeviceDrm {
props_drm
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtPhysicalDeviceDrmFn::name()
}
pub const NAME: &'static CStr = vk::ExtPhysicalDeviceDrmFn::NAME;
}
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/private_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ impl PrivateData {
data
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtPrivateDataFn::name()
}
pub const NAME: &'static CStr = vk::ExtPrivateDataFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtPrivateDataFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/sample_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ impl SampleLocations {
(self.fp.cmd_set_sample_locations_ext)(command_buffer, sample_locations_info)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtSampleLocationsFn::name()
}
pub const NAME: &'static CStr = vk::ExtSampleLocationsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtSampleLocationsFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/tooling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ impl ToolingInfo {
})
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtToolingInfoFn::name()
}
pub const NAME: &'static CStr = vk::ExtToolingInfoFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtToolingInfoFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,7 @@ impl AccelerationStructure {
size_info
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrAccelerationStructureFn::name()
}
pub const NAME: &'static CStr = vk::KhrAccelerationStructureFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrAccelerationStructureFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/android_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl AndroidSurface {
.result_with_success(surface)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrAndroidSurfaceFn::name()
}
pub const NAME: &'static CStr = vk::KhrAndroidSurfaceFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrAndroidSurfaceFn {
Expand Down
Loading

0 comments on commit e288193

Please sign in to comment.