mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 23:24:34 +00:00
Touched up many components due to integration experience
This commit is contained in:
parent
4c91df1c12
commit
bfcc4c6bfa
@ -194,6 +194,8 @@ const char* to_string (InstanceError err) {
|
|||||||
}
|
}
|
||||||
const char* to_string (PhysicalDeviceError err) {
|
const char* to_string (PhysicalDeviceError err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
|
case PhysicalDeviceError::no_surface_provided:
|
||||||
|
return "no_surface_provided";
|
||||||
case PhysicalDeviceError::failed_enumerate_physical_devices:
|
case PhysicalDeviceError::failed_enumerate_physical_devices:
|
||||||
return "failed_enumerate_physical_devices";
|
return "failed_enumerate_physical_devices";
|
||||||
case PhysicalDeviceError::no_physical_devices_found:
|
case PhysicalDeviceError::no_physical_devices_found:
|
||||||
@ -785,6 +787,11 @@ PhysicalDeviceSelector::PhysicalDeviceSelector (Instance const& instance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
detail::Expected<PhysicalDevice, detail::Error<PhysicalDeviceError>> PhysicalDeviceSelector::select () const {
|
detail::Expected<PhysicalDevice, detail::Error<PhysicalDeviceError>> PhysicalDeviceSelector::select () const {
|
||||||
|
if (!system_info.headless && !criteria.defer_surface_initialization) {
|
||||||
|
if (system_info.surface == nullptr)
|
||||||
|
return detail::Error<PhysicalDeviceError>{ PhysicalDeviceError::no_surface_provided };
|
||||||
|
}
|
||||||
|
|
||||||
auto physical_devices =
|
auto physical_devices =
|
||||||
detail::get_vector<VkPhysicalDevice> (vkEnumeratePhysicalDevices, system_info.instance);
|
detail::get_vector<VkPhysicalDevice> (vkEnumeratePhysicalDevices, system_info.instance);
|
||||||
if (!physical_devices.has_value ()) {
|
if (!physical_devices.has_value ()) {
|
||||||
@ -820,16 +827,18 @@ detail::Expected<PhysicalDevice, detail::Error<PhysicalDeviceError>> PhysicalDev
|
|||||||
return detail::Error<PhysicalDeviceError>{ PhysicalDeviceError::no_suitable_device };
|
return detail::Error<PhysicalDeviceError>{ PhysicalDeviceError::no_suitable_device };
|
||||||
}
|
}
|
||||||
PhysicalDevice out_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.surface = system_info.surface;
|
||||||
out_device.features = criteria.required_features;
|
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.queue_families = selected_device.queue_families;
|
||||||
|
|
||||||
out_device.extensions_to_enable.insert (out_device.extensions_to_enable.end (),
|
out_device.extensions_to_enable.insert (out_device.extensions_to_enable.end (),
|
||||||
criteria.required_extensions.begin (),
|
criteria.required_extensions.begin (),
|
||||||
criteria.required_extensions.end ());
|
criteria.required_extensions.end ());
|
||||||
auto desired_extensions_supported =
|
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 (),
|
out_device.extensions_to_enable.insert (out_device.extensions_to_enable.end (),
|
||||||
desired_extensions_supported.begin (),
|
desired_extensions_supported.begin (),
|
||||||
desired_extensions_supported.end ());
|
desired_extensions_supported.end ());
|
||||||
@ -935,7 +944,7 @@ detail::Expected<uint32_t, detail::Error<QueueError>> Device::get_queue_index (Q
|
|||||||
int index = -1;
|
int index = -1;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QueueType::present:
|
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>{ QueueError::present_unavailable };
|
if (index < 0) return detail::Error<QueueError>{ QueueError::present_unavailable };
|
||||||
break;
|
break;
|
||||||
case QueueType::graphics:
|
case QueueType::graphics:
|
||||||
@ -1039,8 +1048,10 @@ detail::Expected<Device, detail::Error<DeviceError>> DeviceBuilder::build () con
|
|||||||
device_create_info.pEnabledFeatures = &info.features;
|
device_create_info.pEnabledFeatures = &info.features;
|
||||||
|
|
||||||
Device device;
|
Device device;
|
||||||
VkResult res = vkCreateDevice (
|
VkResult res = vkCreateDevice (info.physical_device.physical_device,
|
||||||
info.physical_device.phys_device, &device_create_info, info.allocation_callbacks, &device.device);
|
&device_create_info,
|
||||||
|
info.allocation_callbacks,
|
||||||
|
&device.device);
|
||||||
if (res != VK_SUCCESS) {
|
if (res != VK_SUCCESS) {
|
||||||
return detail::Error<DeviceError>{ DeviceError::failed_create_device, res };
|
return detail::Error<DeviceError>{ DeviceError::failed_create_device, res };
|
||||||
}
|
}
|
||||||
@ -1150,7 +1161,7 @@ VkExtent2D find_extent (
|
|||||||
|
|
||||||
SwapchainBuilder::SwapchainBuilder (Device const& device) {
|
SwapchainBuilder::SwapchainBuilder (Device const& device) {
|
||||||
info.device = device.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;
|
info.surface = device.surface;
|
||||||
auto present = device.get_queue_index (QueueType::present);
|
auto present = device.get_queue_index (QueueType::present);
|
||||||
auto graphics = device.get_queue_index (QueueType::graphics);
|
auto graphics = device.get_queue_index (QueueType::graphics);
|
||||||
|
@ -108,6 +108,7 @@ enum class InstanceError {
|
|||||||
requested_extensions_not_present
|
requested_extensions_not_present
|
||||||
};
|
};
|
||||||
enum class PhysicalDeviceError {
|
enum class PhysicalDeviceError {
|
||||||
|
no_surface_provided,
|
||||||
failed_enumerate_physical_devices,
|
failed_enumerate_physical_devices,
|
||||||
no_physical_devices_found,
|
no_physical_devices_found,
|
||||||
no_suitable_device,
|
no_suitable_device,
|
||||||
@ -293,9 +294,13 @@ class PhysicalDeviceSelector;
|
|||||||
class DeviceBuilder;
|
class DeviceBuilder;
|
||||||
|
|
||||||
struct PhysicalDevice {
|
struct PhysicalDevice {
|
||||||
VkPhysicalDevice phys_device = VK_NULL_HANDLE;
|
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
|
||||||
VkSurfaceKHR surface = 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.
|
// Has a queue family that supports compute operations but not graphics nor transfer.
|
||||||
bool has_dedicated_compute_queue () const;
|
bool has_dedicated_compute_queue () const;
|
||||||
// Has a queue family that supports transfer operations but not graphics nor compute.
|
// 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;
|
bool has_separate_transfer_queue () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkPhysicalDeviceFeatures features{};
|
|
||||||
std::vector<const char*> extensions_to_enable;
|
std::vector<const char*> extensions_to_enable;
|
||||||
std::vector<VkQueueFamilyProperties> queue_families;
|
std::vector<VkQueueFamilyProperties> queue_families;
|
||||||
friend class PhysicalDeviceSelector;
|
friend class PhysicalDeviceSelector;
|
||||||
@ -330,7 +334,7 @@ class PhysicalDeviceSelector {
|
|||||||
detail::Expected<PhysicalDevice, detail::Error<PhysicalDeviceError>> select () const;
|
detail::Expected<PhysicalDevice, detail::Error<PhysicalDeviceError>> select () const;
|
||||||
|
|
||||||
// Set the surface in which the physical device should render to.
|
// 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.
|
// Set the desired physical device type to select. Defaults to PreferredDeviceType::discrete.
|
||||||
PhysicalDeviceSelector& prefer_gpu_device_type (PreferredDeviceType type = 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.
|
// Allow selection of a gpu device type that isn't the preferred physical device type. Defaults to true.
|
||||||
|
Loading…
Reference in New Issue
Block a user