Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ash-window: Make enumerate_required_extensions return &[*const c_char] #590

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update Vulkan-Headers to 1.3.208 (#597)
- Added `VK_EXT_headless_surface` instance extension (#589)

### Changed

- Constified extension names (#590)

## [0.36.0] - 2022-02-21

### Changed
Expand Down
2 changes: 2 additions & 0 deletions ash-window/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased] - ReleaseDate

- Make `enumerate_required_extensions()` return `&[*const c_char]` instead of `Vec<&CStr>` to match `ash::vk::InstanceCreateInfo` (#590)

## [0.9.1] - 2022-02-21

### Changed
Expand Down
6 changes: 1 addition & 5 deletions ash-window/examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ fn main() -> Result<(), Box<dyn Error>> {
unsafe {
let entry = ash::Entry::linked();
let surface_extensions = ash_window::enumerate_required_extensions(&window)?;
let instance_extensions = surface_extensions
.iter()
.map(|ext| ext.as_ptr())
.collect::<Vec<_>>();
let app_desc = vk::ApplicationInfo::builder().api_version(vk::make_api_version(0, 1, 0, 0));
let instance_desc = vk::InstanceCreateInfo::builder()
.application_info(&app_desc)
.enabled_extension_names(&instance_extensions);
.enabled_extension_names(surface_extensions);

let instance = entry.create_instance(&instance_desc, None)?;

Expand Down
61 changes: 52 additions & 9 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![warn(trivial_casts, trivial_numeric_casts)]

use std::os::raw::c_char;

use ash::{extensions::khr, prelude::*, vk, Entry, Instance};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use std::ffi::CStr;

#[cfg(any(target_os = "macos", target_os = "ios"))]
use ash::extensions::ext; // portability extensions
Expand Down Expand Up @@ -122,10 +123,16 @@ pub unsafe fn create_surface(
/// The returned extensions will include all extension dependencies.
pub fn enumerate_required_extensions(
window_handle: &dyn HasRawWindowHandle,
) -> VkResult<Vec<&'static CStr>> {
) -> VkResult<&'static [*const c_char]> {
let extensions = match window_handle.raw_window_handle() {
#[cfg(target_os = "windows")]
RawWindowHandle::Windows(_) => vec![khr::Surface::name(), khr::Win32Surface::name()],
RawWindowHandle::Windows(_) => {
const WINDOWS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::Win32Surface::name().as_ptr(),
];
&WINDOWS_EXTS
Ralith marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(any(
target_os = "linux",
Expand All @@ -134,7 +141,13 @@ pub fn enumerate_required_extensions(
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Wayland(_) => vec![khr::Surface::name(), khr::WaylandSurface::name()],
RawWindowHandle::Wayland(_) => {
const WAYLAND_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::WaylandSurface::name().as_ptr(),
];
&WAYLAND_EXTS
}

#[cfg(any(
target_os = "linux",
Expand All @@ -143,7 +156,13 @@ pub fn enumerate_required_extensions(
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Xlib(_) => vec![khr::Surface::name(), khr::XlibSurface::name()],
RawWindowHandle::Xlib(_) => {
const XLIB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::XlibSurface::name().as_ptr(),
];
&XLIB_EXTS
}

#[cfg(any(
target_os = "linux",
Expand All @@ -152,16 +171,40 @@ pub fn enumerate_required_extensions(
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Xcb(_) => vec![khr::Surface::name(), khr::XcbSurface::name()],
RawWindowHandle::Xcb(_) => {
const XCB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::XcbSurface::name().as_ptr(),
];
&XCB_EXTS
}

#[cfg(any(target_os = "android"))]
RawWindowHandle::Android(_) => vec![khr::Surface::name(), khr::AndroidSurface::name()],
RawWindowHandle::Android(_) => {
const ANDROID_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::AndroidSurface::name().as_ptr(),
];
&ANDROID_EXTS
}

#[cfg(any(target_os = "macos"))]
RawWindowHandle::MacOS(_) => vec![khr::Surface::name(), ext::MetalSurface::name()],
RawWindowHandle::MacOS(_) => {
const MACOS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
];
&MACOS_EXTS
}

#[cfg(any(target_os = "ios"))]
RawWindowHandle::IOS(_) => vec![khr::Surface::name(), ext::MetalSurface::name()],
RawWindowHandle::IOS(_) => {
const IOS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
];
&IOS_EXTS
}

_ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT),
};
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 @@ -26,7 +26,7 @@ impl BufferDeviceAddress {
self.fp.get_buffer_device_address_ext(self.handle, info)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtBufferDeviceAddressFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl CalibratedTimestamps {
.result_with_success((timestamps, max_deviation))
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtCalibratedTimestampsFn::name()
}

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 @@ -54,7 +54,7 @@ impl DebugMarker {
.cmd_debug_marker_insert_ext(command_buffer, marker_info);
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtDebugMarkerFn::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 @@ -50,7 +50,7 @@ impl DebugReport {
.result_with_success(debug_cb)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtDebugReportFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/debug_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl DebugUtils {
);
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtDebugUtilsFn::name()
}

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 @@ -175,7 +175,7 @@ impl ExtendedDynamicState {
)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicStateFn::name()
}

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 @@ -66,7 +66,7 @@ impl ExtendedDynamicState2 {
.cmd_set_primitive_restart_enable_ext(command_buffer, primitive_restart_enable.into())
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicState2Fn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/full_screen_exclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl FullScreenExclusive {
.result_with_success(present_modes)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtFullScreenExclusiveFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/headless_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl HeadlessSurface {
.result_with_success(surface)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtHeadlessSurfaceFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/metal_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl MetalSurface {
.result_with_success(surface)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtMetalSurfaceFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/physical_device_drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl PhysicalDeviceDrm {
props_drm
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtPhysicalDeviceDrmFn::name()
}
}
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/private_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl PrivateData {
data
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtPrivateDataFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/tooling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ToolingInfo {
})
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::ExtToolingInfoFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl AccelerationStructure {
size_info
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrAccelerationStructureFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/android_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl AndroidSurface {
.result_with_success(surface)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrAndroidSurfaceFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/buffer_device_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl BufferDeviceAddress {
.get_device_memory_opaque_capture_address_khr(self.handle, info)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrBufferDeviceAddressFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/copy_commands2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl CopyCommands2 {
.cmd_resolve_image2_khr(command_buffer, resolve_image_info)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrCopyCommands2Fn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/create_render_pass2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl CreateRenderPass2 {
.cmd_end_render_pass2_khr(command_buffer, subpass_end_info);
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrCreateRenderpass2Fn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/deferred_host_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl DeferredHostOperations {
.result()
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrDeferredHostOperationsFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Display {
.result_with_success(surface.assume_init())
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrDisplayFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/display_swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DisplaySwapchain {
err_code.result_with_success(swapchains)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrDisplaySwapchainFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/draw_indirect_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl DrawIndirectCount {
);
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrDrawIndirectCountFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/dynamic_rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl DynamicRendering {
self.fp.cmd_end_rendering_khr(command_buffer)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrDynamicRenderingFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/external_fence_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ExternalFenceFd {
.result_with_success(fd)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrExternalFenceFdFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/external_fence_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ExternalFenceWin32 {
.result_with_success(handle)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrExternalFenceWin32Fn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/external_memory_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ExternalMemoryFd {
.result_with_success(memory_fd_properties)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrExternalMemoryFdFn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/external_memory_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ExternalMemoryWin32 {
.result_with_success(memory_win32_handle_properties)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrExternalMemoryWin32Fn::name()
}

Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/external_semaphore_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ExternalSemaphoreFd {
.result_with_success(fd)
}

pub fn name() -> &'static CStr {
pub const fn name() -> &'static CStr {
vk::KhrExternalSemaphoreFdFn::name()
}

Expand Down
Loading