diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index 7770652..6e94f22 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -194,6 +194,8 @@ const char* to_string (InstanceError err) { } const char* to_string (PhysicalDeviceError err) { switch (err) { + case PhysicalDeviceError::no_surface_provided: + return "no_surface_provided"; case PhysicalDeviceError::failed_enumerate_physical_devices: return "failed_enumerate_physical_devices"; case PhysicalDeviceError::no_physical_devices_found: @@ -785,6 +787,11 @@ PhysicalDeviceSelector::PhysicalDeviceSelector (Instance const& instance) { } detail::Expected> PhysicalDeviceSelector::select () const { + if (!system_info.headless && !criteria.defer_surface_initialization) { + if (system_info.surface == nullptr) + return detail::Error{ PhysicalDeviceError::no_surface_provided }; + } + auto physical_devices = detail::get_vector (vkEnumeratePhysicalDevices, system_info.instance); if (!physical_devices.has_value ()) { @@ -820,16 +827,18 @@ detail::Expected> PhysicalDev return detail::Error{ PhysicalDeviceError::no_suitable_device }; } PhysicalDevice out_device{}; - out_device.phys_device = selected_device.phys_device; + out_device.physical_device = selected_device.phys_device; out_device.surface = system_info.surface; out_device.features = criteria.required_features; + out_device.properties = selected_device.device_properties; + out_device.memory_properties = selected_device.mem_properties; out_device.queue_families = selected_device.queue_families; out_device.extensions_to_enable.insert (out_device.extensions_to_enable.end (), criteria.required_extensions.begin (), criteria.required_extensions.end ()); auto desired_extensions_supported = - detail::check_device_extension_support (out_device.phys_device, criteria.desired_extensions); + detail::check_device_extension_support (out_device.physical_device, criteria.desired_extensions); out_device.extensions_to_enable.insert (out_device.extensions_to_enable.end (), desired_extensions_supported.begin (), desired_extensions_supported.end ()); @@ -935,7 +944,7 @@ detail::Expected> Device::get_queue_index (Q int index = -1; switch (type) { case QueueType::present: - index = detail::get_present_queue_index (physical_device.phys_device, surface, queue_families); + index = detail::get_present_queue_index (physical_device.physical_device, surface, queue_families); if (index < 0) return detail::Error{ QueueError::present_unavailable }; break; case QueueType::graphics: @@ -1039,8 +1048,10 @@ detail::Expected> DeviceBuilder::build () con device_create_info.pEnabledFeatures = &info.features; Device device; - VkResult res = vkCreateDevice ( - info.physical_device.phys_device, &device_create_info, info.allocation_callbacks, &device.device); + VkResult res = vkCreateDevice (info.physical_device.physical_device, + &device_create_info, + info.allocation_callbacks, + &device.device); if (res != VK_SUCCESS) { return detail::Error{ DeviceError::failed_create_device, res }; } @@ -1150,7 +1161,7 @@ VkExtent2D find_extent ( SwapchainBuilder::SwapchainBuilder (Device const& device) { info.device = device.device; - info.physical_device = device.physical_device.phys_device; + info.physical_device = device.physical_device.physical_device; info.surface = device.surface; auto present = device.get_queue_index (QueueType::present); auto graphics = device.get_queue_index (QueueType::graphics); diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 516c397..8fab494 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -108,6 +108,7 @@ enum class InstanceError { requested_extensions_not_present }; enum class PhysicalDeviceError { + no_surface_provided, failed_enumerate_physical_devices, no_physical_devices_found, no_suitable_device, @@ -293,9 +294,13 @@ class PhysicalDeviceSelector; class DeviceBuilder; struct PhysicalDevice { - VkPhysicalDevice phys_device = VK_NULL_HANDLE; + VkPhysicalDevice physical_device = VK_NULL_HANDLE; VkSurfaceKHR surface = VK_NULL_HANDLE; + VkPhysicalDeviceFeatures features{}; + VkPhysicalDeviceProperties properties{}; + VkPhysicalDeviceMemoryProperties memory_properties{}; + // Has a queue family that supports compute operations but not graphics nor transfer. bool has_dedicated_compute_queue () const; // Has a queue family that supports transfer operations but not graphics nor compute. @@ -307,7 +312,6 @@ struct PhysicalDevice { bool has_separate_transfer_queue () const; private: - VkPhysicalDeviceFeatures features{}; std::vector extensions_to_enable; std::vector queue_families; friend class PhysicalDeviceSelector; @@ -330,7 +334,7 @@ class PhysicalDeviceSelector { detail::Expected> select () const; // Set the surface in which the physical device should render to. - PhysicalDeviceSelector& set_surface (VkSurfaceKHR instance); + PhysicalDeviceSelector& set_surface (VkSurfaceKHR surface); // Set the desired physical device type to select. Defaults to PreferredDeviceType::discrete. PhysicalDeviceSelector& prefer_gpu_device_type (PreferredDeviceType type = PreferredDeviceType::discrete); // Allow selection of a gpu device type that isn't the preferred physical device type. Defaults to true.