Init initializes the device and all other resources for the surface based on the vulkan surface handle which must be obtained from the OS-specific window, created first (e.g., via glfw)
(gp *GPU, vs vk.Surface)
| 86 | // based on the vulkan surface handle which must be obtained from the |
| 87 | // OS-specific window, created first (e.g., via glfw) |
| 88 | func (sf *Surface) Init(gp *GPU, vs vk.Surface) error { |
| 89 | sf.GPU = gp |
| 90 | sf.Surface = vs |
| 91 | // Get queue family properties |
| 92 | var queueCount uint32 |
| 93 | vk.GetPhysicalDeviceQueueFamilyProperties(sf.GPU.GPU, &queueCount, nil) |
| 94 | queueProperties := make([]vk.QueueFamilyProperties, queueCount) |
| 95 | vk.GetPhysicalDeviceQueueFamilyProperties(sf.GPU.GPU, &queueCount, queueProperties) |
| 96 | if queueCount == 0 { // probably should try another GPU |
| 97 | return errors.New("vulkan error: no queue families found on GPU 0") |
| 98 | } |
| 99 | |
| 100 | // Find a suitable queue family for the target Vulkan mode |
| 101 | // note: this differs from generic Device.FindQueue in |
| 102 | // specifying the surface. |
| 103 | found := false |
| 104 | for i := uint32(0); i < queueCount; i++ { |
| 105 | var supportsPresent vk.Bool32 |
| 106 | vk.GetPhysicalDeviceSurfaceSupport(sf.GPU.GPU, i, sf.Surface, &supportsPresent) |
| 107 | if supportsPresent.B() { |
| 108 | sf.Device.QueueIndex = i |
| 109 | found = true |
| 110 | break |
| 111 | } |
| 112 | } |
| 113 | if !found { |
| 114 | err := errors.New("Surface vulkan error: could not found queue with present capabilities") |
| 115 | return err |
| 116 | } |
| 117 | |
| 118 | sf.Device.MakeDevice(gp) |
| 119 | sf.ConfigSwapchain() |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | // ConfigSwapchain configures the swapchain for surface. |
| 124 | // This assumes that all existing items have been destroyed. |
no test coverage detected