diff --git a/Cargo.lock b/Cargo.lock index 1378b3c8..baa3dc39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2374,6 +2374,8 @@ dependencies = [ "thread_local", "vk-parse", "vulkano-macros", + "x11-dl", + "x11rb", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8b466edb..ef770dfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,8 @@ syn = "2.0" thread_local = "1.1" vk-parse = "0.12" winit = { version = "0.29", default-features = false } +x11-dl = "2.0" +x11rb = "0.13" # Only used in examples glam = "0.25" diff --git a/examples/async-update/Cargo.toml b/examples/async-update/Cargo.toml index 7b9fb935..094781aa 100644 --- a/examples/async-update/Cargo.toml +++ b/examples/async-update/Cargo.toml @@ -14,7 +14,7 @@ doc = false [dependencies] glam = { workspace = true } rand = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } vulkano-taskgraph = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/async-update/main.rs b/examples/async-update/main.rs index 39875a26..4f180867 100644 --- a/examples/async-update/main.rs +++ b/examples/async-update/main.rs @@ -110,9 +110,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -127,7 +124,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -232,6 +229,9 @@ fn main() -> Result<(), impl Error> { let graphics_flight_id = resources.create_flight(MAX_FRAMES_IN_FLIGHT).unwrap(); let transfer_flight_id = resources.create_flight(1).unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let swapchain_format = device .physical_device() .surface_formats(&surface, Default::default()) diff --git a/examples/basic-compute-shader/Cargo.toml b/examples/basic-compute-shader/Cargo.toml index 4684aebf..62058d72 100644 --- a/examples/basic-compute-shader/Cargo.toml +++ b/examples/basic-compute-shader/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/buffer-allocator/Cargo.toml b/examples/buffer-allocator/Cargo.toml index 06f5258a..414572bd 100644 --- a/examples/buffer-allocator/Cargo.toml +++ b/examples/buffer-allocator/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/buffer-allocator/main.rs b/examples/buffer-allocator/main.rs index d60f8d44..6801cbff 100644 --- a/examples/buffer-allocator/main.rs +++ b/examples/buffer-allocator/main.rs @@ -62,9 +62,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -79,7 +76,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -114,6 +111,9 @@ fn main() -> Result<(), impl Error> { let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/clear-attachments/Cargo.toml b/examples/clear-attachments/Cargo.toml index 1926a5b7..2aa399e0 100644 --- a/examples/clear-attachments/Cargo.toml +++ b/examples/clear-attachments/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true } +vulkano = { workspace = true, default-features = true } winit = { workspace = true, default-features = true } diff --git a/examples/clear-attachments/main.rs b/examples/clear-attachments/main.rs index 626665b0..7260c2a3 100644 --- a/examples/clear-attachments/main.rs +++ b/examples/clear-attachments/main.rs @@ -42,9 +42,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -59,7 +56,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -93,6 +90,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/debug/Cargo.toml b/examples/debug/Cargo.toml index db5ce7d5..4372e04b 100644 --- a/examples/debug/Cargo.toml +++ b/examples/debug/Cargo.toml @@ -12,4 +12,4 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true } +vulkano = { workspace = true, default-features = true } diff --git a/examples/deferred/Cargo.toml b/examples/deferred/Cargo.toml index 3cd5623a..ae769dca 100644 --- a/examples/deferred/Cargo.toml +++ b/examples/deferred/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] glam = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/deferred/main.rs b/examples/deferred/main.rs index f759a5de..552e99a5 100644 --- a/examples/deferred/main.rs +++ b/examples/deferred/main.rs @@ -65,9 +65,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -82,7 +79,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -116,6 +113,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, mut images) = { let surface_capabilities = device .physical_device() diff --git a/examples/dynamic-buffers/Cargo.toml b/examples/dynamic-buffers/Cargo.toml index 367b14c7..0cf9dd24 100644 --- a/examples/dynamic-buffers/Cargo.toml +++ b/examples/dynamic-buffers/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/dynamic-local-size/Cargo.toml b/examples/dynamic-local-size/Cargo.toml index 511f8311..c4a9a83b 100644 --- a/examples/dynamic-local-size/Cargo.toml +++ b/examples/dynamic-local-size/Cargo.toml @@ -13,5 +13,5 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/gl-interop/Cargo.toml b/examples/gl-interop/Cargo.toml index 0aa554c4..9a2751b9 100644 --- a/examples/gl-interop/Cargo.toml +++ b/examples/gl-interop/Cargo.toml @@ -13,7 +13,7 @@ doc = false [dependencies] glium = "0.32.1" -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } # Glium has still not been updated to the latest winit version diff --git a/examples/gl-interop/main.rs b/examples/gl-interop/main.rs index 0a8f11b8..d8f951d2 100644 --- a/examples/gl-interop/main.rs +++ b/examples/gl-interop/main.rs @@ -531,9 +531,6 @@ mod linux { .unwrap() }; - let window = Arc::new(WindowBuilder::new().build(event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_external_semaphore: true, khr_external_semaphore_fd: true, @@ -555,7 +552,7 @@ mod linux { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -597,6 +594,9 @@ mod linux { let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/image-self-copy-blit/Cargo.toml b/examples/image-self-copy-blit/Cargo.toml index 873bba4e..db150b8b 100644 --- a/examples/image-self-copy-blit/Cargo.toml +++ b/examples/image-self-copy-blit/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/image-self-copy-blit/main.rs b/examples/image-self-copy-blit/main.rs index 35cb9992..8a6ff7c4 100644 --- a/examples/image-self-copy-blit/main.rs +++ b/examples/image-self-copy-blit/main.rs @@ -67,9 +67,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -84,7 +81,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -118,6 +115,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/image/Cargo.toml b/examples/image/Cargo.toml index 3ff494f8..32a9c806 100644 --- a/examples/image/Cargo.toml +++ b/examples/image/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/image/main.rs b/examples/image/main.rs index f5150de1..caf682b0 100644 --- a/examples/image/main.rs +++ b/examples/image/main.rs @@ -65,9 +65,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -82,7 +79,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -116,6 +113,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/immutable-sampler/Cargo.toml b/examples/immutable-sampler/Cargo.toml index 4fb62fd1..5c180671 100644 --- a/examples/immutable-sampler/Cargo.toml +++ b/examples/immutable-sampler/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/immutable-sampler/main.rs b/examples/immutable-sampler/main.rs index 0efed200..982a3906 100644 --- a/examples/immutable-sampler/main.rs +++ b/examples/immutable-sampler/main.rs @@ -71,9 +71,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -88,7 +85,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -122,6 +119,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/indirect/Cargo.toml b/examples/indirect/Cargo.toml index 1ee17ba2..fa00455e 100644 --- a/examples/indirect/Cargo.toml +++ b/examples/indirect/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/indirect/main.rs b/examples/indirect/main.rs index f77e4ee4..921fa2e4 100644 --- a/examples/indirect/main.rs +++ b/examples/indirect/main.rs @@ -78,9 +78,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, khr_storage_buffer_storage_class: true, @@ -96,7 +93,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -131,6 +128,9 @@ fn main() -> Result<(), impl Error> { let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/instancing/Cargo.toml b/examples/instancing/Cargo.toml index 576c5061..9cfdedbe 100644 --- a/examples/instancing/Cargo.toml +++ b/examples/instancing/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/instancing/main.rs b/examples/instancing/main.rs index 0c076203..21bfcf14 100644 --- a/examples/instancing/main.rs +++ b/examples/instancing/main.rs @@ -77,9 +77,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -94,7 +91,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -129,6 +126,9 @@ fn main() -> Result<(), impl Error> { let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/interactive-fractal/Cargo.toml b/examples/interactive-fractal/Cargo.toml index a7dd078d..bb249aae 100644 --- a/examples/interactive-fractal/Cargo.toml +++ b/examples/interactive-fractal/Cargo.toml @@ -14,7 +14,7 @@ doc = false [dependencies] glam = { workspace = true } rand = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } vulkano-util = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/mesh-shader/Cargo.toml b/examples/mesh-shader/Cargo.toml index 13ec040b..3ffa6778 100644 --- a/examples/mesh-shader/Cargo.toml +++ b/examples/mesh-shader/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/mesh-shader/main.rs b/examples/mesh-shader/main.rs index d6709c08..f0d86afd 100644 --- a/examples/mesh-shader/main.rs +++ b/examples/mesh-shader/main.rs @@ -97,9 +97,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ext_mesh_shader: true, @@ -115,7 +112,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -154,6 +151,9 @@ fn main() -> Result<(), impl Error> { let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/msaa-renderpass/Cargo.toml b/examples/msaa-renderpass/Cargo.toml index 9a7683da..b6ce4232 100644 --- a/examples/msaa-renderpass/Cargo.toml +++ b/examples/msaa-renderpass/Cargo.toml @@ -13,5 +13,5 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/multi-window-game-of-life/Cargo.toml b/examples/multi-window-game-of-life/Cargo.toml index e3727034..4d865fa6 100644 --- a/examples/multi-window-game-of-life/Cargo.toml +++ b/examples/multi-window-game-of-life/Cargo.toml @@ -14,7 +14,7 @@ doc = false [dependencies] glam = { workspace = true } rand = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } vulkano-util = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/multi-window/Cargo.toml b/examples/multi-window/Cargo.toml index 085dad01..50822120 100644 --- a/examples/multi-window/Cargo.toml +++ b/examples/multi-window/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/multi-window/main.rs b/examples/multi-window/main.rs index ae726a40..a735442d 100644 --- a/examples/multi-window/main.rs +++ b/examples/multi-window/main.rs @@ -71,6 +71,54 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); + let device_extensions = DeviceExtensions { + khr_swapchain: true, + ..DeviceExtensions::empty() + }; + let (physical_device, queue_family_index) = instance + .enumerate_physical_devices() + .unwrap() + .filter(|p| p.supported_extensions().contains(&device_extensions)) + .filter_map(|p| { + p.queue_family_properties() + .iter() + .enumerate() + .position(|(i, q)| { + q.queue_flags.intersects(QueueFlags::GRAPHICS) + && p.presentation_support(i as u32, &event_loop).unwrap() + }) + .map(|i| (p, i as u32)) + }) + .min_by_key(|(p, _)| match p.properties().device_type { + PhysicalDeviceType::DiscreteGpu => 0, + PhysicalDeviceType::IntegratedGpu => 1, + PhysicalDeviceType::VirtualGpu => 2, + PhysicalDeviceType::Cpu => 3, + PhysicalDeviceType::Other => 4, + _ => 5, + }) + .unwrap(); + + println!( + "Using device: {} (type: {:?})", + physical_device.properties().device_name, + physical_device.properties().device_type, + ); + + let (device, mut queues) = Device::new( + physical_device, + DeviceCreateInfo { + enabled_extensions: device_extensions, + queue_create_infos: vec![QueueCreateInfo { + queue_family_index, + ..Default::default() + }], + ..Default::default() + }, + ) + .unwrap(); + let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); @@ -80,84 +128,27 @@ fn main() -> Result<(), impl Error> { // Use the window's id as a means to access it from the hashmap. let window_id = window.id(); - // Find the device and a queue. - // TODO: it is assumed the device, queue, and surface surface_capabilities are the same for all - // windows. - - let (device, queue, surface_caps) = { - let device_extensions = DeviceExtensions { - khr_swapchain: true, - ..DeviceExtensions::empty() - }; - let (physical_device, queue_family_index) = instance - .enumerate_physical_devices() - .unwrap() - .filter(|p| p.supported_extensions().contains(&device_extensions)) - .filter_map(|p| { - p.queue_family_properties() - .iter() - .enumerate() - .position(|(i, q)| { - q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) - }) - .map(|i| (p, i as u32)) - }) - .min_by_key(|(p, _)| match p.properties().device_type { - PhysicalDeviceType::DiscreteGpu => 0, - PhysicalDeviceType::IntegratedGpu => 1, - PhysicalDeviceType::VirtualGpu => 2, - PhysicalDeviceType::Cpu => 3, - PhysicalDeviceType::Other => 4, - _ => 5, - }) - .unwrap(); - - println!( - "Using device: {} (type: {:?})", - physical_device.properties().device_name, - physical_device.properties().device_type, - ); - - let (device, mut queues) = Device::new( - physical_device, - DeviceCreateInfo { - enabled_extensions: device_extensions, - queue_create_infos: vec![QueueCreateInfo { - queue_family_index, - ..Default::default() - }], - ..Default::default() - }, - ) - .unwrap(); - + // The swapchain and framebuffer images for this particular window. + let (swapchain, images) = { let surface_capabilities = device .physical_device() .surface_capabilities(&surface, Default::default()) .unwrap(); - - (device, queues.next().unwrap(), surface_capabilities) - }; - - // The swapchain and framebuffer images for this particular window. - let (swapchain, images) = { let image_format = device .physical_device() .surface_formats(&surface, Default::default()) .unwrap()[0] .0; - let window = surface.object().unwrap().downcast_ref::().unwrap(); Swapchain::new( device.clone(), surface.clone(), SwapchainCreateInfo { - min_image_count: surface_caps.min_image_count.max(2), + min_image_count: surface_capabilities.min_image_count.max(2), image_format, image_extent: window.inner_size().into(), image_usage: ImageUsage::COLOR_ATTACHMENT, - composite_alpha: surface_caps + composite_alpha: surface_capabilities .supported_composite_alpha .into_iter() .next() @@ -353,10 +344,9 @@ fn main() -> Result<(), impl Error> { let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); let window_id = window.id(); let (swapchain, images) = { - let composite_alpha = surface_caps - .supported_composite_alpha - .into_iter() - .next() + let surface_capabilities = device + .physical_device() + .surface_capabilities(&surface, Default::default()) .unwrap(); let image_format = device .physical_device() @@ -368,11 +358,15 @@ fn main() -> Result<(), impl Error> { device.clone(), surface, SwapchainCreateInfo { - min_image_count: surface_caps.min_image_count.max(2), + min_image_count: surface_capabilities.min_image_count.max(2), image_format, image_extent: window.inner_size().into(), image_usage: ImageUsage::COLOR_ATTACHMENT, - composite_alpha, + composite_alpha: surface_capabilities + .supported_composite_alpha + .into_iter() + .next() + .unwrap(), ..Default::default() }, ) diff --git a/examples/multiview/Cargo.toml b/examples/multiview/Cargo.toml index 67cbbb1d..d3534838 100644 --- a/examples/multiview/Cargo.toml +++ b/examples/multiview/Cargo.toml @@ -13,5 +13,5 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/occlusion-query/Cargo.toml b/examples/occlusion-query/Cargo.toml index 5cc843fc..49f1cf47 100644 --- a/examples/occlusion-query/Cargo.toml +++ b/examples/occlusion-query/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/occlusion-query/main.rs b/examples/occlusion-query/main.rs index c850a602..bb88fd29 100644 --- a/examples/occlusion-query/main.rs +++ b/examples/occlusion-query/main.rs @@ -60,9 +60,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -77,7 +74,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -111,6 +108,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/offscreen/Cargo.toml b/examples/offscreen/Cargo.toml index a6e808a6..c0b0c158 100644 --- a/examples/offscreen/Cargo.toml +++ b/examples/offscreen/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/pipeline-caching/Cargo.toml b/examples/pipeline-caching/Cargo.toml index b919c142..a38523d6 100644 --- a/examples/pipeline-caching/Cargo.toml +++ b/examples/pipeline-caching/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/push-constants/Cargo.toml b/examples/push-constants/Cargo.toml index 3c2aad51..3143dfb7 100644 --- a/examples/push-constants/Cargo.toml +++ b/examples/push-constants/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/push-descriptors/Cargo.toml b/examples/push-descriptors/Cargo.toml index 38268862..413ccb55 100644 --- a/examples/push-descriptors/Cargo.toml +++ b/examples/push-descriptors/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/push-descriptors/main.rs b/examples/push-descriptors/main.rs index d6958b16..a5cd07fc 100644 --- a/examples/push-descriptors/main.rs +++ b/examples/push-descriptors/main.rs @@ -60,9 +60,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, khr_push_descriptor: true, @@ -78,7 +75,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -112,6 +109,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/runtime-array/Cargo.toml b/examples/runtime-array/Cargo.toml index 6bbcb358..23cf0687 100644 --- a/examples/runtime-array/Cargo.toml +++ b/examples/runtime-array/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/runtime-array/main.rs b/examples/runtime-array/main.rs index 9161202a..3d0a40e5 100644 --- a/examples/runtime-array/main.rs +++ b/examples/runtime-array/main.rs @@ -66,9 +66,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -83,7 +80,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -124,6 +121,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/runtime-shader/Cargo.toml b/examples/runtime-shader/Cargo.toml index 5fefe21f..5137dea4 100644 --- a/examples/runtime-shader/Cargo.toml +++ b/examples/runtime-shader/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true } +vulkano = { workspace = true, default-features = true } winit = { workspace = true, default-features = true } diff --git a/examples/runtime-shader/main.rs b/examples/runtime-shader/main.rs index a0d5cd8f..77196224 100644 --- a/examples/runtime-shader/main.rs +++ b/examples/runtime-shader/main.rs @@ -68,9 +68,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -85,7 +82,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -119,6 +116,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/self-copy-buffer/Cargo.toml b/examples/self-copy-buffer/Cargo.toml index 2324a826..cdc44e50 100644 --- a/examples/self-copy-buffer/Cargo.toml +++ b/examples/self-copy-buffer/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/shader-include/Cargo.toml b/examples/shader-include/Cargo.toml index e46238f2..e03fe394 100644 --- a/examples/shader-include/Cargo.toml +++ b/examples/shader-include/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/shader-types-derive/Cargo.toml b/examples/shader-types-derive/Cargo.toml index a1d67922..ff110f4c 100644 --- a/examples/shader-types-derive/Cargo.toml +++ b/examples/shader-types-derive/Cargo.toml @@ -14,6 +14,6 @@ doc = false [dependencies] ron = { workspace = true } serde = { workspace = true, features = ["derive"] } -vulkano = { workspace = true, features = ["serde", "macros"] } +vulkano = { workspace = true, default-features = true, features = ["serde"] } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/shader-types-sharing/Cargo.toml b/examples/shader-types-sharing/Cargo.toml index 53999492..9b7a0c24 100644 --- a/examples/shader-types-sharing/Cargo.toml +++ b/examples/shader-types-sharing/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/simple-particles/Cargo.toml b/examples/simple-particles/Cargo.toml index 0b66d057..9949001e 100644 --- a/examples/simple-particles/Cargo.toml +++ b/examples/simple-particles/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/simple-particles/main.rs b/examples/simple-particles/main.rs index 67f9c803..63124076 100644 --- a/examples/simple-particles/main.rs +++ b/examples/simple-particles/main.rs @@ -71,17 +71,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new( - WindowBuilder::new() - // For simplicity, we are going to assert that the window size is static. - .with_resizable(false) - .with_title("simple particles") - .with_inner_size(winit::dpi::PhysicalSize::new(WINDOW_WIDTH, WINDOW_HEIGHT)) - .build(&event_loop) - .unwrap(), - ); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -96,7 +85,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -130,6 +119,17 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new( + WindowBuilder::new() + // For simplicity, we are going to assert that the window size is static. + .with_resizable(false) + .with_title("simple particles") + .with_inner_size(winit::dpi::PhysicalSize::new(WINDOW_WIDTH, WINDOW_HEIGHT)) + .build(&event_loop) + .unwrap(), + ); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/specialization-constants/Cargo.toml b/examples/specialization-constants/Cargo.toml index 06a968bd..d5b69e87 100644 --- a/examples/specialization-constants/Cargo.toml +++ b/examples/specialization-constants/Cargo.toml @@ -12,5 +12,5 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } diff --git a/examples/teapot/Cargo.toml b/examples/teapot/Cargo.toml index 373cdc74..83adb4e2 100644 --- a/examples/teapot/Cargo.toml +++ b/examples/teapot/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] glam = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/teapot/main.rs b/examples/teapot/main.rs index 4a9eb547..1e27728e 100644 --- a/examples/teapot/main.rs +++ b/examples/teapot/main.rs @@ -73,9 +73,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -90,7 +87,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -125,6 +122,9 @@ fn main() -> Result<(), impl Error> { let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/tessellation/Cargo.toml b/examples/tessellation/Cargo.toml index 4f9a2001..04ce1cc3 100644 --- a/examples/tessellation/Cargo.toml +++ b/examples/tessellation/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/tessellation/main.rs b/examples/tessellation/main.rs index d5aa14bc..db7296b0 100644 --- a/examples/tessellation/main.rs +++ b/examples/tessellation/main.rs @@ -165,9 +165,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -188,7 +185,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -223,6 +220,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/texture-array/Cargo.toml b/examples/texture-array/Cargo.toml index ef7c48d3..59f30f46 100644 --- a/examples/texture-array/Cargo.toml +++ b/examples/texture-array/Cargo.toml @@ -13,6 +13,6 @@ doc = false [dependencies] png = { workspace = true } -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/texture-array/main.rs b/examples/texture-array/main.rs index 4c0b40fe..63563321 100644 --- a/examples/texture-array/main.rs +++ b/examples/texture-array/main.rs @@ -67,9 +67,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - let device_extensions = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::empty() @@ -84,7 +81,7 @@ fn main() -> Result<(), impl Error> { .enumerate() .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) .map(|i| (p, i as u32)) }) @@ -118,6 +115,9 @@ fn main() -> Result<(), impl Error> { .unwrap(); let queue = queues.next().unwrap(); + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + let (mut swapchain, images) = { let surface_capabilities = device .physical_device() diff --git a/examples/triangle-util/Cargo.toml b/examples/triangle-util/Cargo.toml index 3dbb0297..f5d7a101 100644 --- a/examples/triangle-util/Cargo.toml +++ b/examples/triangle-util/Cargo.toml @@ -13,7 +13,7 @@ doc = false [dependencies] # The `vulkano` crate is the main crate that you must use to use Vulkan. -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } # Provides the `shader!` macro that is used to generate code for using shaders. vulkano-shaders = { workspace = true } # Contains the utility functions that make life easier. diff --git a/examples/triangle-v1_3/Cargo.toml b/examples/triangle-v1_3/Cargo.toml index ed43890f..57a2410b 100644 --- a/examples/triangle-v1_3/Cargo.toml +++ b/examples/triangle-v1_3/Cargo.toml @@ -12,6 +12,6 @@ bench = false doc = false [dependencies] -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } vulkano-shaders = { workspace = true } winit = { workspace = true, default-features = true } diff --git a/examples/triangle-v1_3/main.rs b/examples/triangle-v1_3/main.rs index 1edb5cc3..2936a1ba 100644 --- a/examples/triangle-v1_3/main.rs +++ b/examples/triangle-v1_3/main.rs @@ -80,15 +80,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - // The objective of this example is to draw a triangle on a window. To do so, we first need to - // create the window. We use the `WindowBuilder` from the `winit` crate to do that here. - // - // Before we can render to a window, we must first create a `vulkano::swapchain::Surface` - // object from it, which represents the drawable surface of a window. For that we must wrap the - // `winit::window::Window` in an `Arc`. - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - // Choose device extensions that we're going to use. In order to present images to a surface, // we need a `Swapchain`, which is provided by the `khr_swapchain` extension. let mut device_extensions = DeviceExtensions { @@ -133,7 +124,7 @@ fn main() -> Result<(), impl Error> { // a window surface, as we do in this example, we also need to check that // queues in this queue family are capable of presenting images to the surface. q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) // The code here searches for the first queue family that is suitable. If none is // found, `None` is returned to `filter_map`, which disqualifies this physical @@ -217,6 +208,15 @@ fn main() -> Result<(), impl Error> { // iterator. let queue = queues.next().unwrap(); + // The objective of this example is to draw a triangle on a window. To do so, we first need to + // create the window. We use the `WindowBuilder` from the `winit` crate to do that here. + // + // Before we can render to a window, we must first create a `vulkano::swapchain::Surface` + // object from it, which represents the drawable surface of a window. For that we must wrap the + // `winit::window::Window` in an `Arc`. + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + // Before we can draw on the surface, we have to create what is called a swapchain. Creating a // swapchain allocates the color buffers that will contain the image that will ultimately be // visible on the screen. These images are returned alongside the swapchain. diff --git a/examples/triangle/Cargo.toml b/examples/triangle/Cargo.toml index 09b3b723..8b5d3180 100644 --- a/examples/triangle/Cargo.toml +++ b/examples/triangle/Cargo.toml @@ -13,7 +13,7 @@ doc = false [dependencies] # The `vulkano` crate is the main crate that you must use to use Vulkan. -vulkano = { workspace = true, features = ["macros"] } +vulkano = { workspace = true, default-features = true } # Provides the `shader!` macro that is used to generate code for using shaders. vulkano-shaders = { workspace = true } # The Vulkan library doesn't provide any functionality to create and handle windows, as diff --git a/examples/triangle/main.rs b/examples/triangle/main.rs index 54e70255..e1f51f07 100644 --- a/examples/triangle/main.rs +++ b/examples/triangle/main.rs @@ -75,15 +75,6 @@ fn main() -> Result<(), impl Error> { ) .unwrap(); - // The objective of this example is to draw a triangle on a window. To do so, we first need to - // create the window. We use the `WindowBuilder` from the `winit` crate to do that here. - // - // Before we can render to a window, we must first create a `vulkano::swapchain::Surface` - // object from it, which represents the drawable surface of a window. For that we must wrap the - // `winit::window::Window` in an `Arc`. - let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); - let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); - // Choose device extensions that we're going to use. In order to present images to a surface, // we need a `Swapchain`, which is provided by the `khr_swapchain` extension. let device_extensions = DeviceExtensions { @@ -123,7 +114,7 @@ fn main() -> Result<(), impl Error> { // a window surface, as we do in this example, we also need to check that // queues in this queue family are capable of presenting images to the surface. q.queue_flags.intersects(QueueFlags::GRAPHICS) - && p.surface_support(i as u32, &surface).unwrap_or(false) + && p.presentation_support(i as u32, &event_loop).unwrap() }) // The code here searches for the first queue family that is suitable. If none is // found, `None` is returned to `filter_map`, which disqualifies this physical @@ -187,6 +178,15 @@ fn main() -> Result<(), impl Error> { // iterator. let queue = queues.next().unwrap(); + // The objective of this example is to draw a triangle on a window. To do so, we first need to + // create the window. We use the `WindowBuilder` from the `winit` crate to do that here. + // + // Before we can render to a window, we must first create a `vulkano::swapchain::Surface` + // object from it, which represents the drawable surface of a window. For that we must wrap the + // `winit::window::Window` in an `Arc`. + let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); + let surface = Surface::from_window(instance.clone(), window.clone()).unwrap(); + // Before we can draw on the surface, we have to create what is called a swapchain. Creating a // swapchain allocates the color buffers that will contain the image that will ultimately be // visible on the screen. These images are returned alongside the swapchain. diff --git a/vulkano/Cargo.toml b/vulkano/Cargo.toml index 8c59d7b0..3bb19653 100644 --- a/vulkano/Cargo.toml +++ b/vulkano/Cargo.toml @@ -34,6 +34,10 @@ vulkano-macros = { workspace = true, optional = true } objc = { workspace = true } core-graphics-types = { workspace = true } +[target.'cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "hurd", target_os = "illumos", target_os = "linux", target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))'.dependencies] +x11-dl = { workspace = true, optional = true } +x11rb = { workspace = true, features = ["allow-unsafe-code"], optional = true } + [build-dependencies] ahash = { workspace = true } heck = { workspace = true } @@ -50,9 +54,10 @@ vk-parse = { workspace = true } libc = "0.2.153" [features] -default = ["macros"] -macros = ["dep:vulkano-macros"] +default = ["macros", "x11"] document_unchecked = [] +macros = ["dep:vulkano-macros"] +x11 = ["dep:x11-dl", "dep:x11rb"] [lints] workspace = true diff --git a/vulkano/src/device/physical.rs b/vulkano/src/device/physical.rs index 1586abef..52cf7b08 100644 --- a/vulkano/src/device/physical.rs +++ b/vulkano/src/device/physical.rs @@ -29,6 +29,7 @@ use crate::{ }; use bytemuck::cast_slice; use parking_lot::RwLock; +use raw_window_handle::{HandleError, HasDisplayHandle, RawDisplayHandle}; use std::{ fmt::{Debug, Error as FmtError, Formatter}, mem::MaybeUninit, @@ -420,71 +421,6 @@ impl PhysicalDevice { &self.queue_family_properties } - /// Queries whether the physical device supports presenting to DirectFB surfaces from queues of - /// the given queue family. - /// - /// # Safety - /// - /// - `dfb` must be a valid DirectFB `IDirectFB` handle. - #[inline] - pub unsafe fn directfb_presentation_support( - &self, - queue_family_index: u32, - dfb: *mut ash::vk::IDirectFB, - ) -> Result> { - self.validate_directfb_presentation_support(queue_family_index, dfb)?; - - Ok(self.directfb_presentation_support_unchecked(queue_family_index, dfb)) - } - - fn validate_directfb_presentation_support( - &self, - queue_family_index: u32, - _dfb: *mut ash::vk::IDirectFB, - ) -> Result<(), Box> { - if !self.instance.enabled_extensions().ext_directfb_surface { - return Err(Box::new(ValidationError { - requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( - "ext_directfb_surface", - )])]), - ..Default::default() - })); - } - - if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(Box::new(ValidationError { - context: "queue_family_index".into(), - problem: "is not less than the number of queue families in the physical device" - .into(), - vuids: &[ - "VUID-vkGetPhysicalDeviceDirectFBPresentationSupportEXT-queueFamilyIndex-04119", - ], - ..Default::default() - })); - } - - // VUID-vkGetPhysicalDeviceDirectFBPresentationSupportEXT-dfb-parameter - // Can't validate, therefore unsafe - - Ok(()) - } - - #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - #[inline] - pub unsafe fn directfb_presentation_support_unchecked( - &self, - queue_family_index: u32, - dfb: *mut ash::vk::IDirectFB, - ) -> bool { - let fns = self.instance.fns(); - (fns.ext_directfb_surface - .get_physical_device_direct_fb_presentation_support_ext)( - self.handle, - queue_family_index, - dfb, - ) != 0 - } - /// Returns the properties of displays attached to the physical device. #[inline] pub fn display_properties( @@ -1675,69 +1611,6 @@ impl PhysicalDevice { }) } - /// Queries whether the physical device supports presenting to QNX Screen surfaces from queues - /// of the given queue family. - /// - /// # Safety - /// - /// - `window` must be a valid QNX Screen `_screen_window` handle. - pub unsafe fn qnx_screen_presentation_support( - &self, - queue_family_index: u32, - window: *mut ash::vk::_screen_window, - ) -> Result> { - self.validate_qnx_screen_presentation_support(queue_family_index, window)?; - - Ok(self.qnx_screen_presentation_support_unchecked(queue_family_index, window)) - } - - fn validate_qnx_screen_presentation_support( - &self, - queue_family_index: u32, - _window: *mut ash::vk::_screen_window, - ) -> Result<(), Box> { - if !self.instance.enabled_extensions().qnx_screen_surface { - return Err(Box::new(ValidationError { - requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( - "qnx_screen_surface", - )])]), - ..Default::default() - })); - } - - if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(Box::new(ValidationError { - context: "queue_family_index".into(), - problem: "is not less than the number of queue families in the physical device" - .into(), - vuids: &[ - "VUID-vkGetPhysicalDeviceScreenPresentationSupportQNX-queueFamilyIndex-04743", - ], - ..Default::default() - })); - } - - // VUID-vkGetPhysicalDeviceScreenPresentationSupportQNX-window-parameter - // Can't validate, therefore unsafe - - Ok(()) - } - - #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn qnx_screen_presentation_support_unchecked( - &self, - queue_family_index: u32, - window: *mut ash::vk::_screen_window, - ) -> bool { - let fns = self.instance.fns(); - (fns.qnx_screen_surface - .get_physical_device_screen_presentation_support_qnx)( - self.handle, - queue_family_index, - window, - ) != 0 - } - /// Returns the properties of sparse images with a given image configuration. /// /// The results of this function are cached, so that future calls with the same arguments @@ -2848,10 +2721,16 @@ impl PhysicalDevice { ) } - /// Returns whether queues of the given queue family can draw on the given surface. + /// Returns whether queues of the given queue family support presentation to the given surface. /// - /// The results of this function are cached, so that future calls with the same arguments - /// do not need to make a call to the Vulkan API again. + /// The results of this function are cached, so that future calls with the same arguments do + /// not need to make a call to the Vulkan API again. + /// + /// See also [`presentation_support`] for determining if a queue family supports presentation + /// to the surface of any window of a given event loop, for instance in cases where you have no + /// window and hence no surface at hand to test with or when you could have multiple windows. + /// + /// [`presentation_support`]: Self::presentation_support #[inline] pub fn surface_support( &self, @@ -3020,6 +2899,113 @@ impl PhysicalDevice { } } + /// Returns whether queues of the given queue family support presentation to surfaces of + /// windows of the given event loop. + /// + /// On the X11 platform, this checks if the given queue family supports presentation to + /// surfaces of windows created with the root visual. This means that if you create your + /// window(s) with a different visual, the result of this function doesn't guarantee support + /// for that window's surface, and you should use [`xcb_presentation_support`] or + /// [`xlib_presentation_support`] directly to determine support for presentation to such + /// surfaces. + /// + /// See also [`surface_support`] for determining if a queue family supports presentation to a + /// specific surface. + /// + /// [`xcb_presentation_support`]: Self::xcb_presentation_support + /// [`xlib_presentation_support`]: Self::xlib_presentation_support + /// [`surface_support`]: Self::surface_support + pub fn presentation_support( + &self, + queue_family_index: u32, + event_loop: &impl HasDisplayHandle, + ) -> Result> { + let support = match event_loop + .display_handle() + .map_err(Validated::Error)? + .as_raw() + { + // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap34.html#platformQuerySupport_android + RawDisplayHandle::Android(_) => true, + // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap34.html#platformQuerySupport_macos + RawDisplayHandle::AppKit(_) => true, + RawDisplayHandle::Wayland(display) => { + let display = display.display.as_ptr(); + + unsafe { self.wayland_presentation_support(queue_family_index, display.cast()) }? + } + RawDisplayHandle::Windows(_display) => { + self.win32_presentation_support(queue_family_index)? + } + #[cfg(all( + any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "hurd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris" + ), + feature = "x11" + ))] + RawDisplayHandle::Xcb(display) => { + let screen = display.screen; + let connection = display.connection.unwrap().as_ptr(); + let visual_id = unsafe { get_xcb_root_visual_id(connection, screen) }; + + unsafe { + self.xcb_presentation_support(queue_family_index, connection.cast(), visual_id) + }? + } + #[cfg(all( + any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "hurd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris" + ), + feature = "x11" + ))] + RawDisplayHandle::Xlib(display) => { + let screen = display.screen; + let display = display.display.unwrap().as_ptr(); + let visual_id = unsafe { get_xlib_root_visual_id(display, screen) }; + + unsafe { + self.xlib_presentation_support(queue_family_index, display.cast(), visual_id) + }? + } + #[cfg(all( + any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "hurd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris" + ), + not(feature = "x11") + ))] + RawDisplayHandle::Xcb(_) | RawDisplayHandle::Xlib(_) => panic!("unsupported platform"), + // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap34.html#platformQuerySupport_ios + RawDisplayHandle::UiKit(_) => true, + _ => unimplemented!( + "the event loop was created with a windowing API that is not supported by \ + Vulkan/Vulkano", + ), + }; + + Ok(support) + } + /// Queries whether the physical device supports presenting to Wayland surfaces from queues of /// the given queue family. /// @@ -3188,7 +3174,7 @@ impl PhysicalDevice { &self, queue_family_index: u32, connection: *mut ash::vk::xcb_connection_t, - visual_id: ash::vk::VisualID, + visual_id: ash::vk::xcb_visualid_t, ) -> bool { let fns = self.instance.fns(); (fns.khr_xcb_surface @@ -3266,6 +3252,134 @@ impl PhysicalDevice { visual_id, ) != 0 } + + /// Queries whether the physical device supports presenting to DirectFB surfaces from queues of + /// the given queue family. + /// + /// # Safety + /// + /// - `dfb` must be a valid DirectFB `IDirectFB` handle. + #[inline] + pub unsafe fn directfb_presentation_support( + &self, + queue_family_index: u32, + dfb: *mut ash::vk::IDirectFB, + ) -> Result> { + self.validate_directfb_presentation_support(queue_family_index, dfb)?; + + Ok(self.directfb_presentation_support_unchecked(queue_family_index, dfb)) + } + + fn validate_directfb_presentation_support( + &self, + queue_family_index: u32, + _dfb: *mut ash::vk::IDirectFB, + ) -> Result<(), Box> { + if !self.instance.enabled_extensions().ext_directfb_surface { + return Err(Box::new(ValidationError { + requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( + "ext_directfb_surface", + )])]), + ..Default::default() + })); + } + + if queue_family_index >= self.queue_family_properties.len() as u32 { + return Err(Box::new(ValidationError { + context: "queue_family_index".into(), + problem: "is not less than the number of queue families in the physical device" + .into(), + vuids: &[ + "VUID-vkGetPhysicalDeviceDirectFBPresentationSupportEXT-queueFamilyIndex-04119", + ], + ..Default::default() + })); + } + + // VUID-vkGetPhysicalDeviceDirectFBPresentationSupportEXT-dfb-parameter + // Can't validate, therefore unsafe + + Ok(()) + } + + #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] + #[inline] + pub unsafe fn directfb_presentation_support_unchecked( + &self, + queue_family_index: u32, + dfb: *mut ash::vk::IDirectFB, + ) -> bool { + let fns = self.instance.fns(); + (fns.ext_directfb_surface + .get_physical_device_direct_fb_presentation_support_ext)( + self.handle, + queue_family_index, + dfb, + ) != 0 + } + + /// Queries whether the physical device supports presenting to QNX Screen surfaces from queues + /// of the given queue family. + /// + /// # Safety + /// + /// - `window` must be a valid QNX Screen `_screen_window` handle. + pub unsafe fn qnx_screen_presentation_support( + &self, + queue_family_index: u32, + window: *mut ash::vk::_screen_window, + ) -> Result> { + self.validate_qnx_screen_presentation_support(queue_family_index, window)?; + + Ok(self.qnx_screen_presentation_support_unchecked(queue_family_index, window)) + } + + fn validate_qnx_screen_presentation_support( + &self, + queue_family_index: u32, + _window: *mut ash::vk::_screen_window, + ) -> Result<(), Box> { + if !self.instance.enabled_extensions().qnx_screen_surface { + return Err(Box::new(ValidationError { + requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( + "qnx_screen_surface", + )])]), + ..Default::default() + })); + } + + if queue_family_index >= self.queue_family_properties.len() as u32 { + return Err(Box::new(ValidationError { + context: "queue_family_index".into(), + problem: "is not less than the number of queue families in the physical device" + .into(), + vuids: &[ + "VUID-vkGetPhysicalDeviceScreenPresentationSupportQNX-queueFamilyIndex-04743", + ], + ..Default::default() + })); + } + + // VUID-vkGetPhysicalDeviceScreenPresentationSupportQNX-window-parameter + // Can't validate, therefore unsafe + + Ok(()) + } + + #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] + pub unsafe fn qnx_screen_presentation_support_unchecked( + &self, + queue_family_index: u32, + window: *mut ash::vk::_screen_window, + ) -> bool { + let fns = self.instance.fns(); + (fns.qnx_screen_surface + .get_physical_device_screen_presentation_support_qnx)( + self.handle, + queue_family_index, + window, + ) != 0 + } } impl Debug for PhysicalDevice { @@ -3326,6 +3440,56 @@ unsafe impl InstanceOwned for PhysicalDevice { impl_id_counter!(PhysicalDevice); +#[cfg(all( + any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "hurd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris" + ), + feature = "x11" +))] +unsafe fn get_xcb_root_visual_id( + connection: *mut std::ffi::c_void, + screen_id: std::ffi::c_int, +) -> u32 { + use x11rb::connection::Connection; + + let connection = + unsafe { x11rb::xcb_ffi::XCBConnection::from_raw_xcb_connection(connection, false) } + .unwrap(); + let screen = &connection.setup().roots[screen_id as usize]; + + screen.root_visual +} + +#[cfg(all( + any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "hurd", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris" + ), + feature = "x11" +))] +unsafe fn get_xlib_root_visual_id( + display: *mut std::ffi::c_void, + screen_id: std::ffi::c_int, +) -> u32 { + let xlib_xcb = x11_dl::xlib_xcb::Xlib_xcb::open().unwrap(); + let connection = unsafe { (xlib_xcb.XGetXCBConnection)(display.cast()) }; + + unsafe { get_xcb_root_visual_id(connection, screen_id) } +} + /// Properties of a group of physical devices that can be used to create a single logical device. #[derive(Clone, Debug)] #[non_exhaustive] diff --git a/vulkano/src/lib.rs b/vulkano/src/lib.rs index 601d4296..634a1d1d 100644 --- a/vulkano/src/lib.rs +++ b/vulkano/src/lib.rs @@ -93,6 +93,7 @@ //! | Feature | Description | //! |----------------------|----------------------------------------------------------------| //! | `macros` | Include reexports from [`vulkano-macros`]. Enabled by default. | +//! | `x11` | Support for X11 platforms. Enabled by default. | //! | `document_unchecked` | Include `_unchecked` functions in the generated documentation. | //! | `serde` | Enables (de)serialization of certain types using [`serde`]. | //!