| 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 |  | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
 | 18 |  | 
| Yiwei Zhang | 0f47522 | 2019-04-11 19:38:00 -0700 | [diff] [blame] | 19 | #include <android/hardware/graphics/common/1.0/types.h> | 
| Jesse Hall | 7992781 | 2017-03-23 11:03:23 -0700 | [diff] [blame] | 20 | #include <grallocusage/GrallocUsageConversion.h> | 
| Yiwei Zhang | 69395cd | 2019-07-03 16:55:39 -0700 | [diff] [blame] | 21 | #include <graphicsenv/GraphicsEnv.h> | 
| Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 22 | #include <log/log.h> | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 23 | #include <sync/sync.h> | 
| Yiwei Zhang | 0f47522 | 2019-04-11 19:38:00 -0700 | [diff] [blame] | 24 | #include <system/window.h> | 
 | 25 | #include <ui/BufferQueueDefs.h> | 
| Chia-I Wu | e8e689f | 2016-04-18 08:21:31 +0800 | [diff] [blame] | 26 | #include <utils/StrongPointer.h> | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 27 | #include <utils/Timers.h> | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 28 | #include <utils/Trace.h> | 
| Yiwei Zhang | 0f47522 | 2019-04-11 19:38:00 -0700 | [diff] [blame] | 29 |  | 
 | 30 | #include <algorithm> | 
 | 31 | #include <unordered_set> | 
 | 32 | #include <vector> | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 33 |  | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 34 | #include "driver.h" | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 35 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 36 | using android::hardware::graphics::common::V1_0::BufferUsage; | 
 | 37 |  | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 38 | namespace vulkan { | 
 | 39 | namespace driver { | 
| Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 40 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 41 | namespace { | 
 | 42 |  | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 43 | const VkSurfaceTransformFlagsKHR kSupportedTransforms = | 
 | 44 |     VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR | | 
 | 45 |     VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR | | 
 | 46 |     VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR | | 
 | 47 |     VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR | | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 48 |     VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR | | 
 | 49 |     VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR | | 
 | 50 |     VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR | | 
 | 51 |     VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR | | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 52 |     VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR; | 
 | 53 |  | 
 | 54 | VkSurfaceTransformFlagBitsKHR TranslateNativeToVulkanTransform(int native) { | 
 | 55 |     // Native and Vulkan transforms are isomorphic, but are represented | 
 | 56 |     // differently. Vulkan transforms are built up of an optional horizontal | 
 | 57 |     // mirror, followed by a clockwise 0/90/180/270-degree rotation. Native | 
 | 58 |     // transforms are built up from a horizontal flip, vertical flip, and | 
 | 59 |     // 90-degree rotation, all optional but always in that order. | 
 | 60 |  | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 61 |     switch (native) { | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 62 |         case 0: | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 63 |             return VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 64 |         case NATIVE_WINDOW_TRANSFORM_FLIP_H: | 
 | 65 |             return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR; | 
 | 66 |         case NATIVE_WINDOW_TRANSFORM_FLIP_V: | 
 | 67 |             return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR; | 
 | 68 |         case NATIVE_WINDOW_TRANSFORM_ROT_180: | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 69 |             return VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR; | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 70 |         case NATIVE_WINDOW_TRANSFORM_ROT_90: | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 71 |             return VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR; | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 72 |         case NATIVE_WINDOW_TRANSFORM_FLIP_H | NATIVE_WINDOW_TRANSFORM_ROT_90: | 
 | 73 |             return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR; | 
 | 74 |         case NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_ROT_90: | 
 | 75 |             return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR; | 
 | 76 |         case NATIVE_WINDOW_TRANSFORM_ROT_270: | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 77 |             return VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR; | 
 | 78 |         case NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY: | 
 | 79 |         default: | 
 | 80 |             return VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; | 
 | 81 |     } | 
 | 82 | } | 
 | 83 |  | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 84 | int TranslateVulkanToNativeTransform(VkSurfaceTransformFlagBitsKHR transform) { | 
 | 85 |     switch (transform) { | 
 | 86 |         case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR: | 
 | 87 |             return NATIVE_WINDOW_TRANSFORM_ROT_90; | 
 | 88 |         case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR: | 
 | 89 |             return NATIVE_WINDOW_TRANSFORM_ROT_180; | 
 | 90 |         case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR: | 
 | 91 |             return NATIVE_WINDOW_TRANSFORM_ROT_270; | 
 | 92 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR: | 
 | 93 |             return NATIVE_WINDOW_TRANSFORM_FLIP_H; | 
 | 94 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR: | 
 | 95 |             return NATIVE_WINDOW_TRANSFORM_FLIP_H | | 
 | 96 |                    NATIVE_WINDOW_TRANSFORM_ROT_90; | 
 | 97 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR: | 
 | 98 |             return NATIVE_WINDOW_TRANSFORM_FLIP_V; | 
 | 99 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR: | 
 | 100 |             return NATIVE_WINDOW_TRANSFORM_FLIP_V | | 
 | 101 |                    NATIVE_WINDOW_TRANSFORM_ROT_90; | 
 | 102 |         case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR: | 
 | 103 |         case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR: | 
 | 104 |         default: | 
 | 105 |             return 0; | 
 | 106 |     } | 
 | 107 | } | 
 | 108 |  | 
| Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 109 | int InvertTransformToNative(VkSurfaceTransformFlagBitsKHR transform) { | 
 | 110 |     switch (transform) { | 
 | 111 |         case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR: | 
 | 112 |             return NATIVE_WINDOW_TRANSFORM_ROT_270; | 
 | 113 |         case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR: | 
 | 114 |             return NATIVE_WINDOW_TRANSFORM_ROT_180; | 
 | 115 |         case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR: | 
 | 116 |             return NATIVE_WINDOW_TRANSFORM_ROT_90; | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 117 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR: | 
 | 118 |             return NATIVE_WINDOW_TRANSFORM_FLIP_H; | 
 | 119 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR: | 
 | 120 |             return NATIVE_WINDOW_TRANSFORM_FLIP_H | | 
 | 121 |                    NATIVE_WINDOW_TRANSFORM_ROT_90; | 
 | 122 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR: | 
 | 123 |             return NATIVE_WINDOW_TRANSFORM_FLIP_V; | 
 | 124 |         case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR: | 
 | 125 |             return NATIVE_WINDOW_TRANSFORM_FLIP_V | | 
 | 126 |                    NATIVE_WINDOW_TRANSFORM_ROT_90; | 
| Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 127 |         case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR: | 
 | 128 |         case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR: | 
 | 129 |         default: | 
 | 130 |             return 0; | 
 | 131 |     } | 
 | 132 | } | 
 | 133 |  | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 134 | class TimingInfo { | 
 | 135 |    public: | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 136 |     TimingInfo(const VkPresentTimeGOOGLE* qp, uint64_t nativeFrameId) | 
| Ian Elliott | 2c6355d | 2017-01-19 11:02:13 -0700 | [diff] [blame] | 137 |         : vals_{qp->presentID, qp->desiredPresentTime, 0, 0, 0}, | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 138 |           native_frame_id_(nativeFrameId) {} | 
 | 139 |     bool ready() const { | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 140 |         return (timestamp_desired_present_time_ != | 
 | 141 |                         NATIVE_WINDOW_TIMESTAMP_PENDING && | 
 | 142 |                 timestamp_actual_present_time_ != | 
 | 143 |                         NATIVE_WINDOW_TIMESTAMP_PENDING && | 
 | 144 |                 timestamp_render_complete_time_ != | 
 | 145 |                         NATIVE_WINDOW_TIMESTAMP_PENDING && | 
 | 146 |                 timestamp_composition_latch_time_ != | 
 | 147 |                         NATIVE_WINDOW_TIMESTAMP_PENDING); | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 148 |     } | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 149 |     void calculate(int64_t rdur) { | 
 | 150 |         bool anyTimestampInvalid = | 
 | 151 |                 (timestamp_actual_present_time_ == | 
 | 152 |                         NATIVE_WINDOW_TIMESTAMP_INVALID) || | 
 | 153 |                 (timestamp_render_complete_time_ == | 
 | 154 |                         NATIVE_WINDOW_TIMESTAMP_INVALID) || | 
 | 155 |                 (timestamp_composition_latch_time_ == | 
 | 156 |                         NATIVE_WINDOW_TIMESTAMP_INVALID); | 
 | 157 |         if (anyTimestampInvalid) { | 
 | 158 |             ALOGE("Unexpectedly received invalid timestamp."); | 
 | 159 |             vals_.actualPresentTime = 0; | 
 | 160 |             vals_.earliestPresentTime = 0; | 
 | 161 |             vals_.presentMargin = 0; | 
 | 162 |             return; | 
 | 163 |         } | 
 | 164 |  | 
 | 165 |         vals_.actualPresentTime = | 
 | 166 |                 static_cast<uint64_t>(timestamp_actual_present_time_); | 
 | 167 |         int64_t margin = (timestamp_composition_latch_time_ - | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 168 |                            timestamp_render_complete_time_); | 
 | 169 |         // Calculate vals_.earliestPresentTime, and potentially adjust | 
 | 170 |         // vals_.presentMargin.  The initial value of vals_.earliestPresentTime | 
 | 171 |         // is vals_.actualPresentTime.  If we can subtract rdur (the duration | 
 | 172 |         // of a refresh cycle) from vals_.earliestPresentTime (and also from | 
 | 173 |         // vals_.presentMargin) and still leave a positive margin, then we can | 
 | 174 |         // report to the application that it could have presented earlier than | 
 | 175 |         // it did (per the extension specification).  If for some reason, we | 
 | 176 |         // can do this subtraction repeatedly, we do, since | 
 | 177 |         // vals_.earliestPresentTime really is supposed to be the "earliest". | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 178 |         int64_t early_time = timestamp_actual_present_time_; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 179 |         while ((margin > rdur) && | 
 | 180 |                ((early_time - rdur) > timestamp_composition_latch_time_)) { | 
 | 181 |             early_time -= rdur; | 
 | 182 |             margin -= rdur; | 
 | 183 |         } | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 184 |         vals_.earliestPresentTime = static_cast<uint64_t>(early_time); | 
 | 185 |         vals_.presentMargin = static_cast<uint64_t>(margin); | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 186 |     } | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 187 |     void get_values(VkPastPresentationTimingGOOGLE* values) const { | 
 | 188 |         *values = vals_; | 
 | 189 |     } | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 190 |  | 
 | 191 |    public: | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 192 |     VkPastPresentationTimingGOOGLE vals_ { 0, 0, 0, 0, 0 }; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 193 |  | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 194 |     uint64_t native_frame_id_ { 0 }; | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 195 |     int64_t timestamp_desired_present_time_{ NATIVE_WINDOW_TIMESTAMP_PENDING }; | 
 | 196 |     int64_t timestamp_actual_present_time_ { NATIVE_WINDOW_TIMESTAMP_PENDING }; | 
 | 197 |     int64_t timestamp_render_complete_time_ { NATIVE_WINDOW_TIMESTAMP_PENDING }; | 
 | 198 |     int64_t timestamp_composition_latch_time_ | 
 | 199 |             { NATIVE_WINDOW_TIMESTAMP_PENDING }; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 200 | }; | 
 | 201 |  | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 202 | struct Surface { | 
| Chia-I Wu | e8e689f | 2016-04-18 08:21:31 +0800 | [diff] [blame] | 203 |     android::sp<ANativeWindow> window; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 204 |     VkSwapchainKHR swapchain_handle; | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 205 |     uint64_t consumer_usage; | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 206 | }; | 
 | 207 |  | 
 | 208 | VkSurfaceKHR HandleFromSurface(Surface* surface) { | 
 | 209 |     return VkSurfaceKHR(reinterpret_cast<uint64_t>(surface)); | 
 | 210 | } | 
 | 211 |  | 
 | 212 | Surface* SurfaceFromHandle(VkSurfaceKHR handle) { | 
| Jesse Hall | a3a7a1d | 2015-11-24 11:37:23 -0800 | [diff] [blame] | 213 |     return reinterpret_cast<Surface*>(handle); | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 214 | } | 
 | 215 |  | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 216 | // Maximum number of TimingInfo structs to keep per swapchain: | 
 | 217 | enum { MAX_TIMING_INFOS = 10 }; | 
 | 218 | // Minimum number of frames to look for in the past (so we don't cause | 
 | 219 | // syncronous requests to Surface Flinger): | 
 | 220 | enum { MIN_NUM_FRAMES_AGO = 5 }; | 
 | 221 |  | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 222 | struct Swapchain { | 
| Ian Elliott | ffedb65 | 2017-02-14 10:58:30 -0700 | [diff] [blame] | 223 |     Swapchain(Surface& surface_, | 
 | 224 |               uint32_t num_images_, | 
| silence_dogood | 7359759 | 2019-05-23 16:57:37 -0700 | [diff] [blame] | 225 |               VkPresentModeKHR present_mode, | 
 | 226 |               int pre_transform_) | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 227 |         : surface(surface_), | 
 | 228 |           num_images(num_images_), | 
| Ian Elliott | ffedb65 | 2017-02-14 10:58:30 -0700 | [diff] [blame] | 229 |           mailbox_mode(present_mode == VK_PRESENT_MODE_MAILBOX_KHR), | 
| silence_dogood | 7359759 | 2019-05-23 16:57:37 -0700 | [diff] [blame] | 230 |           pre_transform(pre_transform_), | 
| Chris Forbes | f883564 | 2017-03-30 19:31:40 +1300 | [diff] [blame] | 231 |           frame_timestamps_enabled(false), | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 232 |           acquire_next_image_timeout(-1), | 
| Chris Forbes | f883564 | 2017-03-30 19:31:40 +1300 | [diff] [blame] | 233 |           shared(present_mode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR || | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 234 |                  present_mode == | 
 | 235 |                      VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) { | 
| Ian Elliott | 62c48c9 | 2017-01-20 13:13:20 -0700 | [diff] [blame] | 236 |         ANativeWindow* window = surface.window.get(); | 
| Ian Elliott | be833a2 | 2017-01-25 13:09:20 -0700 | [diff] [blame] | 237 |         native_window_get_refresh_cycle_duration( | 
| Ian Elliott | 62c48c9 | 2017-01-20 13:13:20 -0700 | [diff] [blame] | 238 |             window, | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 239 |             &refresh_duration); | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 240 |     } | 
| Ian Elliott | 3568bfe | 2019-05-03 15:54:46 -0600 | [diff] [blame] | 241 |     uint64_t get_refresh_duration() | 
 | 242 |     { | 
 | 243 |         ANativeWindow* window = surface.window.get(); | 
 | 244 |         native_window_get_refresh_cycle_duration( | 
 | 245 |             window, | 
 | 246 |             &refresh_duration); | 
 | 247 |         return static_cast<uint64_t>(refresh_duration); | 
 | 248 |  | 
 | 249 |     } | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 250 |  | 
 | 251 |     Surface& surface; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 252 |     uint32_t num_images; | 
| Ian Elliott | ffedb65 | 2017-02-14 10:58:30 -0700 | [diff] [blame] | 253 |     bool mailbox_mode; | 
| silence_dogood | 7359759 | 2019-05-23 16:57:37 -0700 | [diff] [blame] | 254 |     int pre_transform; | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 255 |     bool frame_timestamps_enabled; | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 256 |     int64_t refresh_duration; | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 257 |     nsecs_t acquire_next_image_timeout; | 
| Chris Forbes | f883564 | 2017-03-30 19:31:40 +1300 | [diff] [blame] | 258 |     bool shared; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 259 |  | 
 | 260 |     struct Image { | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 261 |         Image() | 
 | 262 |             : image(VK_NULL_HANDLE), | 
 | 263 |               dequeue_fence(-1), | 
 | 264 |               release_fence(-1), | 
 | 265 |               dequeued(false) {} | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 266 |         VkImage image; | 
| Chia-I Wu | e8e689f | 2016-04-18 08:21:31 +0800 | [diff] [blame] | 267 |         android::sp<ANativeWindowBuffer> buffer; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 268 |         // The fence is only valid when the buffer is dequeued, and should be | 
 | 269 |         // -1 any other time. When valid, we own the fd, and must ensure it is | 
 | 270 |         // closed: either by closing it explicitly when queueing the buffer, | 
 | 271 |         // or by passing ownership e.g. to ANativeWindow::cancelBuffer(). | 
 | 272 |         int dequeue_fence; | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 273 |         // This fence is a dup of the sync fd returned from the driver via | 
 | 274 |         // vkQueueSignalReleaseImageANDROID upon vkQueuePresentKHR. We must | 
 | 275 |         // ensure it is closed upon re-presenting or releasing the image. | 
 | 276 |         int release_fence; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 277 |         bool dequeued; | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 278 |     } images[android::BufferQueueDefs::NUM_BUFFER_SLOTS]; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 279 |  | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 280 |     std::vector<TimingInfo> timing; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 281 | }; | 
 | 282 |  | 
 | 283 | VkSwapchainKHR HandleFromSwapchain(Swapchain* swapchain) { | 
 | 284 |     return VkSwapchainKHR(reinterpret_cast<uint64_t>(swapchain)); | 
 | 285 | } | 
 | 286 |  | 
 | 287 | Swapchain* SwapchainFromHandle(VkSwapchainKHR handle) { | 
| Jesse Hall | a3a7a1d | 2015-11-24 11:37:23 -0800 | [diff] [blame] | 288 |     return reinterpret_cast<Swapchain*>(handle); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 289 | } | 
 | 290 |  | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 291 | static bool IsFencePending(int fd) { | 
 | 292 |     if (fd < 0) | 
 | 293 |         return false; | 
 | 294 |  | 
 | 295 |     errno = 0; | 
 | 296 |     return sync_wait(fd, 0 /* timeout */) == -1 && errno == ETIME; | 
 | 297 | } | 
 | 298 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 299 | void ReleaseSwapchainImage(VkDevice device, | 
 | 300 |                            ANativeWindow* window, | 
 | 301 |                            int release_fence, | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 302 |                            Swapchain::Image& image, | 
 | 303 |                            bool defer_if_pending) { | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 304 |     ATRACE_CALL(); | 
 | 305 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 306 |     ALOG_ASSERT(release_fence == -1 || image.dequeued, | 
 | 307 |                 "ReleaseSwapchainImage: can't provide a release fence for " | 
 | 308 |                 "non-dequeued images"); | 
 | 309 |  | 
 | 310 |     if (image.dequeued) { | 
 | 311 |         if (release_fence >= 0) { | 
 | 312 |             // We get here from vkQueuePresentKHR. The application is | 
 | 313 |             // responsible for creating an execution dependency chain from | 
 | 314 |             // vkAcquireNextImage (dequeue_fence) to vkQueuePresentKHR | 
 | 315 |             // (release_fence), so we can drop the dequeue_fence here. | 
 | 316 |             if (image.dequeue_fence >= 0) | 
 | 317 |                 close(image.dequeue_fence); | 
 | 318 |         } else { | 
 | 319 |             // We get here during swapchain destruction, or various serious | 
 | 320 |             // error cases e.g. when we can't create the release_fence during | 
 | 321 |             // vkQueuePresentKHR. In non-error cases, the dequeue_fence should | 
 | 322 |             // have already signalled, since the swapchain images are supposed | 
 | 323 |             // to be idle before the swapchain is destroyed. In error cases, | 
 | 324 |             // there may be rendering in flight to the image, but since we | 
 | 325 |             // weren't able to create a release_fence, waiting for the | 
 | 326 |             // dequeue_fence is about the best we can do. | 
 | 327 |             release_fence = image.dequeue_fence; | 
 | 328 |         } | 
 | 329 |         image.dequeue_fence = -1; | 
 | 330 |  | 
 | 331 |         if (window) { | 
 | 332 |             window->cancelBuffer(window, image.buffer.get(), release_fence); | 
 | 333 |         } else { | 
 | 334 |             if (release_fence >= 0) { | 
 | 335 |                 sync_wait(release_fence, -1 /* forever */); | 
 | 336 |                 close(release_fence); | 
 | 337 |             } | 
 | 338 |         } | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 339 |         release_fence = -1; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 340 |         image.dequeued = false; | 
 | 341 |     } | 
 | 342 |  | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 343 |     if (defer_if_pending && IsFencePending(image.release_fence)) | 
 | 344 |         return; | 
 | 345 |  | 
 | 346 |     if (image.release_fence >= 0) { | 
 | 347 |         close(image.release_fence); | 
 | 348 |         image.release_fence = -1; | 
 | 349 |     } | 
 | 350 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 351 |     if (image.image) { | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 352 |         ATRACE_BEGIN("DestroyImage"); | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 353 |         GetData(device).driver.DestroyImage(device, image.image, nullptr); | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 354 |         ATRACE_END(); | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 355 |         image.image = VK_NULL_HANDLE; | 
 | 356 |     } | 
 | 357 |  | 
 | 358 |     image.buffer.clear(); | 
 | 359 | } | 
 | 360 |  | 
 | 361 | void OrphanSwapchain(VkDevice device, Swapchain* swapchain) { | 
 | 362 |     if (swapchain->surface.swapchain_handle != HandleFromSwapchain(swapchain)) | 
 | 363 |         return; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 364 |     for (uint32_t i = 0; i < swapchain->num_images; i++) { | 
 | 365 |         if (!swapchain->images[i].dequeued) | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 366 |             ReleaseSwapchainImage(device, nullptr, -1, swapchain->images[i], | 
 | 367 |                                   true); | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 368 |     } | 
 | 369 |     swapchain->surface.swapchain_handle = VK_NULL_HANDLE; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 370 |     swapchain->timing.clear(); | 
 | 371 | } | 
 | 372 |  | 
 | 373 | uint32_t get_num_ready_timings(Swapchain& swapchain) { | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 374 |     if (swapchain.timing.size() < MIN_NUM_FRAMES_AGO) { | 
 | 375 |         return 0; | 
 | 376 |     } | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 377 |  | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 378 |     uint32_t num_ready = 0; | 
 | 379 |     const size_t num_timings = swapchain.timing.size() - MIN_NUM_FRAMES_AGO + 1; | 
 | 380 |     for (uint32_t i = 0; i < num_timings; i++) { | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 381 |         TimingInfo& ti = swapchain.timing[i]; | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 382 |         if (ti.ready()) { | 
 | 383 |             // This TimingInfo is ready to be reported to the user.  Add it | 
 | 384 |             // to the num_ready. | 
 | 385 |             num_ready++; | 
 | 386 |             continue; | 
 | 387 |         } | 
 | 388 |         // This TimingInfo is not yet ready to be reported to the user, | 
 | 389 |         // and so we should look for any available timestamps that | 
 | 390 |         // might make it ready. | 
 | 391 |         int64_t desired_present_time = 0; | 
 | 392 |         int64_t render_complete_time = 0; | 
 | 393 |         int64_t composition_latch_time = 0; | 
 | 394 |         int64_t actual_present_time = 0; | 
 | 395 |         // Obtain timestamps: | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 396 |         int err = native_window_get_frame_timestamps( | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 397 |             swapchain.surface.window.get(), ti.native_frame_id_, | 
 | 398 |             &desired_present_time, &render_complete_time, | 
 | 399 |             &composition_latch_time, | 
| Yi Kong | bcbc73a | 2018-07-18 10:13:04 -0700 | [diff] [blame] | 400 |             nullptr,  //&first_composition_start_time, | 
 | 401 |             nullptr,  //&last_composition_start_time, | 
 | 402 |             nullptr,  //&composition_finish_time, | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 403 |             &actual_present_time, | 
| Yi Kong | bcbc73a | 2018-07-18 10:13:04 -0700 | [diff] [blame] | 404 |             nullptr,  //&dequeue_ready_time, | 
 | 405 |             nullptr /*&reads_done_time*/); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 406 |  | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 407 |         if (err != android::OK) { | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 408 |             continue; | 
 | 409 |         } | 
 | 410 |  | 
 | 411 |         // Record the timestamp(s) we received, and then see if this TimingInfo | 
 | 412 |         // is ready to be reported to the user: | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 413 |         ti.timestamp_desired_present_time_ = desired_present_time; | 
 | 414 |         ti.timestamp_actual_present_time_ = actual_present_time; | 
 | 415 |         ti.timestamp_render_complete_time_ = render_complete_time; | 
 | 416 |         ti.timestamp_composition_latch_time_ = composition_latch_time; | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 417 |  | 
 | 418 |         if (ti.ready()) { | 
 | 419 |             // The TimingInfo has received enough timestamps, and should now | 
 | 420 |             // use those timestamps to calculate the info that should be | 
 | 421 |             // reported to the user: | 
 | 422 |             ti.calculate(swapchain.refresh_duration); | 
 | 423 |             num_ready++; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 424 |         } | 
 | 425 |     } | 
 | 426 |     return num_ready; | 
 | 427 | } | 
 | 428 |  | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 429 | void copy_ready_timings(Swapchain& swapchain, | 
 | 430 |                         uint32_t* count, | 
 | 431 |                         VkPastPresentationTimingGOOGLE* timings) { | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 432 |     if (swapchain.timing.empty()) { | 
 | 433 |         *count = 0; | 
 | 434 |         return; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 435 |     } | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 436 |  | 
 | 437 |     size_t last_ready = swapchain.timing.size() - 1; | 
 | 438 |     while (!swapchain.timing[last_ready].ready()) { | 
 | 439 |         if (last_ready == 0) { | 
 | 440 |             *count = 0; | 
 | 441 |             return; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 442 |         } | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 443 |         last_ready--; | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 444 |     } | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 445 |  | 
 | 446 |     uint32_t num_copied = 0; | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 447 |     int32_t num_to_remove = 0; | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 448 |     for (uint32_t i = 0; i <= last_ready && num_copied < *count; i++) { | 
 | 449 |         const TimingInfo& ti = swapchain.timing[i]; | 
 | 450 |         if (ti.ready()) { | 
 | 451 |             ti.get_values(&timings[num_copied]); | 
 | 452 |             num_copied++; | 
 | 453 |         } | 
 | 454 |         num_to_remove++; | 
 | 455 |     } | 
 | 456 |  | 
 | 457 |     // Discard old frames that aren't ready if newer frames are ready. | 
 | 458 |     // We don't expect to get the timing info for those old frames. | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 459 |     swapchain.timing.erase(swapchain.timing.begin(), | 
 | 460 |                            swapchain.timing.begin() + num_to_remove); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 461 |  | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 462 |     *count = num_copied; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 463 | } | 
 | 464 |  | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 465 | android_pixel_format GetNativePixelFormat(VkFormat format) { | 
 | 466 |     android_pixel_format native_format = HAL_PIXEL_FORMAT_RGBA_8888; | 
 | 467 |     switch (format) { | 
 | 468 |         case VK_FORMAT_R8G8B8A8_UNORM: | 
 | 469 |         case VK_FORMAT_R8G8B8A8_SRGB: | 
 | 470 |             native_format = HAL_PIXEL_FORMAT_RGBA_8888; | 
 | 471 |             break; | 
 | 472 |         case VK_FORMAT_R5G6B5_UNORM_PACK16: | 
 | 473 |             native_format = HAL_PIXEL_FORMAT_RGB_565; | 
 | 474 |             break; | 
 | 475 |         case VK_FORMAT_R16G16B16A16_SFLOAT: | 
 | 476 |             native_format = HAL_PIXEL_FORMAT_RGBA_FP16; | 
 | 477 |             break; | 
| Yiwei Zhang | c1ea815 | 2019-02-05 15:11:32 -0800 | [diff] [blame] | 478 |         case VK_FORMAT_A2B10G10R10_UNORM_PACK32: | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 479 |             native_format = HAL_PIXEL_FORMAT_RGBA_1010102; | 
 | 480 |             break; | 
 | 481 |         default: | 
 | 482 |             ALOGV("unsupported swapchain format %d", format); | 
 | 483 |             break; | 
 | 484 |     } | 
 | 485 |     return native_format; | 
 | 486 | } | 
 | 487 |  | 
 | 488 | android_dataspace GetNativeDataspace(VkColorSpaceKHR colorspace) { | 
 | 489 |     switch (colorspace) { | 
 | 490 |         case VK_COLOR_SPACE_SRGB_NONLINEAR_KHR: | 
 | 491 |             return HAL_DATASPACE_V0_SRGB; | 
 | 492 |         case VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT: | 
 | 493 |             return HAL_DATASPACE_DISPLAY_P3; | 
 | 494 |         case VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT: | 
 | 495 |             return HAL_DATASPACE_V0_SCRGB_LINEAR; | 
| Courtney Goeltzenleuchter | b52abee | 2017-08-07 17:13:04 -0600 | [diff] [blame] | 496 |         case VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT: | 
 | 497 |             return HAL_DATASPACE_V0_SCRGB; | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 498 |         case VK_COLOR_SPACE_DCI_P3_LINEAR_EXT: | 
 | 499 |             return HAL_DATASPACE_DCI_P3_LINEAR; | 
 | 500 |         case VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT: | 
 | 501 |             return HAL_DATASPACE_DCI_P3; | 
 | 502 |         case VK_COLOR_SPACE_BT709_LINEAR_EXT: | 
 | 503 |             return HAL_DATASPACE_V0_SRGB_LINEAR; | 
 | 504 |         case VK_COLOR_SPACE_BT709_NONLINEAR_EXT: | 
 | 505 |             return HAL_DATASPACE_V0_SRGB; | 
| Courtney Goeltzenleuchter | c45673f | 2017-03-13 15:58:15 -0600 | [diff] [blame] | 506 |         case VK_COLOR_SPACE_BT2020_LINEAR_EXT: | 
 | 507 |             return HAL_DATASPACE_BT2020_LINEAR; | 
 | 508 |         case VK_COLOR_SPACE_HDR10_ST2084_EXT: | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 509 |             return static_cast<android_dataspace>( | 
 | 510 |                 HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_TRANSFER_ST2084 | | 
 | 511 |                 HAL_DATASPACE_RANGE_FULL); | 
| Courtney Goeltzenleuchter | c45673f | 2017-03-13 15:58:15 -0600 | [diff] [blame] | 512 |         case VK_COLOR_SPACE_DOLBYVISION_EXT: | 
 | 513 |             return static_cast<android_dataspace>( | 
 | 514 |                 HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_TRANSFER_ST2084 | | 
 | 515 |                 HAL_DATASPACE_RANGE_FULL); | 
 | 516 |         case VK_COLOR_SPACE_HDR10_HLG_EXT: | 
 | 517 |             return static_cast<android_dataspace>( | 
 | 518 |                 HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_TRANSFER_HLG | | 
 | 519 |                 HAL_DATASPACE_RANGE_FULL); | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 520 |         case VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT: | 
 | 521 |             return static_cast<android_dataspace>( | 
 | 522 |                 HAL_DATASPACE_STANDARD_ADOBE_RGB | | 
 | 523 |                 HAL_DATASPACE_TRANSFER_LINEAR | HAL_DATASPACE_RANGE_FULL); | 
 | 524 |         case VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT: | 
 | 525 |             return HAL_DATASPACE_ADOBE_RGB; | 
 | 526 |  | 
 | 527 |         // Pass through is intended to allow app to provide data that is passed | 
 | 528 |         // to the display system without modification. | 
 | 529 |         case VK_COLOR_SPACE_PASS_THROUGH_EXT: | 
 | 530 |             return HAL_DATASPACE_ARBITRARY; | 
 | 531 |  | 
 | 532 |         default: | 
 | 533 |             // This indicates that we don't know about the | 
 | 534 |             // dataspace specified and we should indicate that | 
 | 535 |             // it's unsupported | 
 | 536 |             return HAL_DATASPACE_UNKNOWN; | 
 | 537 |     } | 
 | 538 | } | 
 | 539 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 540 | }  // anonymous namespace | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 541 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 542 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 543 | VkResult CreateAndroidSurfaceKHR( | 
| Jesse Hall | f9fa9a5 | 2016-01-08 16:08:51 -0800 | [diff] [blame] | 544 |     VkInstance instance, | 
 | 545 |     const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, | 
 | 546 |     const VkAllocationCallbacks* allocator, | 
 | 547 |     VkSurfaceKHR* out_surface) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 548 |     ATRACE_CALL(); | 
 | 549 |  | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 550 |     if (!allocator) | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 551 |         allocator = &GetData(instance).allocator; | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 552 |     void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Surface), | 
 | 553 |                                          alignof(Surface), | 
 | 554 |                                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 555 |     if (!mem) | 
 | 556 |         return VK_ERROR_OUT_OF_HOST_MEMORY; | 
 | 557 |     Surface* surface = new (mem) Surface; | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 558 |  | 
| Chia-I Wu | e8e689f | 2016-04-18 08:21:31 +0800 | [diff] [blame] | 559 |     surface->window = pCreateInfo->window; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 560 |     surface->swapchain_handle = VK_NULL_HANDLE; | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 561 |     int err = native_window_get_consumer_usage(surface->window.get(), | 
 | 562 |                                                &surface->consumer_usage); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 563 |     if (err != android::OK) { | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 564 |         ALOGE("native_window_get_consumer_usage() failed: %s (%d)", | 
 | 565 |               strerror(-err), err); | 
 | 566 |         surface->~Surface(); | 
 | 567 |         allocator->pfnFree(allocator->pUserData, surface); | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 568 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 569 |     } | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 570 |  | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 571 |     err = | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 572 |         native_window_api_connect(surface->window.get(), NATIVE_WINDOW_API_EGL); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 573 |     if (err != android::OK) { | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 574 |         ALOGE("native_window_api_connect() failed: %s (%d)", strerror(-err), | 
 | 575 |               err); | 
 | 576 |         surface->~Surface(); | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 577 |         allocator->pfnFree(allocator->pUserData, surface); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 578 |         return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 579 |     } | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 580 |  | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 581 |     *out_surface = HandleFromSurface(surface); | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 582 |     return VK_SUCCESS; | 
 | 583 | } | 
 | 584 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 585 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 586 | void DestroySurfaceKHR(VkInstance instance, | 
 | 587 |                        VkSurfaceKHR surface_handle, | 
 | 588 |                        const VkAllocationCallbacks* allocator) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 589 |     ATRACE_CALL(); | 
 | 590 |  | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 591 |     Surface* surface = SurfaceFromHandle(surface_handle); | 
 | 592 |     if (!surface) | 
 | 593 |         return; | 
 | 594 |     native_window_api_disconnect(surface->window.get(), NATIVE_WINDOW_API_EGL); | 
| Jesse Hall | 42a9eec | 2016-06-03 12:39:49 -0700 | [diff] [blame] | 595 |     ALOGV_IF(surface->swapchain_handle != VK_NULL_HANDLE, | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 596 |              "destroyed VkSurfaceKHR 0x%" PRIx64 | 
 | 597 |              " has active VkSwapchainKHR 0x%" PRIx64, | 
 | 598 |              reinterpret_cast<uint64_t>(surface_handle), | 
 | 599 |              reinterpret_cast<uint64_t>(surface->swapchain_handle)); | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 600 |     surface->~Surface(); | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 601 |     if (!allocator) | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 602 |         allocator = &GetData(instance).allocator; | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 603 |     allocator->pfnFree(allocator->pUserData, surface); | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 604 | } | 
 | 605 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 606 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 607 | VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice /*pdev*/, | 
 | 608 |                                             uint32_t /*queue_family*/, | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 609 |                                             VkSurfaceKHR surface_handle, | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 610 |                                             VkBool32* supported) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 611 |     ATRACE_CALL(); | 
 | 612 |  | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 613 |     const Surface* surface = SurfaceFromHandle(surface_handle); | 
 | 614 |     if (!surface) { | 
 | 615 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 616 |     } | 
 | 617 |     const ANativeWindow* window = surface->window.get(); | 
 | 618 |  | 
 | 619 |     int query_value; | 
 | 620 |     int err = window->query(window, NATIVE_WINDOW_FORMAT, &query_value); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 621 |     if (err != android::OK || query_value < 0) { | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 622 |         ALOGE("NATIVE_WINDOW_FORMAT query failed: %s (%d) value=%d", | 
 | 623 |               strerror(-err), err, query_value); | 
 | 624 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 625 |     } | 
 | 626 |  | 
 | 627 |     android_pixel_format native_format = | 
 | 628 |         static_cast<android_pixel_format>(query_value); | 
 | 629 |  | 
 | 630 |     bool format_supported = false; | 
 | 631 |     switch (native_format) { | 
 | 632 |         case HAL_PIXEL_FORMAT_RGBA_8888: | 
 | 633 |         case HAL_PIXEL_FORMAT_RGB_565: | 
| Yiwei Zhang | 5979cb5 | 2018-09-25 16:47:07 -0700 | [diff] [blame] | 634 |         case HAL_PIXEL_FORMAT_RGBA_FP16: | 
| Yiwei Zhang | c1ea815 | 2019-02-05 15:11:32 -0800 | [diff] [blame] | 635 |         case HAL_PIXEL_FORMAT_RGBA_1010102: | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 636 |             format_supported = true; | 
 | 637 |             break; | 
 | 638 |         default: | 
 | 639 |             break; | 
 | 640 |     } | 
 | 641 |  | 
| Yiwei Zhang | c91b9b7 | 2018-06-07 11:13:27 -0700 | [diff] [blame] | 642 |     *supported = static_cast<VkBool32>( | 
 | 643 |         format_supported || (surface->consumer_usage & | 
 | 644 |                              (AHARDWAREBUFFER_USAGE_CPU_READ_MASK | | 
 | 645 |                               AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK)) == 0); | 
| Yiwei Zhang | 6435b32 | 2018-05-08 11:12:17 -0700 | [diff] [blame] | 646 |  | 
| Jesse Hall | a642925 | 2015-11-29 18:59:42 -0800 | [diff] [blame] | 647 |     return VK_SUCCESS; | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 648 | } | 
 | 649 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 650 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 651 | VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR( | 
| Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 652 |     VkPhysicalDevice /*pdev*/, | 
 | 653 |     VkSurfaceKHR surface, | 
 | 654 |     VkSurfaceCapabilitiesKHR* capabilities) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 655 |     ATRACE_CALL(); | 
 | 656 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 657 |     int err; | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 658 |     ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 659 |  | 
 | 660 |     int width, height; | 
 | 661 |     err = window->query(window, NATIVE_WINDOW_DEFAULT_WIDTH, &width); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 662 |     if (err != android::OK) { | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 663 |         ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)", | 
 | 664 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 665 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 666 |     } | 
 | 667 |     err = window->query(window, NATIVE_WINDOW_DEFAULT_HEIGHT, &height); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 668 |     if (err != android::OK) { | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 669 |         ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)", | 
 | 670 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 671 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 672 |     } | 
 | 673 |  | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 674 |     int transform_hint; | 
 | 675 |     err = window->query(window, NATIVE_WINDOW_TRANSFORM_HINT, &transform_hint); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 676 |     if (err != android::OK) { | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 677 |         ALOGE("NATIVE_WINDOW_TRANSFORM_HINT query failed: %s (%d)", | 
 | 678 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 679 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 680 |     } | 
 | 681 |  | 
| Yiwei Zhang | dbd9615 | 2018-02-08 14:22:53 -0800 | [diff] [blame] | 682 |     int max_buffer_count; | 
 | 683 |     err = window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, &max_buffer_count); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 684 |     if (err != android::OK) { | 
| Yiwei Zhang | dbd9615 | 2018-02-08 14:22:53 -0800 | [diff] [blame] | 685 |         ALOGE("NATIVE_WINDOW_MAX_BUFFER_COUNT query failed: %s (%d)", | 
 | 686 |               strerror(-err), err); | 
 | 687 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 688 |     } | 
| Yiwei Zhang | 8e951d5 | 2018-04-12 13:19:46 -0700 | [diff] [blame] | 689 |     capabilities->minImageCount = max_buffer_count == 1 ? 1 : 2; | 
| Yiwei Zhang | dbd9615 | 2018-02-08 14:22:53 -0800 | [diff] [blame] | 690 |     capabilities->maxImageCount = static_cast<uint32_t>(max_buffer_count); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 691 |  | 
| Jesse Hall | fe2662d | 2016-02-09 13:26:59 -0800 | [diff] [blame] | 692 |     capabilities->currentExtent = | 
 | 693 |         VkExtent2D{static_cast<uint32_t>(width), static_cast<uint32_t>(height)}; | 
 | 694 |  | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 695 |     // TODO(http://b/134182502): Figure out what the max extent should be. | 
| Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 696 |     capabilities->minImageExtent = VkExtent2D{1, 1}; | 
 | 697 |     capabilities->maxImageExtent = VkExtent2D{4096, 4096}; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 698 |  | 
| Jesse Hall | fe2662d | 2016-02-09 13:26:59 -0800 | [diff] [blame] | 699 |     capabilities->maxImageArrayLayers = 1; | 
 | 700 |  | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 701 |     capabilities->supportedTransforms = kSupportedTransforms; | 
 | 702 |     capabilities->currentTransform = | 
 | 703 |         TranslateNativeToVulkanTransform(transform_hint); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 704 |  | 
| Jesse Hall | fe2662d | 2016-02-09 13:26:59 -0800 | [diff] [blame] | 705 |     // On Android, window composition is a WindowManager property, not something | 
 | 706 |     // associated with the bufferqueue. It can't be changed from here. | 
 | 707 |     capabilities->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 708 |  | 
| Jesse Hall | b00daad | 2015-11-29 19:46:20 -0800 | [diff] [blame] | 709 |     capabilities->supportedUsageFlags = | 
| Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 710 |         VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | | 
 | 711 |         VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | | 
 | 712 |         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 713 |         VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; | 
 | 714 |  | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 715 |     return VK_SUCCESS; | 
 | 716 | } | 
 | 717 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 718 | VKAPI_ATTR | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 719 | VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, | 
 | 720 |                                             VkSurfaceKHR surface_handle, | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 721 |                                             uint32_t* count, | 
 | 722 |                                             VkSurfaceFormatKHR* formats) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 723 |     ATRACE_CALL(); | 
 | 724 |  | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 725 |     const InstanceData& instance_data = GetData(pdev); | 
 | 726 |  | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 727 |     bool wide_color_support = false; | 
 | 728 |     Surface& surface = *SurfaceFromHandle(surface_handle); | 
 | 729 |     int err = native_window_get_wide_color_support(surface.window.get(), | 
 | 730 |                                                    &wide_color_support); | 
 | 731 |     if (err) { | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 732 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 733 |     } | 
 | 734 |     ALOGV("wide_color_support is: %d", wide_color_support); | 
 | 735 |     wide_color_support = | 
 | 736 |         wide_color_support && | 
 | 737 |         instance_data.hook_extensions.test(ProcHook::EXT_swapchain_colorspace); | 
 | 738 |  | 
| Charlie Lao | 324191f | 2019-12-13 11:03:16 -0800 | [diff] [blame] | 739 |     AHardwareBuffer_Desc desc = {}; | 
 | 740 |     desc.width = 1; | 
 | 741 |     desc.height = 1; | 
 | 742 |     desc.layers = 1; | 
 | 743 |     desc.usage = surface.consumer_usage | | 
 | 744 |                  AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | | 
 | 745 |                  AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER; | 
 | 746 |  | 
 | 747 |     // We must support R8G8B8A8 | 
 | 748 |     std::vector<VkSurfaceFormatKHR> all_formats = { | 
 | 749 |         {VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}, | 
 | 750 |         {VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}}; | 
 | 751 |  | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 752 |     if (wide_color_support) { | 
| Charlie Lao | 324191f | 2019-12-13 11:03:16 -0800 | [diff] [blame] | 753 |         all_formats.emplace_back(VkSurfaceFormatKHR{ | 
 | 754 |             VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); | 
 | 755 |         all_formats.emplace_back(VkSurfaceFormatKHR{ | 
 | 756 |             VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); | 
 | 757 |     } | 
 | 758 |  | 
 | 759 |     desc.format = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM; | 
 | 760 |     if (AHardwareBuffer_isSupported(&desc)) { | 
 | 761 |         all_formats.emplace_back(VkSurfaceFormatKHR{ | 
 | 762 |             VK_FORMAT_R5G6B5_UNORM_PACK16, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); | 
 | 763 |     } | 
 | 764 |  | 
 | 765 |     desc.format = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT; | 
 | 766 |     if (AHardwareBuffer_isSupported(&desc)) { | 
 | 767 |         all_formats.emplace_back(VkSurfaceFormatKHR{ | 
 | 768 |             VK_FORMAT_R16G16B16A16_SFLOAT, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); | 
 | 769 |         if (wide_color_support) { | 
 | 770 |             all_formats.emplace_back( | 
 | 771 |                 VkSurfaceFormatKHR{VK_FORMAT_R16G16B16A16_SFLOAT, | 
 | 772 |                                    VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT}); | 
 | 773 |             all_formats.emplace_back( | 
 | 774 |                 VkSurfaceFormatKHR{VK_FORMAT_R16G16B16A16_SFLOAT, | 
 | 775 |                                    VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT}); | 
 | 776 |         } | 
 | 777 |     } | 
 | 778 |  | 
 | 779 |     desc.format = AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM; | 
 | 780 |     if (AHardwareBuffer_isSupported(&desc)) { | 
 | 781 |         all_formats.emplace_back( | 
 | 782 |             VkSurfaceFormatKHR{VK_FORMAT_A2B10G10R10_UNORM_PACK32, | 
 | 783 |                                VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); | 
 | 784 |         if (wide_color_support) { | 
 | 785 |             all_formats.emplace_back( | 
 | 786 |                 VkSurfaceFormatKHR{VK_FORMAT_A2B10G10R10_UNORM_PACK32, | 
 | 787 |                                    VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); | 
 | 788 |         } | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 789 |     } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 790 |  | 
 | 791 |     VkResult result = VK_SUCCESS; | 
 | 792 |     if (formats) { | 
| Charlie Lao | 324191f | 2019-12-13 11:03:16 -0800 | [diff] [blame] | 793 |         uint32_t transfer_count = all_formats.size(); | 
 | 794 |         if (transfer_count > *count) { | 
 | 795 |             transfer_count = *count; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 796 |             result = VK_INCOMPLETE; | 
| Courtney Goeltzenleuchter | e278daf | 2017-02-02 16:54:57 -0700 | [diff] [blame] | 797 |         } | 
| Charlie Lao | 324191f | 2019-12-13 11:03:16 -0800 | [diff] [blame] | 798 |         std::copy(all_formats.begin(), all_formats.begin() + transfer_count, | 
 | 799 |                   formats); | 
 | 800 |         *count = transfer_count; | 
| Jesse Hall | 7331e22 | 2016-09-15 21:26:01 -0700 | [diff] [blame] | 801 |     } else { | 
| Charlie Lao | 324191f | 2019-12-13 11:03:16 -0800 | [diff] [blame] | 802 |         *count = all_formats.size(); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 803 |     } | 
| Charlie Lao | 324191f | 2019-12-13 11:03:16 -0800 | [diff] [blame] | 804 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 805 |     return result; | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 806 | } | 
 | 807 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 808 | VKAPI_ATTR | 
| Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 809 | VkResult GetPhysicalDeviceSurfaceCapabilities2KHR( | 
 | 810 |     VkPhysicalDevice physicalDevice, | 
 | 811 |     const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, | 
 | 812 |     VkSurfaceCapabilities2KHR* pSurfaceCapabilities) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 813 |     ATRACE_CALL(); | 
 | 814 |  | 
| Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 815 |     VkResult result = GetPhysicalDeviceSurfaceCapabilitiesKHR( | 
 | 816 |         physicalDevice, pSurfaceInfo->surface, | 
 | 817 |         &pSurfaceCapabilities->surfaceCapabilities); | 
 | 818 |  | 
| Chris Forbes | 06bc009 | 2017-03-16 16:46:05 +1300 | [diff] [blame] | 819 |     VkSurfaceCapabilities2KHR* caps = pSurfaceCapabilities; | 
 | 820 |     while (caps->pNext) { | 
 | 821 |         caps = reinterpret_cast<VkSurfaceCapabilities2KHR*>(caps->pNext); | 
 | 822 |  | 
 | 823 |         switch (caps->sType) { | 
 | 824 |             case VK_STRUCTURE_TYPE_SHARED_PRESENT_SURFACE_CAPABILITIES_KHR: { | 
 | 825 |                 VkSharedPresentSurfaceCapabilitiesKHR* shared_caps = | 
 | 826 |                     reinterpret_cast<VkSharedPresentSurfaceCapabilitiesKHR*>( | 
 | 827 |                         caps); | 
 | 828 |                 // Claim same set of usage flags are supported for | 
 | 829 |                 // shared present modes as for other modes. | 
 | 830 |                 shared_caps->sharedPresentSupportedUsageFlags = | 
 | 831 |                     pSurfaceCapabilities->surfaceCapabilities | 
 | 832 |                         .supportedUsageFlags; | 
 | 833 |             } break; | 
 | 834 |  | 
 | 835 |             default: | 
 | 836 |                 // Ignore all other extension structs | 
 | 837 |                 break; | 
 | 838 |         } | 
 | 839 |     } | 
 | 840 |  | 
| Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 841 |     return result; | 
 | 842 | } | 
 | 843 |  | 
 | 844 | VKAPI_ATTR | 
 | 845 | VkResult GetPhysicalDeviceSurfaceFormats2KHR( | 
 | 846 |     VkPhysicalDevice physicalDevice, | 
 | 847 |     const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, | 
 | 848 |     uint32_t* pSurfaceFormatCount, | 
 | 849 |     VkSurfaceFormat2KHR* pSurfaceFormats) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 850 |     ATRACE_CALL(); | 
 | 851 |  | 
| Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 852 |     if (!pSurfaceFormats) { | 
 | 853 |         return GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, | 
 | 854 |                                                   pSurfaceInfo->surface, | 
 | 855 |                                                   pSurfaceFormatCount, nullptr); | 
 | 856 |     } else { | 
 | 857 |         // temp vector for forwarding; we'll marshal it into the pSurfaceFormats | 
 | 858 |         // after the call. | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 859 |         std::vector<VkSurfaceFormatKHR> surface_formats(*pSurfaceFormatCount); | 
| Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 860 |         VkResult result = GetPhysicalDeviceSurfaceFormatsKHR( | 
 | 861 |             physicalDevice, pSurfaceInfo->surface, pSurfaceFormatCount, | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 862 |             surface_formats.data()); | 
| Chris Forbes | 2452cf7 | 2017-03-16 16:30:17 +1300 | [diff] [blame] | 863 |  | 
 | 864 |         if (result == VK_SUCCESS || result == VK_INCOMPLETE) { | 
 | 865 |             // marshal results individually due to stride difference. | 
 | 866 |             // completely ignore any chained extension structs. | 
 | 867 |             uint32_t formats_to_marshal = *pSurfaceFormatCount; | 
 | 868 |             for (uint32_t i = 0u; i < formats_to_marshal; i++) { | 
 | 869 |                 pSurfaceFormats[i].surfaceFormat = surface_formats[i]; | 
 | 870 |             } | 
 | 871 |         } | 
 | 872 |  | 
 | 873 |         return result; | 
 | 874 |     } | 
 | 875 | } | 
 | 876 |  | 
 | 877 | VKAPI_ATTR | 
| Chris Forbes | e8d79a6 | 2017-02-22 12:49:18 +1300 | [diff] [blame] | 878 | VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice pdev, | 
| Yiwei Zhang | e4a559c | 2018-02-15 11:27:36 -0800 | [diff] [blame] | 879 |                                                  VkSurfaceKHR surface, | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 880 |                                                  uint32_t* count, | 
 | 881 |                                                  VkPresentModeKHR* modes) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 882 |     ATRACE_CALL(); | 
 | 883 |  | 
| Yiwei Zhang | e4a559c | 2018-02-15 11:27:36 -0800 | [diff] [blame] | 884 |     int err; | 
 | 885 |     int query_value; | 
 | 886 |     ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); | 
 | 887 |  | 
 | 888 |     err = window->query(window, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &query_value); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 889 |     if (err != android::OK || query_value < 0) { | 
| Yiwei Zhang | e4a559c | 2018-02-15 11:27:36 -0800 | [diff] [blame] | 890 |         ALOGE("NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS query failed: %s (%d) value=%d", | 
 | 891 |               strerror(-err), err, query_value); | 
 | 892 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 893 |     } | 
 | 894 |     uint32_t min_undequeued_buffers = static_cast<uint32_t>(query_value); | 
 | 895 |  | 
 | 896 |     err = window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, &query_value); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 897 |     if (err != android::OK || query_value < 0) { | 
| Yiwei Zhang | e4a559c | 2018-02-15 11:27:36 -0800 | [diff] [blame] | 898 |         ALOGE("NATIVE_WINDOW_MAX_BUFFER_COUNT query failed: %s (%d) value=%d", | 
 | 899 |               strerror(-err), err, query_value); | 
 | 900 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 901 |     } | 
 | 902 |     uint32_t max_buffer_count = static_cast<uint32_t>(query_value); | 
 | 903 |  | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 904 |     std::vector<VkPresentModeKHR> present_modes; | 
| Yiwei Zhang | e4a559c | 2018-02-15 11:27:36 -0800 | [diff] [blame] | 905 |     if (min_undequeued_buffers + 1 < max_buffer_count) | 
 | 906 |         present_modes.push_back(VK_PRESENT_MODE_MAILBOX_KHR); | 
| Chris Forbes | e8d79a6 | 2017-02-22 12:49:18 +1300 | [diff] [blame] | 907 |     present_modes.push_back(VK_PRESENT_MODE_FIFO_KHR); | 
 | 908 |  | 
 | 909 |     VkPhysicalDevicePresentationPropertiesANDROID present_properties; | 
 | 910 |     if (QueryPresentationProperties(pdev, &present_properties)) { | 
 | 911 |         if (present_properties.sharedImage) { | 
 | 912 |             present_modes.push_back(VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR); | 
 | 913 |             present_modes.push_back(VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR); | 
 | 914 |         } | 
 | 915 |     } | 
 | 916 |  | 
 | 917 |     uint32_t num_modes = uint32_t(present_modes.size()); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 918 |  | 
 | 919 |     VkResult result = VK_SUCCESS; | 
 | 920 |     if (modes) { | 
| Chris Forbes | e8d79a6 | 2017-02-22 12:49:18 +1300 | [diff] [blame] | 921 |         if (*count < num_modes) | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 922 |             result = VK_INCOMPLETE; | 
| Chris Forbes | e8d79a6 | 2017-02-22 12:49:18 +1300 | [diff] [blame] | 923 |         *count = std::min(*count, num_modes); | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 924 |         std::copy_n(present_modes.data(), *count, modes); | 
| Jesse Hall | 7331e22 | 2016-09-15 21:26:01 -0700 | [diff] [blame] | 925 |     } else { | 
| Chris Forbes | e8d79a6 | 2017-02-22 12:49:18 +1300 | [diff] [blame] | 926 |         *count = num_modes; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 927 |     } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 928 |     return result; | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 929 | } | 
 | 930 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 931 | VKAPI_ATTR | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 932 | VkResult GetDeviceGroupPresentCapabilitiesKHR( | 
| Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 933 |     VkDevice, | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 934 |     VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 935 |     ATRACE_CALL(); | 
 | 936 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 937 |     ALOGV_IF(pDeviceGroupPresentCapabilities->sType != | 
 | 938 |                  VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHR, | 
 | 939 |              "vkGetDeviceGroupPresentCapabilitiesKHR: invalid " | 
 | 940 |              "VkDeviceGroupPresentCapabilitiesKHR structure type %d", | 
 | 941 |              pDeviceGroupPresentCapabilities->sType); | 
 | 942 |  | 
 | 943 |     memset(pDeviceGroupPresentCapabilities->presentMask, 0, | 
 | 944 |            sizeof(pDeviceGroupPresentCapabilities->presentMask)); | 
 | 945 |  | 
 | 946 |     // assume device group of size 1 | 
 | 947 |     pDeviceGroupPresentCapabilities->presentMask[0] = 1 << 0; | 
 | 948 |     pDeviceGroupPresentCapabilities->modes = | 
 | 949 |         VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR; | 
 | 950 |  | 
 | 951 |     return VK_SUCCESS; | 
 | 952 | } | 
 | 953 |  | 
 | 954 | VKAPI_ATTR | 
 | 955 | VkResult GetDeviceGroupSurfacePresentModesKHR( | 
| Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 956 |     VkDevice, | 
 | 957 |     VkSurfaceKHR, | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 958 |     VkDeviceGroupPresentModeFlagsKHR* pModes) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 959 |     ATRACE_CALL(); | 
 | 960 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 961 |     *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR; | 
 | 962 |     return VK_SUCCESS; | 
 | 963 | } | 
 | 964 |  | 
 | 965 | VKAPI_ATTR | 
| Ian Elliott | cd8ad33 | 2017-10-13 09:21:12 -0600 | [diff] [blame] | 966 | VkResult GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice, | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 967 |                                                VkSurfaceKHR surface, | 
 | 968 |                                                uint32_t* pRectCount, | 
 | 969 |                                                VkRect2D* pRects) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 970 |     ATRACE_CALL(); | 
 | 971 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 972 |     if (!pRects) { | 
 | 973 |         *pRectCount = 1; | 
 | 974 |     } else { | 
 | 975 |         uint32_t count = std::min(*pRectCount, 1u); | 
 | 976 |         bool incomplete = *pRectCount < 1; | 
 | 977 |  | 
 | 978 |         *pRectCount = count; | 
 | 979 |  | 
 | 980 |         if (incomplete) { | 
 | 981 |             return VK_INCOMPLETE; | 
 | 982 |         } | 
 | 983 |  | 
 | 984 |         int err; | 
 | 985 |         ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); | 
 | 986 |  | 
 | 987 |         int width = 0, height = 0; | 
 | 988 |         err = window->query(window, NATIVE_WINDOW_DEFAULT_WIDTH, &width); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 989 |         if (err != android::OK) { | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 990 |             ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)", | 
 | 991 |                   strerror(-err), err); | 
 | 992 |         } | 
 | 993 |         err = window->query(window, NATIVE_WINDOW_DEFAULT_HEIGHT, &height); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 994 |         if (err != android::OK) { | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 995 |             ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)", | 
 | 996 |                   strerror(-err), err); | 
 | 997 |         } | 
 | 998 |  | 
| Yiwei Zhang | a885c06 | 2019-10-24 12:07:57 -0700 | [diff] [blame] | 999 |         // TODO(b/143294545): Return something better than "whole window" | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1000 |         pRects[0].offset.x = 0; | 
 | 1001 |         pRects[0].offset.y = 0; | 
 | 1002 |         pRects[0].extent = VkExtent2D{static_cast<uint32_t>(width), | 
 | 1003 |                                       static_cast<uint32_t>(height)}; | 
 | 1004 |     } | 
 | 1005 |     return VK_SUCCESS; | 
 | 1006 | } | 
 | 1007 |  | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1008 | static void DestroySwapchainInternal(VkDevice device, | 
 | 1009 |                                      VkSwapchainKHR swapchain_handle, | 
 | 1010 |                                      const VkAllocationCallbacks* allocator) { | 
 | 1011 |     ATRACE_CALL(); | 
 | 1012 |  | 
 | 1013 |     const auto& dispatch = GetData(device).driver; | 
 | 1014 |     Swapchain* swapchain = SwapchainFromHandle(swapchain_handle); | 
 | 1015 |     if (!swapchain) { | 
 | 1016 |         return; | 
 | 1017 |     } | 
 | 1018 |  | 
 | 1019 |     bool active = swapchain->surface.swapchain_handle == swapchain_handle; | 
 | 1020 |     ANativeWindow* window = active ? swapchain->surface.window.get() : nullptr; | 
 | 1021 |  | 
 | 1022 |     if (window && swapchain->frame_timestamps_enabled) { | 
 | 1023 |         native_window_enable_frame_timestamps(window, false); | 
 | 1024 |     } | 
 | 1025 |  | 
 | 1026 |     for (uint32_t i = 0; i < swapchain->num_images; i++) { | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 1027 |         ReleaseSwapchainImage(device, window, -1, swapchain->images[i], false); | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1028 |     } | 
 | 1029 |  | 
 | 1030 |     if (active) { | 
 | 1031 |         swapchain->surface.swapchain_handle = VK_NULL_HANDLE; | 
 | 1032 |     } | 
 | 1033 |  | 
 | 1034 |     if (!allocator) { | 
 | 1035 |         allocator = &GetData(device).allocator; | 
 | 1036 |     } | 
 | 1037 |  | 
 | 1038 |     swapchain->~Swapchain(); | 
 | 1039 |     allocator->pfnFree(allocator->pUserData, swapchain); | 
 | 1040 | } | 
 | 1041 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1042 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 1043 | VkResult CreateSwapchainKHR(VkDevice device, | 
 | 1044 |                             const VkSwapchainCreateInfoKHR* create_info, | 
 | 1045 |                             const VkAllocationCallbacks* allocator, | 
 | 1046 |                             VkSwapchainKHR* swapchain_handle) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1047 |     ATRACE_CALL(); | 
 | 1048 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1049 |     int err; | 
 | 1050 |     VkResult result = VK_SUCCESS; | 
 | 1051 |  | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1052 |     ALOGV("vkCreateSwapchainKHR: surface=0x%" PRIx64 | 
 | 1053 |           " minImageCount=%u imageFormat=%u imageColorSpace=%u" | 
 | 1054 |           " imageExtent=%ux%u imageUsage=%#x preTransform=%u presentMode=%u" | 
 | 1055 |           " oldSwapchain=0x%" PRIx64, | 
 | 1056 |           reinterpret_cast<uint64_t>(create_info->surface), | 
 | 1057 |           create_info->minImageCount, create_info->imageFormat, | 
 | 1058 |           create_info->imageColorSpace, create_info->imageExtent.width, | 
 | 1059 |           create_info->imageExtent.height, create_info->imageUsage, | 
 | 1060 |           create_info->preTransform, create_info->presentMode, | 
 | 1061 |           reinterpret_cast<uint64_t>(create_info->oldSwapchain)); | 
 | 1062 |  | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1063 |     if (!allocator) | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 1064 |         allocator = &GetData(device).allocator; | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1065 |  | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 1066 |     android_pixel_format native_pixel_format = | 
 | 1067 |         GetNativePixelFormat(create_info->imageFormat); | 
 | 1068 |     android_dataspace native_dataspace = | 
 | 1069 |         GetNativeDataspace(create_info->imageColorSpace); | 
 | 1070 |     if (native_dataspace == HAL_DATASPACE_UNKNOWN) { | 
 | 1071 |         ALOGE( | 
 | 1072 |             "CreateSwapchainKHR(VkSwapchainCreateInfoKHR.imageColorSpace = %d) " | 
 | 1073 |             "failed: Unsupported color space", | 
 | 1074 |             create_info->imageColorSpace); | 
 | 1075 |         return VK_ERROR_INITIALIZATION_FAILED; | 
 | 1076 |     } | 
 | 1077 |  | 
| Jesse Hall | 42a9eec | 2016-06-03 12:39:49 -0700 | [diff] [blame] | 1078 |     ALOGV_IF(create_info->imageArrayLayers != 1, | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1079 |              "swapchain imageArrayLayers=%u not supported", | 
| Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 1080 |              create_info->imageArrayLayers); | 
| Jesse Hall | 42a9eec | 2016-06-03 12:39:49 -0700 | [diff] [blame] | 1081 |     ALOGV_IF((create_info->preTransform & ~kSupportedTransforms) != 0, | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1082 |              "swapchain preTransform=%#x not supported", | 
| Jesse Hall | 55bc097 | 2016-02-23 16:43:29 -0800 | [diff] [blame] | 1083 |              create_info->preTransform); | 
| Jesse Hall | 42a9eec | 2016-06-03 12:39:49 -0700 | [diff] [blame] | 1084 |     ALOGV_IF(!(create_info->presentMode == VK_PRESENT_MODE_FIFO_KHR || | 
| Chris Forbes | 980ad05 | 2017-01-18 16:55:07 +1300 | [diff] [blame] | 1085 |                create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR || | 
| Chris Forbes | 1d5f68c | 2017-01-31 10:17:01 +1300 | [diff] [blame] | 1086 |                create_info->presentMode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR || | 
 | 1087 |                create_info->presentMode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR), | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1088 |              "swapchain presentMode=%u not supported", | 
| Jesse Hall | 0ae0dce | 2016-02-09 22:13:34 -0800 | [diff] [blame] | 1089 |              create_info->presentMode); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1090 |  | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1091 |     Surface& surface = *SurfaceFromHandle(create_info->surface); | 
 | 1092 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1093 |     if (surface.swapchain_handle != create_info->oldSwapchain) { | 
| Jesse Hall | 42a9eec | 2016-06-03 12:39:49 -0700 | [diff] [blame] | 1094 |         ALOGV("Can't create a swapchain for VkSurfaceKHR 0x%" PRIx64 | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1095 |               " because it already has active swapchain 0x%" PRIx64 | 
 | 1096 |               " but VkSwapchainCreateInfo::oldSwapchain=0x%" PRIx64, | 
 | 1097 |               reinterpret_cast<uint64_t>(create_info->surface), | 
 | 1098 |               reinterpret_cast<uint64_t>(surface.swapchain_handle), | 
 | 1099 |               reinterpret_cast<uint64_t>(create_info->oldSwapchain)); | 
 | 1100 |         return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; | 
 | 1101 |     } | 
 | 1102 |     if (create_info->oldSwapchain != VK_NULL_HANDLE) | 
 | 1103 |         OrphanSwapchain(device, SwapchainFromHandle(create_info->oldSwapchain)); | 
 | 1104 |  | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1105 |     // -- Reset the native window -- | 
 | 1106 |     // The native window might have been used previously, and had its properties | 
 | 1107 |     // changed from defaults. That will affect the answer we get for queries | 
 | 1108 |     // like MIN_UNDEQUED_BUFFERS. Reset to a known/default state before we | 
 | 1109 |     // attempt such queries. | 
 | 1110 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1111 |     // The native window only allows dequeueing all buffers before any have | 
 | 1112 |     // been queued, since after that point at least one is assumed to be in | 
 | 1113 |     // non-FREE state at any given time. Disconnecting and re-connecting | 
 | 1114 |     // orphans the previous buffers, getting us back to the state where we can | 
 | 1115 |     // dequeue all buffers. | 
| Yiwei Zhang | 70a2196 | 2019-05-31 17:26:52 -0700 | [diff] [blame] | 1116 |     // | 
 | 1117 |     // TODO(http://b/134186185) recycle swapchain images more efficiently | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1118 |     ANativeWindow* window = surface.window.get(); | 
 | 1119 |     err = native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); | 
 | 1120 |     ALOGW_IF(err != android::OK, "native_window_api_disconnect failed: %s (%d)", | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1121 |              strerror(-err), err); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1122 |     err = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); | 
 | 1123 |     ALOGW_IF(err != android::OK, "native_window_api_connect failed: %s (%d)", | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1124 |              strerror(-err), err); | 
 | 1125 |  | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1126 |     err = window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, -1); | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 1127 |     if (err != android::OK) { | 
 | 1128 |         ALOGE("window->perform(SET_DEQUEUE_TIMEOUT) failed: %s (%d)", | 
 | 1129 |               strerror(-err), err); | 
 | 1130 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 1131 |     } | 
 | 1132 |  | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1133 |     err = native_window_set_buffer_count(window, 0); | 
 | 1134 |     if (err != android::OK) { | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1135 |         ALOGE("native_window_set_buffer_count(0) failed: %s (%d)", | 
 | 1136 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1137 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1138 |     } | 
 | 1139 |  | 
| Hrishikesh Manohar | 9b7e453 | 2017-01-10 17:52:11 +0530 | [diff] [blame] | 1140 |     int swap_interval = | 
 | 1141 |         create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR ? 0 : 1; | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1142 |     err = window->setSwapInterval(window, swap_interval); | 
 | 1143 |     if (err != android::OK) { | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1144 |         ALOGE("native_window->setSwapInterval(1) failed: %s (%d)", | 
 | 1145 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1146 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1147 |     } | 
 | 1148 |  | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1149 |     err = native_window_set_shared_buffer_mode(window, false); | 
 | 1150 |     if (err != android::OK) { | 
| Chris Forbes | b8042d2 | 2017-01-18 18:07:05 +1300 | [diff] [blame] | 1151 |         ALOGE("native_window_set_shared_buffer_mode(false) failed: %s (%d)", | 
 | 1152 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1153 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Chris Forbes | b8042d2 | 2017-01-18 18:07:05 +1300 | [diff] [blame] | 1154 |     } | 
 | 1155 |  | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1156 |     err = native_window_set_auto_refresh(window, false); | 
 | 1157 |     if (err != android::OK) { | 
| Chris Forbes | b8042d2 | 2017-01-18 18:07:05 +1300 | [diff] [blame] | 1158 |         ALOGE("native_window_set_auto_refresh(false) failed: %s (%d)", | 
 | 1159 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1160 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Chris Forbes | b8042d2 | 2017-01-18 18:07:05 +1300 | [diff] [blame] | 1161 |     } | 
 | 1162 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1163 |     // -- Configure the native window -- | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1164 |  | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 1165 |     const auto& dispatch = GetData(device).driver; | 
| Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 1166 |  | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1167 |     err = native_window_set_buffers_format(window, native_pixel_format); | 
 | 1168 |     if (err != android::OK) { | 
| Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 1169 |         ALOGE("native_window_set_buffers_format(%d) failed: %s (%d)", | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 1170 |               native_pixel_format, strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1171 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 1172 |     } | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1173 |     err = native_window_set_buffers_data_space(window, native_dataspace); | 
 | 1174 |     if (err != android::OK) { | 
| Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 1175 |         ALOGE("native_window_set_buffers_data_space(%d) failed: %s (%d)", | 
| Courtney Goeltzenleuchter | 7d4a64a | 2017-02-17 12:59:11 -0700 | [diff] [blame] | 1176 |               native_dataspace, strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1177 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 1178 |     } | 
 | 1179 |  | 
| Jesse Hall | 3dd678a | 2016-01-08 21:52:01 -0800 | [diff] [blame] | 1180 |     err = native_window_set_buffers_dimensions( | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1181 |         window, static_cast<int>(create_info->imageExtent.width), | 
| Jesse Hall | 3dd678a | 2016-01-08 21:52:01 -0800 | [diff] [blame] | 1182 |         static_cast<int>(create_info->imageExtent.height)); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1183 |     if (err != android::OK) { | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1184 |         ALOGE("native_window_set_buffers_dimensions(%d,%d) failed: %s (%d)", | 
 | 1185 |               create_info->imageExtent.width, create_info->imageExtent.height, | 
 | 1186 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1187 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1188 |     } | 
 | 1189 |  | 
| Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 1190 |     // VkSwapchainCreateInfo::preTransform indicates the transformation the app | 
 | 1191 |     // applied during rendering. native_window_set_transform() expects the | 
 | 1192 |     // inverse: the transform the app is requesting that the compositor perform | 
 | 1193 |     // during composition. With native windows, pre-transform works by rendering | 
 | 1194 |     // with the same transform the compositor is applying (as in Vulkan), but | 
 | 1195 |     // then requesting the inverse transform, so that when the compositor does | 
 | 1196 |     // it's job the two transforms cancel each other out and the compositor ends | 
 | 1197 |     // up applying an identity transform to the app's buffer. | 
 | 1198 |     err = native_window_set_buffers_transform( | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1199 |         window, InvertTransformToNative(create_info->preTransform)); | 
 | 1200 |     if (err != android::OK) { | 
| Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 1201 |         ALOGE("native_window_set_buffers_transform(%d) failed: %s (%d)", | 
 | 1202 |               InvertTransformToNative(create_info->preTransform), | 
 | 1203 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1204 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 178b696 | 2016-02-24 15:39:50 -0800 | [diff] [blame] | 1205 |     } | 
 | 1206 |  | 
| Jesse Hall | f64ca12 | 2015-11-03 16:11:10 -0800 | [diff] [blame] | 1207 |     err = native_window_set_scaling_mode( | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1208 |         window, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); | 
 | 1209 |     if (err != android::OK) { | 
| Jesse Hall | f64ca12 | 2015-11-03 16:11:10 -0800 | [diff] [blame] | 1210 |         ALOGE("native_window_set_scaling_mode(SCALE_TO_WINDOW) failed: %s (%d)", | 
 | 1211 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1212 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | f64ca12 | 2015-11-03 16:11:10 -0800 | [diff] [blame] | 1213 |     } | 
 | 1214 |  | 
| Chris Forbes | 97ef461 | 2017-03-30 19:37:50 +1300 | [diff] [blame] | 1215 |     VkSwapchainImageUsageFlagsANDROID swapchain_image_usage = 0; | 
 | 1216 |     if (create_info->presentMode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR || | 
 | 1217 |         create_info->presentMode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) { | 
 | 1218 |         swapchain_image_usage |= VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID; | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1219 |         err = native_window_set_shared_buffer_mode(window, true); | 
 | 1220 |         if (err != android::OK) { | 
| Chris Forbes | 97ef461 | 2017-03-30 19:37:50 +1300 | [diff] [blame] | 1221 |             ALOGE("native_window_set_shared_buffer_mode failed: %s (%d)", strerror(-err), err); | 
 | 1222 |             return VK_ERROR_SURFACE_LOST_KHR; | 
 | 1223 |         } | 
 | 1224 |     } | 
 | 1225 |  | 
 | 1226 |     if (create_info->presentMode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) { | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1227 |         err = native_window_set_auto_refresh(window, true); | 
 | 1228 |         if (err != android::OK) { | 
| Chris Forbes | 97ef461 | 2017-03-30 19:37:50 +1300 | [diff] [blame] | 1229 |             ALOGE("native_window_set_auto_refresh failed: %s (%d)", strerror(-err), err); | 
 | 1230 |             return VK_ERROR_SURFACE_LOST_KHR; | 
 | 1231 |         } | 
 | 1232 |     } | 
 | 1233 |  | 
| Jesse Hall | e6080bf | 2016-02-28 20:58:50 -0800 | [diff] [blame] | 1234 |     int query_value; | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1235 |     err = window->query(window, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, | 
 | 1236 |                         &query_value); | 
 | 1237 |     if (err != android::OK || query_value < 0) { | 
| Jesse Hall | e6080bf | 2016-02-28 20:58:50 -0800 | [diff] [blame] | 1238 |         ALOGE("window->query failed: %s (%d) value=%d", strerror(-err), err, | 
 | 1239 |               query_value); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1240 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1241 |     } | 
| Jesse Hall | e6080bf | 2016-02-28 20:58:50 -0800 | [diff] [blame] | 1242 |     uint32_t min_undequeued_buffers = static_cast<uint32_t>(query_value); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1243 |     uint32_t num_images = | 
| Ian Elliott | a3515f4 | 2019-05-15 14:11:33 -0600 | [diff] [blame] | 1244 |         (swap_interval ? create_info->minImageCount | 
 | 1245 |                        : std::max(3u, create_info->minImageCount)) - | 
 | 1246 |         1 + min_undequeued_buffers; | 
| Chris Forbes | 2c8fc75 | 2017-03-17 11:28:32 +1300 | [diff] [blame] | 1247 |  | 
 | 1248 |     // Lower layer insists that we have at least two buffers. This is wasteful | 
 | 1249 |     // and we'd like to relax it in the shared case, but not all the pieces are | 
 | 1250 |     // in place for that to work yet. Note we only lie to the lower layer-- we | 
 | 1251 |     // don't want to give the app back a swapchain with extra images (which they | 
 | 1252 |     // can't actually use!). | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1253 |     err = native_window_set_buffer_count(window, std::max(2u, num_images)); | 
 | 1254 |     if (err != android::OK) { | 
| Jesse Hall | 3d1c82a | 2016-04-22 15:28:29 -0700 | [diff] [blame] | 1255 |         ALOGE("native_window_set_buffer_count(%d) failed: %s (%d)", num_images, | 
 | 1256 |               strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1257 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1258 |     } | 
 | 1259 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1260 |     int32_t legacy_usage = 0; | 
| Chris Forbes | 8c47dc9 | 2017-01-12 11:13:58 +1300 | [diff] [blame] | 1261 |     if (dispatch.GetSwapchainGrallocUsage2ANDROID) { | 
| Jesse Hall | d1abd74 | 2017-02-09 21:45:51 -0800 | [diff] [blame] | 1262 |         uint64_t consumer_usage, producer_usage; | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1263 |         ATRACE_BEGIN("GetSwapchainGrallocUsage2ANDROID"); | 
| Courtney Goeltzenleuchter | 894780b | 2017-04-03 16:11:30 -0600 | [diff] [blame] | 1264 |         result = dispatch.GetSwapchainGrallocUsage2ANDROID( | 
 | 1265 |             device, create_info->imageFormat, create_info->imageUsage, | 
 | 1266 |             swapchain_image_usage, &consumer_usage, &producer_usage); | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1267 |         ATRACE_END(); | 
| Chris Forbes | 8c47dc9 | 2017-01-12 11:13:58 +1300 | [diff] [blame] | 1268 |         if (result != VK_SUCCESS) { | 
 | 1269 |             ALOGE("vkGetSwapchainGrallocUsage2ANDROID failed: %d", result); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1270 |             return VK_ERROR_SURFACE_LOST_KHR; | 
| Chris Forbes | 8c47dc9 | 2017-01-12 11:13:58 +1300 | [diff] [blame] | 1271 |         } | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1272 |         legacy_usage = | 
| Jesse Hall | 7992781 | 2017-03-23 11:03:23 -0700 | [diff] [blame] | 1273 |             android_convertGralloc1To0Usage(producer_usage, consumer_usage); | 
| Chris Forbes | 8c47dc9 | 2017-01-12 11:13:58 +1300 | [diff] [blame] | 1274 |     } else if (dispatch.GetSwapchainGrallocUsageANDROID) { | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1275 |         ATRACE_BEGIN("GetSwapchainGrallocUsageANDROID"); | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1276 |         result = dispatch.GetSwapchainGrallocUsageANDROID( | 
| Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 1277 |             device, create_info->imageFormat, create_info->imageUsage, | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1278 |             &legacy_usage); | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1279 |         ATRACE_END(); | 
| Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 1280 |         if (result != VK_SUCCESS) { | 
 | 1281 |             ALOGE("vkGetSwapchainGrallocUsageANDROID failed: %d", result); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1282 |             return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 1283 |         } | 
| Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 1284 |     } | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1285 |     uint64_t native_usage = static_cast<uint64_t>(legacy_usage); | 
 | 1286 |  | 
 | 1287 |     bool createProtectedSwapchain = false; | 
 | 1288 |     if (create_info->flags & VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR) { | 
 | 1289 |         createProtectedSwapchain = true; | 
 | 1290 |         native_usage |= BufferUsage::PROTECTED; | 
 | 1291 |     } | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1292 |     err = native_window_set_usage(window, native_usage); | 
 | 1293 |     if (err != android::OK) { | 
| Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 1294 |         ALOGE("native_window_set_usage failed: %s (%d)", strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1295 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | 70f9335 | 2015-11-04 09:41:31 -0800 | [diff] [blame] | 1296 |     } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1297 |  | 
| Yiwei Zhang | 69395cd | 2019-07-03 16:55:39 -0700 | [diff] [blame] | 1298 |     int transform_hint; | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1299 |     err = window->query(window, NATIVE_WINDOW_TRANSFORM_HINT, &transform_hint); | 
 | 1300 |     if (err != android::OK) { | 
| Yiwei Zhang | 69395cd | 2019-07-03 16:55:39 -0700 | [diff] [blame] | 1301 |         ALOGE("NATIVE_WINDOW_TRANSFORM_HINT query failed: %s (%d)", | 
 | 1302 |               strerror(-err), err); | 
 | 1303 |         return VK_ERROR_SURFACE_LOST_KHR; | 
 | 1304 |     } | 
 | 1305 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1306 |     // -- Allocate our Swapchain object -- | 
 | 1307 |     // After this point, we must deallocate the swapchain on error. | 
 | 1308 |  | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1309 |     void* mem = allocator->pfnAllocation(allocator->pUserData, | 
 | 1310 |                                          sizeof(Swapchain), alignof(Swapchain), | 
 | 1311 |                                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 1312 |     if (!mem) | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1313 |         return VK_ERROR_OUT_OF_HOST_MEMORY; | 
| silence_dogood | 7359759 | 2019-05-23 16:57:37 -0700 | [diff] [blame] | 1314 |     Swapchain* swapchain = new (mem) | 
 | 1315 |         Swapchain(surface, num_images, create_info->presentMode, | 
 | 1316 |                   TranslateVulkanToNativeTransform(create_info->preTransform)); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1317 |     // -- Dequeue all buffers and create a VkImage for each -- | 
 | 1318 |     // Any failures during or after this must cancel the dequeued buffers. | 
 | 1319 |  | 
| Chris Forbes | b56287a | 2017-01-12 14:28:58 +1300 | [diff] [blame] | 1320 |     VkSwapchainImageCreateInfoANDROID swapchain_image_create = { | 
 | 1321 | #pragma clang diagnostic push | 
 | 1322 | #pragma clang diagnostic ignored "-Wold-style-cast" | 
 | 1323 |         .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID, | 
 | 1324 | #pragma clang diagnostic pop | 
 | 1325 |         .pNext = nullptr, | 
 | 1326 |         .usage = swapchain_image_usage, | 
 | 1327 |     }; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1328 |     VkNativeBufferANDROID image_native_buffer = { | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1329 | #pragma clang diagnostic push | 
 | 1330 | #pragma clang diagnostic ignored "-Wold-style-cast" | 
 | 1331 |         .sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID, | 
 | 1332 | #pragma clang diagnostic pop | 
| Chris Forbes | b56287a | 2017-01-12 14:28:58 +1300 | [diff] [blame] | 1333 |         .pNext = &swapchain_image_create, | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1334 |     }; | 
 | 1335 |     VkImageCreateInfo image_create = { | 
 | 1336 |         .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, | 
 | 1337 |         .pNext = &image_native_buffer, | 
| Nick Desaulniers | e745a3e | 2019-10-18 10:38:45 -0700 | [diff] [blame] | 1338 |         .flags = createProtectedSwapchain ? VK_IMAGE_CREATE_PROTECTED_BIT : 0u, | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1339 |         .imageType = VK_IMAGE_TYPE_2D, | 
| Jesse Hall | 517274a | 2016-02-10 00:07:18 -0800 | [diff] [blame] | 1340 |         .format = create_info->imageFormat, | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1341 |         .extent = {0, 0, 1}, | 
 | 1342 |         .mipLevels = 1, | 
| Jesse Hall | a15a4bf | 2015-11-19 22:48:02 -0800 | [diff] [blame] | 1343 |         .arrayLayers = 1, | 
| Jesse Hall | 091ed9e | 2015-11-30 00:55:29 -0800 | [diff] [blame] | 1344 |         .samples = VK_SAMPLE_COUNT_1_BIT, | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1345 |         .tiling = VK_IMAGE_TILING_OPTIMAL, | 
| Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 1346 |         .usage = create_info->imageUsage, | 
| Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 1347 |         .sharingMode = create_info->imageSharingMode, | 
| Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 1348 |         .queueFamilyIndexCount = create_info->queueFamilyIndexCount, | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1349 |         .pQueueFamilyIndices = create_info->pQueueFamilyIndices, | 
 | 1350 |     }; | 
 | 1351 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1352 |     for (uint32_t i = 0; i < num_images; i++) { | 
 | 1353 |         Swapchain::Image& img = swapchain->images[i]; | 
 | 1354 |  | 
 | 1355 |         ANativeWindowBuffer* buffer; | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1356 |         err = window->dequeueBuffer(window, &buffer, &img.dequeue_fence); | 
 | 1357 |         if (err != android::OK) { | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1358 |             ALOGE("dequeueBuffer[%u] failed: %s (%d)", i, strerror(-err), err); | 
| Yiwei Zhang | 702beb4 | 2019-11-29 17:59:55 -0800 | [diff] [blame] | 1359 |             switch (-err) { | 
 | 1360 |                 case ENOMEM: | 
 | 1361 |                     result = VK_ERROR_OUT_OF_DEVICE_MEMORY; | 
 | 1362 |                     break; | 
 | 1363 |                 default: | 
 | 1364 |                     result = VK_ERROR_SURFACE_LOST_KHR; | 
 | 1365 |                     break; | 
 | 1366 |             } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1367 |             break; | 
 | 1368 |         } | 
| Chia-I Wu | e8e689f | 2016-04-18 08:21:31 +0800 | [diff] [blame] | 1369 |         img.buffer = buffer; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1370 |         img.dequeued = true; | 
 | 1371 |  | 
 | 1372 |         image_create.extent = | 
| Jesse Hall | 3dd678a | 2016-01-08 21:52:01 -0800 | [diff] [blame] | 1373 |             VkExtent3D{static_cast<uint32_t>(img.buffer->width), | 
 | 1374 |                        static_cast<uint32_t>(img.buffer->height), | 
 | 1375 |                        1}; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1376 |         image_native_buffer.handle = img.buffer->handle; | 
 | 1377 |         image_native_buffer.stride = img.buffer->stride; | 
 | 1378 |         image_native_buffer.format = img.buffer->format; | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1379 |         image_native_buffer.usage = int(img.buffer->usage); | 
| Chris Forbes | 8e0c3f5 | 2017-05-19 14:47:29 -0700 | [diff] [blame] | 1380 |         android_convertGralloc0To1Usage(int(img.buffer->usage), | 
 | 1381 |             &image_native_buffer.usage2.producer, | 
 | 1382 |             &image_native_buffer.usage2.consumer); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1383 |  | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1384 |         ATRACE_BEGIN("CreateImage"); | 
| Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 1385 |         result = | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1386 |             dispatch.CreateImage(device, &image_create, nullptr, &img.image); | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1387 |         ATRACE_END(); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1388 |         if (result != VK_SUCCESS) { | 
 | 1389 |             ALOGD("vkCreateImage w/ native buffer failed: %u", result); | 
 | 1390 |             break; | 
 | 1391 |         } | 
 | 1392 |     } | 
 | 1393 |  | 
 | 1394 |     // -- Cancel all buffers, returning them to the queue -- | 
 | 1395 |     // If an error occurred before, also destroy the VkImage and release the | 
 | 1396 |     // buffer reference. Otherwise, we retain a strong reference to the buffer. | 
| Chris Forbes | 31b85c2 | 2018-05-29 15:03:28 -0700 | [diff] [blame] | 1397 |     for (uint32_t i = 0; i < num_images; i++) { | 
 | 1398 |         Swapchain::Image& img = swapchain->images[i]; | 
 | 1399 |         if (img.dequeued) { | 
 | 1400 |             if (!swapchain->shared) { | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1401 |                 window->cancelBuffer(window, img.buffer.get(), | 
 | 1402 |                                      img.dequeue_fence); | 
| Chris Forbes | e0ced03 | 2017-03-30 19:44:15 +1300 | [diff] [blame] | 1403 |                 img.dequeue_fence = -1; | 
 | 1404 |                 img.dequeued = false; | 
 | 1405 |             } | 
| Chris Forbes | 31b85c2 | 2018-05-29 15:03:28 -0700 | [diff] [blame] | 1406 |         } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1407 |     } | 
 | 1408 |  | 
 | 1409 |     if (result != VK_SUCCESS) { | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1410 |         DestroySwapchainInternal(device, HandleFromSwapchain(swapchain), | 
 | 1411 |                                  allocator); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1412 |         return result; | 
 | 1413 |     } | 
 | 1414 |  | 
| Yiwei Zhang | 69395cd | 2019-07-03 16:55:39 -0700 | [diff] [blame] | 1415 |     if (transform_hint != swapchain->pre_transform) { | 
 | 1416 |         // Log that the app is not doing pre-rotation. | 
 | 1417 |         android::GraphicsEnv::getInstance().setTargetStats( | 
 | 1418 |             android::GpuStatsInfo::Stats::FALSE_PREROTATION); | 
 | 1419 |     } | 
 | 1420 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1421 |     surface.swapchain_handle = HandleFromSwapchain(swapchain); | 
 | 1422 |     *swapchain_handle = surface.swapchain_handle; | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 1423 |     return VK_SUCCESS; | 
 | 1424 | } | 
 | 1425 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 1426 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 1427 | void DestroySwapchainKHR(VkDevice device, | 
 | 1428 |                          VkSwapchainKHR swapchain_handle, | 
 | 1429 |                          const VkAllocationCallbacks* allocator) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1430 |     ATRACE_CALL(); | 
 | 1431 |  | 
| Yiwei Zhang | 533cea9 | 2019-06-03 18:43:24 -0700 | [diff] [blame] | 1432 |     DestroySwapchainInternal(device, swapchain_handle, allocator); | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 1433 | } | 
 | 1434 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 1435 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 1436 | VkResult GetSwapchainImagesKHR(VkDevice, | 
 | 1437 |                                VkSwapchainKHR swapchain_handle, | 
 | 1438 |                                uint32_t* count, | 
 | 1439 |                                VkImage* images) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1440 |     ATRACE_CALL(); | 
 | 1441 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1442 |     Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1443 |     ALOGW_IF(swapchain.surface.swapchain_handle != swapchain_handle, | 
 | 1444 |              "getting images for non-active swapchain 0x%" PRIx64 | 
 | 1445 |              "; only dequeued image handles are valid", | 
 | 1446 |              reinterpret_cast<uint64_t>(swapchain_handle)); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1447 |     VkResult result = VK_SUCCESS; | 
 | 1448 |     if (images) { | 
 | 1449 |         uint32_t n = swapchain.num_images; | 
 | 1450 |         if (*count < swapchain.num_images) { | 
 | 1451 |             n = *count; | 
 | 1452 |             result = VK_INCOMPLETE; | 
 | 1453 |         } | 
 | 1454 |         for (uint32_t i = 0; i < n; i++) | 
 | 1455 |             images[i] = swapchain.images[i].image; | 
| Jesse Hall | 7331e22 | 2016-09-15 21:26:01 -0700 | [diff] [blame] | 1456 |         *count = n; | 
 | 1457 |     } else { | 
 | 1458 |         *count = swapchain.num_images; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1459 |     } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1460 |     return result; | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 1461 | } | 
 | 1462 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 1463 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 1464 | VkResult AcquireNextImageKHR(VkDevice device, | 
 | 1465 |                              VkSwapchainKHR swapchain_handle, | 
 | 1466 |                              uint64_t timeout, | 
 | 1467 |                              VkSemaphore semaphore, | 
 | 1468 |                              VkFence vk_fence, | 
 | 1469 |                              uint32_t* image_index) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1470 |     ATRACE_CALL(); | 
 | 1471 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1472 |     Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); | 
| Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 1473 |     ANativeWindow* window = swapchain.surface.window.get(); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1474 |     VkResult result; | 
 | 1475 |     int err; | 
 | 1476 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1477 |     if (swapchain.surface.swapchain_handle != swapchain_handle) | 
 | 1478 |         return VK_ERROR_OUT_OF_DATE_KHR; | 
 | 1479 |  | 
| Chris Forbes | c88409c | 2017-03-30 19:47:37 +1300 | [diff] [blame] | 1480 |     if (swapchain.shared) { | 
 | 1481 |         // In shared mode, we keep the buffer dequeued all the time, so we don't | 
 | 1482 |         // want to dequeue a buffer here. Instead, just ask the driver to ensure | 
 | 1483 |         // the semaphore and fence passed to us will be signalled. | 
 | 1484 |         *image_index = 0; | 
 | 1485 |         result = GetData(device).driver.AcquireImageANDROID( | 
 | 1486 |                 device, swapchain.images[*image_index].image, -1, semaphore, vk_fence); | 
 | 1487 |         return result; | 
 | 1488 |     } | 
 | 1489 |  | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 1490 |     const nsecs_t acquire_next_image_timeout = | 
 | 1491 |         timeout > (uint64_t)std::numeric_limits<nsecs_t>::max() ? -1 : timeout; | 
 | 1492 |     if (acquire_next_image_timeout != swapchain.acquire_next_image_timeout) { | 
 | 1493 |         // Cache the timeout to avoid the duplicate binder cost. | 
 | 1494 |         err = window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, | 
 | 1495 |                               acquire_next_image_timeout); | 
 | 1496 |         if (err != android::OK) { | 
 | 1497 |             ALOGE("window->perform(SET_DEQUEUE_TIMEOUT) failed: %s (%d)", | 
 | 1498 |                   strerror(-err), err); | 
 | 1499 |             return VK_ERROR_SURFACE_LOST_KHR; | 
 | 1500 |         } | 
 | 1501 |         swapchain.acquire_next_image_timeout = acquire_next_image_timeout; | 
 | 1502 |     } | 
 | 1503 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1504 |     ANativeWindowBuffer* buffer; | 
| Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 1505 |     int fence_fd; | 
 | 1506 |     err = window->dequeueBuffer(window, &buffer, &fence_fd); | 
| Yiwei Zhang | c0f8a2c | 2020-04-30 20:23:13 -0700 | [diff] [blame] | 1507 |     if (err == android::TIMED_OUT || err == android::INVALID_OPERATION) { | 
| Yiwei Zhang | 705c2e6 | 2019-12-18 23:12:43 -0800 | [diff] [blame] | 1508 |         ALOGW("dequeueBuffer timed out: %s (%d)", strerror(-err), err); | 
 | 1509 |         return timeout ? VK_TIMEOUT : VK_NOT_READY; | 
 | 1510 |     } else if (err != android::OK) { | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1511 |         ALOGE("dequeueBuffer failed: %s (%d)", strerror(-err), err); | 
| Mike Stroyan | 762c813 | 2017-02-22 11:43:09 -0700 | [diff] [blame] | 1512 |         return VK_ERROR_SURFACE_LOST_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1513 |     } | 
 | 1514 |  | 
 | 1515 |     uint32_t idx; | 
 | 1516 |     for (idx = 0; idx < swapchain.num_images; idx++) { | 
 | 1517 |         if (swapchain.images[idx].buffer.get() == buffer) { | 
 | 1518 |             swapchain.images[idx].dequeued = true; | 
| Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 1519 |             swapchain.images[idx].dequeue_fence = fence_fd; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1520 |             break; | 
 | 1521 |         } | 
 | 1522 |     } | 
 | 1523 |     if (idx == swapchain.num_images) { | 
 | 1524 |         ALOGE("dequeueBuffer returned unrecognized buffer"); | 
| Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 1525 |         window->cancelBuffer(window, buffer, fence_fd); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1526 |         return VK_ERROR_OUT_OF_DATE_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1527 |     } | 
 | 1528 |  | 
 | 1529 |     int fence_clone = -1; | 
| Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 1530 |     if (fence_fd != -1) { | 
 | 1531 |         fence_clone = dup(fence_fd); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1532 |         if (fence_clone == -1) { | 
 | 1533 |             ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", | 
 | 1534 |                   strerror(errno), errno); | 
| Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 1535 |             sync_wait(fence_fd, -1 /* forever */); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1536 |         } | 
 | 1537 |     } | 
 | 1538 |  | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 1539 |     result = GetData(device).driver.AcquireImageANDROID( | 
| Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1540 |         device, swapchain.images[idx].image, fence_clone, semaphore, vk_fence); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1541 |     if (result != VK_SUCCESS) { | 
| Jesse Hall | ab9aeef | 2015-11-04 10:56:20 -0800 | [diff] [blame] | 1542 |         // NOTE: we're relying on AcquireImageANDROID to close fence_clone, | 
 | 1543 |         // even if the call fails. We could close it ourselves on failure, but | 
 | 1544 |         // that would create a race condition if the driver closes it on a | 
 | 1545 |         // failure path: some other thread might create an fd with the same | 
 | 1546 |         // number between the time the driver closes it and the time we close | 
 | 1547 |         // it. We must assume one of: the driver *always* closes it even on | 
 | 1548 |         // failure, or *never* closes it on failure. | 
| Jesse Hall | 0619380 | 2015-12-03 16:12:51 -0800 | [diff] [blame] | 1549 |         window->cancelBuffer(window, buffer, fence_fd); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1550 |         swapchain.images[idx].dequeued = false; | 
 | 1551 |         swapchain.images[idx].dequeue_fence = -1; | 
 | 1552 |         return result; | 
 | 1553 |     } | 
 | 1554 |  | 
 | 1555 |     *image_index = idx; | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 1556 |     return VK_SUCCESS; | 
 | 1557 | } | 
 | 1558 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1559 | VKAPI_ATTR | 
 | 1560 | VkResult AcquireNextImage2KHR(VkDevice device, | 
 | 1561 |                               const VkAcquireNextImageInfoKHR* pAcquireInfo, | 
 | 1562 |                               uint32_t* pImageIndex) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1563 |     ATRACE_CALL(); | 
 | 1564 |  | 
| Daniel Koch | f25f5bb | 2017-10-05 00:26:58 -0400 | [diff] [blame] | 1565 |     return AcquireNextImageKHR(device, pAcquireInfo->swapchain, | 
 | 1566 |                                pAcquireInfo->timeout, pAcquireInfo->semaphore, | 
 | 1567 |                                pAcquireInfo->fence, pImageIndex); | 
 | 1568 | } | 
 | 1569 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1570 | static VkResult WorstPresentResult(VkResult a, VkResult b) { | 
 | 1571 |     // See the error ranking for vkQueuePresentKHR at the end of section 29.6 | 
 | 1572 |     // (in spec version 1.0.14). | 
 | 1573 |     static const VkResult kWorstToBest[] = { | 
 | 1574 |         VK_ERROR_DEVICE_LOST, | 
 | 1575 |         VK_ERROR_SURFACE_LOST_KHR, | 
 | 1576 |         VK_ERROR_OUT_OF_DATE_KHR, | 
 | 1577 |         VK_ERROR_OUT_OF_DEVICE_MEMORY, | 
 | 1578 |         VK_ERROR_OUT_OF_HOST_MEMORY, | 
 | 1579 |         VK_SUBOPTIMAL_KHR, | 
 | 1580 |     }; | 
 | 1581 |     for (auto result : kWorstToBest) { | 
 | 1582 |         if (a == result || b == result) | 
 | 1583 |             return result; | 
 | 1584 |     } | 
 | 1585 |     ALOG_ASSERT(a == VK_SUCCESS, "invalid vkQueuePresentKHR result %d", a); | 
 | 1586 |     ALOG_ASSERT(b == VK_SUCCESS, "invalid vkQueuePresentKHR result %d", b); | 
 | 1587 |     return a != VK_SUCCESS ? a : b; | 
 | 1588 | } | 
 | 1589 |  | 
| Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 1590 | VKAPI_ATTR | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 1591 | VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1592 |     ATRACE_CALL(); | 
 | 1593 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1594 |     ALOGV_IF(present_info->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, | 
 | 1595 |              "vkQueuePresentKHR: invalid VkPresentInfoKHR structure type %d", | 
 | 1596 |              present_info->sType); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1597 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1598 |     VkDevice device = GetData(queue).driver_device; | 
| Chia-I Wu | 4a6a916 | 2016-03-26 07:17:34 +0800 | [diff] [blame] | 1599 |     const auto& dispatch = GetData(queue).driver; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1600 |     VkResult final_result = VK_SUCCESS; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1601 |  | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1602 |     // Look at the pNext chain for supported extension structs: | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1603 |     const VkPresentRegionsKHR* present_regions = nullptr; | 
 | 1604 |     const VkPresentTimesInfoGOOGLE* present_times = nullptr; | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1605 |     const VkPresentRegionsKHR* next = | 
 | 1606 |         reinterpret_cast<const VkPresentRegionsKHR*>(present_info->pNext); | 
 | 1607 |     while (next) { | 
 | 1608 |         switch (next->sType) { | 
 | 1609 |             case VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR: | 
 | 1610 |                 present_regions = next; | 
 | 1611 |                 break; | 
| Ian Elliott | 14866bb | 2017-01-20 09:15:48 -0700 | [diff] [blame] | 1612 |             case VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE: | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1613 |                 present_times = | 
 | 1614 |                     reinterpret_cast<const VkPresentTimesInfoGOOGLE*>(next); | 
 | 1615 |                 break; | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1616 |             default: | 
 | 1617 |                 ALOGV("QueuePresentKHR ignoring unrecognized pNext->sType = %x", | 
 | 1618 |                       next->sType); | 
 | 1619 |                 break; | 
 | 1620 |         } | 
 | 1621 |         next = reinterpret_cast<const VkPresentRegionsKHR*>(next->pNext); | 
 | 1622 |     } | 
 | 1623 |     ALOGV_IF( | 
 | 1624 |         present_regions && | 
 | 1625 |             present_regions->swapchainCount != present_info->swapchainCount, | 
 | 1626 |         "VkPresentRegions::swapchainCount != VkPresentInfo::swapchainCount"); | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1627 |     ALOGV_IF(present_times && | 
 | 1628 |                  present_times->swapchainCount != present_info->swapchainCount, | 
 | 1629 |              "VkPresentTimesInfoGOOGLE::swapchainCount != " | 
 | 1630 |              "VkPresentInfo::swapchainCount"); | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1631 |     const VkPresentRegionKHR* regions = | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1632 |         (present_regions) ? present_regions->pRegions : nullptr; | 
 | 1633 |     const VkPresentTimeGOOGLE* times = | 
 | 1634 |         (present_times) ? present_times->pTimes : nullptr; | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1635 |     const VkAllocationCallbacks* allocator = &GetData(device).allocator; | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1636 |     android_native_rect_t* rects = nullptr; | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1637 |     uint32_t nrects = 0; | 
 | 1638 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1639 |     for (uint32_t sc = 0; sc < present_info->swapchainCount; sc++) { | 
 | 1640 |         Swapchain& swapchain = | 
| Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 1641 |             *SwapchainFromHandle(present_info->pSwapchains[sc]); | 
| Jesse Hall | f4ab2b1 | 2015-11-30 16:04:55 -0800 | [diff] [blame] | 1642 |         uint32_t image_idx = present_info->pImageIndices[sc]; | 
| Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 1643 |         Swapchain::Image& img = swapchain.images[image_idx]; | 
| Ian Elliott | ffedb65 | 2017-02-14 10:58:30 -0700 | [diff] [blame] | 1644 |         const VkPresentRegionKHR* region = | 
 | 1645 |             (regions && !swapchain.mailbox_mode) ? ®ions[sc] : nullptr; | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1646 |         const VkPresentTimeGOOGLE* time = (times) ? ×[sc] : nullptr; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1647 |         VkResult swapchain_result = VK_SUCCESS; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1648 |         VkResult result; | 
 | 1649 |         int err; | 
 | 1650 |  | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1651 |         int fence = -1; | 
| Jesse Hall | 275d76c | 2016-01-08 22:39:16 -0800 | [diff] [blame] | 1652 |         result = dispatch.QueueSignalReleaseImageANDROID( | 
 | 1653 |             queue, present_info->waitSemaphoreCount, | 
 | 1654 |             present_info->pWaitSemaphores, img.image, &fence); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1655 |         if (result != VK_SUCCESS) { | 
| Jesse Hall | ab9aeef | 2015-11-04 10:56:20 -0800 | [diff] [blame] | 1656 |             ALOGE("QueueSignalReleaseImageANDROID failed: %d", result); | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1657 |             swapchain_result = result; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1658 |         } | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 1659 |         if (img.release_fence >= 0) | 
 | 1660 |             close(img.release_fence); | 
 | 1661 |         img.release_fence = fence < 0 ? -1 : dup(fence); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1662 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1663 |         if (swapchain.surface.swapchain_handle == | 
 | 1664 |             present_info->pSwapchains[sc]) { | 
 | 1665 |             ANativeWindow* window = swapchain.surface.window.get(); | 
 | 1666 |             if (swapchain_result == VK_SUCCESS) { | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1667 |                 if (region) { | 
 | 1668 |                     // Process the incremental-present hint for this swapchain: | 
 | 1669 |                     uint32_t rcount = region->rectangleCount; | 
 | 1670 |                     if (rcount > nrects) { | 
 | 1671 |                         android_native_rect_t* new_rects = | 
 | 1672 |                             static_cast<android_native_rect_t*>( | 
 | 1673 |                                 allocator->pfnReallocation( | 
 | 1674 |                                     allocator->pUserData, rects, | 
 | 1675 |                                     sizeof(android_native_rect_t) * rcount, | 
 | 1676 |                                     alignof(android_native_rect_t), | 
 | 1677 |                                     VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); | 
 | 1678 |                         if (new_rects) { | 
 | 1679 |                             rects = new_rects; | 
 | 1680 |                             nrects = rcount; | 
 | 1681 |                         } else { | 
 | 1682 |                             rcount = 0;  // Ignore the hint for this swapchain | 
 | 1683 |                         } | 
 | 1684 |                     } | 
 | 1685 |                     for (uint32_t r = 0; r < rcount; ++r) { | 
 | 1686 |                         if (region->pRectangles[r].layer > 0) { | 
 | 1687 |                             ALOGV( | 
 | 1688 |                                 "vkQueuePresentKHR ignoring invalid layer " | 
 | 1689 |                                 "(%u); using layer 0 instead", | 
 | 1690 |                                 region->pRectangles[r].layer); | 
 | 1691 |                         } | 
 | 1692 |                         int x = region->pRectangles[r].offset.x; | 
 | 1693 |                         int y = region->pRectangles[r].offset.y; | 
 | 1694 |                         int width = static_cast<int>( | 
 | 1695 |                             region->pRectangles[r].extent.width); | 
 | 1696 |                         int height = static_cast<int>( | 
 | 1697 |                             region->pRectangles[r].extent.height); | 
 | 1698 |                         android_native_rect_t* cur_rect = &rects[r]; | 
 | 1699 |                         cur_rect->left = x; | 
 | 1700 |                         cur_rect->top = y + height; | 
 | 1701 |                         cur_rect->right = x + width; | 
 | 1702 |                         cur_rect->bottom = y; | 
 | 1703 |                     } | 
 | 1704 |                     native_window_set_surface_damage(window, rects, rcount); | 
 | 1705 |                 } | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1706 |                 if (time) { | 
 | 1707 |                     if (!swapchain.frame_timestamps_enabled) { | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 1708 |                         ALOGV( | 
 | 1709 |                             "Calling " | 
 | 1710 |                             "native_window_enable_frame_timestamps(true)"); | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1711 |                         native_window_enable_frame_timestamps(window, true); | 
 | 1712 |                         swapchain.frame_timestamps_enabled = true; | 
 | 1713 |                     } | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1714 |  | 
 | 1715 |                     // Record the nativeFrameId so it can be later correlated to | 
 | 1716 |                     // this present. | 
 | 1717 |                     uint64_t nativeFrameId = 0; | 
 | 1718 |                     err = native_window_get_next_frame_id( | 
 | 1719 |                             window, &nativeFrameId); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1720 |                     if (err != android::OK) { | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1721 |                         ALOGE("Failed to get next native frame ID."); | 
 | 1722 |                     } | 
 | 1723 |  | 
 | 1724 |                     // Add a new timing record with the user's presentID and | 
 | 1725 |                     // the nativeFrameId. | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1726 |                     swapchain.timing.emplace_back(time, nativeFrameId); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1727 |                     while (swapchain.timing.size() > MAX_TIMING_INFOS) { | 
| Yiwei Zhang | 5e86220 | 2019-06-21 14:59:16 -0700 | [diff] [blame] | 1728 |                         swapchain.timing.erase(swapchain.timing.begin()); | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 1729 |                     } | 
 | 1730 |                     if (time->desiredPresentTime) { | 
 | 1731 |                         // Set the desiredPresentTime: | 
 | 1732 |                         ALOGV( | 
 | 1733 |                             "Calling " | 
 | 1734 |                             "native_window_set_buffers_timestamp(%" PRId64 ")", | 
 | 1735 |                             time->desiredPresentTime); | 
 | 1736 |                         native_window_set_buffers_timestamp( | 
 | 1737 |                             window, | 
 | 1738 |                             static_cast<int64_t>(time->desiredPresentTime)); | 
 | 1739 |                     } | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1740 |                 } | 
| Chris Forbes | fca0f29 | 2017-03-30 19:48:39 +1300 | [diff] [blame] | 1741 |  | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1742 |                 err = window->queueBuffer(window, img.buffer.get(), fence); | 
 | 1743 |                 // queueBuffer always closes fence, even on error | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1744 |                 if (err != android::OK) { | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1745 |                     ALOGE("queueBuffer failed: %s (%d)", strerror(-err), err); | 
 | 1746 |                     swapchain_result = WorstPresentResult( | 
 | 1747 |                         swapchain_result, VK_ERROR_OUT_OF_DATE_KHR); | 
| Yiwei Zhang | 0b46847 | 2019-06-03 18:57:19 -0700 | [diff] [blame] | 1748 |                 } else { | 
 | 1749 |                     if (img.dequeue_fence >= 0) { | 
 | 1750 |                         close(img.dequeue_fence); | 
 | 1751 |                         img.dequeue_fence = -1; | 
 | 1752 |                     } | 
 | 1753 |                     img.dequeued = false; | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1754 |                 } | 
| Chris Forbes | fca0f29 | 2017-03-30 19:48:39 +1300 | [diff] [blame] | 1755 |  | 
 | 1756 |                 // If the swapchain is in shared mode, immediately dequeue the | 
 | 1757 |                 // buffer so it can be presented again without an intervening | 
 | 1758 |                 // call to AcquireNextImageKHR. We expect to get the same buffer | 
 | 1759 |                 // back from every call to dequeueBuffer in this mode. | 
 | 1760 |                 if (swapchain.shared && swapchain_result == VK_SUCCESS) { | 
 | 1761 |                     ANativeWindowBuffer* buffer; | 
 | 1762 |                     int fence_fd; | 
 | 1763 |                     err = window->dequeueBuffer(window, &buffer, &fence_fd); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1764 |                     if (err != android::OK) { | 
| Chris Forbes | fca0f29 | 2017-03-30 19:48:39 +1300 | [diff] [blame] | 1765 |                         ALOGE("dequeueBuffer failed: %s (%d)", strerror(-err), err); | 
 | 1766 |                         swapchain_result = WorstPresentResult(swapchain_result, | 
 | 1767 |                             VK_ERROR_SURFACE_LOST_KHR); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1768 |                     } else if (img.buffer != buffer) { | 
| Chris Forbes | fca0f29 | 2017-03-30 19:48:39 +1300 | [diff] [blame] | 1769 |                         ALOGE("got wrong image back for shared swapchain"); | 
 | 1770 |                         swapchain_result = WorstPresentResult(swapchain_result, | 
 | 1771 |                             VK_ERROR_SURFACE_LOST_KHR); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1772 |                     } else { | 
| Chris Forbes | fca0f29 | 2017-03-30 19:48:39 +1300 | [diff] [blame] | 1773 |                         img.dequeue_fence = fence_fd; | 
 | 1774 |                         img.dequeued = true; | 
 | 1775 |                     } | 
 | 1776 |                 } | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1777 |             } | 
 | 1778 |             if (swapchain_result != VK_SUCCESS) { | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1779 |                 OrphanSwapchain(device, &swapchain); | 
 | 1780 |             } | 
| silence_dogood | 7359759 | 2019-05-23 16:57:37 -0700 | [diff] [blame] | 1781 |             int window_transform_hint; | 
 | 1782 |             err = window->query(window, NATIVE_WINDOW_TRANSFORM_HINT, | 
 | 1783 |                                 &window_transform_hint); | 
| Yiwei Zhang | f5030b4 | 2019-12-19 00:10:04 -0800 | [diff] [blame] | 1784 |             if (err != android::OK) { | 
| silence_dogood | 7359759 | 2019-05-23 16:57:37 -0700 | [diff] [blame] | 1785 |                 ALOGE("NATIVE_WINDOW_TRANSFORM_HINT query failed: %s (%d)", | 
 | 1786 |                       strerror(-err), err); | 
 | 1787 |                 swapchain_result = WorstPresentResult( | 
 | 1788 |                     swapchain_result, VK_ERROR_SURFACE_LOST_KHR); | 
 | 1789 |             } | 
 | 1790 |             if (swapchain.pre_transform != window_transform_hint) { | 
 | 1791 |                 swapchain_result = | 
 | 1792 |                     WorstPresentResult(swapchain_result, VK_SUBOPTIMAL_KHR); | 
 | 1793 |             } | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1794 |         } else { | 
| Yiwei Zhang | da2e479 | 2020-09-22 10:08:03 -0700 | [diff] [blame] | 1795 |             ReleaseSwapchainImage(device, nullptr, fence, img, true); | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1796 |             swapchain_result = VK_ERROR_OUT_OF_DATE_KHR; | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1797 |         } | 
 | 1798 |  | 
| Jesse Hall | a9e5703 | 2015-11-30 01:03:10 -0800 | [diff] [blame] | 1799 |         if (present_info->pResults) | 
| Jesse Hall | dc22507 | 2016-05-30 22:40:14 -0700 | [diff] [blame] | 1800 |             present_info->pResults[sc] = swapchain_result; | 
 | 1801 |  | 
 | 1802 |         if (swapchain_result != final_result) | 
 | 1803 |             final_result = WorstPresentResult(final_result, swapchain_result); | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1804 |     } | 
| Ian Elliott | cb35113 | 2016-12-13 10:30:40 -0700 | [diff] [blame] | 1805 |     if (rects) { | 
 | 1806 |         allocator->pfnFree(allocator->pUserData, rects); | 
 | 1807 |     } | 
| Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 1808 |  | 
 | 1809 |     return final_result; | 
 | 1810 | } | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 1811 |  | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1812 | VKAPI_ATTR | 
 | 1813 | VkResult GetRefreshCycleDurationGOOGLE( | 
 | 1814 |     VkDevice, | 
| Ian Elliott | 62c48c9 | 2017-01-20 13:13:20 -0700 | [diff] [blame] | 1815 |     VkSwapchainKHR swapchain_handle, | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1816 |     VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1817 |     ATRACE_CALL(); | 
 | 1818 |  | 
| Ian Elliott | 62c48c9 | 2017-01-20 13:13:20 -0700 | [diff] [blame] | 1819 |     Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1820 |     VkResult result = VK_SUCCESS; | 
 | 1821 |  | 
| Ian Elliott | 3568bfe | 2019-05-03 15:54:46 -0600 | [diff] [blame] | 1822 |     pDisplayTimingProperties->refreshDuration = swapchain.get_refresh_duration(); | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1823 |  | 
 | 1824 |     return result; | 
 | 1825 | } | 
 | 1826 |  | 
 | 1827 | VKAPI_ATTR | 
 | 1828 | VkResult GetPastPresentationTimingGOOGLE( | 
 | 1829 |     VkDevice, | 
 | 1830 |     VkSwapchainKHR swapchain_handle, | 
 | 1831 |     uint32_t* count, | 
 | 1832 |     VkPastPresentationTimingGOOGLE* timings) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1833 |     ATRACE_CALL(); | 
 | 1834 |  | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1835 |     Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); | 
| Yiwei Zhang | 9d18783 | 2019-07-22 15:15:47 -0700 | [diff] [blame] | 1836 |     if (swapchain.surface.swapchain_handle != swapchain_handle) { | 
 | 1837 |         return VK_ERROR_OUT_OF_DATE_KHR; | 
 | 1838 |     } | 
 | 1839 |  | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1840 |     ANativeWindow* window = swapchain.surface.window.get(); | 
 | 1841 |     VkResult result = VK_SUCCESS; | 
 | 1842 |  | 
 | 1843 |     if (!swapchain.frame_timestamps_enabled) { | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 1844 |         ALOGV("Calling native_window_enable_frame_timestamps(true)"); | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1845 |         native_window_enable_frame_timestamps(window, true); | 
 | 1846 |         swapchain.frame_timestamps_enabled = true; | 
 | 1847 |     } | 
 | 1848 |  | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1849 |     if (timings) { | 
| Yiwei Zhang | 9d18783 | 2019-07-22 15:15:47 -0700 | [diff] [blame] | 1850 |         // Get the latest ready timing count before copying, since the copied | 
 | 1851 |         // timing info will be erased in copy_ready_timings function. | 
 | 1852 |         uint32_t n = get_num_ready_timings(swapchain); | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 1853 |         copy_ready_timings(swapchain, count, timings); | 
| Yiwei Zhang | 9d18783 | 2019-07-22 15:15:47 -0700 | [diff] [blame] | 1854 |         // Check the *count here against the recorded ready timing count, since | 
 | 1855 |         // *count can be overwritten per spec describes. | 
 | 1856 |         if (*count < n) { | 
 | 1857 |             result = VK_INCOMPLETE; | 
 | 1858 |         } | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1859 |     } else { | 
| Ian Elliott | 8a97726 | 2017-01-19 09:05:58 -0700 | [diff] [blame] | 1860 |         *count = get_num_ready_timings(swapchain); | 
| Ian Elliott | 4c8bb2a | 2016-12-29 11:07:26 -0700 | [diff] [blame] | 1861 |     } | 
 | 1862 |  | 
 | 1863 |     return result; | 
 | 1864 | } | 
 | 1865 |  | 
| Chris Forbes | 0f2ac2e | 2017-01-18 13:33:53 +1300 | [diff] [blame] | 1866 | VKAPI_ATTR | 
 | 1867 | VkResult GetSwapchainStatusKHR( | 
 | 1868 |     VkDevice, | 
| Chris Forbes | 4e18ba8 | 2017-01-20 12:50:17 +1300 | [diff] [blame] | 1869 |     VkSwapchainKHR swapchain_handle) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1870 |     ATRACE_CALL(); | 
 | 1871 |  | 
| Chris Forbes | 4e18ba8 | 2017-01-20 12:50:17 +1300 | [diff] [blame] | 1872 |     Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); | 
| Chris Forbes | 0f2ac2e | 2017-01-18 13:33:53 +1300 | [diff] [blame] | 1873 |     VkResult result = VK_SUCCESS; | 
 | 1874 |  | 
| Chris Forbes | 4e18ba8 | 2017-01-20 12:50:17 +1300 | [diff] [blame] | 1875 |     if (swapchain.surface.swapchain_handle != swapchain_handle) { | 
 | 1876 |         return VK_ERROR_OUT_OF_DATE_KHR; | 
 | 1877 |     } | 
 | 1878 |  | 
| Yiwei Zhang | a885c06 | 2019-10-24 12:07:57 -0700 | [diff] [blame] | 1879 |     // TODO(b/143296009): Implement this function properly | 
| Chris Forbes | 0f2ac2e | 2017-01-18 13:33:53 +1300 | [diff] [blame] | 1880 |  | 
 | 1881 |     return result; | 
 | 1882 | } | 
 | 1883 |  | 
| Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 1884 | VKAPI_ATTR void SetHdrMetadataEXT( | 
| Courtney Goeltzenleuchter | 7671d46 | 2018-01-24 11:51:01 -0800 | [diff] [blame] | 1885 |     VkDevice, | 
| Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 1886 |     uint32_t swapchainCount, | 
 | 1887 |     const VkSwapchainKHR* pSwapchains, | 
 | 1888 |     const VkHdrMetadataEXT* pHdrMetadataEXTs) { | 
| Yiwei Zhang | fdd0c2a | 2019-01-30 20:16:37 -0800 | [diff] [blame] | 1889 |     ATRACE_CALL(); | 
| Courtney Goeltzenleuchter | 7671d46 | 2018-01-24 11:51:01 -0800 | [diff] [blame] | 1890 |  | 
 | 1891 |     for (uint32_t idx = 0; idx < swapchainCount; idx++) { | 
 | 1892 |         Swapchain* swapchain = SwapchainFromHandle(pSwapchains[idx]); | 
 | 1893 |         if (!swapchain) | 
 | 1894 |             continue; | 
 | 1895 |  | 
 | 1896 |         if (swapchain->surface.swapchain_handle != pSwapchains[idx]) continue; | 
 | 1897 |  | 
 | 1898 |         ANativeWindow* window = swapchain->surface.window.get(); | 
 | 1899 |  | 
 | 1900 |         VkHdrMetadataEXT vulkanMetadata = pHdrMetadataEXTs[idx]; | 
 | 1901 |         const android_smpte2086_metadata smpteMetdata = { | 
 | 1902 |             {vulkanMetadata.displayPrimaryRed.x, | 
 | 1903 |              vulkanMetadata.displayPrimaryRed.y}, | 
 | 1904 |             {vulkanMetadata.displayPrimaryGreen.x, | 
 | 1905 |              vulkanMetadata.displayPrimaryGreen.y}, | 
 | 1906 |             {vulkanMetadata.displayPrimaryBlue.x, | 
 | 1907 |              vulkanMetadata.displayPrimaryBlue.y}, | 
 | 1908 |             {vulkanMetadata.whitePoint.x, vulkanMetadata.whitePoint.y}, | 
 | 1909 |             vulkanMetadata.maxLuminance, | 
 | 1910 |             vulkanMetadata.minLuminance}; | 
 | 1911 |         native_window_set_buffers_smpte2086_metadata(window, &smpteMetdata); | 
 | 1912 |  | 
 | 1913 |         const android_cta861_3_metadata cta8613Metadata = { | 
 | 1914 |             vulkanMetadata.maxContentLightLevel, | 
 | 1915 |             vulkanMetadata.maxFrameAverageLightLevel}; | 
 | 1916 |         native_window_set_buffers_cta861_3_metadata(window, &cta8613Metadata); | 
 | 1917 |     } | 
 | 1918 |  | 
| Courtney Goeltzenleuchter | d634c48 | 2017-01-05 15:55:31 -0700 | [diff] [blame] | 1919 |     return; | 
 | 1920 | } | 
 | 1921 |  | 
| Yiwei Zhang | 0f47522 | 2019-04-11 19:38:00 -0700 | [diff] [blame] | 1922 | static void InterceptBindImageMemory2( | 
 | 1923 |     uint32_t bind_info_count, | 
 | 1924 |     const VkBindImageMemoryInfo* bind_infos, | 
 | 1925 |     std::vector<VkNativeBufferANDROID>* out_native_buffers, | 
 | 1926 |     std::vector<VkBindImageMemoryInfo>* out_bind_infos) { | 
 | 1927 |     out_native_buffers->clear(); | 
 | 1928 |     out_bind_infos->clear(); | 
 | 1929 |  | 
 | 1930 |     if (!bind_info_count) | 
 | 1931 |         return; | 
 | 1932 |  | 
 | 1933 |     std::unordered_set<uint32_t> intercepted_indexes; | 
 | 1934 |  | 
 | 1935 |     for (uint32_t idx = 0; idx < bind_info_count; idx++) { | 
 | 1936 |         auto info = reinterpret_cast<const VkBindImageMemorySwapchainInfoKHR*>( | 
 | 1937 |             bind_infos[idx].pNext); | 
 | 1938 |         while (info && | 
 | 1939 |                info->sType != | 
 | 1940 |                    VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR) { | 
 | 1941 |             info = reinterpret_cast<const VkBindImageMemorySwapchainInfoKHR*>( | 
 | 1942 |                 info->pNext); | 
 | 1943 |         } | 
 | 1944 |  | 
 | 1945 |         if (!info) | 
 | 1946 |             continue; | 
 | 1947 |  | 
 | 1948 |         ALOG_ASSERT(info->swapchain != VK_NULL_HANDLE, | 
 | 1949 |                     "swapchain handle must not be NULL"); | 
 | 1950 |         const Swapchain* swapchain = SwapchainFromHandle(info->swapchain); | 
 | 1951 |         ALOG_ASSERT( | 
 | 1952 |             info->imageIndex < swapchain->num_images, | 
 | 1953 |             "imageIndex must be less than the number of images in swapchain"); | 
 | 1954 |  | 
 | 1955 |         ANativeWindowBuffer* buffer = | 
 | 1956 |             swapchain->images[info->imageIndex].buffer.get(); | 
 | 1957 |         VkNativeBufferANDROID native_buffer = { | 
 | 1958 | #pragma clang diagnostic push | 
 | 1959 | #pragma clang diagnostic ignored "-Wold-style-cast" | 
 | 1960 |             .sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID, | 
 | 1961 | #pragma clang diagnostic pop | 
 | 1962 |             .pNext = bind_infos[idx].pNext, | 
 | 1963 |             .handle = buffer->handle, | 
 | 1964 |             .stride = buffer->stride, | 
 | 1965 |             .format = buffer->format, | 
 | 1966 |             .usage = int(buffer->usage), | 
 | 1967 |         }; | 
 | 1968 |         // Reserve enough space to avoid letting re-allocation invalidate the | 
 | 1969 |         // addresses of the elements inside. | 
 | 1970 |         out_native_buffers->reserve(bind_info_count); | 
 | 1971 |         out_native_buffers->emplace_back(native_buffer); | 
 | 1972 |  | 
 | 1973 |         // Reserve the space now since we know how much is needed now. | 
 | 1974 |         out_bind_infos->reserve(bind_info_count); | 
 | 1975 |         out_bind_infos->emplace_back(bind_infos[idx]); | 
 | 1976 |         out_bind_infos->back().pNext = &out_native_buffers->back(); | 
 | 1977 |  | 
 | 1978 |         intercepted_indexes.insert(idx); | 
 | 1979 |     } | 
 | 1980 |  | 
 | 1981 |     if (intercepted_indexes.empty()) | 
 | 1982 |         return; | 
 | 1983 |  | 
 | 1984 |     for (uint32_t idx = 0; idx < bind_info_count; idx++) { | 
 | 1985 |         if (intercepted_indexes.count(idx)) | 
 | 1986 |             continue; | 
 | 1987 |         out_bind_infos->emplace_back(bind_infos[idx]); | 
 | 1988 |     } | 
 | 1989 | } | 
 | 1990 |  | 
| Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 1991 | VKAPI_ATTR | 
 | 1992 | VkResult BindImageMemory2(VkDevice device, | 
 | 1993 |                           uint32_t bindInfoCount, | 
 | 1994 |                           const VkBindImageMemoryInfo* pBindInfos) { | 
 | 1995 |     ATRACE_CALL(); | 
 | 1996 |  | 
| Yiwei Zhang | 0f47522 | 2019-04-11 19:38:00 -0700 | [diff] [blame] | 1997 |     // out_native_buffers is for maintaining the lifecycle of the constructed | 
 | 1998 |     // VkNativeBufferANDROID objects inside InterceptBindImageMemory2. | 
 | 1999 |     std::vector<VkNativeBufferANDROID> out_native_buffers; | 
 | 2000 |     std::vector<VkBindImageMemoryInfo> out_bind_infos; | 
 | 2001 |     InterceptBindImageMemory2(bindInfoCount, pBindInfos, &out_native_buffers, | 
 | 2002 |                               &out_bind_infos); | 
 | 2003 |     return GetData(device).driver.BindImageMemory2( | 
 | 2004 |         device, bindInfoCount, | 
 | 2005 |         out_bind_infos.empty() ? pBindInfos : out_bind_infos.data()); | 
| Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 2006 | } | 
 | 2007 |  | 
 | 2008 | VKAPI_ATTR | 
 | 2009 | VkResult BindImageMemory2KHR(VkDevice device, | 
 | 2010 |                              uint32_t bindInfoCount, | 
 | 2011 |                              const VkBindImageMemoryInfo* pBindInfos) { | 
 | 2012 |     ATRACE_CALL(); | 
 | 2013 |  | 
| Yiwei Zhang | 0f47522 | 2019-04-11 19:38:00 -0700 | [diff] [blame] | 2014 |     std::vector<VkNativeBufferANDROID> out_native_buffers; | 
 | 2015 |     std::vector<VkBindImageMemoryInfo> out_bind_infos; | 
 | 2016 |     InterceptBindImageMemory2(bindInfoCount, pBindInfos, &out_native_buffers, | 
 | 2017 |                               &out_bind_infos); | 
 | 2018 |     return GetData(device).driver.BindImageMemory2KHR( | 
 | 2019 |         device, bindInfoCount, | 
 | 2020 |         out_bind_infos.empty() ? pBindInfos : out_bind_infos.data()); | 
| Yiwei Zhang | 2314310 | 2019-04-10 18:24:05 -0700 | [diff] [blame] | 2021 | } | 
 | 2022 |  | 
| Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 2023 | }  // namespace driver | 
| Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 2024 | }  // namespace vulkan |