Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // SurfaceVk.cpp: |
| 7 | // Implements the class methods for SurfaceVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/SurfaceVk.h" |
| 11 | |
| 12 | #include "common/debug.h" |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 13 | #include "libANGLE/Context.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 14 | #include "libANGLE/Display.h" |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 15 | #include "libANGLE/Surface.h" |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 16 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 17 | #include "libANGLE/renderer/vulkan/DisplayVk.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 18 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 19 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 21 | #include "third_party/trace_event/trace_event.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 22 | |
| 23 | namespace rx |
| 24 | { |
| 25 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 26 | namespace |
| 27 | { |
| 28 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 29 | VkPresentModeKHR GetDesiredPresentMode(const std::vector<VkPresentModeKHR> &presentModes, |
| 30 | EGLint minSwapInterval, |
| 31 | EGLint maxSwapInterval) |
| 32 | { |
| 33 | ASSERT(!presentModes.empty()); |
| 34 | |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 35 | // Use FIFO mode for v-sync, since it throttles you to the display rate. |
| 36 | // |
| 37 | // However, for performance testing (for now), we want to issue draws as fast as possible so we |
| 38 | // use either of the following, if available, in order specified here: |
| 39 | // |
| 40 | // - Mailbox is similar to triple-buffering. |
| 41 | // - Immediate is similar to single-buffering. |
| 42 | // |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 43 | // TODO(jmadill): Properly select present mode and re-create display if changed. |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 44 | bool mailboxAvailable = false; |
| 45 | bool immediateAvailable = false; |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 46 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 47 | for (VkPresentModeKHR presentMode : presentModes) |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 48 | { |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 49 | switch (presentMode) |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 50 | { |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 51 | case VK_PRESENT_MODE_MAILBOX_KHR: |
| 52 | mailboxAvailable = true; |
| 53 | break; |
| 54 | case VK_PRESENT_MODE_IMMEDIATE_KHR: |
| 55 | immediateAvailable = true; |
| 56 | break; |
| 57 | default: |
| 58 | break; |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 62 | // Note that VK_PRESENT_MODE_FIFO_KHR is guaranteed to be available. |
| 63 | return mailboxAvailable |
| 64 | ? VK_PRESENT_MODE_MAILBOX_KHR |
| 65 | : immediateAvailable ? VK_PRESENT_MODE_IMMEDIATE_KHR : VK_PRESENT_MODE_FIFO_KHR; |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 68 | constexpr VkImageUsageFlags kSurfaceVKImageUsageFlags = |
| 69 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 70 | constexpr VkImageUsageFlags kSurfaceVKColorImageUsageFlags = |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 71 | kSurfaceVKImageUsageFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 72 | constexpr VkImageUsageFlags kSurfaceVKDepthStencilImageUsageFlags = |
| 73 | kSurfaceVKImageUsageFlags | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 74 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 75 | } // namespace |
| 76 | |
Shahbaz Youssefi | 29b4941 | 2019-01-07 14:03:06 -0500 | [diff] [blame] | 77 | OffscreenSurfaceVk::AttachmentImage::AttachmentImage() |
| 78 | : renderTarget(&image, &imageView, 0, nullptr) |
| 79 | {} |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 80 | |
| 81 | OffscreenSurfaceVk::AttachmentImage::~AttachmentImage() = default; |
| 82 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 83 | angle::Result OffscreenSurfaceVk::AttachmentImage::initialize(DisplayVk *displayVk, |
| 84 | EGLint width, |
| 85 | EGLint height, |
| 86 | const vk::Format &vkFormat) |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 87 | { |
Geoff Lang | 38971fd | 2018-06-28 15:19:18 -0400 | [diff] [blame] | 88 | RendererVk *renderer = displayVk->getRenderer(); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 89 | |
| 90 | const angle::Format &textureFormat = vkFormat.textureFormat(); |
| 91 | bool isDepthOrStencilFormat = textureFormat.depthBits > 0 || textureFormat.stencilBits > 0; |
| 92 | const VkImageUsageFlags usage = isDepthOrStencilFormat ? kSurfaceVKDepthStencilImageUsageFlags |
| 93 | : kSurfaceVKColorImageUsageFlags; |
| 94 | |
| 95 | gl::Extents extents(static_cast<int>(width), static_cast<int>(height), 1); |
Shahbaz Youssefi | b5ba549 | 2019-01-02 15:19:22 -0500 | [diff] [blame] | 96 | ANGLE_TRY(image.init(displayVk, gl::TextureType::_2D, extents, vkFormat, 1, usage, 1, 1)); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 97 | |
| 98 | VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 99 | ANGLE_TRY(image.initMemory(displayVk, renderer->getMemoryProperties(), flags)); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 100 | |
| 101 | VkImageAspectFlags aspect = vk::GetFormatAspectFlags(textureFormat); |
| 102 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 103 | ANGLE_TRY(image.initImageView(displayVk, gl::TextureType::_2D, aspect, gl::SwizzleState(), |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 104 | &imageView, 1)); |
| 105 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 106 | return angle::Result::Continue; |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 109 | void OffscreenSurfaceVk::AttachmentImage::destroy(const egl::Display *display) |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 110 | { |
| 111 | const DisplayVk *displayVk = vk::GetImpl(display); |
| 112 | RendererVk *renderer = displayVk->getRenderer(); |
| 113 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 114 | image.release(renderer); |
| 115 | renderer->releaseObject(renderer->getCurrentQueueSerial(), &imageView); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 118 | OffscreenSurfaceVk::OffscreenSurfaceVk(const egl::SurfaceState &surfaceState, |
| 119 | EGLint width, |
| 120 | EGLint height) |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 121 | : SurfaceImpl(surfaceState), mWidth(width), mHeight(height) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 122 | {} |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 123 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 124 | OffscreenSurfaceVk::~OffscreenSurfaceVk() {} |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 125 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 126 | egl::Error OffscreenSurfaceVk::initialize(const egl::Display *display) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 127 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 128 | DisplayVk *displayVk = vk::GetImpl(display); |
| 129 | angle::Result result = initializeImpl(displayVk); |
| 130 | return angle::ToEGL(result, displayVk, EGL_BAD_SURFACE); |
| 131 | } |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 132 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 133 | angle::Result OffscreenSurfaceVk::initializeImpl(DisplayVk *displayVk) |
| 134 | { |
| 135 | RendererVk *renderer = displayVk->getRenderer(); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 136 | const egl::Config *config = mState.config; |
| 137 | |
| 138 | if (config->renderTargetFormat != GL_NONE) |
| 139 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 140 | ANGLE_TRY(mColorAttachment.initialize(displayVk, mWidth, mHeight, |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 141 | renderer->getFormat(config->renderTargetFormat))); |
| 142 | } |
| 143 | |
| 144 | if (config->depthStencilFormat != GL_NONE) |
| 145 | { |
| 146 | ANGLE_TRY(mDepthStencilAttachment.initialize( |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 147 | displayVk, mWidth, mHeight, renderer->getFormat(config->depthStencilFormat))); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 150 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 153 | void OffscreenSurfaceVk::destroy(const egl::Display *display) |
| 154 | { |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 155 | mColorAttachment.destroy(display); |
| 156 | mDepthStencilAttachment.destroy(display); |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 159 | FramebufferImpl *OffscreenSurfaceVk::createDefaultFramebuffer(const gl::Context *context, |
| 160 | const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 161 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 162 | RendererVk *renderer = vk::GetImpl(context)->getRenderer(); |
| 163 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 164 | // Use a user FBO for an offscreen RT. |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 165 | return FramebufferVk::CreateUserFBO(renderer, state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 168 | egl::Error OffscreenSurfaceVk::swap(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 169 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 170 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 173 | egl::Error OffscreenSurfaceVk::postSubBuffer(const gl::Context * /*context*/, |
| 174 | EGLint /*x*/, |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 175 | EGLint /*y*/, |
| 176 | EGLint /*width*/, |
| 177 | EGLint /*height*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 178 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 179 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 182 | egl::Error OffscreenSurfaceVk::querySurfacePointerANGLE(EGLint /*attribute*/, void ** /*value*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 183 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 184 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 185 | return egl::EglBadCurrentSurface(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 186 | } |
| 187 | |
Geoff Lang | ccafa62 | 2018-05-02 13:07:53 -0400 | [diff] [blame] | 188 | egl::Error OffscreenSurfaceVk::bindTexImage(const gl::Context * /*context*/, |
| 189 | gl::Texture * /*texture*/, |
| 190 | EGLint /*buffer*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 191 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 192 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Geoff Lang | ccafa62 | 2018-05-02 13:07:53 -0400 | [diff] [blame] | 195 | egl::Error OffscreenSurfaceVk::releaseTexImage(const gl::Context * /*context*/, EGLint /*buffer*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 196 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 197 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 200 | egl::Error OffscreenSurfaceVk::getSyncValues(EGLuint64KHR * /*ust*/, |
| 201 | EGLuint64KHR * /*msc*/, |
| 202 | EGLuint64KHR * /*sbc*/) |
| 203 | { |
| 204 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 205 | return egl::EglBadAccess(); |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 208 | void OffscreenSurfaceVk::setSwapInterval(EGLint /*interval*/) {} |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 209 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 210 | EGLint OffscreenSurfaceVk::getWidth() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 211 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 212 | return mWidth; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 215 | EGLint OffscreenSurfaceVk::getHeight() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 216 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 217 | return mHeight; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 220 | EGLint OffscreenSurfaceVk::isPostSubBufferSupported() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 221 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 222 | return EGL_FALSE; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 223 | } |
| 224 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 225 | EGLint OffscreenSurfaceVk::getSwapBehavior() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 226 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 227 | return EGL_BUFFER_PRESERVED; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 230 | angle::Result OffscreenSurfaceVk::getAttachmentRenderTarget( |
| 231 | const gl::Context *context, |
| 232 | GLenum binding, |
| 233 | const gl::ImageIndex &imageIndex, |
| 234 | FramebufferAttachmentRenderTarget **rtOut) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 235 | { |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 236 | if (binding == GL_BACK) |
| 237 | { |
| 238 | *rtOut = &mColorAttachment.renderTarget; |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | ASSERT(binding == GL_DEPTH || binding == GL_STENCIL || binding == GL_DEPTH_STENCIL); |
| 243 | *rtOut = &mDepthStencilAttachment.renderTarget; |
| 244 | } |
| 245 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 246 | return angle::Result::Continue; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 247 | } |
| 248 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 249 | angle::Result OffscreenSurfaceVk::initializeContents(const gl::Context *context, |
| 250 | const gl::ImageIndex &imageIndex) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 251 | { |
| 252 | UNIMPLEMENTED(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 253 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 256 | WindowSurfaceVk::SwapchainImage::SwapchainImage() = default; |
| 257 | WindowSurfaceVk::SwapchainImage::~SwapchainImage() = default; |
| 258 | |
| 259 | WindowSurfaceVk::SwapchainImage::SwapchainImage(SwapchainImage &&other) |
| 260 | : image(std::move(other.image)), |
| 261 | imageView(std::move(other.imageView)), |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 262 | framebuffer(std::move(other.framebuffer)) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 263 | {} |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 264 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 265 | WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, |
| 266 | EGLNativeWindowType window, |
| 267 | EGLint width, |
| 268 | EGLint height) |
| 269 | : SurfaceImpl(surfaceState), |
| 270 | mNativeWindowType(window), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 271 | mSurface(VK_NULL_HANDLE), |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 272 | mInstance(VK_NULL_HANDLE), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 273 | mSwapchain(VK_NULL_HANDLE), |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 274 | mSwapchainPresentMode(VK_PRESENT_MODE_FIFO_KHR), |
Shahbaz Youssefi | 29b4941 | 2019-01-07 14:03:06 -0500 | [diff] [blame] | 275 | mColorRenderTarget(nullptr, nullptr, 0, nullptr), |
| 276 | mDepthStencilRenderTarget(&mDepthStencilImage, &mDepthStencilImageView, 0, nullptr), |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 277 | mCurrentSwapchainImageIndex(0), |
| 278 | mCurrentSwapSerialIndex(0) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 279 | {} |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 280 | |
| 281 | WindowSurfaceVk::~WindowSurfaceVk() |
| 282 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 283 | ASSERT(mSurface == VK_NULL_HANDLE); |
| 284 | ASSERT(mSwapchain == VK_NULL_HANDLE); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 285 | } |
| 286 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 287 | void WindowSurfaceVk::destroy(const egl::Display *display) |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 288 | { |
Geoff Lang | 38971fd | 2018-06-28 15:19:18 -0400 | [diff] [blame] | 289 | DisplayVk *displayVk = vk::GetImpl(display); |
| 290 | RendererVk *renderer = displayVk->getRenderer(); |
| 291 | VkDevice device = renderer->getDevice(); |
| 292 | VkInstance instance = renderer->getInstance(); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 293 | |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 294 | // We might not need to flush the pipe here. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 295 | (void)renderer->finish(displayVk); |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 296 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 297 | mDepthStencilImage.release(renderer); |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 298 | mDepthStencilImageView.destroy(device); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 299 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 300 | for (SwapchainImage &swapchainImage : mSwapchainImages) |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 301 | { |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 302 | // Although we don't own the swapchain image handles, we need to keep our shutdown clean. |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 303 | swapchainImage.image.resetImageWeakReference(); |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 304 | swapchainImage.image.destroy(device); |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 305 | swapchainImage.imageView.destroy(device); |
| 306 | swapchainImage.framebuffer.destroy(device); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 307 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 308 | |
| 309 | if (mSwapchain) |
| 310 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 311 | vkDestroySwapchainKHR(device, mSwapchain, nullptr); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 312 | mSwapchain = VK_NULL_HANDLE; |
| 313 | } |
| 314 | |
| 315 | if (mSurface) |
| 316 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 317 | vkDestroySurfaceKHR(instance, mSurface, nullptr); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 318 | mSurface = VK_NULL_HANDLE; |
| 319 | } |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 320 | } |
| 321 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 322 | egl::Error WindowSurfaceVk::initialize(const egl::Display *display) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 323 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 324 | DisplayVk *displayVk = vk::GetImpl(display); |
| 325 | angle::Result result = initializeImpl(displayVk); |
| 326 | return angle::ToEGL(result, displayVk, EGL_BAD_SURFACE); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 329 | angle::Result WindowSurfaceVk::initializeImpl(DisplayVk *displayVk) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 330 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 331 | RendererVk *renderer = displayVk->getRenderer(); |
| 332 | |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 333 | gl::Extents windowSize; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 334 | ANGLE_TRY(createSurfaceVk(displayVk, &windowSize)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 335 | |
| 336 | uint32_t presentQueue = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 337 | ANGLE_TRY(renderer->selectPresentQueueForSurface(displayVk, mSurface, &presentQueue)); |
Jamie Madill | c6dbc25 | 2018-04-30 19:07:56 -0400 | [diff] [blame] | 338 | ANGLE_UNUSED_VARIABLE(presentQueue); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 339 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 340 | const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 341 | |
| 342 | VkSurfaceCapabilitiesKHR surfaceCaps; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 343 | ANGLE_VK_TRY(displayVk, |
| 344 | vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface, &surfaceCaps)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 345 | |
| 346 | // Adjust width and height to the swapchain if necessary. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 347 | uint32_t width = surfaceCaps.currentExtent.width; |
| 348 | uint32_t height = surfaceCaps.currentExtent.height; |
| 349 | |
| 350 | // TODO(jmadill): Support devices which don't support copy. We use this for ReadPixels. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 351 | ANGLE_VK_CHECK(displayVk, |
| 352 | (surfaceCaps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) != 0, |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 353 | VK_ERROR_INITIALIZATION_FAILED); |
| 354 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 355 | EGLAttrib attribWidth = mState.attributes.get(EGL_WIDTH, 0); |
| 356 | EGLAttrib attribHeight = mState.attributes.get(EGL_HEIGHT, 0); |
| 357 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 358 | if (surfaceCaps.currentExtent.width == 0xFFFFFFFFu) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 359 | { |
| 360 | ASSERT(surfaceCaps.currentExtent.height == 0xFFFFFFFFu); |
| 361 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 362 | if (attribWidth == 0) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 363 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 364 | width = windowSize.width; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 365 | } |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 366 | if (attribHeight == 0) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 367 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 368 | height = windowSize.height; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 372 | gl::Extents extents(static_cast<int>(width), static_cast<int>(height), 1); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 373 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 374 | uint32_t presentModeCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 375 | ANGLE_VK_TRY(displayVk, vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 376 | &presentModeCount, nullptr)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 377 | ASSERT(presentModeCount > 0); |
| 378 | |
| 379 | std::vector<VkPresentModeKHR> presentModes(presentModeCount); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 380 | ANGLE_VK_TRY(displayVk, vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 381 | physicalDevice, mSurface, &presentModeCount, presentModes.data())); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 382 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 383 | // Select appropriate present mode based on vsync parameter. |
| 384 | // TODO(jmadill): More complete implementation, which allows for changing and more values. |
| 385 | const EGLint minSwapInterval = mState.config->minSwapInterval; |
| 386 | const EGLint maxSwapInterval = mState.config->maxSwapInterval; |
| 387 | ASSERT(minSwapInterval == 0 || minSwapInterval == 1); |
| 388 | ASSERT(maxSwapInterval == 0 || maxSwapInterval == 1); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 389 | |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 390 | mSwapchainPresentMode = GetDesiredPresentMode(presentModes, minSwapInterval, maxSwapInterval); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 391 | |
| 392 | // Determine number of swapchain images. Aim for one more than the minimum. |
| 393 | uint32_t minImageCount = surfaceCaps.minImageCount + 1; |
| 394 | if (surfaceCaps.maxImageCount > 0 && minImageCount > surfaceCaps.maxImageCount) |
| 395 | { |
| 396 | minImageCount = surfaceCaps.maxImageCount; |
| 397 | } |
| 398 | |
| 399 | // Default to identity transform. |
| 400 | VkSurfaceTransformFlagBitsKHR preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
| 401 | if ((surfaceCaps.supportedTransforms & preTransform) == 0) |
| 402 | { |
| 403 | preTransform = surfaceCaps.currentTransform; |
| 404 | } |
| 405 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 406 | uint32_t surfaceFormatCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 407 | ANGLE_VK_TRY(displayVk, vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, |
| 408 | &surfaceFormatCount, nullptr)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 409 | |
| 410 | std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 411 | ANGLE_VK_TRY(displayVk, |
| 412 | vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 413 | surfaceFormats.data())); |
| 414 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 415 | const vk::Format &format = renderer->getFormat(mState.config->renderTargetFormat); |
| 416 | VkFormat nativeFormat = format.vkTextureFormat; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 417 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 418 | if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED) |
| 419 | { |
| 420 | // This is fine. |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | bool foundFormat = false; |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 425 | for (const VkSurfaceFormatKHR &surfaceFormat : surfaceFormats) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 426 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 427 | if (surfaceFormat.format == nativeFormat) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 428 | { |
| 429 | foundFormat = true; |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 434 | ANGLE_VK_CHECK(displayVk, foundFormat, VK_ERROR_INITIALIZATION_FAILED); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 435 | } |
| 436 | |
Yuly Novikov | 12da5e7 | 2018-01-23 18:34:53 -0500 | [diff] [blame] | 437 | VkCompositeAlphaFlagBitsKHR compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 438 | if ((surfaceCaps.supportedCompositeAlpha & compositeAlpha) == 0) |
| 439 | { |
| 440 | compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; |
| 441 | } |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 442 | ANGLE_VK_CHECK(displayVk, (surfaceCaps.supportedCompositeAlpha & compositeAlpha) != 0, |
Yuly Novikov | 12da5e7 | 2018-01-23 18:34:53 -0500 | [diff] [blame] | 443 | VK_ERROR_INITIALIZATION_FAILED); |
| 444 | |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 445 | // We need transfer src for reading back from the backbuffer. |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 446 | VkImageUsageFlags imageUsageFlags = kSurfaceVKColorImageUsageFlags; |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 447 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 448 | VkSwapchainCreateInfoKHR swapchainInfo = {}; |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 449 | swapchainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 450 | swapchainInfo.flags = 0; |
| 451 | swapchainInfo.surface = mSurface; |
| 452 | swapchainInfo.minImageCount = minImageCount; |
| 453 | swapchainInfo.imageFormat = nativeFormat; |
| 454 | swapchainInfo.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 455 | swapchainInfo.imageExtent.width = width; |
| 456 | swapchainInfo.imageExtent.height = height; |
| 457 | swapchainInfo.imageArrayLayers = 1; |
| 458 | swapchainInfo.imageUsage = imageUsageFlags; |
| 459 | swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 460 | swapchainInfo.queueFamilyIndexCount = 0; |
| 461 | swapchainInfo.pQueueFamilyIndices = nullptr; |
| 462 | swapchainInfo.preTransform = preTransform; |
| 463 | swapchainInfo.compositeAlpha = compositeAlpha; |
| 464 | swapchainInfo.presentMode = mSwapchainPresentMode; |
| 465 | swapchainInfo.clipped = VK_TRUE; |
| 466 | swapchainInfo.oldSwapchain = VK_NULL_HANDLE; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 467 | |
Jamie Madill | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 468 | VkDevice device = renderer->getDevice(); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 469 | ANGLE_VK_TRY(displayVk, vkCreateSwapchainKHR(device, &swapchainInfo, nullptr, &mSwapchain)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 470 | |
| 471 | // Intialize the swapchain image views. |
| 472 | uint32_t imageCount = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 473 | ANGLE_VK_TRY(displayVk, vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, nullptr)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 474 | |
| 475 | std::vector<VkImage> swapchainImages(imageCount); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 476 | ANGLE_VK_TRY(displayVk, |
| 477 | vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, swapchainImages.data())); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 478 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 479 | VkClearColorValue transparentBlack = {}; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 480 | transparentBlack.float32[0] = 0.0f; |
| 481 | transparentBlack.float32[1] = 0.0f; |
| 482 | transparentBlack.float32[2] = 0.0f; |
| 483 | transparentBlack.float32[3] = 0.0f; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 484 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 485 | mSwapchainImages.resize(imageCount); |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 486 | mSwapSerials.resize(imageCount); |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 487 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 488 | for (uint32_t imageIndex = 0; imageIndex < imageCount; ++imageIndex) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 489 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 490 | SwapchainImage &member = mSwapchainImages[imageIndex]; |
| 491 | member.image.init2DWeakReference(swapchainImages[imageIndex], extents, format, 1); |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 492 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 493 | ANGLE_TRY(member.image.initImageView(displayVk, gl::TextureType::_2D, |
Jamie Madill | eebe219 | 2018-07-11 09:01:18 -0400 | [diff] [blame] | 494 | VK_IMAGE_ASPECT_COLOR_BIT, gl::SwizzleState(), |
| 495 | &member.imageView, 1)); |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 496 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 497 | // Allocate a command buffer for clearing our images to black. |
| 498 | vk::CommandBuffer *commandBuffer = nullptr; |
| 499 | ANGLE_TRY(member.image.recordCommands(displayVk, &commandBuffer)); |
| 500 | |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 501 | // Set transfer dest layout, and clear the image to black. |
Luc Ferron | c20b950 | 2018-05-24 09:30:17 -0400 | [diff] [blame] | 502 | member.image.clearColor(transparentBlack, 0, 1, commandBuffer); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 503 | } |
| 504 | |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 505 | // Get the first available swapchain iamge. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 506 | ANGLE_TRY(nextSwapchainImage(displayVk)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 507 | |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 508 | // Initialize depth/stencil if requested. |
| 509 | if (mState.config->depthStencilFormat != GL_NONE) |
| 510 | { |
| 511 | const vk::Format &dsFormat = renderer->getFormat(mState.config->depthStencilFormat); |
| 512 | |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 513 | const VkImageUsageFlags dsUsage = kSurfaceVKDepthStencilImageUsageFlags; |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 514 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 515 | ANGLE_TRY(mDepthStencilImage.init(displayVk, gl::TextureType::_2D, extents, dsFormat, 1, |
Shahbaz Youssefi | b5ba549 | 2019-01-02 15:19:22 -0500 | [diff] [blame] | 516 | dsUsage, 1, 1)); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 517 | ANGLE_TRY(mDepthStencilImage.initMemory(displayVk, renderer->getMemoryProperties(), |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 518 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 519 | |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 520 | const VkImageAspectFlags aspect = vk::GetDepthStencilAspectFlags(dsFormat.textureFormat()); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 521 | VkClearDepthStencilValue depthStencilClearValue = {1.0f, 0}; |
| 522 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 523 | // Clear the image. |
| 524 | vk::CommandBuffer *commandBuffer = nullptr; |
| 525 | ANGLE_TRY(mDepthStencilImage.recordCommands(displayVk, &commandBuffer)); |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 526 | mDepthStencilImage.clearDepthStencil(aspect, aspect, depthStencilClearValue, commandBuffer); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 527 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 528 | ANGLE_TRY(mDepthStencilImage.initImageView(displayVk, gl::TextureType::_2D, aspect, |
Luc Ferron | 6641053 | 2018-04-20 12:47:45 -0400 | [diff] [blame] | 529 | gl::SwizzleState(), &mDepthStencilImageView, 1)); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 530 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 531 | // We will need to pass depth/stencil image views to the RenderTargetVk in the future. |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 532 | } |
| 533 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 534 | return angle::Result::Continue; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 535 | } |
| 536 | |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 537 | FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::Context *context, |
| 538 | const gl::FramebufferState &state) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 539 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 540 | RendererVk *renderer = vk::GetImpl(context)->getRenderer(); |
| 541 | return FramebufferVk::CreateDefaultFBO(renderer, state, this); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 542 | } |
| 543 | |
Courtney Goeltzenleuchter | f0d258c | 2018-09-11 09:37:48 -0600 | [diff] [blame] | 544 | egl::Error WindowSurfaceVk::swapWithDamage(const gl::Context *context, |
Ian Elliott | bcb7890 | 2018-12-19 11:46:29 -0700 | [diff] [blame] | 545 | EGLint *rects, |
| 546 | EGLint n_rects) |
Courtney Goeltzenleuchter | f0d258c | 2018-09-11 09:37:48 -0600 | [diff] [blame] | 547 | { |
| 548 | DisplayVk *displayVk = vk::GetImpl(context->getCurrentDisplay()); |
Ian Elliott | bcb7890 | 2018-12-19 11:46:29 -0700 | [diff] [blame] | 549 | angle::Result result = swapImpl(displayVk, rects, n_rects); |
Courtney Goeltzenleuchter | f0d258c | 2018-09-11 09:37:48 -0600 | [diff] [blame] | 550 | return angle::ToEGL(result, displayVk, EGL_BAD_SURFACE); |
| 551 | } |
| 552 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 553 | egl::Error WindowSurfaceVk::swap(const gl::Context *context) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 554 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 555 | DisplayVk *displayVk = vk::GetImpl(context->getCurrentDisplay()); |
Ian Elliott | bcb7890 | 2018-12-19 11:46:29 -0700 | [diff] [blame] | 556 | angle::Result result = swapImpl(displayVk, nullptr, 0); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 557 | return angle::ToEGL(result, displayVk, EGL_BAD_SURFACE); |
| 558 | } |
| 559 | |
Ian Elliott | bcb7890 | 2018-12-19 11:46:29 -0700 | [diff] [blame] | 560 | angle::Result WindowSurfaceVk::swapImpl(DisplayVk *displayVk, EGLint *rects, EGLint n_rects) |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 561 | { |
| 562 | RendererVk *renderer = displayVk->getRenderer(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 563 | |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 564 | // If the swapchain is not in mailbox mode, throttle the submissions. NOTE(syoussefi): this can |
| 565 | // be done in mailbox mode too, just currently unnecessary. |
| 566 | if (mSwapchainPresentMode != VK_PRESENT_MODE_MAILBOX_KHR) |
| 567 | { |
| 568 | TRACE_EVENT0("gpu.angle", "WindowSurfaceVk::swapImpl: Throttle CPU"); |
| 569 | ANGLE_TRY(renderer->finishToSerial(displayVk, mSwapSerials[mCurrentSwapSerialIndex])); |
| 570 | } |
| 571 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 572 | vk::CommandBuffer *swapCommands = nullptr; |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 573 | ANGLE_TRY(mSwapchainImages[mCurrentSwapchainImageIndex].image.recordCommands(displayVk, |
| 574 | &swapCommands)); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 575 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 576 | SwapchainImage &image = mSwapchainImages[mCurrentSwapchainImageIndex]; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 577 | |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 578 | image.image.changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, |
| 579 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 580 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, swapCommands); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 581 | |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 582 | ANGLE_TRY(renderer->flush(displayVk)); |
| 583 | |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 584 | // Remember the serial of the last submission. |
| 585 | mSwapSerials[mCurrentSwapSerialIndex++] = renderer->getLastSubmittedQueueSerial(); |
| 586 | mCurrentSwapSerialIndex = |
| 587 | mCurrentSwapSerialIndex == mSwapSerials.size() ? 0 : mCurrentSwapSerialIndex; |
| 588 | |
| 589 | // Ask the renderer what semaphore it signaled in the last flush. |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 590 | const vk::Semaphore *commandsCompleteSemaphore = |
| 591 | renderer->getSubmitLastSignaledSemaphore(displayVk); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 592 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 593 | VkPresentInfoKHR presentInfo = {}; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 594 | presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 595 | presentInfo.waitSemaphoreCount = commandsCompleteSemaphore ? 1 : 0; |
| 596 | presentInfo.pWaitSemaphores = |
| 597 | commandsCompleteSemaphore ? commandsCompleteSemaphore->ptr() : nullptr; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 598 | presentInfo.swapchainCount = 1; |
| 599 | presentInfo.pSwapchains = &mSwapchain; |
| 600 | presentInfo.pImageIndices = &mCurrentSwapchainImageIndex; |
| 601 | presentInfo.pResults = nullptr; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 602 | |
Ian Elliott | bcb7890 | 2018-12-19 11:46:29 -0700 | [diff] [blame] | 603 | VkPresentRegionsKHR presentRegions = {}; |
| 604 | if (renderer->getFeatures().supportsIncrementalPresent && (n_rects > 0)) |
| 605 | { |
| 606 | VkPresentRegionKHR presentRegion = {}; |
| 607 | std::vector<VkRectLayerKHR> vk_rects(n_rects); |
| 608 | EGLint *egl_rects = rects; |
| 609 | presentRegion.rectangleCount = n_rects; |
| 610 | for (EGLint rect = 0; rect < n_rects; rect++) |
| 611 | { |
| 612 | vk_rects[rect].offset.x = *egl_rects++; |
| 613 | vk_rects[rect].offset.y = *egl_rects++; |
| 614 | vk_rects[rect].extent.width = *egl_rects++; |
| 615 | vk_rects[rect].extent.height = *egl_rects++; |
| 616 | vk_rects[rect].layer = 0; |
| 617 | } |
| 618 | presentRegion.pRectangles = vk_rects.data(); |
| 619 | |
| 620 | presentRegions.sType = VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR; |
| 621 | presentRegions.pNext = nullptr; |
| 622 | presentRegions.swapchainCount = 1; |
| 623 | presentRegions.pRegions = &presentRegion; |
| 624 | |
| 625 | presentInfo.pNext = &presentRegions; |
| 626 | } |
| 627 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 628 | ANGLE_VK_TRY(displayVk, vkQueuePresentKHR(renderer->getQueue(), &presentInfo)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 629 | |
Shahbaz Youssefi | 6165602 | 2018-10-24 15:00:50 -0400 | [diff] [blame] | 630 | { |
| 631 | // Note: TRACE_EVENT0 is put here instead of inside the function to workaround this issue: |
| 632 | // http://anglebug.com/2927 |
| 633 | TRACE_EVENT0("gpu.angle", "nextSwapchainImage"); |
| 634 | // Get the next available swapchain image. |
| 635 | ANGLE_TRY(nextSwapchainImage(displayVk)); |
| 636 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 637 | |
Shahbaz Youssefi | 996628a | 2018-09-24 16:39:26 -0400 | [diff] [blame] | 638 | ANGLE_TRY(renderer->syncPipelineCacheVk(displayVk)); |
| 639 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 640 | return angle::Result::Continue; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 643 | angle::Result WindowSurfaceVk::nextSwapchainImage(DisplayVk *displayVk) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 644 | { |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 645 | VkDevice device = displayVk->getDevice(); |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 646 | RendererVk *renderer = displayVk->getRenderer(); |
| 647 | |
| 648 | const vk::Semaphore *acquireNextImageSemaphore = nullptr; |
| 649 | ANGLE_TRY(renderer->allocateSubmitWaitSemaphore(displayVk, &acquireNextImageSemaphore)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 650 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 651 | ANGLE_VK_TRY(displayVk, vkAcquireNextImageKHR(device, mSwapchain, UINT64_MAX, |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 652 | acquireNextImageSemaphore->getHandle(), |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 653 | VK_NULL_HANDLE, &mCurrentSwapchainImageIndex)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 654 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 655 | SwapchainImage &image = mSwapchainImages[mCurrentSwapchainImageIndex]; |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 656 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 657 | // Update RenderTarget pointers. |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 658 | mColorRenderTarget.updateSwapchainImage(&image.image, &image.imageView); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 659 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 660 | return angle::Result::Continue; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 661 | } |
| 662 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 663 | egl::Error WindowSurfaceVk::postSubBuffer(const gl::Context *context, |
| 664 | EGLint x, |
| 665 | EGLint y, |
| 666 | EGLint width, |
| 667 | EGLint height) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 668 | { |
| 669 | // TODO(jmadill) |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 670 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | egl::Error WindowSurfaceVk::querySurfacePointerANGLE(EGLint attribute, void **value) |
| 674 | { |
| 675 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 676 | return egl::EglBadCurrentSurface(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 677 | } |
| 678 | |
Geoff Lang | ccafa62 | 2018-05-02 13:07:53 -0400 | [diff] [blame] | 679 | egl::Error WindowSurfaceVk::bindTexImage(const gl::Context *context, |
| 680 | gl::Texture *texture, |
| 681 | EGLint buffer) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 682 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 683 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 684 | } |
| 685 | |
Geoff Lang | ccafa62 | 2018-05-02 13:07:53 -0400 | [diff] [blame] | 686 | egl::Error WindowSurfaceVk::releaseTexImage(const gl::Context *context, EGLint buffer) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 687 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 688 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 689 | } |
| 690 | |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 691 | egl::Error WindowSurfaceVk::getSyncValues(EGLuint64KHR * /*ust*/, |
| 692 | EGLuint64KHR * /*msc*/, |
| 693 | EGLuint64KHR * /*sbc*/) |
| 694 | { |
| 695 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 696 | return egl::EglBadAccess(); |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 699 | void WindowSurfaceVk::setSwapInterval(EGLint interval) {} |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 700 | |
| 701 | EGLint WindowSurfaceVk::getWidth() const |
| 702 | { |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 703 | return static_cast<EGLint>(mColorRenderTarget.getImageExtents().width); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | EGLint WindowSurfaceVk::getHeight() const |
| 707 | { |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 708 | return static_cast<EGLint>(mColorRenderTarget.getImageExtents().height); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | EGLint WindowSurfaceVk::isPostSubBufferSupported() const |
| 712 | { |
| 713 | // TODO(jmadill) |
| 714 | return EGL_FALSE; |
| 715 | } |
| 716 | |
| 717 | EGLint WindowSurfaceVk::getSwapBehavior() const |
| 718 | { |
| 719 | // TODO(jmadill) |
| 720 | return EGL_BUFFER_DESTROYED; |
| 721 | } |
| 722 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 723 | angle::Result WindowSurfaceVk::getAttachmentRenderTarget(const gl::Context *context, |
| 724 | GLenum binding, |
| 725 | const gl::ImageIndex &imageIndex, |
| 726 | FramebufferAttachmentRenderTarget **rtOut) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 727 | { |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 728 | if (binding == GL_BACK) |
| 729 | { |
| 730 | *rtOut = &mColorRenderTarget; |
| 731 | } |
| 732 | else |
| 733 | { |
| 734 | ASSERT(binding == GL_DEPTH || binding == GL_STENCIL || binding == GL_DEPTH_STENCIL); |
| 735 | *rtOut = &mDepthStencilRenderTarget; |
| 736 | } |
| 737 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 738 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 739 | } |
| 740 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 741 | angle::Result WindowSurfaceVk::getCurrentFramebuffer(vk::Context *context, |
| 742 | const vk::RenderPass &compatibleRenderPass, |
| 743 | vk::Framebuffer **framebufferOut) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 744 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 745 | vk::Framebuffer ¤tFramebuffer = mSwapchainImages[mCurrentSwapchainImageIndex].framebuffer; |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 746 | |
| 747 | if (currentFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 748 | { |
| 749 | // Validation layers should detect if the render pass is really compatible. |
Jamie Madill | 5598148 | 2018-07-11 09:01:18 -0400 | [diff] [blame] | 750 | *framebufferOut = ¤tFramebuffer; |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 751 | return angle::Result::Continue; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 752 | } |
| 753 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 754 | VkFramebufferCreateInfo framebufferInfo = {}; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 755 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 756 | const gl::Extents &extents = mColorRenderTarget.getImageExtents(); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 757 | std::array<VkImageView, 2> imageViews = {{VK_NULL_HANDLE, mDepthStencilImageView.getHandle()}}; |
| 758 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 759 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 760 | framebufferInfo.flags = 0; |
| 761 | framebufferInfo.renderPass = compatibleRenderPass.getHandle(); |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 762 | framebufferInfo.attachmentCount = (mDepthStencilImage.valid() ? 2u : 1u); |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 763 | framebufferInfo.pAttachments = imageViews.data(); |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 764 | framebufferInfo.width = static_cast<uint32_t>(extents.width); |
| 765 | framebufferInfo.height = static_cast<uint32_t>(extents.height); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 766 | framebufferInfo.layers = 1; |
| 767 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 768 | for (SwapchainImage &swapchainImage : mSwapchainImages) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 769 | { |
Jamie Madill | f618c9e | 2018-02-15 14:45:40 -0500 | [diff] [blame] | 770 | imageViews[0] = swapchainImage.imageView.getHandle(); |
Yuly Novikov | 2778029 | 2018-11-09 11:19:49 -0500 | [diff] [blame] | 771 | ANGLE_VK_TRY(context, |
| 772 | swapchainImage.framebuffer.init(context->getDevice(), framebufferInfo)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 773 | } |
| 774 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 775 | ASSERT(currentFramebuffer.valid()); |
Jamie Madill | 5598148 | 2018-07-11 09:01:18 -0400 | [diff] [blame] | 776 | *framebufferOut = ¤tFramebuffer; |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 777 | return angle::Result::Continue; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 778 | } |
| 779 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 780 | angle::Result WindowSurfaceVk::initializeContents(const gl::Context *context, |
| 781 | const gl::ImageIndex &imageIndex) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 782 | { |
| 783 | UNIMPLEMENTED(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 784 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 785 | } |
| 786 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 787 | } // namespace rx |