mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-10 02:41:47 +00:00
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:
parent
cf8411ae78
commit
83d58fc6d4
@ -51,9 +51,11 @@ void device_init()
|
||||
}
|
||||
vkb::Device device = dev_ret.value();
|
||||
|
||||
VkQueue graphics_queue = get_queue_graphics(device).value();
|
||||
VkQueue compute_queue = get_queue_compute(device).value();
|
||||
VkQueue transfer_queue = get_queue_transfer(device).value();
|
||||
auto graphics_queue_ret = get_graphics_queue(device).value();
|
||||
if (!graphics_queue_ret.has_value()){
|
||||
//error
|
||||
}
|
||||
VkQueue graphics_queue = graphics_queue_ret.value();
|
||||
}
|
||||
|
||||
```
|
||||
|
@ -186,13 +186,13 @@ detail::Expected<Instance, detail::Error<InstanceError>> InstanceBuilder::build
|
||||
}
|
||||
|
||||
if (!info.headless_context) {
|
||||
extensions.push_back (VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
extensions.push_back ("VK_KHR_surface");
|
||||
#if defined(_WIN32)
|
||||
extensions.push_back ("VK_KHR_win32_surface");
|
||||
#elif defined(__ANDROID__)
|
||||
extensions.push_back (VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
|
||||
extensions.push_back ("VK_KHR_android_surface");
|
||||
#elif defined(_DIRECT2DISPLAY)
|
||||
extensions.push_back (VK_KHR_DISPLAY_EXTENSION_NAME);
|
||||
extensions.push_back ("VK_KHR_display");
|
||||
#elif defined(__linux__)
|
||||
extensions.push_back ("VK_KHR_xcb_surface");
|
||||
extensions.push_back ("VK_KHR_xlib_surface");
|
||||
@ -355,6 +355,8 @@ InstanceBuilder& InstanceBuilder::add_validation_feature_disable (VkValidationFe
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ---- Physical Device ---- //
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct SurfaceSupportDetails {
|
||||
@ -497,18 +499,30 @@ int get_graphics_queue_index (std::vector<VkQueueFamilyProperties> const& famili
|
||||
return -1;
|
||||
}
|
||||
int get_distinct_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
|
||||
int compute = -1;
|
||||
for (int i = 0; i < families.size (); i++) {
|
||||
if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) &&
|
||||
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0))
|
||||
return i;
|
||||
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
|
||||
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == 0) {
|
||||
return i;
|
||||
} else {
|
||||
compute = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return compute;
|
||||
}
|
||||
int get_distinct_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
|
||||
int transfer = -1;
|
||||
for (int i = 0; i < families.size (); i++) {
|
||||
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) &&
|
||||
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0))
|
||||
return true;
|
||||
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
|
||||
if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
|
||||
return i;
|
||||
} else {
|
||||
transfer = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -736,10 +750,6 @@ PhysicalDeviceSelector& PhysicalDeviceSelector::select_first_device_unconditiona
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ---- Queue Selection ---- //
|
||||
|
||||
|
||||
|
||||
// ---- Device ---- //
|
||||
|
||||
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) {
|
||||
int present = get_present_queue_index (
|
||||
@ -865,31 +875,31 @@ VkQueue get_queue (VkDevice device, int32_t family) {
|
||||
detail::Expected<VkQueue, detail::Error<QueueError>> get_present_queue (Device const& device) {
|
||||
int present = get_present_queue_index (
|
||||
device.physical_device.phys_device, device.surface, device.queue_families);
|
||||
if (present >= 0) {
|
||||
return get_queue (device.device, present);
|
||||
if (present < 0) {
|
||||
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) {
|
||||
int graphics = get_graphics_queue_index (device.queue_families);
|
||||
if (graphics >= 0) {
|
||||
return get_queue (device.device, graphics);
|
||||
if (graphics < 0) {
|
||||
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) {
|
||||
int compute = get_distinct_compute_queue_index (device.queue_families);
|
||||
if (compute >= 0) {
|
||||
return get_queue (device.device, compute);
|
||||
if (compute < 0) {
|
||||
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) {
|
||||
int transfer = get_distinct_transfer_queue_index (device.queue_families);
|
||||
if (transfer >= 0) {
|
||||
return get_queue (device.device, transfer);
|
||||
if (transfer < 0) {
|
||||
return detail::Error<QueueError>{ QueueError::transfer_unavailable };
|
||||
}
|
||||
return detail::Error<QueueError>{ QueueError::transfer_unavailable };
|
||||
return get_queue (device.device, transfer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,8 +113,6 @@ struct Instance {
|
||||
|
||||
private:
|
||||
bool headless = false;
|
||||
bool validation_enabled = false;
|
||||
bool debug_callback_enabled = false;
|
||||
|
||||
friend class InstanceBuilder;
|
||||
friend class PhysicalDeviceSelector;
|
||||
@ -321,14 +319,15 @@ struct Device {
|
||||
void destroy_device (Device device);
|
||||
|
||||
struct CustomQueueDescription {
|
||||
uint32_t index;
|
||||
uint32_t count;
|
||||
uint32_t index = 0;
|
||||
uint32_t count = 0;
|
||||
std::vector<float> priorities;
|
||||
};
|
||||
|
||||
class DeviceBuilder {
|
||||
public:
|
||||
DeviceBuilder (PhysicalDevice device);
|
||||
DeviceBuilder (PhysicalDevice physical_device);
|
||||
|
||||
detail::Expected<Device, detail::Error<DeviceError>> build ();
|
||||
|
||||
template <typename T> DeviceBuilder& add_pNext (T* structure);
|
||||
|
Loading…
Reference in New Issue
Block a user