Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <memory> |
| 19 | |
| 20 | #include <gui/BufferQueue.h> |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 21 | #include <log/log.h> |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 22 | #include <sync/sync.h> |
| 23 | |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 24 | #include "driver.h" |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 25 | |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 26 | // TODO(jessehall): Currently we don't have a good error code for when a native |
| 27 | // window operation fails. Just returning INITIALIZATION_FAILED for now. Later |
| 28 | // versions (post SDK 0.9) of the API/extension have a better error code. |
| 29 | // When updating to that version, audit all error returns. |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 30 | namespace vulkan { |
| 31 | namespace driver { |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 32 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 33 | namespace { |
| 34 | |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | // These functions/classes form an adaptor that allows objects to be refcounted |
| 37 | // by both android::sp<> and std::shared_ptr<> simultaneously, and delegates |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 38 | // allocation of the shared_ptr<> control structure to VkAllocationCallbacks. |
| 39 | // The |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 40 | // platform holds a reference to the ANativeWindow using its embedded reference |
| 41 | // count, and the ANativeWindow implementation holds references to the |
| 42 | // ANativeWindowBuffers using their embedded reference counts, so the |
| 43 | // shared_ptr *must* cooperate with these and hold at least one reference to |
| 44 | // the object using the embedded reference count. |
| 45 | |
| 46 | template <typename T> |
| 47 | struct NativeBaseDeleter { |
| 48 | void operator()(T* obj) { obj->common.decRef(&obj->common); } |
| 49 | }; |
| 50 | |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 51 | template <typename Host> |
| 52 | struct AllocScope {}; |
| 53 | |
| 54 | template <> |
| 55 | struct AllocScope<VkInstance> { |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 56 | static const VkSystemAllocationScope kScope = |
| 57 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE; |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | template <> |
| 61 | struct AllocScope<VkDevice> { |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 62 | static const VkSystemAllocationScope kScope = |
| 63 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE; |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 66 | template <typename T> |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 67 | class VulkanAllocator { |
| 68 | public: |
| 69 | typedef T value_type; |
| 70 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 71 | VulkanAllocator(const VkAllocationCallbacks& allocator, |
| 72 | VkSystemAllocationScope scope) |
| 73 | : allocator_(allocator), scope_(scope) {} |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 74 | |
| 75 | template <typename U> |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 76 | explicit VulkanAllocator(const VulkanAllocator<U>& other) |
| 77 | : allocator_(other.allocator_), scope_(other.scope_) {} |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 78 | |
| 79 | T* allocate(size_t n) const { |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 80 | T* p = static_cast<T*>(allocator_.pfnAllocation( |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 81 | allocator_.pUserData, n * sizeof(T), alignof(T), scope_)); |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 82 | if (!p) |
| 83 | throw std::bad_alloc(); |
| 84 | return p; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 85 | } |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 86 | void deallocate(T* p, size_t) const noexcept { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 87 | return allocator_.pfnFree(allocator_.pUserData, p); |
| 88 | } |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 89 | |
| 90 | private: |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 91 | template <typename U> |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 92 | friend class VulkanAllocator; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 93 | const VkAllocationCallbacks& allocator_; |
| 94 | const VkSystemAllocationScope scope_; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 97 | template <typename T, typename Host> |
| 98 | std::shared_ptr<T> InitSharedPtr(Host host, T* obj) { |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 99 | try { |
| 100 | obj->common.incRef(&obj->common); |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 101 | return std::shared_ptr<T>(obj, NativeBaseDeleter<T>(), |
| 102 | VulkanAllocator<T>(GetData(host).allocator, |
| 103 | AllocScope<Host>::kScope)); |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 104 | } catch (std::bad_alloc&) { |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 105 | return nullptr; |
| 106 | } |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 109 | const VkSurfaceTransformFlagsKHR kSupportedTransforms = |
| 110 | VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR | |
| 111 | VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR | |
| 112 | VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR | |
| 113 | VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR | |
| 114 | // TODO(jessehall): See TODO in TranslateNativeToVulkanTransform. |
| 115 | // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR | |
| 116 | // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR | |
| 117 | // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR | |
| 118 | // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR | |
| 119 | VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR; |
| 120 | |
| 121 | VkSurfaceTransformFlagBitsKHR TranslateNativeToVulkanTransform(int native) { |
| 122 | // Native and Vulkan transforms are isomorphic, but are represented |
| 123 | // differently. Vulkan transforms are built up of an optional horizontal |
| 124 | // mirror, followed by a clockwise 0/90/180/270-degree rotation. Native |
| 125 | // transforms are built up from a horizontal flip, vertical flip, and |
| 126 | // 90-degree rotation, all optional but always in that order. |
| 127 | |
| 128 | // TODO(jessehall): For now, only support pure rotations, not |
| 129 | // flip or flip-and-rotate, until I have more time to test them and build |
| 130 | // sample code. As far as I know we never actually use anything besides |
| 131 | // pure rotations anyway. |
| 132 | |
| 133 | switch (native) { |
| 134 | case 0: // 0x0 |
| 135 | return VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
| 136 | // case NATIVE_WINDOW_TRANSFORM_FLIP_H: // 0x1 |
| 137 | // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR; |
| 138 | // case NATIVE_WINDOW_TRANSFORM_FLIP_V: // 0x2 |
| 139 | // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR; |
| 140 | case NATIVE_WINDOW_TRANSFORM_ROT_180: // FLIP_H | FLIP_V |
| 141 | return VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR; |
| 142 | case NATIVE_WINDOW_TRANSFORM_ROT_90: // 0x4 |
| 143 | return VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR; |
| 144 | // case NATIVE_WINDOW_TRANSFORM_FLIP_H | NATIVE_WINDOW_TRANSFORM_ROT_90: |
| 145 | // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR; |
| 146 | // case NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_ROT_90: |
| 147 | // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR; |
| 148 | case NATIVE_WINDOW_TRANSFORM_ROT_270: // FLIP_H | FLIP_V | ROT_90 |
| 149 | return VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR; |
| 150 | case NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY: |
| 151 | default: |
| 152 | return VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
| 153 | } |
| 154 | } |
| 155 | |
Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 156 | int InvertTransformToNative(VkSurfaceTransformFlagBitsKHR transform) { |
| 157 | switch (transform) { |
| 158 | case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR: |
| 159 | return NATIVE_WINDOW_TRANSFORM_ROT_270; |
| 160 | case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR: |
| 161 | return NATIVE_WINDOW_TRANSFORM_ROT_180; |
| 162 | case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR: |
| 163 | return NATIVE_WINDOW_TRANSFORM_ROT_90; |
| 164 | // TODO(jessehall): See TODO in TranslateNativeToVulkanTransform. |
| 165 | // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR: |
| 166 | // return NATIVE_WINDOW_TRANSFORM_FLIP_H; |
| 167 | // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR: |
| 168 | // return NATIVE_WINDOW_TRANSFORM_FLIP_H | |
| 169 | // NATIVE_WINDOW_TRANSFORM_ROT_90; |
| 170 | // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR: |
| 171 | // return NATIVE_WINDOW_TRANSFORM_FLIP_V; |
| 172 | // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR: |
| 173 | // return NATIVE_WINDOW_TRANSFORM_FLIP_V | |
| 174 | // NATIVE_WINDOW_TRANSFORM_ROT_90; |
| 175 | case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR: |
| 176 | case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR: |
| 177 | default: |
| 178 | return 0; |
| 179 | } |
| 180 | } |
| 181 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 182 | // ---------------------------------------------------------------------------- |
| 183 | |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 184 | struct Surface { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 185 | std::shared_ptr<ANativeWindow> window; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | VkSurfaceKHR HandleFromSurface(Surface* surface) { |
| 189 | return VkSurfaceKHR(reinterpret_cast<uint64_t>(surface)); |
| 190 | } |
| 191 | |
| 192 | Surface* SurfaceFromHandle(VkSurfaceKHR handle) { |
Jesse Hall | a3a7a1d | 2015-11-24 11:37:23 -0800 | [diff] [blame] | 193 | return reinterpret_cast<Surface*>(handle); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | struct Swapchain { |
| 197 | Swapchain(Surface& surface_, uint32_t num_images_) |
| 198 | : surface(surface_), num_images(num_images_) {} |
| 199 | |
| 200 | Surface& surface; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 201 | uint32_t num_images; |
| 202 | |
| 203 | struct Image { |
| 204 | Image() : image(VK_NULL_HANDLE), dequeue_fence(-1), dequeued(false) {} |
| 205 | VkImage image; |
| 206 | std::shared_ptr<ANativeWindowBuffer> buffer; |
| 207 | // The fence is only valid when the buffer is dequeued, and should be |
| 208 | // -1 any other time. When valid, we own the fd, and must ensure it is |
| 209 | // closed: either by closing it explicitly when queueing the buffer, |
| 210 | // or by passing ownership e.g. to ANativeWindow::cancelBuffer(). |
| 211 | int dequeue_fence; |
| 212 | bool dequeued; |
| 213 | } images[android::BufferQueue::NUM_BUFFER_SLOTS]; |
| 214 | }; |
| 215 | |
| 216 | VkSwapchainKHR HandleFromSwapchain(Swapchain* swapchain) { |
| 217 | return VkSwapchainKHR(reinterpret_cast<uint64_t>(swapchain)); |
| 218 | } |
| 219 | |
| 220 | Swapchain* SwapchainFromHandle(VkSwapchainKHR handle) { |
Jesse Hall | a3a7a1d | 2015-11-24 11:37:23 -0800 | [diff] [blame] | 221 | return reinterpret_cast<Swapchain*>(handle); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | } // anonymous namespace |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 225 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 226 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 227 | VkResult CreateAndroidSurfaceKHR( |
Jesse Hall | f9fa9a5 | 2016-01-08 16:08:51 -0800 | [diff] [blame] | 228 | VkInstance instance, |
| 229 | const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, |
| 230 | const VkAllocationCallbacks* allocator, |
| 231 | VkSurfaceKHR* out_surface) { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 232 | if (!allocator) |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 233 | allocator = &GetData(instance).allocator; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 234 | void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Surface), |
| 235 | alignof(Surface), |
| 236 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 237 | if (!mem) |
| 238 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 239 | Surface* surface = new (mem) Surface; |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 240 | |
Jesse Hall | f9fa9a5 | 2016-01-08 16:08:51 -0800 | [diff] [blame] | 241 | surface->window = InitSharedPtr(instance, pCreateInfo->window); |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 242 | if (!surface->window) { |
| 243 | ALOGE("surface creation failed: out of memory"); |
| 244 | surface->~Surface(); |
| 245 | allocator->pfnFree(allocator->pUserData, surface); |
| 246 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 247 | } |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 248 | |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 249 | // TODO(jessehall): Create and use NATIVE_WINDOW_API_VULKAN. |
| 250 | int err = |
| 251 | native_window_api_connect(surface->window.get(), NATIVE_WINDOW_API_EGL); |
| 252 | if (err != 0) { |
| 253 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 254 | // errors and translate them to valid Vulkan result codes? |
| 255 | ALOGE("native_window_api_connect() failed: %s (%d)", strerror(-err), |
| 256 | err); |
| 257 | surface->~Surface(); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 258 | allocator->pfnFree(allocator->pUserData, surface); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 259 | return VK_ERROR_INITIALIZATION_FAILED; |
| 260 | } |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 261 | |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 262 | *out_surface = HandleFromSurface(surface); |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 263 | return VK_SUCCESS; |
| 264 | } |
| 265 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 266 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 267 | void DestroySurfaceKHR(VkInstance instance, |
| 268 | VkSurfaceKHR surface_handle, |
| 269 | const VkAllocationCallbacks* allocator) { |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 270 | Surface* surface = SurfaceFromHandle(surface_handle); |
| 271 | if (!surface) |
| 272 | return; |
| 273 | native_window_api_disconnect(surface->window.get(), NATIVE_WINDOW_API_EGL); |
| 274 | surface->~Surface(); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 275 | if (!allocator) |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 276 | allocator = &GetData(instance).allocator; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 277 | allocator->pfnFree(allocator->pUserData, surface); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 280 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 281 | VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice /*pdev*/, |
| 282 | uint32_t /*queue_family*/, |
| 283 | VkSurfaceKHR /*surface*/, |
| 284 | VkBool32* supported) { |
Jesse Hall | 0e74f00 | 2015-11-30 11:37:59 -0800 | [diff] [blame] | 285 | *supported = VK_TRUE; |
Jesse Hall | a642925 | 2015-11-29 18:59:42 -0800 | [diff] [blame] | 286 | return VK_SUCCESS; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 289 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 290 | VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR( |
Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 291 | VkPhysicalDevice /*pdev*/, |
| 292 | VkSurfaceKHR surface, |
| 293 | VkSurfaceCapabilitiesKHR* capabilities) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 294 | int err; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 295 | ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 296 | |
| 297 | int width, height; |
| 298 | err = window->query(window, NATIVE_WINDOW_DEFAULT_WIDTH, &width); |
| 299 | if (err != 0) { |
| 300 | ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)", |
| 301 | strerror(-err), err); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 302 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 303 | } |
| 304 | err = window->query(window, NATIVE_WINDOW_DEFAULT_HEIGHT, &height); |
| 305 | if (err != 0) { |
| 306 | ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)", |
| 307 | strerror(-err), err); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 308 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 311 | int transform_hint; |
| 312 | err = window->query(window, NATIVE_WINDOW_TRANSFORM_HINT, &transform_hint); |
| 313 | if (err != 0) { |
| 314 | ALOGE("NATIVE_WINDOW_TRANSFORM_HINT query failed: %s (%d)", |
| 315 | strerror(-err), err); |
| 316 | return VK_ERROR_INITIALIZATION_FAILED; |
| 317 | } |
| 318 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 319 | // TODO(jessehall): Figure out what the min/max values should be. |
Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 320 | capabilities->minImageCount = 2; |
| 321 | capabilities->maxImageCount = 3; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 322 | |
Jesse Hall | fe2662d | 2016-02-09 13:26:59 -0800 | [diff] [blame] | 323 | capabilities->currentExtent = |
| 324 | VkExtent2D{static_cast<uint32_t>(width), static_cast<uint32_t>(height)}; |
| 325 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 326 | // TODO(jessehall): Figure out what the max extent should be. Maximum |
| 327 | // texture dimension maybe? |
Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 328 | capabilities->minImageExtent = VkExtent2D{1, 1}; |
| 329 | capabilities->maxImageExtent = VkExtent2D{4096, 4096}; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 330 | |
Jesse Hall | fe2662d | 2016-02-09 13:26:59 -0800 | [diff] [blame] | 331 | capabilities->maxImageArrayLayers = 1; |
| 332 | |
Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 333 | capabilities->supportedTransforms = kSupportedTransforms; |
| 334 | capabilities->currentTransform = |
| 335 | TranslateNativeToVulkanTransform(transform_hint); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 336 | |
Jesse Hall | fe2662d | 2016-02-09 13:26:59 -0800 | [diff] [blame] | 337 | // On Android, window composition is a WindowManager property, not something |
| 338 | // associated with the bufferqueue. It can't be changed from here. |
| 339 | capabilities->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 340 | |
| 341 | // TODO(jessehall): I think these are right, but haven't thought hard about |
| 342 | // it. Do we need to query the driver for support of any of these? |
| 343 | // Currently not included: |
| 344 | // - VK_IMAGE_USAGE_GENERAL: maybe? does this imply cpu mappable? |
| 345 | // - VK_IMAGE_USAGE_DEPTH_STENCIL_BIT: definitely not |
| 346 | // - VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT: definitely not |
Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 347 | capabilities->supportedUsageFlags = |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 348 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | |
| 349 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | |
| 350 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 351 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; |
| 352 | |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 353 | return VK_SUCCESS; |
| 354 | } |
| 355 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 356 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 357 | VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice /*pdev*/, |
| 358 | VkSurfaceKHR /*surface*/, |
| 359 | uint32_t* count, |
| 360 | VkSurfaceFormatKHR* formats) { |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 361 | // TODO(jessehall): Fill out the set of supported formats. Longer term, add |
| 362 | // a new gralloc method to query whether a (format, usage) pair is |
| 363 | // supported, and check that for each gralloc format that corresponds to a |
| 364 | // Vulkan format. Shorter term, just add a few more formats to the ones |
| 365 | // hardcoded below. |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 366 | |
| 367 | const VkSurfaceFormatKHR kFormats[] = { |
| 368 | {VK_FORMAT_R8G8B8A8_UNORM, VK_COLORSPACE_SRGB_NONLINEAR_KHR}, |
| 369 | {VK_FORMAT_R8G8B8A8_SRGB, VK_COLORSPACE_SRGB_NONLINEAR_KHR}, |
Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 370 | {VK_FORMAT_R5G6B5_UNORM_PACK16, VK_COLORSPACE_SRGB_NONLINEAR_KHR}, |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 371 | }; |
| 372 | const uint32_t kNumFormats = sizeof(kFormats) / sizeof(kFormats[0]); |
| 373 | |
| 374 | VkResult result = VK_SUCCESS; |
| 375 | if (formats) { |
| 376 | if (*count < kNumFormats) |
| 377 | result = VK_INCOMPLETE; |
| 378 | std::copy(kFormats, kFormats + std::min(*count, kNumFormats), formats); |
| 379 | } |
| 380 | *count = kNumFormats; |
| 381 | return result; |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 384 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 385 | VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice /*pdev*/, |
| 386 | VkSurfaceKHR /*surface*/, |
| 387 | uint32_t* count, |
| 388 | VkPresentModeKHR* modes) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 389 | const VkPresentModeKHR kModes[] = { |
| 390 | VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_FIFO_KHR, |
| 391 | }; |
| 392 | const uint32_t kNumModes = sizeof(kModes) / sizeof(kModes[0]); |
| 393 | |
| 394 | VkResult result = VK_SUCCESS; |
| 395 | if (modes) { |
| 396 | if (*count < kNumModes) |
| 397 | result = VK_INCOMPLETE; |
| 398 | std::copy(kModes, kModes + std::min(*count, kNumModes), modes); |
| 399 | } |
| 400 | *count = kNumModes; |
| 401 | return result; |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 404 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 405 | VkResult CreateSwapchainKHR(VkDevice device, |
| 406 | const VkSwapchainCreateInfoKHR* create_info, |
| 407 | const VkAllocationCallbacks* allocator, |
| 408 | VkSwapchainKHR* swapchain_handle) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 409 | int err; |
| 410 | VkResult result = VK_SUCCESS; |
| 411 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 412 | if (!allocator) |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 413 | allocator = &GetData(device).allocator; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 414 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 415 | ALOGV_IF(create_info->imageArrayLayers != 1, |
| 416 | "Swapchain imageArrayLayers (%u) != 1 not supported", |
| 417 | create_info->imageArrayLayers); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 418 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 419 | ALOGE_IF(create_info->imageColorSpace != VK_COLORSPACE_SRGB_NONLINEAR_KHR, |
| 420 | "color spaces other than SRGB_NONLINEAR not yet implemented"); |
| 421 | ALOGE_IF(create_info->oldSwapchain, |
| 422 | "swapchain re-creation not yet implemented"); |
Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 423 | ALOGE_IF((create_info->preTransform & ~kSupportedTransforms) != 0, |
| 424 | "swapchain preTransform %d not supported", |
| 425 | create_info->preTransform); |
Jesse Hall | 0ae0dce | 2016-02-09 22:13:34 -0800 | [diff] [blame] | 426 | ALOGW_IF(!(create_info->presentMode == VK_PRESENT_MODE_FIFO_KHR || |
| 427 | create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR), |
| 428 | "swapchain present mode %d not supported", |
| 429 | create_info->presentMode); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 430 | |
| 431 | // -- Configure the native window -- |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 432 | |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 433 | Surface& surface = *SurfaceFromHandle(create_info->surface); |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 434 | const auto& dispatch = GetData(device).driver; |
Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 435 | |
Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 436 | int native_format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 437 | switch (create_info->imageFormat) { |
| 438 | case VK_FORMAT_R8G8B8A8_UNORM: |
| 439 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 440 | native_format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 441 | break; |
| 442 | case VK_FORMAT_R5G6B5_UNORM_PACK16: |
| 443 | native_format = HAL_PIXEL_FORMAT_RGB_565; |
| 444 | break; |
| 445 | default: |
| 446 | ALOGE("unsupported swapchain format %d", create_info->imageFormat); |
| 447 | break; |
| 448 | } |
| 449 | err = native_window_set_buffers_format(surface.window.get(), native_format); |
| 450 | if (err != 0) { |
| 451 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 452 | // errors and translate them to valid Vulkan result codes? |
| 453 | ALOGE("native_window_set_buffers_format(%d) failed: %s (%d)", |
| 454 | native_format, strerror(-err), err); |
| 455 | return VK_ERROR_INITIALIZATION_FAILED; |
| 456 | } |
| 457 | err = native_window_set_buffers_data_space(surface.window.get(), |
| 458 | HAL_DATASPACE_SRGB_LINEAR); |
| 459 | if (err != 0) { |
| 460 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 461 | // errors and translate them to valid Vulkan result codes? |
| 462 | ALOGE("native_window_set_buffers_data_space(%d) failed: %s (%d)", |
| 463 | HAL_DATASPACE_SRGB_LINEAR, strerror(-err), err); |
| 464 | return VK_ERROR_INITIALIZATION_FAILED; |
| 465 | } |
| 466 | |
Jesse Hall | 3dd678a | 2016-01-08 21:52:01 -0800 | [diff] [blame] | 467 | err = native_window_set_buffers_dimensions( |
| 468 | surface.window.get(), static_cast<int>(create_info->imageExtent.width), |
| 469 | static_cast<int>(create_info->imageExtent.height)); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 470 | if (err != 0) { |
| 471 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 472 | // errors and translate them to valid Vulkan result codes? |
| 473 | ALOGE("native_window_set_buffers_dimensions(%d,%d) failed: %s (%d)", |
| 474 | create_info->imageExtent.width, create_info->imageExtent.height, |
| 475 | strerror(-err), err); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 476 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 479 | // VkSwapchainCreateInfo::preTransform indicates the transformation the app |
| 480 | // applied during rendering. native_window_set_transform() expects the |
| 481 | // inverse: the transform the app is requesting that the compositor perform |
| 482 | // during composition. With native windows, pre-transform works by rendering |
| 483 | // with the same transform the compositor is applying (as in Vulkan), but |
| 484 | // then requesting the inverse transform, so that when the compositor does |
| 485 | // it's job the two transforms cancel each other out and the compositor ends |
| 486 | // up applying an identity transform to the app's buffer. |
| 487 | err = native_window_set_buffers_transform( |
| 488 | surface.window.get(), |
| 489 | InvertTransformToNative(create_info->preTransform)); |
| 490 | if (err != 0) { |
| 491 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 492 | // errors and translate them to valid Vulkan result codes? |
| 493 | ALOGE("native_window_set_buffers_transform(%d) failed: %s (%d)", |
| 494 | InvertTransformToNative(create_info->preTransform), |
| 495 | strerror(-err), err); |
| 496 | return VK_ERROR_INITIALIZATION_FAILED; |
| 497 | } |
| 498 | |
Jesse Hall | f64ca12 | 2015-11-03 16:11:10 -0800 | [diff] [blame] | 499 | err = native_window_set_scaling_mode( |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 500 | surface.window.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
Jesse Hall | f64ca12 | 2015-11-03 16:11:10 -0800 | [diff] [blame] | 501 | if (err != 0) { |
| 502 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 503 | // errors and translate them to valid Vulkan result codes? |
| 504 | ALOGE("native_window_set_scaling_mode(SCALE_TO_WINDOW) failed: %s (%d)", |
| 505 | strerror(-err), err); |
Jesse Hall | f64ca12 | 2015-11-03 16:11:10 -0800 | [diff] [blame] | 506 | return VK_ERROR_INITIALIZATION_FAILED; |
| 507 | } |
| 508 | |
Jesse Hall | e6080bf | 2016-02-28 20:58:50 -0800 | [diff] [blame] | 509 | int query_value; |
| 510 | err = surface.window->query(surface.window.get(), |
| 511 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, |
| 512 | &query_value); |
| 513 | if (err != 0 || query_value < 0) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 514 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 515 | // errors and translate them to valid Vulkan result codes? |
Jesse Hall | e6080bf | 2016-02-28 20:58:50 -0800 | [diff] [blame] | 516 | ALOGE("window->query failed: %s (%d) value=%d", strerror(-err), err, |
| 517 | query_value); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 518 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 519 | } |
Jesse Hall | e6080bf | 2016-02-28 20:58:50 -0800 | [diff] [blame] | 520 | uint32_t min_undequeued_buffers = static_cast<uint32_t>(query_value); |
Jesse Hall | 0ae0dce | 2016-02-09 22:13:34 -0800 | [diff] [blame] | 521 | // The MIN_UNDEQUEUED_BUFFERS query doesn't know whether we'll be using |
| 522 | // async mode or not, and assumes not. But in async mode, the BufferQueue |
| 523 | // requires an extra undequeued buffer. |
| 524 | // See BufferQueueCore::getMinUndequeuedBufferCountLocked(). |
| 525 | if (create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR) |
| 526 | min_undequeued_buffers += 1; |
| 527 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 528 | uint32_t num_images = |
| 529 | (create_info->minImageCount - 1) + min_undequeued_buffers; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 530 | err = native_window_set_buffer_count(surface.window.get(), num_images); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 531 | if (err != 0) { |
| 532 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 533 | // errors and translate them to valid Vulkan result codes? |
| 534 | ALOGE("native_window_set_buffer_count failed: %s (%d)", strerror(-err), |
| 535 | err); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 536 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 539 | int gralloc_usage = 0; |
| 540 | // TODO(jessehall): Remove conditional once all drivers have been updated |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 541 | if (dispatch.GetSwapchainGrallocUsageANDROID) { |
| 542 | result = dispatch.GetSwapchainGrallocUsageANDROID( |
Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 543 | device, create_info->imageFormat, create_info->imageUsage, |
Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 544 | &gralloc_usage); |
| 545 | if (result != VK_SUCCESS) { |
| 546 | ALOGE("vkGetSwapchainGrallocUsageANDROID failed: %d", result); |
Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 547 | return VK_ERROR_INITIALIZATION_FAILED; |
| 548 | } |
| 549 | } else { |
| 550 | gralloc_usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; |
| 551 | } |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 552 | err = native_window_set_usage(surface.window.get(), gralloc_usage); |
Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 553 | if (err != 0) { |
| 554 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 555 | // errors and translate them to valid Vulkan result codes? |
| 556 | ALOGE("native_window_set_usage failed: %s (%d)", strerror(-err), err); |
Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 557 | return VK_ERROR_INITIALIZATION_FAILED; |
| 558 | } |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 559 | |
Jesse Hall | 0ae0dce | 2016-02-09 22:13:34 -0800 | [diff] [blame] | 560 | err = surface.window->setSwapInterval( |
| 561 | surface.window.get(), |
| 562 | create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR ? 0 : 1); |
| 563 | if (err != 0) { |
| 564 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 565 | // errors and translate them to valid Vulkan result codes? |
| 566 | ALOGE("native_window->setSwapInterval failed: %s (%d)", strerror(-err), |
| 567 | err); |
| 568 | return VK_ERROR_INITIALIZATION_FAILED; |
| 569 | } |
| 570 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 571 | // -- Allocate our Swapchain object -- |
| 572 | // After this point, we must deallocate the swapchain on error. |
| 573 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 574 | void* mem = allocator->pfnAllocation(allocator->pUserData, |
| 575 | sizeof(Swapchain), alignof(Swapchain), |
| 576 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 577 | if (!mem) |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 578 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 579 | Swapchain* swapchain = new (mem) Swapchain(surface, num_images); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 580 | |
| 581 | // -- Dequeue all buffers and create a VkImage for each -- |
| 582 | // Any failures during or after this must cancel the dequeued buffers. |
| 583 | |
| 584 | VkNativeBufferANDROID image_native_buffer = { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 585 | #pragma clang diagnostic push |
| 586 | #pragma clang diagnostic ignored "-Wold-style-cast" |
| 587 | .sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID, |
| 588 | #pragma clang diagnostic pop |
| 589 | .pNext = nullptr, |
| 590 | }; |
| 591 | VkImageCreateInfo image_create = { |
| 592 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 593 | .pNext = &image_native_buffer, |
| 594 | .imageType = VK_IMAGE_TYPE_2D, |
Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 595 | .format = create_info->imageFormat, |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 596 | .extent = {0, 0, 1}, |
| 597 | .mipLevels = 1, |
Jesse Hall | a15a4bf | 2015-11-19 22:48:02 -0800 | [diff] [blame] | 598 | .arrayLayers = 1, |
Jesse Hall | 091ed9e | 2015-11-30 00:55:29 -0800 | [diff] [blame] | 599 | .samples = VK_SAMPLE_COUNT_1_BIT, |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 600 | .tiling = VK_IMAGE_TILING_OPTIMAL, |
Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 601 | .usage = create_info->imageUsage, |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 602 | .flags = 0, |
Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 603 | .sharingMode = create_info->imageSharingMode, |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 604 | .queueFamilyIndexCount = create_info->queueFamilyIndexCount, |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 605 | .pQueueFamilyIndices = create_info->pQueueFamilyIndices, |
| 606 | }; |
| 607 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 608 | for (uint32_t i = 0; i < num_images; i++) { |
| 609 | Swapchain::Image& img = swapchain->images[i]; |
| 610 | |
| 611 | ANativeWindowBuffer* buffer; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 612 | err = surface.window->dequeueBuffer(surface.window.get(), &buffer, |
| 613 | &img.dequeue_fence); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 614 | if (err != 0) { |
| 615 | // TODO(jessehall): Improve error reporting. Can we enumerate |
| 616 | // possible errors and translate them to valid Vulkan result codes? |
| 617 | ALOGE("dequeueBuffer[%u] failed: %s (%d)", i, strerror(-err), err); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 618 | result = VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 619 | break; |
| 620 | } |
| 621 | img.buffer = InitSharedPtr(device, buffer); |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 622 | if (!img.buffer) { |
| 623 | ALOGE("swapchain creation failed: out of memory"); |
| 624 | surface.window->cancelBuffer(surface.window.get(), buffer, |
| 625 | img.dequeue_fence); |
| 626 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 627 | break; |
| 628 | } |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 629 | img.dequeued = true; |
| 630 | |
| 631 | image_create.extent = |
Jesse Hall | 3dd678a | 2016-01-08 21:52:01 -0800 | [diff] [blame] | 632 | VkExtent3D{static_cast<uint32_t>(img.buffer->width), |
| 633 | static_cast<uint32_t>(img.buffer->height), |
| 634 | 1}; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 635 | image_native_buffer.handle = img.buffer->handle; |
| 636 | image_native_buffer.stride = img.buffer->stride; |
| 637 | image_native_buffer.format = img.buffer->format; |
| 638 | image_native_buffer.usage = img.buffer->usage; |
| 639 | |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 640 | result = |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 641 | dispatch.CreateImage(device, &image_create, nullptr, &img.image); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 642 | if (result != VK_SUCCESS) { |
| 643 | ALOGD("vkCreateImage w/ native buffer failed: %u", result); |
| 644 | break; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | // -- Cancel all buffers, returning them to the queue -- |
| 649 | // If an error occurred before, also destroy the VkImage and release the |
| 650 | // buffer reference. Otherwise, we retain a strong reference to the buffer. |
| 651 | // |
| 652 | // TODO(jessehall): The error path here is the same as DestroySwapchain, |
| 653 | // but not the non-error path. Should refactor/unify. |
| 654 | for (uint32_t i = 0; i < num_images; i++) { |
| 655 | Swapchain::Image& img = swapchain->images[i]; |
| 656 | if (img.dequeued) { |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 657 | surface.window->cancelBuffer(surface.window.get(), img.buffer.get(), |
| 658 | img.dequeue_fence); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 659 | img.dequeue_fence = -1; |
| 660 | img.dequeued = false; |
| 661 | } |
| 662 | if (result != VK_SUCCESS) { |
| 663 | if (img.image) |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 664 | dispatch.DestroyImage(device, img.image, nullptr); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
| 668 | if (result != VK_SUCCESS) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 669 | swapchain->~Swapchain(); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 670 | allocator->pfnFree(allocator->pUserData, swapchain); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 671 | return result; |
| 672 | } |
| 673 | |
| 674 | *swapchain_handle = HandleFromSwapchain(swapchain); |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 675 | return VK_SUCCESS; |
| 676 | } |
| 677 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 678 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 679 | void DestroySwapchainKHR(VkDevice device, |
| 680 | VkSwapchainKHR swapchain_handle, |
| 681 | const VkAllocationCallbacks* allocator) { |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 682 | const auto& dispatch = GetData(device).driver; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 683 | Swapchain* swapchain = SwapchainFromHandle(swapchain_handle); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 684 | const std::shared_ptr<ANativeWindow>& window = swapchain->surface.window; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 685 | |
| 686 | for (uint32_t i = 0; i < swapchain->num_images; i++) { |
| 687 | Swapchain::Image& img = swapchain->images[i]; |
| 688 | if (img.dequeued) { |
| 689 | window->cancelBuffer(window.get(), img.buffer.get(), |
| 690 | img.dequeue_fence); |
| 691 | img.dequeue_fence = -1; |
| 692 | img.dequeued = false; |
| 693 | } |
| 694 | if (img.image) { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 695 | dispatch.DestroyImage(device, img.image, nullptr); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 699 | if (!allocator) |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 700 | allocator = &GetData(device).allocator; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 701 | swapchain->~Swapchain(); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 702 | allocator->pfnFree(allocator->pUserData, swapchain); |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 705 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 706 | VkResult GetSwapchainImagesKHR(VkDevice, |
| 707 | VkSwapchainKHR swapchain_handle, |
| 708 | uint32_t* count, |
| 709 | VkImage* images) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 710 | Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); |
| 711 | VkResult result = VK_SUCCESS; |
| 712 | if (images) { |
| 713 | uint32_t n = swapchain.num_images; |
| 714 | if (*count < swapchain.num_images) { |
| 715 | n = *count; |
| 716 | result = VK_INCOMPLETE; |
| 717 | } |
| 718 | for (uint32_t i = 0; i < n; i++) |
| 719 | images[i] = swapchain.images[i].image; |
| 720 | } |
| 721 | *count = swapchain.num_images; |
| 722 | return result; |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 725 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 726 | VkResult AcquireNextImageKHR(VkDevice device, |
| 727 | VkSwapchainKHR swapchain_handle, |
| 728 | uint64_t timeout, |
| 729 | VkSemaphore semaphore, |
| 730 | VkFence vk_fence, |
| 731 | uint32_t* image_index) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 732 | Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 733 | ANativeWindow* window = swapchain.surface.window.get(); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 734 | VkResult result; |
| 735 | int err; |
| 736 | |
| 737 | ALOGW_IF( |
| 738 | timeout != UINT64_MAX, |
| 739 | "vkAcquireNextImageKHR: non-infinite timeouts not yet implemented"); |
| 740 | |
| 741 | ANativeWindowBuffer* buffer; |
Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 742 | int fence_fd; |
| 743 | err = window->dequeueBuffer(window, &buffer, &fence_fd); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 744 | if (err != 0) { |
| 745 | // TODO(jessehall): Improve error reporting. Can we enumerate possible |
| 746 | // errors and translate them to valid Vulkan result codes? |
| 747 | ALOGE("dequeueBuffer failed: %s (%d)", strerror(-err), err); |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 748 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | uint32_t idx; |
| 752 | for (idx = 0; idx < swapchain.num_images; idx++) { |
| 753 | if (swapchain.images[idx].buffer.get() == buffer) { |
| 754 | swapchain.images[idx].dequeued = true; |
Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 755 | swapchain.images[idx].dequeue_fence = fence_fd; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 756 | break; |
| 757 | } |
| 758 | } |
| 759 | if (idx == swapchain.num_images) { |
| 760 | ALOGE("dequeueBuffer returned unrecognized buffer"); |
Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 761 | window->cancelBuffer(window, buffer, fence_fd); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 762 | return VK_ERROR_OUT_OF_DATE_KHR; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | int fence_clone = -1; |
Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 766 | if (fence_fd != -1) { |
| 767 | fence_clone = dup(fence_fd); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 768 | if (fence_clone == -1) { |
| 769 | ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", |
| 770 | strerror(errno), errno); |
Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 771 | sync_wait(fence_fd, -1 /* forever */); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 775 | result = GetData(device).driver.AcquireImageANDROID( |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 776 | device, swapchain.images[idx].image, fence_clone, semaphore, vk_fence); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 777 | if (result != VK_SUCCESS) { |
Jesse Hall | ab9aeef | 2015-11-04 10:56:20 -0800 | [diff] [blame] | 778 | // NOTE: we're relying on AcquireImageANDROID to close fence_clone, |
| 779 | // even if the call fails. We could close it ourselves on failure, but |
| 780 | // that would create a race condition if the driver closes it on a |
| 781 | // failure path: some other thread might create an fd with the same |
| 782 | // number between the time the driver closes it and the time we close |
| 783 | // it. We must assume one of: the driver *always* closes it even on |
| 784 | // failure, or *never* closes it on failure. |
Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 785 | window->cancelBuffer(window, buffer, fence_fd); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 786 | swapchain.images[idx].dequeued = false; |
| 787 | swapchain.images[idx].dequeue_fence = -1; |
| 788 | return result; |
| 789 | } |
| 790 | |
| 791 | *image_index = idx; |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 792 | return VK_SUCCESS; |
| 793 | } |
| 794 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 795 | VKAPI_ATTR |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 796 | VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info) { |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 797 | ALOGV_IF(present_info->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, |
| 798 | "vkQueuePresentKHR: invalid VkPresentInfoKHR structure type %d", |
| 799 | present_info->sType); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 800 | ALOGV_IF(present_info->pNext, "VkPresentInfo::pNext != NULL"); |
| 801 | |
Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 802 | const auto& dispatch = GetData(queue).driver; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 803 | VkResult final_result = VK_SUCCESS; |
| 804 | for (uint32_t sc = 0; sc < present_info->swapchainCount; sc++) { |
| 805 | Swapchain& swapchain = |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 806 | *SwapchainFromHandle(present_info->pSwapchains[sc]); |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 807 | ANativeWindow* window = swapchain.surface.window.get(); |
Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 808 | uint32_t image_idx = present_info->pImageIndices[sc]; |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 809 | Swapchain::Image& img = swapchain.images[image_idx]; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 810 | VkResult result; |
| 811 | int err; |
| 812 | |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 813 | int fence = -1; |
Jesse Hall | 275d76c | 2016-01-08 22:39:16 -0800 | [diff] [blame] | 814 | result = dispatch.QueueSignalReleaseImageANDROID( |
| 815 | queue, present_info->waitSemaphoreCount, |
| 816 | present_info->pWaitSemaphores, img.image, &fence); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 817 | if (result != VK_SUCCESS) { |
Jesse Hall | ab9aeef | 2015-11-04 10:56:20 -0800 | [diff] [blame] | 818 | ALOGE("QueueSignalReleaseImageANDROID failed: %d", result); |
Jesse Hall | a9e5703 | 2015-11-30 01:03:10 -0800 | [diff] [blame] | 819 | if (present_info->pResults) |
| 820 | present_info->pResults[sc] = result; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 821 | if (final_result == VK_SUCCESS) |
| 822 | final_result = result; |
| 823 | // TODO(jessehall): What happens to the buffer here? Does the app |
| 824 | // still own it or not, i.e. should we cancel the buffer? Hard to |
| 825 | // do correctly without synchronizing, though I guess we could wait |
| 826 | // for the queue to idle. |
| 827 | continue; |
| 828 | } |
| 829 | |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 830 | err = window->queueBuffer(window, img.buffer.get(), fence); |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 831 | if (err != 0) { |
| 832 | // TODO(jessehall): What now? We should probably cancel the buffer, |
| 833 | // I guess? |
| 834 | ALOGE("queueBuffer failed: %s (%d)", strerror(-err), err); |
Jesse Hall | a9e5703 | 2015-11-30 01:03:10 -0800 | [diff] [blame] | 835 | if (present_info->pResults) |
| 836 | present_info->pResults[sc] = result; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 837 | if (final_result == VK_SUCCESS) |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 838 | final_result = VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 839 | continue; |
| 840 | } |
| 841 | |
| 842 | if (img.dequeue_fence != -1) { |
| 843 | close(img.dequeue_fence); |
| 844 | img.dequeue_fence = -1; |
| 845 | } |
| 846 | img.dequeued = false; |
Jesse Hall | a9e5703 | 2015-11-30 01:03:10 -0800 | [diff] [blame] | 847 | |
| 848 | if (present_info->pResults) |
| 849 | present_info->pResults[sc] = VK_SUCCESS; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | return final_result; |
| 853 | } |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 854 | |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 855 | } // namespace driver |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 856 | } // namespace vulkan |