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" |
| 16 | #include "libANGLE/renderer/vulkan/DisplayVk.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 17 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 18 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame] | 19 | #include "libANGLE/renderer/vulkan/formatutilsvk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 20 | |
| 21 | namespace rx |
| 22 | { |
| 23 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 24 | namespace |
| 25 | { |
| 26 | |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame] | 27 | const vk::Format &GetVkFormatFromConfig(const egl::Config &config) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 28 | { |
| 29 | // TODO(jmadill): Properly handle format interpretation. |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame] | 30 | return vk::Format::Get(GL_BGRA8_EXT); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 31 | } |
| 32 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 33 | VkPresentModeKHR GetDesiredPresentMode(const std::vector<VkPresentModeKHR> &presentModes, |
| 34 | EGLint minSwapInterval, |
| 35 | EGLint maxSwapInterval) |
| 36 | { |
| 37 | ASSERT(!presentModes.empty()); |
| 38 | |
| 39 | // Use FIFO mode for v-sync, since it throttles you to the display rate. Mailbox is more |
| 40 | // similar to triple-buffering. For now we hard-code Mailbox for perf tseting. |
| 41 | // TODO(jmadill): Properly select present mode and re-create display if changed. |
| 42 | VkPresentModeKHR bestChoice = VK_PRESENT_MODE_MAILBOX_KHR; |
| 43 | |
| 44 | for (auto presentMode : presentModes) |
| 45 | { |
| 46 | if (presentMode == bestChoice) |
| 47 | { |
| 48 | return bestChoice; |
| 49 | } |
| 50 | } |
| 51 | |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 52 | WARN() << "Present mode " << bestChoice << " not available. Falling back to " |
| 53 | << presentModes[0]; |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 54 | return presentModes[0]; |
| 55 | } |
| 56 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 57 | } // namespace |
| 58 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 59 | OffscreenSurfaceVk::OffscreenSurfaceVk(const egl::SurfaceState &surfaceState, |
| 60 | EGLint width, |
| 61 | EGLint height) |
| 62 | : SurfaceImpl(surfaceState), mWidth(width), mHeight(height) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 66 | OffscreenSurfaceVk::~OffscreenSurfaceVk() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 70 | egl::Error OffscreenSurfaceVk::initialize(const egl::Display *display) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 71 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 72 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 75 | FramebufferImpl *OffscreenSurfaceVk::createDefaultFramebuffer(const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 76 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 77 | // Use a user FBO for an offscreen RT. |
| 78 | return FramebufferVk::CreateUserFBO(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame^] | 81 | egl::Error OffscreenSurfaceVk::swap(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 82 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 83 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame^] | 86 | egl::Error OffscreenSurfaceVk::postSubBuffer(const gl::Context * /*context*/, |
| 87 | EGLint /*x*/, |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 88 | EGLint /*y*/, |
| 89 | EGLint /*width*/, |
| 90 | EGLint /*height*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 91 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 92 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 95 | egl::Error OffscreenSurfaceVk::querySurfacePointerANGLE(EGLint /*attribute*/, void ** /*value*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 96 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 97 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 98 | return egl::EglBadCurrentSurface(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 101 | egl::Error OffscreenSurfaceVk::bindTexImage(gl::Texture * /*texture*/, EGLint /*buffer*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 102 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 103 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 106 | egl::Error OffscreenSurfaceVk::releaseTexImage(EGLint /*buffer*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 107 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 108 | return egl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 111 | egl::Error OffscreenSurfaceVk::getSyncValues(EGLuint64KHR * /*ust*/, |
| 112 | EGLuint64KHR * /*msc*/, |
| 113 | EGLuint64KHR * /*sbc*/) |
| 114 | { |
| 115 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 116 | return egl::EglBadAccess(); |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 119 | void OffscreenSurfaceVk::setSwapInterval(EGLint /*interval*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 120 | { |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 123 | EGLint OffscreenSurfaceVk::getWidth() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 124 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 125 | return mWidth; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 128 | EGLint OffscreenSurfaceVk::getHeight() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 129 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 130 | return mHeight; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 133 | EGLint OffscreenSurfaceVk::isPostSubBufferSupported() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 134 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 135 | return EGL_FALSE; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 138 | EGLint OffscreenSurfaceVk::getSwapBehavior() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 139 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 140 | return EGL_BUFFER_PRESERVED; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 143 | gl::Error OffscreenSurfaceVk::getAttachmentRenderTarget( |
Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 144 | GLenum /*binding*/, |
| 145 | const gl::ImageIndex & /*imageIndex*/, |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 146 | FramebufferAttachmentRenderTarget ** /*rtOut*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 147 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 148 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 149 | return gl::InternalError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 152 | WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, |
| 153 | EGLNativeWindowType window, |
| 154 | EGLint width, |
| 155 | EGLint height) |
| 156 | : SurfaceImpl(surfaceState), |
| 157 | mNativeWindowType(window), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 158 | mSurface(VK_NULL_HANDLE), |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 159 | mInstance(VK_NULL_HANDLE), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 160 | mSwapchain(VK_NULL_HANDLE), |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 161 | mRenderTarget(), |
| 162 | mCurrentSwapchainImageIndex(0) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 163 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 164 | mRenderTarget.extents.width = static_cast<GLint>(width); |
| 165 | mRenderTarget.extents.height = static_cast<GLint>(height); |
| 166 | mRenderTarget.extents.depth = 1; |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 167 | mRenderTarget.resource = this; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | WindowSurfaceVk::~WindowSurfaceVk() |
| 171 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 172 | ASSERT(mSurface == VK_NULL_HANDLE); |
| 173 | ASSERT(mSwapchain == VK_NULL_HANDLE); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 176 | void WindowSurfaceVk::destroy(const egl::Display *display) |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 177 | { |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 178 | const DisplayVk *displayVk = GetImplAs<DisplayVk>(display); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 179 | RendererVk *rendererVk = displayVk->getRenderer(); |
| 180 | VkDevice device = rendererVk->getDevice(); |
| 181 | VkInstance instance = rendererVk->getInstance(); |
| 182 | |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 183 | rendererVk->finish(); |
| 184 | |
| 185 | mImageAvailableSemaphore.destroy(device); |
| 186 | mRenderingCompleteSemaphore.destroy(device); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 187 | |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 188 | for (auto &imageView : mSwapchainImageViews) |
| 189 | { |
| 190 | imageView.destroy(device); |
| 191 | } |
| 192 | |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 193 | // Although we don't own the swapchain image handles, we need to keep our shutdown clean. |
| 194 | for (auto &image : mSwapchainImages) |
| 195 | { |
| 196 | image.reset(); |
| 197 | } |
| 198 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 199 | for (auto &framebuffer : mSwapchainFramebuffers) |
| 200 | { |
| 201 | framebuffer.destroy(device); |
| 202 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 203 | |
| 204 | if (mSwapchain) |
| 205 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 206 | vkDestroySwapchainKHR(device, mSwapchain, nullptr); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 207 | mSwapchain = VK_NULL_HANDLE; |
| 208 | } |
| 209 | |
| 210 | if (mSurface) |
| 211 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 212 | vkDestroySurfaceKHR(instance, mSurface, nullptr); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 213 | mSurface = VK_NULL_HANDLE; |
| 214 | } |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 217 | egl::Error WindowSurfaceVk::initialize(const egl::Display *display) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 218 | { |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 219 | const DisplayVk *displayVk = GetImplAs<DisplayVk>(display); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 220 | return initializeImpl(displayVk->getRenderer()).toEGL(EGL_BAD_SURFACE); |
| 221 | } |
| 222 | |
| 223 | vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) |
| 224 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 225 | gl::Extents windowSize; |
| 226 | ANGLE_TRY_RESULT(createSurfaceVk(renderer), windowSize); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 227 | |
| 228 | uint32_t presentQueue = 0; |
| 229 | ANGLE_TRY_RESULT(renderer->selectPresentQueueForSurface(mSurface), presentQueue); |
| 230 | |
| 231 | const auto &physicalDevice = renderer->getPhysicalDevice(); |
| 232 | |
| 233 | VkSurfaceCapabilitiesKHR surfaceCaps; |
| 234 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface, &surfaceCaps)); |
| 235 | |
| 236 | // Adjust width and height to the swapchain if necessary. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 237 | uint32_t width = surfaceCaps.currentExtent.width; |
| 238 | uint32_t height = surfaceCaps.currentExtent.height; |
| 239 | |
| 240 | // TODO(jmadill): Support devices which don't support copy. We use this for ReadPixels. |
| 241 | ANGLE_VK_CHECK((surfaceCaps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) != 0, |
| 242 | VK_ERROR_INITIALIZATION_FAILED); |
| 243 | |
| 244 | if (surfaceCaps.currentExtent.width == 0xFFFFFFFFu) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 245 | { |
| 246 | ASSERT(surfaceCaps.currentExtent.height == 0xFFFFFFFFu); |
| 247 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 248 | if (mRenderTarget.extents.width == 0) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 249 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 250 | width = windowSize.width; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 251 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 252 | if (mRenderTarget.extents.height == 0) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 253 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 254 | height = windowSize.height; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 258 | mRenderTarget.extents.width = static_cast<int>(width); |
| 259 | mRenderTarget.extents.height = static_cast<int>(height); |
| 260 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 261 | uint32_t presentModeCount = 0; |
| 262 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 263 | &presentModeCount, nullptr)); |
| 264 | ASSERT(presentModeCount > 0); |
| 265 | |
| 266 | std::vector<VkPresentModeKHR> presentModes(presentModeCount); |
| 267 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 268 | &presentModeCount, presentModes.data())); |
| 269 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 270 | // Select appropriate present mode based on vsync parameter. |
| 271 | // TODO(jmadill): More complete implementation, which allows for changing and more values. |
| 272 | const EGLint minSwapInterval = mState.config->minSwapInterval; |
| 273 | const EGLint maxSwapInterval = mState.config->maxSwapInterval; |
| 274 | ASSERT(minSwapInterval == 0 || minSwapInterval == 1); |
| 275 | ASSERT(maxSwapInterval == 0 || maxSwapInterval == 1); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 276 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 277 | VkPresentModeKHR swapchainPresentMode = |
| 278 | GetDesiredPresentMode(presentModes, minSwapInterval, maxSwapInterval); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 279 | |
| 280 | // Determine number of swapchain images. Aim for one more than the minimum. |
| 281 | uint32_t minImageCount = surfaceCaps.minImageCount + 1; |
| 282 | if (surfaceCaps.maxImageCount > 0 && minImageCount > surfaceCaps.maxImageCount) |
| 283 | { |
| 284 | minImageCount = surfaceCaps.maxImageCount; |
| 285 | } |
| 286 | |
| 287 | // Default to identity transform. |
| 288 | VkSurfaceTransformFlagBitsKHR preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
| 289 | if ((surfaceCaps.supportedTransforms & preTransform) == 0) |
| 290 | { |
| 291 | preTransform = surfaceCaps.currentTransform; |
| 292 | } |
| 293 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 294 | uint32_t surfaceFormatCount = 0; |
| 295 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
| 296 | nullptr)); |
| 297 | |
| 298 | std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount); |
| 299 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
| 300 | surfaceFormats.data())); |
| 301 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 302 | mRenderTarget.format = &GetVkFormatFromConfig(*mState.config); |
| 303 | auto nativeFormat = mRenderTarget.format->native; |
| 304 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 305 | if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED) |
| 306 | { |
| 307 | // This is fine. |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | bool foundFormat = false; |
| 312 | for (const auto &surfaceFormat : surfaceFormats) |
| 313 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 314 | if (surfaceFormat.format == nativeFormat) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 315 | { |
| 316 | foundFormat = true; |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | ANGLE_VK_CHECK(foundFormat, VK_ERROR_INITIALIZATION_FAILED); |
| 322 | } |
| 323 | |
| 324 | VkSwapchainCreateInfoKHR swapchainInfo; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 325 | swapchainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 326 | swapchainInfo.pNext = nullptr; |
| 327 | swapchainInfo.flags = 0; |
| 328 | swapchainInfo.surface = mSurface; |
| 329 | swapchainInfo.minImageCount = minImageCount; |
| 330 | swapchainInfo.imageFormat = nativeFormat; |
| 331 | swapchainInfo.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 332 | swapchainInfo.imageExtent.width = width; |
| 333 | swapchainInfo.imageExtent.height = height; |
| 334 | swapchainInfo.imageArrayLayers = 1; |
| 335 | swapchainInfo.imageUsage = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 336 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 337 | swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 338 | swapchainInfo.queueFamilyIndexCount = 0; |
| 339 | swapchainInfo.pQueueFamilyIndices = nullptr; |
| 340 | swapchainInfo.preTransform = preTransform; |
| 341 | swapchainInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 342 | swapchainInfo.presentMode = swapchainPresentMode; |
| 343 | swapchainInfo.clipped = VK_TRUE; |
| 344 | swapchainInfo.oldSwapchain = VK_NULL_HANDLE; |
| 345 | |
| 346 | const auto &device = renderer->getDevice(); |
| 347 | ANGLE_VK_TRY(vkCreateSwapchainKHR(device, &swapchainInfo, nullptr, &mSwapchain)); |
| 348 | |
| 349 | // Intialize the swapchain image views. |
| 350 | uint32_t imageCount = 0; |
| 351 | ANGLE_VK_TRY(vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, nullptr)); |
| 352 | |
| 353 | std::vector<VkImage> swapchainImages(imageCount); |
| 354 | ANGLE_VK_TRY(vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, swapchainImages.data())); |
| 355 | |
| 356 | // CommandBuffer is a singleton in the Renderer. |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 357 | vk::CommandBuffer *commandBuffer = nullptr; |
| 358 | ANGLE_TRY(renderer->getStartedCommandBuffer(&commandBuffer)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 359 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 360 | VkClearColorValue transparentBlack; |
| 361 | transparentBlack.float32[0] = 0.0f; |
| 362 | transparentBlack.float32[1] = 0.0f; |
| 363 | transparentBlack.float32[2] = 0.0f; |
| 364 | transparentBlack.float32[3] = 0.0f; |
| 365 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 366 | mSwapchainImages.resize(imageCount); |
| 367 | mSwapchainImageViews.resize(imageCount); |
| 368 | |
| 369 | for (uint32_t imageIndex = 0; imageIndex < imageCount; ++imageIndex) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 370 | { |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 371 | VkImage swapchainImage = swapchainImages[imageIndex]; |
| 372 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 373 | VkImageViewCreateInfo imageViewInfo; |
| 374 | imageViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 375 | imageViewInfo.pNext = nullptr; |
| 376 | imageViewInfo.flags = 0; |
| 377 | imageViewInfo.image = swapchainImage; |
| 378 | imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 379 | imageViewInfo.format = nativeFormat; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 380 | imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_R; |
| 381 | imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_G; |
| 382 | imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_B; |
| 383 | imageViewInfo.components.a = VK_COMPONENT_SWIZZLE_A; |
| 384 | imageViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 385 | imageViewInfo.subresourceRange.baseMipLevel = 0; |
| 386 | imageViewInfo.subresourceRange.levelCount = 1; |
| 387 | imageViewInfo.subresourceRange.baseArrayLayer = 0; |
| 388 | imageViewInfo.subresourceRange.layerCount = 1; |
| 389 | |
| 390 | vk::Image image(swapchainImage); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 391 | vk::ImageView imageView; |
| 392 | ANGLE_TRY(imageView.init(device, imageViewInfo)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 393 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 394 | // Set transfer dest layout, and clear the image to black. |
| 395 | image.changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 396 | commandBuffer); |
| 397 | commandBuffer->clearSingleColorImage(image, transparentBlack); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 398 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 399 | mSwapchainImages[imageIndex].retain(device, std::move(image)); |
| 400 | mSwapchainImageViews[imageIndex].retain(device, std::move(imageView)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 401 | } |
| 402 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 403 | ANGLE_TRY(renderer->submitAndFinishCommandBuffer(commandBuffer)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 404 | |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 405 | ANGLE_TRY(mImageAvailableSemaphore.init(device)); |
| 406 | ANGLE_TRY(mRenderingCompleteSemaphore.init(device)); |
| 407 | |
| 408 | // Get the first available swapchain iamge. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 409 | ANGLE_TRY(nextSwapchainImage(renderer)); |
| 410 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 411 | return vk::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::FramebufferState &state) |
| 415 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 416 | return FramebufferVk::CreateDefaultFBO(state, this); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 417 | } |
| 418 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame^] | 419 | egl::Error WindowSurfaceVk::swap(const gl::Context *context) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 420 | { |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame^] | 421 | const DisplayVk *displayVk = GetImplAs<DisplayVk>(context->getCurrentDisplay()); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 422 | return swapImpl(displayVk->getRenderer()).toEGL(EGL_BAD_ALLOC); |
| 423 | } |
| 424 | |
| 425 | vk::Error WindowSurfaceVk::swapImpl(RendererVk *renderer) |
| 426 | { |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 427 | vk::CommandBuffer *currentCB = nullptr; |
| 428 | ANGLE_TRY(renderer->getStartedCommandBuffer(¤tCB)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 429 | |
| 430 | auto *image = &mSwapchainImages[mCurrentSwapchainImageIndex]; |
| 431 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 432 | image->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, |
| 433 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 434 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, currentCB); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 435 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 436 | ANGLE_TRY(renderer->submitCommandsWithSync(currentCB, mImageAvailableSemaphore, |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 437 | mRenderingCompleteSemaphore)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 438 | |
| 439 | VkPresentInfoKHR presentInfo; |
| 440 | presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
| 441 | presentInfo.pNext = nullptr; |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 442 | presentInfo.waitSemaphoreCount = 1; |
| 443 | presentInfo.pWaitSemaphores = mRenderingCompleteSemaphore.ptr(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 444 | presentInfo.swapchainCount = 1; |
| 445 | presentInfo.pSwapchains = &mSwapchain; |
| 446 | presentInfo.pImageIndices = &mCurrentSwapchainImageIndex; |
| 447 | presentInfo.pResults = nullptr; |
| 448 | |
| 449 | ANGLE_VK_TRY(vkQueuePresentKHR(renderer->getQueue(), &presentInfo)); |
| 450 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 451 | // Get the next available swapchain image. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 452 | ANGLE_TRY(nextSwapchainImage(renderer)); |
| 453 | |
| 454 | return vk::NoError(); |
| 455 | } |
| 456 | |
| 457 | vk::Error WindowSurfaceVk::nextSwapchainImage(RendererVk *renderer) |
| 458 | { |
| 459 | VkDevice device = renderer->getDevice(); |
| 460 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 461 | ANGLE_VK_TRY(vkAcquireNextImageKHR(device, mSwapchain, std::numeric_limits<uint64_t>::max(), |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 462 | mImageAvailableSemaphore.getHandle(), VK_NULL_HANDLE, |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 463 | &mCurrentSwapchainImageIndex)); |
| 464 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 465 | // Update RenderTarget pointers. |
| 466 | mRenderTarget.image = &mSwapchainImages[mCurrentSwapchainImageIndex]; |
| 467 | mRenderTarget.imageView = &mSwapchainImageViews[mCurrentSwapchainImageIndex]; |
| 468 | |
| 469 | return vk::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 470 | } |
| 471 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame^] | 472 | egl::Error WindowSurfaceVk::postSubBuffer(const gl::Context *context, |
| 473 | EGLint x, |
| 474 | EGLint y, |
| 475 | EGLint width, |
| 476 | EGLint height) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 477 | { |
| 478 | // TODO(jmadill) |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 479 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | egl::Error WindowSurfaceVk::querySurfacePointerANGLE(EGLint attribute, void **value) |
| 483 | { |
| 484 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 485 | return egl::EglBadCurrentSurface(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | egl::Error WindowSurfaceVk::bindTexImage(gl::Texture *texture, EGLint buffer) |
| 489 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 490 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | egl::Error WindowSurfaceVk::releaseTexImage(EGLint buffer) |
| 494 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 495 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 496 | } |
| 497 | |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 498 | egl::Error WindowSurfaceVk::getSyncValues(EGLuint64KHR * /*ust*/, |
| 499 | EGLuint64KHR * /*msc*/, |
| 500 | EGLuint64KHR * /*sbc*/) |
| 501 | { |
| 502 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 503 | return egl::EglBadAccess(); |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 506 | void WindowSurfaceVk::setSwapInterval(EGLint interval) |
| 507 | { |
| 508 | } |
| 509 | |
| 510 | EGLint WindowSurfaceVk::getWidth() const |
| 511 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 512 | return static_cast<EGLint>(mRenderTarget.extents.width); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | EGLint WindowSurfaceVk::getHeight() const |
| 516 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 517 | return static_cast<EGLint>(mRenderTarget.extents.height); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | EGLint WindowSurfaceVk::isPostSubBufferSupported() const |
| 521 | { |
| 522 | // TODO(jmadill) |
| 523 | return EGL_FALSE; |
| 524 | } |
| 525 | |
| 526 | EGLint WindowSurfaceVk::getSwapBehavior() const |
| 527 | { |
| 528 | // TODO(jmadill) |
| 529 | return EGL_BUFFER_DESTROYED; |
| 530 | } |
| 531 | |
Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 532 | gl::Error WindowSurfaceVk::getAttachmentRenderTarget(GLenum /*binding*/, |
| 533 | const gl::ImageIndex & /*target*/, |
| 534 | FramebufferAttachmentRenderTarget **rtOut) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 535 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 536 | *rtOut = &mRenderTarget; |
| 537 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 538 | } |
| 539 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 540 | gl::ErrorOrResult<vk::Framebuffer *> WindowSurfaceVk::getCurrentFramebuffer( |
| 541 | VkDevice device, |
| 542 | const vk::RenderPass &compatibleRenderPass) |
| 543 | { |
| 544 | if (!mSwapchainFramebuffers.empty()) |
| 545 | { |
| 546 | // Validation layers should detect if the render pass is really compatible. |
| 547 | return &mSwapchainFramebuffers[mCurrentSwapchainImageIndex]; |
| 548 | } |
| 549 | |
| 550 | VkFramebufferCreateInfo framebufferInfo; |
| 551 | |
| 552 | // TODO(jmadill): Depth/Stencil attachments. |
| 553 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 554 | framebufferInfo.pNext = nullptr; |
| 555 | framebufferInfo.flags = 0; |
| 556 | framebufferInfo.renderPass = compatibleRenderPass.getHandle(); |
| 557 | framebufferInfo.attachmentCount = 1u; |
| 558 | framebufferInfo.pAttachments = nullptr; |
| 559 | framebufferInfo.width = static_cast<uint32_t>(mRenderTarget.extents.width); |
| 560 | framebufferInfo.height = static_cast<uint32_t>(mRenderTarget.extents.height); |
| 561 | framebufferInfo.layers = 1; |
| 562 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 563 | mSwapchainFramebuffers.resize(mSwapchainImageViews.size()); |
| 564 | for (size_t imageIndex = 0; imageIndex < mSwapchainFramebuffers.size(); ++imageIndex) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 565 | { |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 566 | const auto &imageView = mSwapchainImageViews[imageIndex]; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 567 | VkImageView imageViewHandle = imageView.getHandle(); |
| 568 | framebufferInfo.pAttachments = &imageViewHandle; |
| 569 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 570 | vk::Framebuffer framebuffer; |
| 571 | ANGLE_TRY(framebuffer.init(device, framebufferInfo)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 572 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 573 | mSwapchainFramebuffers[imageIndex].retain(device, std::move(framebuffer)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | // We should only initialize framebuffers on the first swap. |
| 577 | ASSERT(mCurrentSwapchainImageIndex == 0u); |
| 578 | return &mSwapchainFramebuffers[mCurrentSwapchainImageIndex]; |
| 579 | } |
| 580 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 581 | } // namespace rx |