-
Notifications
You must be signed in to change notification settings - Fork 187
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: Add get_present_support()
helper
#774
base: master
Are you sure you want to change the base?
Changes from 5 commits
92594f6
c19e5be
2e71e15
512e8a3
d1df8c8
c4921a7
f84911a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,26 @@ rust-version = "1.64.0" | |
ash = { path = "../ash", version = "0.37", default-features = false } | ||
raw-window-handle = "0.5" | ||
|
||
[target.'cfg(unix)'.dependencies] | ||
x11-dl = { version = "2.21.0", optional = true } | ||
x11 = { version = "2.21.0", features = ["xlib"], optional = true } | ||
xcb = { version = "1.2.2", optional = true } | ||
|
||
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] | ||
raw-window-metal = "0.3" | ||
|
||
[dev-dependencies] | ||
winit = "0.28.0" | ||
ash = { path = "../ash", version = "0.37", default-features = false, features = ["linked"] } | ||
xcb = { version = "1.2.2" } | ||
|
||
[features] | ||
default = ["x11-dl", "xcb"] | ||
|
||
[[example]] | ||
name = "winit" | ||
required-features = ["ash/linked"] | ||
|
||
[[example]] | ||
name = "xcb" | ||
required-features = ["ash/linked"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also require the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not quite sure whether normal dependencies are available in examples. Will test this and change if possible. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
use ash::vk; | ||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; | ||
use std::error::Error; | ||
use std::{error::Error, ffi::CStr}; | ||
use winit::{ | ||
dpi::PhysicalSize, | ||
event::{Event, VirtualKeyCode, WindowEvent}, | ||
|
@@ -29,6 +29,31 @@ fn main() -> Result<(), Box<dyn Error>> { | |
|
||
let instance = entry.create_instance(&instance_desc, None)?; | ||
|
||
let devices = instance.enumerate_physical_devices()?; | ||
for dev in devices { | ||
let props = instance.get_physical_device_properties(dev); | ||
let queue_families = instance.get_physical_device_queue_family_properties(dev); | ||
let dev_name = CStr::from_ptr(props.device_name.as_ptr()).to_str().unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: I should replace this in #746. |
||
|
||
for i in 0..queue_families.len() { | ||
let present_support = ash_window::get_present_support( | ||
&entry, | ||
&instance, | ||
dev, | ||
i as _, | ||
event_loop.raw_display_handle(), | ||
)?; | ||
println!( | ||
"{dev_name}, queue {i} {} presenting to the surface", | ||
if present_support { | ||
"supports" | ||
} else { | ||
"does not support" | ||
} | ||
); | ||
} | ||
} | ||
|
||
let window = WindowBuilder::new() | ||
.with_inner_size(PhysicalSize::<u32>::from((800, 600))) | ||
.build(&event_loop)?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use std::{error::Error, ffi::CStr}; | ||
|
||
use ash::vk; | ||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle}; | ||
use xcb::{x, Xid}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let (xcb, screen_index) = xcb::Connection::connect(None)?; | ||
|
||
let screen = xcb.get_setup().roots().nth(screen_index as usize).unwrap(); | ||
|
||
let mut display_handle = XcbDisplayHandle::empty(); | ||
display_handle.connection = xcb.get_raw_conn().cast(); | ||
display_handle.screen = screen_index; | ||
let display_handle = RawDisplayHandle::Xcb(display_handle); | ||
|
||
unsafe { | ||
let entry = ash::Entry::linked(); | ||
let surface_extensions = ash_window::enumerate_required_extensions(display_handle)?; | ||
|
||
let app_desc = vk::ApplicationInfo::default().api_version(vk::make_api_version(0, 1, 0, 0)); | ||
let instance_desc = vk::InstanceCreateInfo::default() | ||
.application_info(&app_desc) | ||
.enabled_extension_names(surface_extensions); | ||
|
||
let instance = entry.create_instance(&instance_desc, None)?; | ||
|
||
let devices = instance.enumerate_physical_devices()?; | ||
for dev in devices { | ||
let props = instance.get_physical_device_properties(dev); | ||
let queue_families = instance.get_physical_device_queue_family_properties(dev); | ||
let dev_name = CStr::from_ptr(props.device_name.as_ptr()).to_str().unwrap(); | ||
|
||
for i in 0..queue_families.len() { | ||
let present_support = ash_window::get_present_support( | ||
&entry, | ||
&instance, | ||
dev, | ||
i as _, | ||
display_handle, | ||
)?; | ||
println!( | ||
"{dev_name}, queue {i} {} presenting to the surface", | ||
MarijnS95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if present_support { | ||
"supports" | ||
} else { | ||
"does not support" | ||
} | ||
); | ||
} | ||
} | ||
|
||
let window = xcb.generate_id::<x::Window>(); | ||
xcb.send_request(&x::CreateWindow { | ||
depth: x::COPY_FROM_PARENT as _, | ||
wid: window, | ||
parent: screen.root(), | ||
x: 0, | ||
y: 0, | ||
width: 800, | ||
height: 600, | ||
border_width: 10, | ||
class: x::WindowClass::InputOutput, | ||
visual: screen.root_visual(), | ||
value_list: &[ | ||
x::Cw::BackPixel(screen.white_pixel()), | ||
x::Cw::EventMask(x::EventMask::EXPOSURE | x::EventMask::KEY_PRESS), | ||
], | ||
}); | ||
|
||
let cookie = xcb.send_request_checked(&x::MapWindow { window }); | ||
xcb.check_request(cookie)?; | ||
|
||
let mut window_handle = XcbWindowHandle::empty(); | ||
window_handle.window = window.resource_id(); | ||
window_handle.visual_id = screen.root_visual(); | ||
let window_handle = RawWindowHandle::Xcb(window_handle); | ||
|
||
// Create a surface from winit window. | ||
let surface = | ||
ash_window::create_surface(&entry, &instance, display_handle, window_handle, None)?; | ||
let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance); | ||
println!("surface: {surface:?}"); | ||
|
||
while xcb.wait_for_event().is_ok() {} | ||
|
||
surface_fn.destroy_surface(surface, None); | ||
instance.destroy_instance(None); | ||
} | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ impl WaylandSurface { | |
&self, | ||
physical_device: vk::PhysicalDevice, | ||
queue_family_index: u32, | ||
wl_display: &mut vk::wl_display, | ||
wl_display: *mut vk::wl_display, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should write these down as breaking changes in the |
||
) -> bool { | ||
let b = (self.fp.get_physical_device_wayland_presentation_support_khr)( | ||
physical_device, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring
xcb
by default means we need libxcb present at buildtime, right? While probably most environments will have this, disabling it will make it easier for downstream users to get CI working in minimal VMs and such.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for defaulting this is to have the least surprising behavior by default. I dont think the default should be to not support a very broadly used platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know winit doesn't use xcb. Where in the raw-window-handle ecosystem is xcb broadly used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, however if winit at some point decides to switch to xcb, it should be defaulted again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think winit will want to avoid adding foreign build-time dependencies for the same reason.