-
Notifications
You must be signed in to change notification settings - Fork 229
ash-window: Add get_present_support() helper
#774
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
Open
Rob2309
wants to merge
7
commits into
ash-rs:master
Choose a base branch
from
Rob2309:get-present-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92594f6
Added ash_window::get_present_support
Rob2309 c19e5be
Fixed xlib and xcb present querying, fixed line lengths
Rob2309 2e71e15
Fixed docs, made all features optional
Rob2309 512e8a3
Added usage of get_present_support to winit example
Rob2309 d1df8c8
Added xcb example for get_present_support
Rob2309 c4921a7
Fixed message in examples
Rob2309 f84911a
Removed forced xcb dev-dependency, added changelog entries
Rob2309 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
Collaborator
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 surfaces", | ||
| if present_support { | ||
| "supports" | ||
| } else { | ||
| "does not support" | ||
| } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| let window = WindowBuilder::new() | ||
| .with_inner_size(PhysicalSize::<u32>::from((800, 600))) | ||
| .build(&event_loop)?; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 surfaces", | ||
| 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(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
xcbby 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.