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