FindQueue finds queue for given flag bits, sets in QueueIndex returns error if not found.
(gp *GPU, flags vk.QueueFlagBits)
| 37 | // FindQueue finds queue for given flag bits, sets in QueueIndex |
| 38 | // returns error if not found. |
| 39 | func (dv *Device) FindQueue(gp *GPU, flags vk.QueueFlagBits) error { |
| 40 | // Get queue family properties |
| 41 | var queueCount uint32 |
| 42 | vk.GetPhysicalDeviceQueueFamilyProperties(gp.GPU, &queueCount, nil) |
| 43 | queueProperties := make([]vk.QueueFamilyProperties, queueCount) |
| 44 | vk.GetPhysicalDeviceQueueFamilyProperties(gp.GPU, &queueCount, queueProperties) |
| 45 | if queueCount == 0 { // probably should try another GPU |
| 46 | return errors.New("vulkan error: no queue families found on GPU 0") |
| 47 | } |
| 48 | |
| 49 | // Find a suitable queue family for the target Vulkan mode |
| 50 | found := false |
| 51 | required := vk.QueueFlags(flags) |
| 52 | for i := uint32(0); i < queueCount; i++ { |
| 53 | queueProperties[i].Deref() |
| 54 | if queueProperties[i].QueueFlags&required != 0 { |
| 55 | dv.QueueIndex = i |
| 56 | found = true |
| 57 | break |
| 58 | } |
| 59 | } |
| 60 | if !found { |
| 61 | err := errors.New("GPU vulkan error: could not found queue with graphics capabilities") |
| 62 | return err |
| 63 | } |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | // MakeDevice and Queue based on QueueIndex |
| 68 | func (dv *Device) MakeDevice(gp *GPU) { |