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