diff --git a/examples/src/bin/basic-compute-shader.rs b/examples/src/bin/basic-compute-shader.rs index ad9c328a..7af9fa10 100644 --- a/examples/src/bin/basic-compute-shader.rs +++ b/examples/src/bin/basic-compute-shader.rs @@ -17,8 +17,9 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::ComputePipeline; use vulkano::pipeline::ComputePipelineAbstract; use vulkano::sync; @@ -35,10 +36,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { // The Vulkan specs guarantee that a compliant implementation must provide at least one queue // that supports compute operations. @@ -65,7 +63,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/buffer-pool.rs b/examples/src/bin/buffer-pool.rs index 1d6987e6..fd983fd9 100644 --- a/examples/src/bin/buffer-pool.rs +++ b/examples/src/bin/buffer-pool.rs @@ -25,10 +25,11 @@ use vulkano::buffer::CpuBufferPool; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::render_pass::{Framebuffer, FramebufferAbstract, RenderPass, Subpass}; @@ -62,10 +63,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -89,7 +87,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/debug.rs b/examples/src/bin/debug.rs index dda22827..a0822102 100644 --- a/examples/src/bin/debug.rs +++ b/examples/src/bin/debug.rs @@ -7,6 +7,7 @@ // notice may not be copied, modified, or distributed except // according to those terms. +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::Format; use vulkano::image::ImageDimensions; @@ -14,7 +15,7 @@ use vulkano::image::ImmutableImage; use vulkano::image::MipmapsCount; use vulkano::instance; use vulkano::instance::debug::{DebugCallback, MessageSeverity, MessageType}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::Version; fn main() { @@ -116,10 +117,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { Some( p.queue_families() @@ -140,7 +138,9 @@ fn main() { let (_, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), vec![(queue_family, 0.5)], ) .expect("failed to create device"); diff --git a/examples/src/bin/deferred/main.rs b/examples/src/bin/deferred/main.rs index c0bcdd5b..7e5def77 100644 --- a/examples/src/bin/deferred/main.rs +++ b/examples/src/bin/deferred/main.rs @@ -30,10 +30,11 @@ use crate::triangle_draw_system::*; use cgmath::Matrix4; use cgmath::SquareMatrix; use cgmath::Vector3; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::ImageUsage; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::swapchain; use vulkano::swapchain::{AcquireError, Swapchain, SwapchainCreationError}; use vulkano::sync; @@ -63,10 +64,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -90,7 +88,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/dynamic-buffers.rs b/examples/src/bin/dynamic-buffers.rs index 40f963c4..cd822402 100644 --- a/examples/src/bin/dynamic-buffers.rs +++ b/examples/src/bin/dynamic-buffers.rs @@ -19,8 +19,9 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::layout::PipelineLayout; use vulkano::pipeline::shader::EntryPointAbstract; use vulkano::pipeline::ComputePipeline; @@ -37,10 +38,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -64,7 +62,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/dynamic-local-size.rs b/examples/src/bin/dynamic-local-size.rs index 07551eba..75d813fe 100644 --- a/examples/src/bin/dynamic-local-size.rs +++ b/examples/src/bin/dynamic-local-size.rs @@ -21,10 +21,11 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::Format; use vulkano::image::{view::ImageView, ImageDimensions, StorageImage}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::ComputePipeline; use vulkano::pipeline::ComputePipelineAbstract; use vulkano::sync; @@ -50,10 +51,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -77,7 +75,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/image/main.rs b/examples/src/bin/image/main.rs index 342bb72f..b8e3527f 100644 --- a/examples/src/bin/image/main.rs +++ b/examples/src/bin/image/main.rs @@ -15,12 +15,13 @@ use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::Format; use vulkano::image::{ view::ImageView, ImageDimensions, ImageUsage, ImmutableImage, MipmapsCount, SwapchainImage, }; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::pipeline::GraphicsPipelineAbstract; @@ -53,10 +54,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -80,7 +78,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/immutable-buffer-initialization.rs b/examples/src/bin/immutable-buffer-initialization.rs index aba2a63c..1f0850fd 100644 --- a/examples/src/bin/immutable-buffer-initialization.rs +++ b/examples/src/bin/immutable-buffer-initialization.rs @@ -13,8 +13,9 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, ImmutableBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::ComputePipeline; use vulkano::pipeline::ComputePipelineAbstract; use vulkano::sync; @@ -32,10 +33,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -59,7 +57,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/indirect.rs b/examples/src/bin/indirect.rs index 225cd332..eb580094 100644 --- a/examples/src/bin/indirect.rs +++ b/examples/src/bin/indirect.rs @@ -38,10 +38,11 @@ use vulkano::command_buffer::{ SubpassContents, }; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::{ComputePipeline, ComputePipelineAbstract, GraphicsPipeline}; use vulkano::render_pass::{Framebuffer, FramebufferAbstract, RenderPass, Subpass}; @@ -78,10 +79,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -105,7 +103,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/instancing.rs b/examples/src/bin/instancing.rs index 8425e8f5..7f8b676a 100644 --- a/examples/src/bin/instancing.rs +++ b/examples/src/bin/instancing.rs @@ -23,10 +23,11 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::vertex::OneVertexOneInstanceDefinition; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; @@ -75,10 +76,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -102,7 +100,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/msaa-renderpass.rs b/examples/src/bin/msaa-renderpass.rs index fef8c51f..97bed213 100644 --- a/examples/src/bin/msaa-renderpass.rs +++ b/examples/src/bin/msaa-renderpass.rs @@ -74,13 +74,14 @@ use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, PrimaryCommandBuffer, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::ClearValue; use vulkano::format::Format; use vulkano::image::{ view::ImageView, AttachmentImage, ImageDimensions, SampleCount, StorageImage, }; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::render_pass::{Framebuffer, Subpass}; @@ -97,10 +98,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics()) @@ -124,7 +122,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/multi-window.rs b/examples/src/bin/multi-window.rs index 73791c42..1f1e7448 100644 --- a/examples/src/bin/multi-window.rs +++ b/examples/src/bin/multi-window.rs @@ -22,10 +22,11 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::render_pass::{Framebuffer, FramebufferAbstract, RenderPass, Subpass}; @@ -75,8 +76,7 @@ fn main() { }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions + p.supported_extensions().intersection(&device_extensions) == device_extensions }) .filter_map(|p| { p.queue_families() @@ -101,7 +101,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/multiview.rs b/examples/src/bin/multiview.rs index 5c6bc467..7b5a7d54 100644 --- a/examples/src/bin/multiview.rs +++ b/examples/src/bin/multiview.rs @@ -23,6 +23,7 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::Format; use vulkano::image::view::ImageView; @@ -30,8 +31,7 @@ use vulkano::image::{ ImageAccess, ImageCreateFlags, ImageDimensions, ImageLayout, ImageUsage, SampleCount, StorageImage, }; -use vulkano::instance::PhysicalDevice; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::render_pass::{ @@ -65,8 +65,7 @@ fn main() { }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions + p.supported_extensions().intersection(&device_extensions) == device_extensions }) .filter(|&p| { p.supported_features().superset_of(&features) @@ -105,7 +104,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &features, - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/occlusion-query.rs b/examples/src/bin/occlusion-query.rs index dbd44a34..e67781ee 100644 --- a/examples/src/bin/occlusion-query.rs +++ b/examples/src/bin/occlusion-query.rs @@ -16,10 +16,11 @@ use vulkano::buffer::{BufferAccess, BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, DeviceOwned, Features}; use vulkano::format::Format; use vulkano::image::{view::ImageView, AttachmentImage, ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::query::{QueryControlFlags, QueryPool, QueryResultFlags, QueryType}; @@ -48,10 +49,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -75,7 +73,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/pipeline-caching.rs b/examples/src/bin/pipeline-caching.rs index 447aa373..9880fd68 100644 --- a/examples/src/bin/pipeline-caching.rs +++ b/examples/src/bin/pipeline-caching.rs @@ -32,8 +32,9 @@ use std::fs::File; use std::io::Read; use std::io::Write; use std::sync::Arc; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::cache::PipelineCache; use vulkano::pipeline::ComputePipeline; use vulkano::Version; @@ -48,10 +49,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -76,7 +74,9 @@ fn main() { let (device, _) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/push-constants.rs b/examples/src/bin/push-constants.rs index 2252c5e2..e1f4aea1 100644 --- a/examples/src/bin/push-constants.rs +++ b/examples/src/bin/push-constants.rs @@ -13,8 +13,9 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::{ComputePipeline, ComputePipelineAbstract}; use vulkano::sync; use vulkano::sync::GpuFuture; @@ -28,10 +29,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -55,7 +53,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/runtime-shader/main.rs b/examples/src/bin/runtime-shader/main.rs index 7a775e5f..57d67001 100644 --- a/examples/src/bin/runtime-shader/main.rs +++ b/examples/src/bin/runtime-shader/main.rs @@ -29,11 +29,12 @@ use vulkano::buffer::BufferUsage; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::Format; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::layout::PipelineLayoutDesc; use vulkano::pipeline::shader::{ GraphicsShaderType, ShaderInterface, ShaderInterfaceEntry, ShaderModule, @@ -75,10 +76,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -102,7 +100,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/shader-include/main.rs b/examples/src/bin/shader-include/main.rs index 169eeceb..dd93d0b6 100644 --- a/examples/src/bin/shader-include/main.rs +++ b/examples/src/bin/shader-include/main.rs @@ -15,8 +15,9 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::{ComputePipeline, ComputePipelineAbstract}; use vulkano::sync; use vulkano::sync::GpuFuture; @@ -24,16 +25,12 @@ use vulkano::Version; fn main() { let instance = Instance::new(None, Version::V1_1, &InstanceExtensions::none(), None).unwrap(); - let device_extensions = DeviceExtensions { khr_storage_buffer_storage_class: true, ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -57,7 +54,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/specialization-constants.rs b/examples/src/bin/specialization-constants.rs index 51e7f66d..18730d94 100644 --- a/examples/src/bin/specialization-constants.rs +++ b/examples/src/bin/specialization-constants.rs @@ -13,8 +13,9 @@ use std::sync::Arc; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; -use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::{Instance, InstanceExtensions}; use vulkano::pipeline::{ComputePipeline, ComputePipelineAbstract}; use vulkano::sync; use vulkano::sync::GpuFuture; @@ -28,10 +29,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_compute()) @@ -55,7 +53,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/teapot/main.rs b/examples/src/bin/teapot/main.rs index 4f6415e0..3e03ef47 100644 --- a/examples/src/bin/teapot/main.rs +++ b/examples/src/bin/teapot/main.rs @@ -18,12 +18,13 @@ use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::format::Format; use vulkano::image::attachment::AttachmentImage; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::vertex::TwoBuffersDefinition; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract}; @@ -55,10 +56,7 @@ fn main() { ..DeviceExtensions::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter_map(|p| { p.queue_families() .find(|&q| q.supports_graphics() && surface.is_supported(q).unwrap_or(false)) @@ -82,7 +80,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &Features::none(), - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/tessellation.rs b/examples/src/bin/tessellation.rs index 4def3905..6139991e 100644 --- a/examples/src/bin/tessellation.rs +++ b/examples/src/bin/tessellation.rs @@ -23,10 +23,11 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::render_pass::{Framebuffer, FramebufferAbstract, RenderPass, Subpass}; @@ -154,10 +155,7 @@ fn main() { ..Features::none() }; let (physical_device, queue_family) = PhysicalDevice::enumerate(&instance) - .filter(|&p| { - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions - }) + .filter(|&p| p.supported_extensions().intersection(&device_extensions) == device_extensions) .filter(|&p| p.supported_features().superset_of(&features)) .filter_map(|p| { p.queue_families() @@ -182,7 +180,9 @@ fn main() { let (device, mut queues) = Device::new( physical_device, &features, - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index 8058af7a..6f50d587 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -21,10 +21,11 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::command_buffer::{ AutoCommandBufferBuilder, CommandBufferUsage, DynamicState, SubpassContents, }; +use vulkano::device::physical::{PhysicalDevice, PhysicalDeviceType}; use vulkano::device::{Device, DeviceExtensions, Features}; use vulkano::image::view::ImageView; use vulkano::image::{ImageUsage, SwapchainImage}; -use vulkano::instance::{Instance, PhysicalDevice, PhysicalDeviceType}; +use vulkano::instance::Instance; use vulkano::pipeline::viewport::Viewport; use vulkano::pipeline::GraphicsPipeline; use vulkano::render_pass::{Framebuffer, FramebufferAbstract, RenderPass, Subpass}; @@ -81,8 +82,7 @@ fn main() { // Some devices may not support the extensions or features that your application, or // report properties and limits that are not sufficient for your application. These // should be filtered out here. - DeviceExtensions::supported_by_device(p).intersection(&device_extensions) - == device_extensions + p.supported_extensions().intersection(&device_extensions) == device_extensions }) .filter_map(|p| { // For each physical device, we try to find a suitable queue family that will execute @@ -159,7 +159,9 @@ fn main() { // Some devices require certain extensions to be enabled if they are present // (e.g. `khr_portability_subset`). We add them to the device extensions that we're going to // enable. - &DeviceExtensions::required_extensions(physical_device).union(&device_extensions), + &physical_device + .required_extensions() + .union(&device_extensions), [(queue_family, 0.5)].iter().cloned(), ) .unwrap(); diff --git a/vulkano-shaders/src/codegen.rs b/vulkano-shaders/src/codegen.rs index c3dc03b7..e87b8ab7 100644 --- a/vulkano-shaders/src/codegen.rs +++ b/vulkano-shaders/src/codegen.rs @@ -233,7 +233,7 @@ where (1, 4) => { cap_checks.push(quote! { if device.api_version() < Version::V1_2 - && !device.loaded_extensions().khr_spirv_1_4 { + && !device.enabled_extensions().khr_spirv_1_4 { panic!("Device API version 1.2 or extension VK_KHR_spirv_1_4 required"); } }); @@ -283,7 +283,7 @@ where for extension in extensions { let ident = Ident::new(extension, Span::call_site()); cap_checks.push(quote! { - if !device.loaded_extensions().#ident { + if !device.enabled_extensions().#ident { panic!("Device extension {:?} required", #extension); } }); diff --git a/vulkano-win/src/winit.rs b/vulkano-win/src/winit.rs index fba68637..2223b304 100644 --- a/vulkano-win/src/winit.rs +++ b/vulkano-win/src/winit.rs @@ -151,7 +151,7 @@ unsafe fn winit_to_surface>( _ => { // No wayland display found, check if we can use xlib. // If not, we use xcb. - if instance.loaded_extensions().khr_xlib_surface { + if instance.enabled_extensions().khr_xlib_surface { Surface::from_xlib( instance, win.borrow().xlib_display().unwrap(), diff --git a/vulkano/autogen/properties.rs b/vulkano/autogen/properties.rs index 94e49e51..99f89045 100644 --- a/vulkano/autogen/properties.rs +++ b/vulkano/autogen/properties.rs @@ -328,21 +328,21 @@ fn vulkano_type(ty: &str, len: Option<&str>) -> &'static str { "uint32_t" => "u32", "uint64_t" => "u64", "VkBool32" => "bool", - "VkConformanceVersion" => "crate::instance::ConformanceVersion", + "VkConformanceVersion" => "crate::device::physical::ConformanceVersion", "VkDeviceSize" => "u64", - "VkDriverId" => "crate::instance::DriverId", + "VkDriverId" => "crate::device::physical::DriverId", "VkExtent2D" => "[u32; 2]", - "VkPhysicalDeviceType" => "crate::instance::PhysicalDeviceType", - "VkPointClippingBehavior" => "crate::instance::PointClippingBehavior", + "VkPhysicalDeviceType" => "crate::device::physical::PhysicalDeviceType", + "VkPointClippingBehavior" => "crate::device::physical::PointClippingBehavior", "VkResolveModeFlags" => "crate::render_pass::ResolveModes", "VkSampleCountFlags" => "crate::image::SampleCounts", "VkSampleCountFlagBits" => "crate::image::SampleCount", - "VkShaderCorePropertiesFlagsAMD" => "crate::instance::ShaderCoreProperties", + "VkShaderCorePropertiesFlagsAMD" => "crate::device::physical::ShaderCoreProperties", "VkShaderFloatControlsIndependence" => { - "crate::instance::ShaderFloatControlsIndependence" + "crate::device::physical::ShaderFloatControlsIndependence" } "VkShaderStageFlags" => "crate::descriptor::descriptor::ShaderStages", - "VkSubgroupFeatureFlags" => "crate::instance::SubgroupFeatures", + "VkSubgroupFeatureFlags" => "crate::device::physical::SubgroupFeatures", _ => unimplemented!("{}", ty), } } diff --git a/vulkano/src/buffer/cpu_access.rs b/vulkano/src/buffer/cpu_access.rs index a0728342..eb04cb9d 100644 --- a/vulkano/src/buffer/cpu_access.rs +++ b/vulkano/src/buffer/cpu_access.rs @@ -22,11 +22,11 @@ use crate::buffer::traits::BufferAccess; use crate::buffer::traits::BufferInner; use crate::buffer::traits::TypedBufferAccess; use crate::buffer::BufferUsage; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; use crate::device::Queue; use crate::image::ImageAccess; -use crate::instance::QueueFamily; use crate::memory::pool::AllocFromRequirementsFilter; use crate::memory::pool::AllocLayout; use crate::memory::pool::MappingRequirement; diff --git a/vulkano/src/buffer/device_local.rs b/vulkano/src/buffer/device_local.rs index 76248c08..16e35d0e 100644 --- a/vulkano/src/buffer/device_local.rs +++ b/vulkano/src/buffer/device_local.rs @@ -19,11 +19,11 @@ use crate::buffer::traits::BufferAccess; use crate::buffer::traits::BufferInner; use crate::buffer::traits::TypedBufferAccess; use crate::buffer::BufferUsage; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; use crate::device::Queue; use crate::image::ImageAccess; -use crate::instance::QueueFamily; use crate::memory::pool::AllocFromRequirementsFilter; use crate::memory::pool::AllocLayout; use crate::memory::pool::MappingRequirement; @@ -170,8 +170,8 @@ impl DeviceLocalBuffer { where I: IntoIterator>, { - assert!(device.loaded_extensions().khr_external_memory_fd); - assert!(device.loaded_extensions().khr_external_memory); + assert!(device.enabled_extensions().khr_external_memory_fd); + assert!(device.enabled_extensions().khr_external_memory); let queue_families = queue_families .into_iter() diff --git a/vulkano/src/buffer/immutable.rs b/vulkano/src/buffer/immutable.rs index 91b8ce25..5f645bcb 100644 --- a/vulkano/src/buffer/immutable.rs +++ b/vulkano/src/buffer/immutable.rs @@ -30,11 +30,11 @@ use crate::command_buffer::CommandBufferExecFuture; use crate::command_buffer::CommandBufferUsage; use crate::command_buffer::PrimaryAutoCommandBuffer; use crate::command_buffer::PrimaryCommandBuffer; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; use crate::device::Queue; use crate::image::ImageAccess; -use crate::instance::QueueFamily; use crate::memory::pool::AllocFromRequirementsFilter; use crate::memory::pool::AllocLayout; use crate::memory::pool::MappingRequirement; diff --git a/vulkano/src/buffer/sys.rs b/vulkano/src/buffer/sys.rs index 30f82727..e95f8cd0 100644 --- a/vulkano/src/buffer/sys.rs +++ b/vulkano/src/buffer/sys.rs @@ -155,14 +155,14 @@ impl UnsafeBuffer { } let mut output = if device.api_version() >= Version::V1_1 - || device.loaded_extensions().khr_get_memory_requirements2 + || device.enabled_extensions().khr_get_memory_requirements2 { let infos = ash::vk::BufferMemoryRequirementsInfo2 { buffer: buffer, ..Default::default() }; - let mut output2 = if device.loaded_extensions().khr_dedicated_allocation { + let mut output2 = if device.enabled_extensions().khr_dedicated_allocation { Some(ash::vk::MemoryDedicatedRequirementsKHR::default()) } else { None diff --git a/vulkano/src/command_buffer/auto.rs b/vulkano/src/command_buffer/auto.rs index a5d00e93..778f4111 100644 --- a/vulkano/src/command_buffer/auto.rs +++ b/vulkano/src/command_buffer/auto.rs @@ -39,6 +39,7 @@ use crate::command_buffer::StateCacherOutcome; use crate::command_buffer::SubpassContents; use crate::descriptor::descriptor::{DescriptorBufferDesc, DescriptorDescTy}; use crate::descriptor::descriptor_set::{DescriptorSetDesc, DescriptorSetsCollection}; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; use crate::device::Queue; @@ -49,7 +50,6 @@ use crate::image::ImageAccess; use crate::image::ImageAspect; use crate::image::ImageAspects; use crate::image::ImageLayout; -use crate::instance::QueueFamily; use crate::pipeline::input_assembly::Index; use crate::pipeline::layout::PipelineLayout; use crate::pipeline::vertex::VertexSource; @@ -2796,10 +2796,10 @@ mod tests { use crate::command_buffer::CommandBufferUsage; use crate::command_buffer::ExecuteCommandsError; use crate::command_buffer::PrimaryCommandBuffer; + use crate::device::physical::PhysicalDevice; use crate::device::Device; use crate::device::DeviceExtensions; use crate::device::Features; - use crate::instance; use crate::sync::GpuFuture; use std::sync::Arc; @@ -2807,7 +2807,7 @@ mod tests { fn copy_buffer_dimensions() { let instance = instance!(); - let phys = match instance::PhysicalDevice::enumerate(&instance).next() { + let phys = match PhysicalDevice::enumerate(&instance).next() { Some(p) => p, None => return, }; diff --git a/vulkano/src/command_buffer/pool/mod.rs b/vulkano/src/command_buffer/pool/mod.rs index 07f54d31..e7a6fb6c 100644 --- a/vulkano/src/command_buffer/pool/mod.rs +++ b/vulkano/src/command_buffer/pool/mod.rs @@ -16,7 +16,7 @@ //! trait. By default vulkano will use the `StandardCommandPool` struct, but you can implement //! this trait yourself by wrapping around the `UnsafeCommandPool` type. -use crate::instance::QueueFamily; +use crate::device::physical::QueueFamily; use crate::device::DeviceOwned; use crate::OomError; diff --git a/vulkano/src/command_buffer/pool/standard.rs b/vulkano/src/command_buffer/pool/standard.rs index 1bc800bf..a98ff965 100644 --- a/vulkano/src/command_buffer/pool/standard.rs +++ b/vulkano/src/command_buffer/pool/standard.rs @@ -23,7 +23,7 @@ use crate::command_buffer::pool::CommandPoolAlloc; use crate::command_buffer::pool::CommandPoolBuilderAlloc; use crate::command_buffer::pool::UnsafeCommandPool; use crate::command_buffer::pool::UnsafeCommandPoolAlloc; -use crate::instance::QueueFamily; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; diff --git a/vulkano/src/command_buffer/pool/sys.rs b/vulkano/src/command_buffer/pool/sys.rs index 9887da01..1748f92c 100644 --- a/vulkano/src/command_buffer/pool/sys.rs +++ b/vulkano/src/command_buffer/pool/sys.rs @@ -8,9 +8,9 @@ // according to those terms. use crate::check_errors; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; -use crate::instance::QueueFamily; use crate::Error; use crate::OomError; use crate::Version; @@ -149,7 +149,7 @@ impl UnsafeCommandPool { pub fn trim(&self) -> Result<(), CommandPoolTrimError> { unsafe { if !(self.device.api_version() >= Version::V1_1 - || self.device.loaded_extensions().khr_maintenance1) + || self.device.enabled_extensions().khr_maintenance1) { return Err(CommandPoolTrimError::Maintenance1ExtensionNotEnabled); } diff --git a/vulkano/src/command_buffer/submit/queue_present.rs b/vulkano/src/command_buffer/submit/queue_present.rs index bd245754..28f4229a 100644 --- a/vulkano/src/command_buffer/submit/queue_present.rs +++ b/vulkano/src/command_buffer/submit/queue_present.rs @@ -98,7 +98,7 @@ impl<'a> SubmitPresentBuilder<'a> { if swapchain .device() - .loaded_extensions() + .enabled_extensions() .khr_incremental_present { let vk_present_region = match present_region { @@ -141,7 +141,7 @@ impl<'a> SubmitPresentBuilder<'a> { let present_regions = { if !self.present_regions.is_empty() { - debug_assert!(queue.device().loaded_extensions().khr_incremental_present); + debug_assert!(queue.device().enabled_extensions().khr_incremental_present); debug_assert_eq!(self.swapchains.len(), self.present_regions.len()); let mut current_index = 0; for present_region in &mut self.present_regions { diff --git a/vulkano/src/command_buffer/validity/query.rs b/vulkano/src/command_buffer/validity/query.rs index 45c18b86..b5a4d245 100644 --- a/vulkano/src/command_buffer/validity/query.rs +++ b/vulkano/src/command_buffer/validity/query.rs @@ -8,9 +8,9 @@ // according to those terms. use crate::buffer::TypedBufferAccess; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::DeviceOwned; -use crate::instance::QueueFamily; use crate::query::GetResultsError; use crate::query::QueryControlFlags; use crate::query::QueryPool; diff --git a/vulkano/src/device/extensions.rs b/vulkano/src/device/extensions.rs index 7203e281..b6d0c440 100644 --- a/vulkano/src/device/extensions.rs +++ b/vulkano/src/device/extensions.rs @@ -7,14 +7,10 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::check_errors; +use crate::device::physical::PhysicalDevice; pub use crate::extensions::{ ExtensionRestriction, ExtensionRestrictionError, SupportedExtensionsError, }; -use crate::instance::PhysicalDevice; -use crate::VulkanObject; -use std::ffi::CStr; -use std::ptr; macro_rules! device_extensions { ( @@ -118,52 +114,33 @@ pub(crate) use device_extensions; impl DeviceExtensions { /// See the docs of supported_by_device(). + #[deprecated( + since = "0.25", + note = "Use PhysicalDevice::supported_extensions instead" + )] pub fn supported_by_device_raw( physical_device: PhysicalDevice, ) -> Result { - let fns = physical_device.instance().fns(); - - let properties: Vec = unsafe { - let mut num = 0; - check_errors(fns.v1_0.enumerate_device_extension_properties( - physical_device.internal_object(), - ptr::null(), - &mut num, - ptr::null_mut(), - ))?; - - let mut properties = Vec::with_capacity(num as usize); - check_errors(fns.v1_0.enumerate_device_extension_properties( - physical_device.internal_object(), - ptr::null(), - &mut num, - properties.as_mut_ptr(), - ))?; - properties.set_len(num as usize); - properties - }; - - Ok(Self::from(properties.iter().map(|property| unsafe { - CStr::from_ptr(property.extension_name.as_ptr()) - }))) + Ok(*physical_device.supported_extensions()) } /// Returns a `DeviceExtensions` object with extensions supported by the `PhysicalDevice`. + #[deprecated( + since = "0.25", + note = "Use PhysicalDevice::supported_extensions instead" + )] pub fn supported_by_device(physical_device: PhysicalDevice) -> Self { - match DeviceExtensions::supported_by_device_raw(physical_device) { - Ok(l) => l, - Err(SupportedExtensionsError::LoadingError(_)) => unreachable!(), - Err(SupportedExtensionsError::OomError(e)) => panic!("{:?}", e), - } + *physical_device.supported_extensions() } /// Returns a `DeviceExtensions` object with extensions required as well as supported by the `PhysicalDevice`. /// They are needed to be passed to `Device::new(...)`. + #[deprecated( + since = "0.25", + note = "Use PhysicalDevice::required_extensions instead" + )] pub fn required_extensions(physical_device: PhysicalDevice) -> Self { - let supported = Self::supported_by_device(physical_device); - let required_if_supported = Self::required_if_supported_extensions(); - - required_if_supported.intersection(&supported) + *physical_device.required_extensions() } } diff --git a/vulkano/src/device/features.rs b/vulkano/src/device/features.rs index 59675c33..e028d826 100644 --- a/vulkano/src/device/features.rs +++ b/vulkano/src/device/features.rs @@ -31,7 +31,7 @@ macro_rules! features { /// /// ``` /// use vulkano::device::Features; - /// # let physical_device: vulkano::instance::PhysicalDevice = return; + /// # let physical_device: vulkano::device::physical::PhysicalDevice = return; /// let minimal_features = Features { /// geometry_shader: true, /// .. Features::none() diff --git a/vulkano/src/device/mod.rs b/vulkano/src/device/mod.rs index 411a9c87..2575e91a 100644 --- a/vulkano/src/device/mod.rs +++ b/vulkano/src/device/mod.rs @@ -20,7 +20,7 @@ //! use vulkano::device::Features; //! use vulkano::instance::Instance; //! use vulkano::instance::InstanceExtensions; -//! use vulkano::instance::PhysicalDevice; +//! use vulkano::device::physical::PhysicalDevice; //! use vulkano::Version; //! //! // Creating the instance. See the documentation of the `instance` module. @@ -98,6 +98,8 @@ pub use crate::autogen::DeviceExtensions; use crate::check_errors; use crate::command_buffer::pool::StandardCommandPool; use crate::descriptor::descriptor_set::StdDescriptorPool; +use crate::device::physical::PhysicalDevice; +use crate::device::physical::QueueFamily; pub use crate::extensions::{ ExtensionRestriction, ExtensionRestrictionError, SupportedExtensionsError, }; @@ -109,8 +111,6 @@ use crate::image::ImageTiling; use crate::image::ImageType; use crate::image::ImageUsage; use crate::instance::Instance; -use crate::instance::PhysicalDevice; -use crate::instance::QueueFamily; use crate::memory::pool::StdMemoryPool; use crate::Error; use crate::OomError; @@ -140,6 +140,7 @@ use std::sync::Weak; pub(crate) mod extensions; pub(crate) mod features; +pub mod physical; pub(crate) mod properties; /// Represents a Vulkan context. @@ -207,9 +208,9 @@ impl Device { // Check if the extensions are correct requested_extensions.check_requirements( - &DeviceExtensions::supported_by_device(physical_device), + physical_device.supported_extensions(), api_version, - instance.loaded_extensions(), + instance.enabled_extensions(), )?; let mut requested_features = requested_features.clone(); @@ -290,7 +291,7 @@ impl Device { features_ffi.make_chain( api_version, requested_extensions, - instance.loaded_extensions(), + instance.enabled_extensions(), ); features_ffi.write(&requested_features); @@ -304,7 +305,7 @@ impl Device { // to save it alongside the instance. (`vkEnumerateDeviceLayerProperties` should get // the right list post-1.0.13, but not pre-1.0.13, so we can't use it here.) let layers_ptrs = instance - .loaded_layers() + .enabled_layers() .map(|layer| layer.as_ptr()) .collect::>(); @@ -315,7 +316,7 @@ impl Device { .collect::>(); let has_khr_get_physical_device_properties2 = instance - .loaded_extensions() + .enabled_extensions() .khr_get_physical_device_properties2; let infos = ash::vk::DeviceCreateInfo { @@ -465,7 +466,7 @@ impl Device { /// Returns the extensions that have been enabled on the device. #[inline] - pub fn loaded_extensions(&self) -> &DeviceExtensions { + pub fn enabled_extensions(&self) -> &DeviceExtensions { &self.extensions } @@ -937,11 +938,11 @@ unsafe impl SynchronizedVulkanObject for Queue { #[cfg(test)] mod tests { + use crate::device::physical::PhysicalDevice; use crate::device::Device; use crate::device::DeviceCreationError; use crate::device::DeviceExtensions; use crate::device::{FeatureRestriction, FeatureRestrictionError, Features}; - use crate::instance; use std::sync::Arc; #[test] @@ -953,7 +954,7 @@ mod tests { #[test] fn too_many_queues() { let instance = instance!(); - let physical = match instance::PhysicalDevice::enumerate(&instance).next() { + let physical = match PhysicalDevice::enumerate(&instance).next() { Some(p) => p, None => return, }; @@ -975,7 +976,7 @@ mod tests { #[test] fn unsupposed_features() { let instance = instance!(); - let physical = match instance::PhysicalDevice::enumerate(&instance).next() { + let physical = match PhysicalDevice::enumerate(&instance).next() { Some(p) => p, None => return, }; @@ -1005,7 +1006,7 @@ mod tests { #[test] fn priority_out_of_range() { let instance = instance!(); - let physical = match instance::PhysicalDevice::enumerate(&instance).next() { + let physical = match PhysicalDevice::enumerate(&instance).next() { Some(p) => p, None => return, }; diff --git a/vulkano/src/instance/physical_device.rs b/vulkano/src/device/physical.rs similarity index 59% rename from vulkano/src/instance/physical_device.rs rename to vulkano/src/device/physical.rs index 73641f65..833a6f4f 100644 --- a/vulkano/src/instance/physical_device.rs +++ b/vulkano/src/device/physical.rs @@ -21,13 +21,25 @@ use std::mem::MaybeUninit; use std::ptr; use std::sync::Arc; -pub(super) fn init_physical_devices( - instance: &Instance, -) -> Result, InstanceCreationError> { - let fns = instance.fns(); - let instance_extensions = instance.loaded_extensions(); +#[derive(Clone, Debug)] +pub(crate) struct PhysicalDeviceInfo { + handle: ash::vk::PhysicalDevice, + api_version: Version, + supported_extensions: DeviceExtensions, + required_extensions: DeviceExtensions, + supported_features: Features, + properties: Properties, + memory_properties: ash::vk::PhysicalDeviceMemoryProperties, + queue_families: Vec, +} - let physical_devices: Vec = unsafe { +pub(crate) fn init_physical_devices( + instance: &Instance, +) -> Result, InstanceCreationError> { + let fns = instance.fns(); + let instance_extensions = instance.enabled_extensions(); + + let handles: Vec = unsafe { let mut num = 0; check_errors(fns.v1_0.enumerate_physical_devices( instance.internal_object(), @@ -35,23 +47,24 @@ pub(super) fn init_physical_devices( ptr::null_mut(), ))?; - let mut devices = Vec::with_capacity(num as usize); + let mut handles = Vec::with_capacity(num as usize); check_errors(fns.v1_0.enumerate_physical_devices( instance.internal_object(), &mut num, - devices.as_mut_ptr(), + handles.as_mut_ptr(), ))?; - devices.set_len(num as usize); - devices + handles.set_len(num as usize); + handles }; - let info: Vec<_> = physical_devices + let mut infos: Vec = handles .into_iter() - .map(|physical_device| -> Result<_, InstanceCreationError> { + .enumerate() + .map(|(index, handle)| -> Result<_, InstanceCreationError> { let api_version = unsafe { let mut output = MaybeUninit::uninit(); fns.v1_0 - .get_physical_device_properties(physical_device, output.as_mut_ptr()); + .get_physical_device_properties(handle, output.as_mut_ptr()); let api_version = Version::try_from(output.assume_init().api_version).unwrap(); std::cmp::min(instance.max_api_version(), api_version) }; @@ -59,7 +72,7 @@ pub(super) fn init_physical_devices( let extension_properties: Vec = unsafe { let mut num = 0; check_errors(fns.v1_0.enumerate_device_extension_properties( - physical_device, + handle, ptr::null(), &mut num, ptr::null_mut(), @@ -67,7 +80,7 @@ pub(super) fn init_physical_devices( let mut properties = Vec::with_capacity(num as usize); check_errors(fns.v1_0.enumerate_device_extension_properties( - physical_device, + handle, ptr::null(), &mut num, properties.as_mut_ptr(), @@ -76,220 +89,191 @@ pub(super) fn init_physical_devices( properties }; - let extensions = DeviceExtensions::from( + let supported_extensions = DeviceExtensions::from( extension_properties .iter() .map(|property| unsafe { CStr::from_ptr(property.extension_name.as_ptr()) }), ); - Ok((physical_device, api_version, extensions)) + let required_extensions = supported_extensions + .intersection(&DeviceExtensions::required_if_supported_extensions()); + + Ok(PhysicalDeviceInfo { + handle, + api_version, + supported_extensions, + required_extensions, + supported_features: Default::default(), + properties: Default::default(), + memory_properties: Default::default(), + queue_families: Default::default(), + }) }) .collect::>()?; - // Getting the properties of all physical devices. + // Getting the remaining infos. // If possible, we use VK_KHR_get_physical_device_properties2. - let physical_devices = if instance.api_version() >= Version::V1_1 + if instance.api_version() >= Version::V1_1 || instance_extensions.khr_get_physical_device_properties2 { - init_physical_devices_inner2(instance, info) + init_physical_devices_inner2(instance, &mut infos) } else { - init_physical_devices_inner(instance, info) + init_physical_devices_inner(instance, &mut infos) }; - Ok(physical_devices) + Ok(infos) } /// Initialize all physical devices -fn init_physical_devices_inner(instance: &Instance, info: I) -> Vec -where - I: IntoIterator, -{ +fn init_physical_devices_inner(instance: &Instance, infos: &mut [PhysicalDeviceInfo]) { let fns = instance.fns(); - info.into_iter() - .map(|(physical_device, api_version, supported_extensions)| { - let properties: Properties = unsafe { - let mut output = PropertiesFfi::default(); - output.make_chain( - api_version, - &supported_extensions, - instance.loaded_extensions(), - ); - fns.v1_0.get_physical_device_properties( - physical_device, - &mut output.head_as_mut().properties, - ); - Properties::from(&output) - }; + for info in infos.into_iter() { + info.supported_features = unsafe { + let mut output = FeaturesFfi::default(); + fns.v1_0 + .get_physical_device_features(info.handle, &mut output.head_as_mut().features); + Features::from(&output) + }; - let queue_families = unsafe { - let mut num = 0; - fns.v1_0.get_physical_device_queue_family_properties( - physical_device, - &mut num, - ptr::null_mut(), - ); + info.properties = unsafe { + let mut output = PropertiesFfi::default(); + output.make_chain( + info.api_version, + &info.supported_extensions, + instance.enabled_extensions(), + ); + fns.v1_0 + .get_physical_device_properties(info.handle, &mut output.head_as_mut().properties); + Properties::from(&output) + }; - let mut families = Vec::with_capacity(num as usize); - fns.v1_0.get_physical_device_queue_family_properties( - physical_device, - &mut num, - families.as_mut_ptr(), - ); - families.set_len(num as usize); - families - }; + info.memory_properties = unsafe { + let mut output = MaybeUninit::uninit(); + fns.v1_0 + .get_physical_device_memory_properties(info.handle, output.as_mut_ptr()); + output.assume_init() + }; - let memory_properties: ash::vk::PhysicalDeviceMemoryProperties = unsafe { - let mut output = MaybeUninit::uninit(); - fns.v1_0 - .get_physical_device_memory_properties(physical_device, output.as_mut_ptr()); - output.assume_init() - }; + info.queue_families = unsafe { + let mut num = 0; + fns.v1_0.get_physical_device_queue_family_properties( + info.handle, + &mut num, + ptr::null_mut(), + ); - let available_features: Features = unsafe { - let mut output = FeaturesFfi::default(); - fns.v1_0.get_physical_device_features( - physical_device, - &mut output.head_as_mut().features, - ); - Features::from(&output) - }; - - PhysicalDeviceInfos { - physical_device, - api_version, - properties, - memory_properties, - queue_families, - available_features, - } - }) - .collect() + let mut families = Vec::with_capacity(num as usize); + fns.v1_0.get_physical_device_queue_family_properties( + info.handle, + &mut num, + families.as_mut_ptr(), + ); + families.set_len(num as usize); + families + }; + } } /// Initialize all physical devices, but use VK_KHR_get_physical_device_properties2 /// TODO: Query extension-specific physical device properties, once a new instance extension is supported. -fn init_physical_devices_inner2(instance: &Instance, info: I) -> Vec -where - I: IntoIterator, -{ +fn init_physical_devices_inner2(instance: &Instance, infos: &mut [PhysicalDeviceInfo]) { let fns = instance.fns(); - info.into_iter() - .map(|(physical_device, api_version, supported_extensions)| { - let properties: Properties = unsafe { - let mut output = PropertiesFfi::default(); - output.make_chain( - api_version, - &supported_extensions, - instance.loaded_extensions(), + for info in infos.into_iter() { + info.supported_features = unsafe { + let mut output = FeaturesFfi::default(); + output.make_chain( + info.api_version, + &info.supported_extensions, + instance.enabled_extensions(), + ); + + if instance.api_version() >= Version::V1_1 { + fns.v1_1 + .get_physical_device_features2(info.handle, output.head_as_mut()); + } else { + fns.khr_get_physical_device_properties2 + .get_physical_device_features2_khr(info.handle, output.head_as_mut()); + } + + Features::from(&output) + }; + + info.properties = unsafe { + let mut output = PropertiesFfi::default(); + output.make_chain( + info.api_version, + &info.supported_extensions, + instance.enabled_extensions(), + ); + + if instance.api_version() >= Version::V1_1 { + fns.v1_1 + .get_physical_device_properties2(info.handle, output.head_as_mut()); + } else { + fns.khr_get_physical_device_properties2 + .get_physical_device_properties2_khr(info.handle, output.head_as_mut()); + } + + Properties::from(&output) + }; + + info.memory_properties = unsafe { + let mut output = ash::vk::PhysicalDeviceMemoryProperties2KHR::default(); + + if instance.api_version() >= Version::V1_1 { + fns.v1_1 + .get_physical_device_memory_properties2(info.handle, &mut output); + } else { + fns.khr_get_physical_device_properties2 + .get_physical_device_memory_properties2_khr(info.handle, &mut output); + } + + output.memory_properties + }; + + info.queue_families = unsafe { + let mut num = 0; + + if instance.api_version() >= Version::V1_1 { + fns.v1_1.get_physical_device_queue_family_properties2( + info.handle, + &mut num, + ptr::null_mut(), ); - - if instance.api_version() >= Version::V1_1 { - fns.v1_1 - .get_physical_device_properties2(physical_device, output.head_as_mut()); - } else { - fns.khr_get_physical_device_properties2 - .get_physical_device_properties2_khr(physical_device, output.head_as_mut()); - } - - Properties::from(&output) - }; - - let queue_families = unsafe { - let mut num = 0; - - if instance.api_version() >= Version::V1_1 { - fns.v1_1.get_physical_device_queue_family_properties2( - physical_device, + } else { + fns.khr_get_physical_device_properties2 + .get_physical_device_queue_family_properties2_khr( + info.handle, &mut num, ptr::null_mut(), ); - } else { - fns.khr_get_physical_device_properties2 - .get_physical_device_queue_family_properties2_khr( - physical_device, - &mut num, - ptr::null_mut(), - ); - } + } - let mut families = vec![ash::vk::QueueFamilyProperties2::default(); num as usize]; + let mut families = vec![ash::vk::QueueFamilyProperties2::default(); num as usize]; - if instance.api_version() >= Version::V1_1 { - fns.v1_1.get_physical_device_queue_family_properties2( - physical_device, + if instance.api_version() >= Version::V1_1 { + fns.v1_1.get_physical_device_queue_family_properties2( + info.handle, + &mut num, + families.as_mut_ptr(), + ); + } else { + fns.khr_get_physical_device_properties2 + .get_physical_device_queue_family_properties2_khr( + info.handle, &mut num, families.as_mut_ptr(), ); - } else { - fns.khr_get_physical_device_properties2 - .get_physical_device_queue_family_properties2_khr( - physical_device, - &mut num, - families.as_mut_ptr(), - ); - } - - families - .into_iter() - .map(|family| family.queue_family_properties) - .collect() - }; - - let memory_properties: ash::vk::PhysicalDeviceMemoryProperties = unsafe { - let mut output = ash::vk::PhysicalDeviceMemoryProperties2KHR::default(); - - if instance.api_version() >= Version::V1_1 { - fns.v1_1 - .get_physical_device_memory_properties2(physical_device, &mut output); - } else { - fns.khr_get_physical_device_properties2 - .get_physical_device_memory_properties2_khr(physical_device, &mut output); - } - - output.memory_properties - }; - - let available_features: Features = unsafe { - let mut output = FeaturesFfi::default(); - output.make_chain( - api_version, - &supported_extensions, - instance.loaded_extensions(), - ); - - if instance.api_version() >= Version::V1_1 { - fns.v1_1 - .get_physical_device_features2(physical_device, output.head_as_mut()); - } else { - fns.khr_get_physical_device_properties2 - .get_physical_device_features2_khr(physical_device, output.head_as_mut()); - } - - Features::from(&output) - }; - - PhysicalDeviceInfos { - physical_device, - api_version, - properties, - memory_properties, - queue_families, - available_features, } - }) - .collect() -} -pub(super) struct PhysicalDeviceInfos { - physical_device: ash::vk::PhysicalDevice, - api_version: Version, - properties: Properties, - queue_families: Vec, - memory_properties: ash::vk::PhysicalDeviceMemoryProperties, - available_features: Features, + families + .into_iter() + .map(|family| family.queue_family_properties) + .collect() + }; + } } /// Represents one of the available devices on this machine. @@ -303,7 +287,7 @@ pub(super) struct PhysicalDeviceInfos { /// # use vulkano::instance::Instance; /// # use vulkano::instance::InstanceExtensions; /// # use vulkano::Version; -/// use vulkano::instance::PhysicalDevice; +/// use vulkano::device::physical::PhysicalDevice; /// /// # let instance = Instance::new(None, Version::V1_1, &InstanceExtensions::none(), None).unwrap(); /// for physical_device in PhysicalDevice::enumerate(&instance) { @@ -314,10 +298,11 @@ pub(super) struct PhysicalDeviceInfos { /// println!("Name: {}", dev.properties().device_name.as_ref().unwrap()); /// } /// ``` -#[derive(Debug, Copy, Clone)] +#[derive(Clone, Copy, Debug)] pub struct PhysicalDevice<'a> { instance: &'a Arc, - device: usize, + index: usize, + info: &'a PhysicalDeviceInfo, } impl<'a> PhysicalDevice<'a> { @@ -329,7 +314,7 @@ impl<'a> PhysicalDevice<'a> { /// # use vulkano::instance::Instance; /// # use vulkano::instance::InstanceExtensions; /// # use vulkano::Version; - /// use vulkano::instance::PhysicalDevice; + /// use vulkano::device::physical::PhysicalDevice; /// /// # let instance = Instance::new(None, Version::V1_1, &InstanceExtensions::none(), None).unwrap(); /// for physical_device in PhysicalDevice::enumerate(&instance) { @@ -337,11 +322,18 @@ impl<'a> PhysicalDevice<'a> { /// } /// ``` #[inline] - pub fn enumerate(instance: &'a Arc) -> PhysicalDevicesIter<'a> { - PhysicalDevicesIter { - instance, - current_id: 0, - } + pub fn enumerate( + instance: &'a Arc, + ) -> impl ExactSizeIterator> { + instance + .physical_device_infos + .iter() + .enumerate() + .map(move |(index, info)| PhysicalDevice { + instance, + index, + info, + }) } /// Returns a physical device from its index. Returns `None` if out of range. @@ -353,7 +345,7 @@ impl<'a> PhysicalDevice<'a> { /// ```no_run /// use vulkano::instance::Instance; /// use vulkano::instance::InstanceExtensions; - /// use vulkano::instance::PhysicalDevice; + /// use vulkano::device::physical::PhysicalDevice; /// use vulkano::Version; /// /// let instance = Instance::new(None, Version::V1_1, &InstanceExtensions::none(), None).unwrap(); @@ -361,14 +353,14 @@ impl<'a> PhysicalDevice<'a> { /// ``` #[inline] pub fn from_index(instance: &'a Arc, index: usize) -> Option> { - if instance.physical_devices.len() > index { - Some(PhysicalDevice { + instance + .physical_device_infos + .get(index) + .map(|info| PhysicalDevice { instance, - device: index, + index, + info, }) - } else { - None - } } /// Returns the instance corresponding to this physical device. @@ -376,10 +368,10 @@ impl<'a> PhysicalDevice<'a> { /// # Example /// /// ```no_run - /// use vulkano::instance::PhysicalDevice; + /// use vulkano::device::physical::PhysicalDevice; /// /// fn do_something(physical_device: PhysicalDevice) { - /// let _loaded_extensions = physical_device.instance().loaded_extensions(); + /// let _loaded_extensions = physical_device.instance().enabled_extensions(); /// // ... /// } /// ``` @@ -394,7 +386,7 @@ impl<'a> PhysicalDevice<'a> { /// instance and an index. #[inline] pub fn index(&self) -> usize { - self.device + self.index } /// Returns the version of Vulkan supported by this device. @@ -404,59 +396,56 @@ impl<'a> PhysicalDevice<'a> { /// `max_api_version`. #[inline] pub fn api_version(&self) -> Version { - self.infos().api_version + self.info.api_version } - /// Returns the Vulkan properties reported by the device. + /// Returns the extensions that are supported by this physical device. + #[inline] + pub fn supported_extensions(&self) -> &'a DeviceExtensions { + &self.info.supported_extensions + } + + /// Returns the extensions that must be enabled as a minimum when creating a `Device` from this + /// physical device. + pub fn required_extensions(&self) -> &'a DeviceExtensions { + &self.info.required_extensions + } + + /// Returns the properties reported by the device. #[inline] pub fn properties(&self) -> &'a Properties { - &self.infos().properties + &self.info.properties } - /// Returns the Vulkan features that are supported by this physical device. + /// Returns the features that are supported by this physical device. #[inline] pub fn supported_features(&self) -> &'a Features { - &self.infos().available_features - } - - /// Builds an iterator that enumerates all the queue families on this physical device. - #[inline] - pub fn queue_families(&self) -> QueueFamiliesIter<'a> { - QueueFamiliesIter { - physical_device: *self, - current_id: 0, - } - } - - /// Returns the queue family with the given index, or `None` if out of range. - #[inline] - pub fn queue_family_by_id(&self, id: u32) -> Option> { - if (id as usize) < self.infos().queue_families.len() { - Some(QueueFamily { - physical_device: *self, - id, - }) - } else { - None - } + &self.info.supported_features } /// Builds an iterator that enumerates all the memory types on this physical device. #[inline] - pub fn memory_types(&self) -> MemoryTypesIter<'a> { - MemoryTypesIter { - physical_device: *self, - current_id: 0, - } + pub fn memory_types(&self) -> impl ExactSizeIterator> { + let physical_device = *self; + self.info.memory_properties.memory_types + [0..self.info.memory_properties.memory_type_count as usize] + .iter() + .enumerate() + .map(move |(id, info)| MemoryType { + physical_device, + id: id as u32, + info, + }) } /// Returns the memory type with the given index, or `None` if out of range. #[inline] pub fn memory_type_by_id(&self, id: u32) -> Option> { - if id < self.infos().memory_properties.memory_type_count { + if id < self.info.memory_properties.memory_type_count { Some(MemoryType { physical_device: *self, id, + info: &self.info.memory_properties.memory_types[id as usize], }) } else { None @@ -465,30 +454,60 @@ impl<'a> PhysicalDevice<'a> { /// Builds an iterator that enumerates all the memory heaps on this physical device. #[inline] - pub fn memory_heaps(&self) -> MemoryHeapsIter<'a> { - MemoryHeapsIter { - physical_device: *self, - current_id: 0, - } + pub fn memory_heaps(&self) -> impl ExactSizeIterator> { + let physical_device = *self; + self.info.memory_properties.memory_heaps + [0..self.info.memory_properties.memory_heap_count as usize] + .iter() + .enumerate() + .map(move |(id, info)| MemoryHeap { + physical_device, + id: id as u32, + info, + }) } /// Returns the memory heap with the given index, or `None` if out of range. #[inline] pub fn memory_heap_by_id(&self, id: u32) -> Option> { - if id < self.infos().memory_properties.memory_heap_count { + if id < self.info.memory_properties.memory_heap_count { Some(MemoryHeap { physical_device: *self, id, + info: &self.info.memory_properties.memory_heaps[id as usize], }) } else { None } } - // Internal function to make it easier to get the infos of this device. + /// Builds an iterator that enumerates all the queue families on this physical device. #[inline] - fn infos(&self) -> &'a PhysicalDeviceInfos { - &self.instance.physical_devices[self.device] + pub fn queue_families(&self) -> impl ExactSizeIterator> { + let physical_device = *self; + self.info + .queue_families + .iter() + .enumerate() + .map(move |(id, properties)| QueueFamily { + physical_device, + id: id as u32, + properties, + }) + } + + /// Returns the queue family with the given index, or `None` if out of range. + #[inline] + pub fn queue_family_by_id(&self, id: u32) -> Option> { + if (id as usize) < self.info.queue_families.len() { + Some(QueueFamily { + physical_device: *self, + id, + properties: &self.info.queue_families[id as usize], + }) + } else { + None + } } } @@ -497,44 +516,10 @@ unsafe impl<'a> VulkanObject for PhysicalDevice<'a> { #[inline] fn internal_object(&self) -> ash::vk::PhysicalDevice { - self.infos().physical_device + self.info.handle } } -/// Iterator for all the physical devices available on hardware. -#[derive(Debug, Clone)] -pub struct PhysicalDevicesIter<'a> { - instance: &'a Arc, - current_id: usize, -} - -impl<'a> Iterator for PhysicalDevicesIter<'a> { - type Item = PhysicalDevice<'a>; - - #[inline] - fn next(&mut self) -> Option> { - if self.current_id >= self.instance.physical_devices.len() { - return None; - } - - let dev = PhysicalDevice { - instance: self.instance, - device: self.current_id, - }; - - self.current_id += 1; - Some(dev) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let len = self.instance.physical_devices.len() - self.current_id; - (len, Some(len)) - } -} - -impl<'a> ExactSizeIterator for PhysicalDevicesIter<'a> {} - /// Type of a physical device. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)] #[repr(i32)] @@ -567,6 +552,119 @@ impl TryFrom for PhysicalDeviceType { } } +/// Represents a memory type in a physical device. +#[derive(Debug, Copy, Clone)] +pub struct MemoryType<'a> { + physical_device: PhysicalDevice<'a>, + id: u32, + info: &'a ash::vk::MemoryType, +} + +impl<'a> MemoryType<'a> { + /// Returns the physical device associated to this memory type. + #[inline] + pub fn physical_device(&self) -> PhysicalDevice<'a> { + self.physical_device + } + + /// Returns the identifier of this memory type within the physical device. + #[inline] + pub fn id(&self) -> u32 { + self.id + } + + /// Returns the heap that corresponds to this memory type. + #[inline] + pub fn heap(&self) -> MemoryHeap<'a> { + self.physical_device + .memory_heap_by_id(self.info.heap_index) + .unwrap() + } + + /// Returns true if the memory type is located on the device, which means that it's the most + /// efficient for GPU accesses. + #[inline] + pub fn is_device_local(&self) -> bool { + !(self.info.property_flags & ash::vk::MemoryPropertyFlags::DEVICE_LOCAL).is_empty() + } + + /// Returns true if the memory type can be accessed by the host. + #[inline] + pub fn is_host_visible(&self) -> bool { + !(self.info.property_flags & ash::vk::MemoryPropertyFlags::HOST_VISIBLE).is_empty() + } + + /// Returns true if modifications made by the host or the GPU on this memory type are + /// instantaneously visible to the other party. False means that changes have to be flushed. + /// + /// You don't need to worry about this, as this library handles that for you. + #[inline] + pub fn is_host_coherent(&self) -> bool { + !(self.info.property_flags & ash::vk::MemoryPropertyFlags::HOST_COHERENT).is_empty() + } + + /// Returns true if memory of this memory type is cached by the host. Host memory accesses to + /// cached memory is faster than for uncached memory. However you are not guaranteed that it + /// is coherent. + #[inline] + pub fn is_host_cached(&self) -> bool { + !(self.info.property_flags & ash::vk::MemoryPropertyFlags::HOST_CACHED).is_empty() + } + + /// Returns true if allocations made to this memory type is lazy. + /// + /// This means that no actual allocation is performed. Instead memory is automatically + /// allocated by the Vulkan implementation. + /// + /// Memory of this type can only be used on images created with a certain flag. Memory of this + /// type is never host-visible. + #[inline] + pub fn is_lazily_allocated(&self) -> bool { + !(self.info.property_flags & ash::vk::MemoryPropertyFlags::LAZILY_ALLOCATED).is_empty() + } +} + +/// Represents a memory heap in a physical device. +#[derive(Debug, Copy, Clone)] +pub struct MemoryHeap<'a> { + physical_device: PhysicalDevice<'a>, + id: u32, + info: &'a ash::vk::MemoryHeap, +} + +impl<'a> MemoryHeap<'a> { + /// Returns the physical device associated to this memory heap. + #[inline] + pub fn physical_device(&self) -> PhysicalDevice<'a> { + self.physical_device + } + + /// Returns the identifier of this memory heap within the physical device. + #[inline] + pub fn id(&self) -> u32 { + self.id + } + + /// Returns the size in bytes on this heap. + #[inline] + pub fn size(&self) -> usize { + self.info.size as usize + } + + /// Returns true if the heap is local to the GPU. + #[inline] + pub fn is_device_local(&self) -> bool { + !(self.info.flags & ash::vk::MemoryHeapFlags::DEVICE_LOCAL).is_empty() + } + + /// Returns true if the heap is multi-instance enabled, that is allocation from such + /// heap will replicate to each physical-device's instance of heap. + #[inline] + pub fn is_multi_instance(&self) -> bool { + !(self.info.flags & ash::vk::MemoryHeapFlags::MULTI_INSTANCE).is_empty() + } +} + /// Represents a queue family in a physical device. /// /// A queue family is group of one or multiple queues. All queues of one family have the same @@ -575,6 +673,7 @@ impl TryFrom for PhysicalDeviceType { pub struct QueueFamily<'a> { physical_device: PhysicalDevice<'a>, id: u32, + properties: &'a ash::vk::QueueFamilyProperties, } impl<'a> QueueFamily<'a> { @@ -595,7 +694,7 @@ impl<'a> QueueFamily<'a> { /// Guaranteed to be at least 1 (or else that family wouldn't exist). #[inline] pub fn queues_count(&self) -> usize { - self.physical_device.infos().queue_families[self.id as usize].queue_count as usize + self.properties.queue_count as usize } /// If timestamps are supported, returns the number of bits supported by timestamp operations. @@ -603,8 +702,7 @@ impl<'a> QueueFamily<'a> { /// If timestamps are not supported, returns None. #[inline] pub fn timestamp_valid_bits(&self) -> Option { - let value = - self.physical_device.infos().queue_families[self.id as usize].timestamp_valid_bits; + let value = self.properties.timestamp_valid_bits; if value == 0 { None } else { @@ -616,21 +714,20 @@ impl<'a> QueueFamily<'a> { /// of `[width, height, depth]` #[inline] pub fn min_image_transfer_granularity(&self) -> [u32; 3] { - let ref granularity = self.physical_device.infos().queue_families[self.id as usize] - .min_image_transfer_granularity; + let ref granularity = self.properties.min_image_transfer_granularity; [granularity.width, granularity.height, granularity.depth] } /// Returns `true` if queues of this family can execute graphics operations. #[inline] pub fn supports_graphics(&self) -> bool { - !(self.flags() & ash::vk::QueueFlags::GRAPHICS).is_empty() + !(self.properties.queue_flags & ash::vk::QueueFlags::GRAPHICS).is_empty() } /// Returns `true` if queues of this family can execute compute operations. #[inline] pub fn supports_compute(&self) -> bool { - !(self.flags() & ash::vk::QueueFlags::COMPUTE).is_empty() + !(self.properties.queue_flags & ash::vk::QueueFlags::COMPUTE).is_empty() } /// Returns `true` if queues of this family can execute transfer operations. @@ -640,25 +737,19 @@ impl<'a> QueueFamily<'a> { /// > to indicate a special relationship with the DMA module and more efficient transfers. #[inline] pub fn explicitly_supports_transfers(&self) -> bool { - !(self.flags() & ash::vk::QueueFlags::TRANSFER).is_empty() + !(self.properties.queue_flags & ash::vk::QueueFlags::TRANSFER).is_empty() } /// Returns `true` if queues of this family can execute sparse resources binding operations. #[inline] pub fn supports_sparse_binding(&self) -> bool { - !(self.flags() & ash::vk::QueueFlags::SPARSE_BINDING).is_empty() + !(self.properties.queue_flags & ash::vk::QueueFlags::SPARSE_BINDING).is_empty() } /// Returns `true` if the queues of this family support a particular pipeline stage. #[inline] pub fn supports_stage(&self, stage: PipelineStage) -> bool { - !(self.flags() & stage.required_queue_flags()).is_empty() - } - - /// Internal utility function that returns the flags of this queue family. - #[inline] - fn flags(&self) -> ash::vk::QueueFlags { - self.physical_device.infos().queue_families[self.id as usize].queue_flags + !(self.properties.queue_flags & stage.required_queue_flags()).is_empty() } } @@ -671,255 +762,6 @@ impl<'a> PartialEq for QueueFamily<'a> { impl<'a> Eq for QueueFamily<'a> {} -/// Iterator for all the queue families available on a physical device. -#[derive(Debug, Clone)] -pub struct QueueFamiliesIter<'a> { - physical_device: PhysicalDevice<'a>, - current_id: u32, -} - -impl<'a> Iterator for QueueFamiliesIter<'a> { - type Item = QueueFamily<'a>; - - #[inline] - fn next(&mut self) -> Option> { - if self.current_id as usize >= self.physical_device.infos().queue_families.len() { - return None; - } - - let dev = QueueFamily { - physical_device: self.physical_device, - id: self.current_id, - }; - - self.current_id += 1; - Some(dev) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let len = self.physical_device.infos().queue_families.len(); - let remain = len - self.current_id as usize; - (remain, Some(remain)) - } -} - -impl<'a> ExactSizeIterator for QueueFamiliesIter<'a> {} - -/// Represents a memory type in a physical device. -#[derive(Debug, Copy, Clone)] -pub struct MemoryType<'a> { - physical_device: PhysicalDevice<'a>, - id: u32, -} - -impl<'a> MemoryType<'a> { - /// Returns the physical device associated to this memory type. - #[inline] - pub fn physical_device(&self) -> PhysicalDevice<'a> { - self.physical_device - } - - /// Returns the identifier of this memory type within the physical device. - #[inline] - pub fn id(&self) -> u32 { - self.id - } - - /// Returns the heap that corresponds to this memory type. - #[inline] - pub fn heap(&self) -> MemoryHeap<'a> { - let heap_id = self.physical_device.infos().memory_properties.memory_types[self.id as usize] - .heap_index; - MemoryHeap { - physical_device: self.physical_device, - id: heap_id, - } - } - - /// Returns true if the memory type is located on the device, which means that it's the most - /// efficient for GPU accesses. - #[inline] - pub fn is_device_local(&self) -> bool { - !(self.flags() & ash::vk::MemoryPropertyFlags::DEVICE_LOCAL).is_empty() - } - - /// Returns true if the memory type can be accessed by the host. - #[inline] - pub fn is_host_visible(&self) -> bool { - !(self.flags() & ash::vk::MemoryPropertyFlags::HOST_VISIBLE).is_empty() - } - - /// Returns true if modifications made by the host or the GPU on this memory type are - /// instantaneously visible to the other party. False means that changes have to be flushed. - /// - /// You don't need to worry about this, as this library handles that for you. - #[inline] - pub fn is_host_coherent(&self) -> bool { - !(self.flags() & ash::vk::MemoryPropertyFlags::HOST_COHERENT).is_empty() - } - - /// Returns true if memory of this memory type is cached by the host. Host memory accesses to - /// cached memory is faster than for uncached memory. However you are not guaranteed that it - /// is coherent. - #[inline] - pub fn is_host_cached(&self) -> bool { - !(self.flags() & ash::vk::MemoryPropertyFlags::HOST_CACHED).is_empty() - } - - /// Returns true if allocations made to this memory type is lazy. - /// - /// This means that no actual allocation is performed. Instead memory is automatically - /// allocated by the Vulkan implementation. - /// - /// Memory of this type can only be used on images created with a certain flag. Memory of this - /// type is never host-visible. - #[inline] - pub fn is_lazily_allocated(&self) -> bool { - !(self.flags() & ash::vk::MemoryPropertyFlags::LAZILY_ALLOCATED).is_empty() - } - - /// Internal utility function that returns the flags of this queue family. - #[inline] - fn flags(&self) -> ash::vk::MemoryPropertyFlags { - self.physical_device.infos().memory_properties.memory_types[self.id as usize].property_flags - } -} - -/// Iterator for all the memory types available on a physical device. -#[derive(Debug, Clone)] -pub struct MemoryTypesIter<'a> { - physical_device: PhysicalDevice<'a>, - current_id: u32, -} - -impl<'a> Iterator for MemoryTypesIter<'a> { - type Item = MemoryType<'a>; - - #[inline] - fn next(&mut self) -> Option> { - if self.current_id - >= self - .physical_device - .infos() - .memory_properties - .memory_type_count - { - return None; - } - - let dev = MemoryType { - physical_device: self.physical_device, - id: self.current_id, - }; - - self.current_id += 1; - Some(dev) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let len = self - .physical_device - .infos() - .memory_properties - .memory_type_count; - let remain = (len - self.current_id) as usize; - (remain, Some(remain)) - } -} - -impl<'a> ExactSizeIterator for MemoryTypesIter<'a> {} - -/// Represents a memory heap in a physical device. -#[derive(Debug, Copy, Clone)] -pub struct MemoryHeap<'a> { - physical_device: PhysicalDevice<'a>, - id: u32, -} - -impl<'a> MemoryHeap<'a> { - /// Returns the physical device associated to this memory heap. - #[inline] - pub fn physical_device(&self) -> PhysicalDevice<'a> { - self.physical_device - } - - /// Returns the identifier of this memory heap within the physical device. - #[inline] - pub fn id(&self) -> u32 { - self.id - } - - /// Returns the size in bytes on this heap. - #[inline] - pub fn size(&self) -> usize { - self.physical_device.infos().memory_properties.memory_heaps[self.id as usize].size as usize - } - - /// Returns true if the heap is local to the GPU. - #[inline] - pub fn is_device_local(&self) -> bool { - let flags = - self.physical_device.infos().memory_properties.memory_heaps[self.id as usize].flags; - !(flags & ash::vk::MemoryHeapFlags::DEVICE_LOCAL).is_empty() - } - - /// Returns true if the heap is multi-instance enabled, that is allocation from such - /// heap will replicate to each physical-device's instance of heap. - #[inline] - pub fn is_multi_instance(&self) -> bool { - let flags = - self.physical_device.infos().memory_properties.memory_heaps[self.id as usize].flags; - !(flags & ash::vk::MemoryHeapFlags::MULTI_INSTANCE).is_empty() - } -} - -/// Iterator for all the memory heaps available on a physical device. -#[derive(Debug, Clone)] -pub struct MemoryHeapsIter<'a> { - physical_device: PhysicalDevice<'a>, - current_id: u32, -} - -impl<'a> Iterator for MemoryHeapsIter<'a> { - type Item = MemoryHeap<'a>; - - #[inline] - fn next(&mut self) -> Option> { - if self.current_id - >= self - .physical_device - .infos() - .memory_properties - .memory_heap_count - { - return None; - } - - let dev = MemoryHeap { - physical_device: self.physical_device, - id: self.current_id, - }; - - self.current_id += 1; - Some(dev) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let len = self - .physical_device - .infos() - .memory_properties - .memory_heap_count; - let remain = (len - self.current_id) as usize; - (remain, Some(remain)) - } -} - -impl<'a> ExactSizeIterator for MemoryHeapsIter<'a> {} - /// The version of the Vulkan conformance test that a driver is conformant against. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct ConformanceVersion { diff --git a/vulkano/src/device/properties.rs b/vulkano/src/device/properties.rs index 500b951d..1ab83d13 100644 --- a/vulkano/src/device/properties.rs +++ b/vulkano/src/device/properties.rs @@ -1,9 +1,9 @@ use crate::descriptor::descriptor::ShaderStages; -use crate::image::{SampleCount, SampleCounts}; -use crate::instance::{ +use crate::device::physical::{ ConformanceVersion, DriverId, PhysicalDeviceType, PointClippingBehavior, ShaderCoreProperties, ShaderFloatControlsIndependence, SubgroupFeatures, }; +use crate::image::{SampleCount, SampleCounts}; use crate::render_pass::ResolveModes; use crate::Version; use std::convert::TryInto; diff --git a/vulkano/src/format.rs b/vulkano/src/format.rs index 7e159e9c..d262ba1b 100644 --- a/vulkano/src/format.rs +++ b/vulkano/src/format.rs @@ -92,8 +92,8 @@ //! // TODO: storage formats //! +use crate::device::physical::PhysicalDevice; use crate::image::ImageAspects; -use crate::instance::PhysicalDevice; use crate::VulkanObject; use half::f16; use std::convert::TryFrom; diff --git a/vulkano/src/image/immutable.rs b/vulkano/src/image/immutable.rs index 1ed199af..50193a5e 100644 --- a/vulkano/src/image/immutable.rs +++ b/vulkano/src/image/immutable.rs @@ -16,6 +16,7 @@ use crate::command_buffer::CommandBufferExecFuture; use crate::command_buffer::CommandBufferUsage; use crate::command_buffer::PrimaryAutoCommandBuffer; use crate::command_buffer::PrimaryCommandBuffer; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::device::Queue; use crate::format::Format; @@ -32,7 +33,6 @@ use crate::image::ImageLayout; use crate::image::ImageUsage; use crate::image::MipmapsCount; use crate::image::SampleCount; -use crate::instance::QueueFamily; use crate::memory::pool::AllocFromRequirementsFilter; use crate::memory::pool::AllocLayout; use crate::memory::pool::MappingRequirement; diff --git a/vulkano/src/image/storage.rs b/vulkano/src/image/storage.rs index 5ddff19b..cfcba15d 100644 --- a/vulkano/src/image/storage.rs +++ b/vulkano/src/image/storage.rs @@ -8,6 +8,7 @@ // according to those terms. use crate::buffer::BufferAccess; +use crate::device::physical::QueueFamily; use crate::device::Device; use crate::format::ClearValue; use crate::format::Format; @@ -24,7 +25,6 @@ use crate::image::ImageInner; use crate::image::ImageLayout; use crate::image::ImageUsage; use crate::image::SampleCount; -use crate::instance::QueueFamily; use crate::memory::pool::AllocFromRequirementsFilter; use crate::memory::pool::AllocLayout; use crate::memory::pool::MappingRequirement; diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index 2182ffe8..3eea3b47 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -177,7 +177,7 @@ impl UnsafeImage { { return Err(ImageCreationError::UnsupportedUsage); } - if device.api_version() >= Version::V1_1 || device.loaded_extensions().khr_maintenance1 + if device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_maintenance1 { if usage.transfer_source && !features.transfer_src { return Err(ImageCreationError::UnsupportedUsage); @@ -588,7 +588,7 @@ impl UnsafeImage { }; let mem_reqs = if device.api_version() >= Version::V1_1 - || device.loaded_extensions().khr_get_memory_requirements2 + || device.enabled_extensions().khr_get_memory_requirements2 { let infos = ash::vk::ImageMemoryRequirementsInfo2 { image, @@ -596,7 +596,7 @@ impl UnsafeImage { }; let mut output2 = if device.api_version() >= Version::V1_1 - || device.loaded_extensions().khr_dedicated_allocation + || device.enabled_extensions().khr_dedicated_allocation { Some(ash::vk::MemoryDedicatedRequirements::default()) } else { diff --git a/vulkano/src/instance/debug.rs b/vulkano/src/instance/debug.rs index c6b93a54..bb4d2a7b 100644 --- a/vulkano/src/instance/debug.rs +++ b/vulkano/src/instance/debug.rs @@ -74,7 +74,7 @@ impl DebugCallback { where F: Fn(&Message) + 'static + Send + panic::RefUnwindSafe, { - if !instance.loaded_extensions().ext_debug_utils { + if !instance.enabled_extensions().ext_debug_utils { return Err(DebugCallbackCreationError::MissingExtension); } diff --git a/vulkano/src/instance/instance.rs b/vulkano/src/instance/instance.rs index b887f1e2..a2117733 100644 --- a/vulkano/src/instance/instance.rs +++ b/vulkano/src/instance/instance.rs @@ -8,13 +8,13 @@ // according to those terms. use crate::check_errors; +use crate::device::physical::{init_physical_devices, PhysicalDeviceInfo}; use crate::extensions::ExtensionRestrictionError; use crate::fns::InstanceFunctions; use crate::instance::loader; use crate::instance::loader::FunctionPointers; use crate::instance::loader::Loader; use crate::instance::loader::LoadingError; -use crate::instance::physical_device::{init_physical_devices, PhysicalDeviceInfos}; use crate::instance::InstanceExtensions; use crate::Error; use crate::OomError; @@ -180,7 +180,7 @@ pub struct Instance { // The highest allowed API version for instances and devices created from it. max_api_version: Version, - pub(super) physical_devices: Vec, + pub(crate) physical_device_infos: Vec, fns: InstanceFunctions, extensions: InstanceExtensions, layers: SmallVec<[CString; 16]>, @@ -387,7 +387,7 @@ impl Instance { api_version, max_api_version, //alloc: None, - physical_devices: Vec::new(), + physical_device_infos: Vec::new(), fns, extensions: extensions.clone(), layers, @@ -395,7 +395,7 @@ impl Instance { }; // Enumerating all physical devices. - instance.physical_devices = init_physical_devices(&instance)?; + instance.physical_device_infos = init_physical_devices(&instance)?; Ok(Arc::new(instance)) } @@ -431,29 +431,15 @@ impl Instance { } /// Returns the extensions that have been enabled on the instance. - /// - /// This list is equal to what was passed to `Instance::new()`. - /// - /// # Example - /// - /// ```no_run - /// use vulkano::instance::Instance; - /// use vulkano::instance::InstanceExtensions; - /// use vulkano::Version; - /// - /// let extensions = InstanceExtensions::supported_by_core().unwrap(); - /// let instance = Instance::new(None, Version::V1_1, &extensions, None).unwrap(); - /// assert_eq!(instance.loaded_extensions(), &extensions); - /// ``` #[inline] - pub fn loaded_extensions(&self) -> &InstanceExtensions { + pub fn enabled_extensions(&self) -> &InstanceExtensions { &self.extensions } /// Returns the layers that have been enabled on the instance. #[doc(hidden)] #[inline] - pub fn loaded_layers(&self) -> slice::Iter { + pub fn enabled_layers(&self) -> slice::Iter { self.layers.iter() } } @@ -680,7 +666,7 @@ impl From for InstanceCreationError { #[cfg(test)] mod tests { - use crate::instance; + use crate::device::physical::PhysicalDevice; #[test] fn create_instance() { @@ -691,7 +677,7 @@ mod tests { fn queue_family_by_id() { let instance = instance!(); - let phys = match instance::PhysicalDevice::enumerate(&instance).next() { + let phys = match PhysicalDevice::enumerate(&instance).next() { Some(p) => p, None => return, }; diff --git a/vulkano/src/instance/mod.rs b/vulkano/src/instance/mod.rs index 47da49d9..c6adfc7d 100644 --- a/vulkano/src/instance/mod.rs +++ b/vulkano/src/instance/mod.rs @@ -31,7 +31,7 @@ //! # use vulkano::instance::Instance; //! # use vulkano::instance::InstanceExtensions; //! # use vulkano::Version; -//! use vulkano::instance::PhysicalDevice; +//! use vulkano::device::physical::PhysicalDevice; //! //! # let instance = Instance::new(None, Version::V1_1, &InstanceExtensions::none(), None).unwrap(); //! for physical_device in PhysicalDevice::enumerate(&instance) { @@ -60,21 +60,6 @@ pub use self::layers::LayerProperties; pub use self::layers::LayersIterator; pub use self::layers::LayersListError; pub use self::loader::LoadingError; -pub use self::physical_device::ConformanceVersion; -pub use self::physical_device::DriverId; -pub use self::physical_device::MemoryHeap; -pub use self::physical_device::MemoryHeapsIter; -pub use self::physical_device::MemoryType; -pub use self::physical_device::MemoryTypesIter; -pub use self::physical_device::PhysicalDevice; -pub use self::physical_device::PhysicalDeviceType; -pub use self::physical_device::PhysicalDevicesIter; -pub use self::physical_device::PointClippingBehavior; -pub use self::physical_device::QueueFamiliesIter; -pub use self::physical_device::QueueFamily; -pub use self::physical_device::ShaderCoreProperties; -pub use self::physical_device::ShaderFloatControlsIndependence; -pub use self::physical_device::SubgroupFeatures; pub use crate::extensions::{ ExtensionRestriction, ExtensionRestrictionError, SupportedExtensionsError, }; @@ -85,4 +70,3 @@ pub(crate) mod extensions; mod instance; mod layers; pub mod loader; -mod physical_device; diff --git a/vulkano/src/memory/device_memory.rs b/vulkano/src/memory/device_memory.rs index 94e142bf..60b590e1 100644 --- a/vulkano/src/memory/device_memory.rs +++ b/vulkano/src/memory/device_memory.rs @@ -8,9 +8,9 @@ // according to those terms. use crate::check_errors; +use crate::device::physical::MemoryType; use crate::device::Device; use crate::device::DeviceOwned; -use crate::instance::MemoryType; use crate::memory::Content; use crate::memory::DedicatedAlloc; use crate::memory::ExternalMemoryHandleType; @@ -269,7 +269,7 @@ impl<'a> DeviceMemoryBuilder<'a> { let mut export_handle_bits = ash::vk::ExternalMemoryHandleTypeFlags::empty(); if self.dedicated_info.is_some() { - if !self.device.loaded_extensions().khr_dedicated_allocation { + if !self.device.enabled_extensions().khr_dedicated_allocation { return Err(DeviceMemoryAllocError::MissingExtension( "khr_dedicated_allocation", )); @@ -291,7 +291,7 @@ impl<'a> DeviceMemoryBuilder<'a> { if !(export_handle_bits & ash::vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) .is_empty() { - if !self.device.loaded_extensions().ext_external_memory_dma_buf { + if !self.device.enabled_extensions().ext_external_memory_dma_buf { return Err(DeviceMemoryAllocError::MissingExtension( "ext_external_memory_dmabuf", )); @@ -300,7 +300,7 @@ impl<'a> DeviceMemoryBuilder<'a> { if !(export_handle_bits & ash::vk::ExternalMemoryHandleTypeFlags::OPAQUE_FD).is_empty() { - if !self.device.loaded_extensions().khr_external_memory_fd { + if !self.device.enabled_extensions().khr_external_memory_fd { return Err(DeviceMemoryAllocError::MissingExtension( "khr_external_memory_fd", )); @@ -310,7 +310,7 @@ impl<'a> DeviceMemoryBuilder<'a> { if !(import_handle_bits & ash::vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) .is_empty() { - if !self.device.loaded_extensions().ext_external_memory_dma_buf { + if !self.device.enabled_extensions().ext_external_memory_dma_buf { return Err(DeviceMemoryAllocError::MissingExtension( "ext_external_memory_dmabuf", )); @@ -319,7 +319,7 @@ impl<'a> DeviceMemoryBuilder<'a> { if !(import_handle_bits & ash::vk::ExternalMemoryHandleTypeFlags::OPAQUE_FD).is_empty() { - if !self.device.loaded_extensions().khr_external_memory_fd { + if !self.device.enabled_extensions().khr_external_memory_fd { return Err(DeviceMemoryAllocError::MissingExtension( "khr_external_memory_fd", )); diff --git a/vulkano/src/memory/mod.rs b/vulkano/src/memory/mod.rs index 9df055f2..f2e01407 100644 --- a/vulkano/src/memory/mod.rs +++ b/vulkano/src/memory/mod.rs @@ -20,7 +20,7 @@ //! //! ``` //! // Enumerating memory heaps. -//! # let physical_device: vulkano::instance::PhysicalDevice = return; +//! # let physical_device: vulkano::device::physical::PhysicalDevice = return; //! for heap in physical_device.memory_heaps() { //! println!("Heap #{:?} has a capacity of {:?} bytes", heap.id(), heap.size()); //! } @@ -37,7 +37,7 @@ //! //! ``` //! // Enumerating memory types. -//! # let physical_device: vulkano::instance::PhysicalDevice = return; +//! # let physical_device: vulkano::device::physical::PhysicalDevice = return; //! for ty in physical_device.memory_types() { //! println!("Memory type belongs to heap #{:?}", ty.heap().id()); //! println!("Host-accessible: {:?}", ty.is_host_visible()); diff --git a/vulkano/src/memory/pool/host_visible.rs b/vulkano/src/memory/pool/host_visible.rs index fa48605b..680f16ae 100644 --- a/vulkano/src/memory/pool/host_visible.rs +++ b/vulkano/src/memory/pool/host_visible.rs @@ -12,9 +12,9 @@ use std::ops::Range; use std::sync::Arc; use std::sync::Mutex; +use crate::device::physical::MemoryType; use crate::device::Device; use crate::instance::Instance; -use crate::instance::MemoryType; use crate::memory::DeviceMemory; use crate::memory::DeviceMemoryAllocError; use crate::memory::MappedDeviceMemory; diff --git a/vulkano/src/memory/pool/mod.rs b/vulkano/src/memory/pool/mod.rs index 83853c28..402efb48 100644 --- a/vulkano/src/memory/pool/mod.rs +++ b/vulkano/src/memory/pool/mod.rs @@ -7,8 +7,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. +use crate::device::physical::MemoryType; use crate::device::{Device, DeviceOwned}; -use crate::instance::MemoryType; use crate::memory::DedicatedAlloc; use crate::memory::DeviceMemory; use crate::memory::DeviceMemoryAllocError; @@ -153,7 +153,7 @@ pub unsafe trait MemoryPool: DeviceOwned { // Redirect to `self.alloc_generic` if we don't perform a dedicated allocation. if !requirements.prefer_dedicated - || !self.device().loaded_extensions().khr_dedicated_allocation + || !self.device().enabled_extensions().khr_dedicated_allocation { let alloc = self.alloc_generic( mem_ty, @@ -211,13 +211,13 @@ pub unsafe trait MemoryPool: DeviceOwned { where F: FnMut(MemoryType) -> AllocFromRequirementsFilter, { - assert!(self.device().loaded_extensions().khr_external_memory_fd); - assert!(self.device().loaded_extensions().khr_external_memory); + assert!(self.device().enabled_extensions().khr_external_memory_fd); + assert!(self.device().enabled_extensions().khr_external_memory); let mem_ty = choose_allocation_memory_type(self.device(), requirements, filter, map); if !requirements.prefer_dedicated - || !self.device().loaded_extensions().khr_dedicated_allocation + || !self.device().enabled_extensions().khr_dedicated_allocation { let alloc = self.alloc_generic_with_exportable_fd( mem_ty, diff --git a/vulkano/src/memory/pool/non_host_visible.rs b/vulkano/src/memory/pool/non_host_visible.rs index b7ebb5a3..d55367c7 100644 --- a/vulkano/src/memory/pool/non_host_visible.rs +++ b/vulkano/src/memory/pool/non_host_visible.rs @@ -7,17 +7,16 @@ // notice may not be copied, modified, or distributed except // according to those terms. +use crate::device::physical::MemoryType; +use crate::device::Device; +use crate::instance::Instance; +use crate::memory::DeviceMemory; +use crate::memory::DeviceMemoryAllocError; use std::cmp; use std::ops::Range; use std::sync::Arc; use std::sync::Mutex; -use crate::device::Device; -use crate::instance::Instance; -use crate::instance::MemoryType; -use crate::memory::DeviceMemory; -use crate::memory::DeviceMemoryAllocError; - /// Memory pool that operates on a given memory type. #[derive(Debug)] pub struct StdNonHostVisibleMemoryTypePool { diff --git a/vulkano/src/memory/pool/pool.rs b/vulkano/src/memory/pool/pool.rs index a1757896..1931893c 100644 --- a/vulkano/src/memory/pool/pool.rs +++ b/vulkano/src/memory/pool/pool.rs @@ -14,9 +14,9 @@ use std::hash::BuildHasherDefault; use std::sync::Arc; use std::sync::Mutex; +use crate::device::physical::MemoryType; use crate::device::Device; use crate::device::DeviceOwned; -use crate::instance::MemoryType; use crate::memory::pool::AllocLayout; use crate::memory::pool::MappingRequirement; use crate::memory::pool::MemoryPool; diff --git a/vulkano/src/sampler.rs b/vulkano/src/sampler.rs index 3fff78e5..ec6e27f7 100644 --- a/vulkano/src/sampler.rs +++ b/vulkano/src/sampler.rs @@ -299,7 +299,7 @@ impl Sampler { .iter() .any(|&mode| mode == SamplerAddressMode::MirrorClampToEdge) { - if !device.loaded_extensions().khr_sampler_mirror_clamp_to_edge { + if !device.enabled_extensions().khr_sampler_mirror_clamp_to_edge { return Err(SamplerCreationError::SamplerMirrorClampToEdgeExtensionNotEnabled); } } diff --git a/vulkano/src/swapchain/display.rs b/vulkano/src/swapchain/display.rs index d9ccf4da..67f135ea 100644 --- a/vulkano/src/swapchain/display.rs +++ b/vulkano/src/swapchain/display.rs @@ -29,8 +29,8 @@ #![allow(unused_variables)] // TODO: this module isn't finished use crate::check_errors; +use crate::device::physical::PhysicalDevice; use crate::instance::Instance; -use crate::instance::PhysicalDevice; use crate::swapchain::SupportedSurfaceTransforms; use crate::OomError; use crate::VulkanObject; @@ -58,7 +58,7 @@ impl DisplayPlane { pub fn enumerate_raw(device: PhysicalDevice) -> Result, OomError> { let fns = device.instance().fns(); - assert!(device.instance().loaded_extensions().khr_display); // TODO: return error instead + assert!(device.instance().enabled_extensions().khr_display); // TODO: return error instead let num = unsafe { let mut num: u32 = 0; @@ -182,7 +182,7 @@ impl Display { /// See the docs of enumerate(). pub fn enumerate_raw(device: PhysicalDevice) -> Result, OomError> { let fns = device.instance().fns(); - assert!(device.instance().loaded_extensions().khr_display); // TODO: return error instead + assert!(device.instance().enabled_extensions().khr_display); // TODO: return error instead let num = unsafe { let mut num = 0; @@ -353,7 +353,7 @@ pub struct DisplayMode { impl DisplayMode { /*pub fn new(display: &Display) -> Result, OomError> { let fns = instance.fns(); - assert!(device.instance().loaded_extensions().khr_display); // TODO: return error instead + assert!(device.instance().enabled_extensions().khr_display); // TODO: return error instead let parameters = ash::vk::DisplayModeParametersKHR { visibleRegion: ash::vk::Extent2D { width: , height: }, diff --git a/vulkano/src/swapchain/surface.rs b/vulkano/src/swapchain/surface.rs index e4227bf0..9bf5fd8d 100644 --- a/vulkano/src/swapchain/surface.rs +++ b/vulkano/src/swapchain/surface.rs @@ -8,11 +8,11 @@ // according to those terms. use crate::check_errors; +use crate::device::physical::PhysicalDevice; +use crate::device::physical::QueueFamily; use crate::format::Format; use crate::image::ImageUsage; use crate::instance::Instance; -use crate::instance::PhysicalDevice; -use crate::instance::QueueFamily; use crate::swapchain::capabilities::SupportedSurfaceTransforms; use crate::swapchain::display::DisplayMode; use crate::swapchain::display::DisplayPlane; @@ -76,7 +76,7 @@ impl Surface { .display() .physical_device() .instance() - .loaded_extensions() + .enabled_extensions() .khr_display { return Err(SurfaceCreationError::MissingExtension { @@ -145,7 +145,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().khr_win32_surface { + if !instance.enabled_extensions().khr_win32_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_KHR_win32_surface", }); @@ -193,7 +193,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().khr_xcb_surface { + if !instance.enabled_extensions().khr_xcb_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_KHR_xcb_surface", }); @@ -241,7 +241,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().khr_xlib_surface { + if !instance.enabled_extensions().khr_xlib_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_KHR_xlib_surface", }); @@ -289,7 +289,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().khr_wayland_surface { + if !instance.enabled_extensions().khr_wayland_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_KHR_wayland_surface", }); @@ -334,7 +334,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().khr_android_surface { + if !instance.enabled_extensions().khr_android_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_KHR_android_surface", }); @@ -379,7 +379,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().mvk_ios_surface { + if !instance.enabled_extensions().mvk_ios_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_MVK_ios_surface", }); @@ -424,7 +424,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().mvk_macos_surface { + if !instance.enabled_extensions().mvk_macos_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_MVK_macos_surface", }); @@ -468,7 +468,7 @@ impl Surface { ) -> Result>, SurfaceCreationError> { let fns = instance.fns(); - if !instance.loaded_extensions().nn_vi_surface { + if !instance.enabled_extensions().nn_vi_surface { return Err(SurfaceCreationError::MissingExtension { name: "VK_NN_vi_surface", }); diff --git a/vulkano/src/swapchain/swapchain.rs b/vulkano/src/swapchain/swapchain.rs index 7b1e337d..f61160ae 100644 --- a/vulkano/src/swapchain/swapchain.rs +++ b/vulkano/src/swapchain/swapchain.rs @@ -678,7 +678,7 @@ impl SwapchainBuilder { } } - if !device.loaded_extensions().khr_swapchain { + if !device.enabled_extensions().khr_swapchain { return Err(SwapchainCreationError::MissingExtensionKHRSwapchain); } @@ -687,14 +687,14 @@ impl SwapchainBuilder { // TODO: VK_EXT_FULL_SCREEN_EXCLUSIVE requires these extensions, so they should always // be enabled if it is. A separate check here is unnecessary; this should be checked at // device creation. - if device.loaded_extensions().ext_full_screen_exclusive + if device.enabled_extensions().ext_full_screen_exclusive && surface .instance() - .loaded_extensions() + .enabled_extensions() .khr_get_physical_device_properties2 && surface .instance() - .loaded_extensions() + .enabled_extensions() .khr_get_surface_capabilities2 { surface_full_screen_exclusive_info = Some(ash::vk::SurfaceFullScreenExclusiveInfoEXT { diff --git a/vulkano/src/sync/semaphore/semaphore.rs b/vulkano/src/sync/semaphore/semaphore.rs index de28b89b..29c99521 100644 --- a/vulkano/src/sync/semaphore/semaphore.rs +++ b/vulkano/src/sync/semaphore/semaphore.rs @@ -94,7 +94,7 @@ where && !self .device .instance() - .loaded_extensions() + .enabled_extensions() .khr_external_semaphore_capabilities { Err(SemaphoreError::MissingExtension( @@ -166,8 +166,8 @@ where pub fn export_opaque_fd(&self) -> Result { let fns = self.device.fns(); - assert!(self.device.loaded_extensions().khr_external_semaphore); - assert!(self.device.loaded_extensions().khr_external_semaphore_fd); + assert!(self.device.enabled_extensions().khr_external_semaphore); + assert!(self.device.enabled_extensions().khr_external_semaphore_fd); let fd = unsafe { let info = ash::vk::SemaphoreGetFdInfoKHR { @@ -280,9 +280,9 @@ impl From for SemaphoreError { #[cfg(test)] mod tests { - + use crate::device::physical::PhysicalDevice; use crate::device::{Device, DeviceExtensions}; - use crate::instance::{Instance, InstanceExtensions, PhysicalDevice}; + use crate::instance::{Instance, InstanceExtensions}; use crate::VulkanObject; use crate::{sync::Semaphore, Version}; @@ -345,7 +345,7 @@ mod tests { ) .unwrap(); - let supported_ext = DeviceExtensions::supported_by_device(physical.clone()); + let supported_ext = physical.supported_extensions(); if supported_ext.khr_external_semaphore && supported_ext.khr_external_semaphore_fd { let sem = Semaphore::alloc_with_exportable_fd(device.clone()).unwrap(); let fd = sem.export_opaque_fd().unwrap(); diff --git a/vulkano/src/tests.rs b/vulkano/src/tests.rs index 35268227..40b2d902 100644 --- a/vulkano/src/tests.rs +++ b/vulkano/src/tests.rs @@ -30,14 +30,14 @@ macro_rules! instance { /// Creates a device and a queue for graphics operations. macro_rules! gfx_dev_and_queue { ($($feature:ident),*) => ({ - use crate::instance; + use crate::device::physical::PhysicalDevice; use crate::device::Device; use crate::device::DeviceExtensions; use crate::device::Features; let instance = instance!(); - let physical = match instance::PhysicalDevice::enumerate(&instance).next() { + let physical = match PhysicalDevice::enumerate(&instance).next() { Some(p) => p, None => return };