Fixed example in readme, made transfer/compute queue selection find a distinct queue,

removed uncessary private members in vkb::Instance, and removed superfluous comment headers
This commit is contained in:
Charles Giessen 2020-02-17 13:13:09 -07:00
parent cf8411ae78
commit 83d58fc6d4
3 changed files with 44 additions and 33 deletions

View File

@ -51,9 +51,11 @@ void device_init()
} }
vkb::Device device = dev_ret.value(); vkb::Device device = dev_ret.value();
VkQueue graphics_queue = get_queue_graphics(device).value(); auto graphics_queue_ret = get_graphics_queue(device).value();
VkQueue compute_queue = get_queue_compute(device).value(); if (!graphics_queue_ret.has_value()){
VkQueue transfer_queue = get_queue_transfer(device).value(); //error
}
VkQueue graphics_queue = graphics_queue_ret.value();
} }
``` ```

View File

@ -186,13 +186,13 @@ detail::Expected<Instance, detail::Error<InstanceError>> InstanceBuilder::build
} }
if (!info.headless_context) { if (!info.headless_context) {
extensions.push_back (VK_KHR_SURFACE_EXTENSION_NAME); extensions.push_back ("VK_KHR_surface");
#if defined(_WIN32) #if defined(_WIN32)
extensions.push_back ("VK_KHR_win32_surface"); extensions.push_back ("VK_KHR_win32_surface");
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
extensions.push_back (VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); extensions.push_back ("VK_KHR_android_surface");
#elif defined(_DIRECT2DISPLAY) #elif defined(_DIRECT2DISPLAY)
extensions.push_back (VK_KHR_DISPLAY_EXTENSION_NAME); extensions.push_back ("VK_KHR_display");
#elif defined(__linux__) #elif defined(__linux__)
extensions.push_back ("VK_KHR_xcb_surface"); extensions.push_back ("VK_KHR_xcb_surface");
extensions.push_back ("VK_KHR_xlib_surface"); extensions.push_back ("VK_KHR_xlib_surface");
@ -355,6 +355,8 @@ InstanceBuilder& InstanceBuilder::add_validation_feature_disable (VkValidationFe
return *this; return *this;
} }
// ---- Physical Device ---- //
namespace detail { namespace detail {
struct SurfaceSupportDetails { struct SurfaceSupportDetails {
@ -497,18 +499,30 @@ int get_graphics_queue_index (std::vector<VkQueueFamilyProperties> const& famili
return -1; return -1;
} }
int get_distinct_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_distinct_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
int compute = -1;
for (int i = 0; i < families.size (); i++) { for (int i = 0; i < families.size (); i++) {
if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) && if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) &&
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) ((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == 0) {
return i; return i;
} else {
compute = i;
} }
return -1; }
}
return compute;
} }
int get_distinct_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_distinct_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
int transfer = -1;
for (int i = 0; i < families.size (); i++) { for (int i = 0; i < families.size (); i++) {
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) && if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) &&
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) ((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
return true; if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
return i;
} else {
transfer = i;
}
}
} }
return -1; return -1;
} }
@ -736,10 +750,6 @@ PhysicalDeviceSelector& PhysicalDeviceSelector::select_first_device_unconditiona
return *this; return *this;
} }
// ---- Queue Selection ---- //
// ---- Device ---- // // ---- Device ---- //
void destroy_device (Device device) { vkDestroyDevice (device.device, nullptr); } void destroy_device (Device device) { vkDestroyDevice (device.device, nullptr); }
@ -832,7 +842,7 @@ DeviceBuilder& DeviceBuilder::custom_queue_setup (std::vector<CustomQueueDescrip
} }
// ---- Getting Queues ---- // // ---- Queues ---- //
detail::Expected<uint32_t, detail::Error<QueueError>> get_present_queue_index (Device const& device) { detail::Expected<uint32_t, detail::Error<QueueError>> get_present_queue_index (Device const& device) {
int present = get_present_queue_index ( int present = get_present_queue_index (
@ -865,32 +875,32 @@ VkQueue get_queue (VkDevice device, int32_t family) {
detail::Expected<VkQueue, detail::Error<QueueError>> get_present_queue (Device const& device) { detail::Expected<VkQueue, detail::Error<QueueError>> get_present_queue (Device const& device) {
int present = get_present_queue_index ( int present = get_present_queue_index (
device.physical_device.phys_device, device.surface, device.queue_families); device.physical_device.phys_device, device.surface, device.queue_families);
if (present >= 0) { if (present < 0) {
return get_queue (device.device, present);
}
return detail::Error<QueueError>{ QueueError::present_unavailable }; return detail::Error<QueueError>{ QueueError::present_unavailable };
} }
return get_queue (device.device, present);
}
detail::Expected<VkQueue, detail::Error<QueueError>> get_graphics_queue (Device const& device) { detail::Expected<VkQueue, detail::Error<QueueError>> get_graphics_queue (Device const& device) {
int graphics = get_graphics_queue_index (device.queue_families); int graphics = get_graphics_queue_index (device.queue_families);
if (graphics >= 0) { if (graphics < 0) {
return get_queue (device.device, graphics);
}
return detail::Error<QueueError>{ QueueError::invalid_queue_family_index }; return detail::Error<QueueError>{ QueueError::invalid_queue_family_index };
} }
return get_queue (device.device, graphics);
}
detail::Expected<VkQueue, detail::Error<QueueError>> get_compute_queue (Device const& device) { detail::Expected<VkQueue, detail::Error<QueueError>> get_compute_queue (Device const& device) {
int compute = get_distinct_compute_queue_index (device.queue_families); int compute = get_distinct_compute_queue_index (device.queue_families);
if (compute >= 0) { if (compute < 0) {
return get_queue (device.device, compute);
}
return detail::Error<QueueError>{ QueueError::compute_unavailable }; return detail::Error<QueueError>{ QueueError::compute_unavailable };
} }
return get_queue (device.device, compute);
}
detail::Expected<VkQueue, detail::Error<QueueError>> get_transfer_queue (Device const& device) { detail::Expected<VkQueue, detail::Error<QueueError>> get_transfer_queue (Device const& device) {
int transfer = get_distinct_transfer_queue_index (device.queue_families); int transfer = get_distinct_transfer_queue_index (device.queue_families);
if (transfer >= 0) { if (transfer < 0) {
return get_queue (device.device, transfer);
}
return detail::Error<QueueError>{ QueueError::transfer_unavailable }; return detail::Error<QueueError>{ QueueError::transfer_unavailable };
} }
return get_queue (device.device, transfer);
}
namespace detail { namespace detail {

View File

@ -113,8 +113,6 @@ struct Instance {
private: private:
bool headless = false; bool headless = false;
bool validation_enabled = false;
bool debug_callback_enabled = false;
friend class InstanceBuilder; friend class InstanceBuilder;
friend class PhysicalDeviceSelector; friend class PhysicalDeviceSelector;
@ -321,14 +319,15 @@ struct Device {
void destroy_device (Device device); void destroy_device (Device device);
struct CustomQueueDescription { struct CustomQueueDescription {
uint32_t index; uint32_t index = 0;
uint32_t count; uint32_t count = 0;
std::vector<float> priorities; std::vector<float> priorities;
}; };
class DeviceBuilder { class DeviceBuilder {
public: public:
DeviceBuilder (PhysicalDevice device); DeviceBuilder (PhysicalDevice physical_device);
detail::Expected<Device, detail::Error<DeviceError>> build (); detail::Expected<Device, detail::Error<DeviceError>> build ();
template <typename T> DeviceBuilder& add_pNext (T* structure); template <typename T> DeviceBuilder& add_pNext (T* structure);