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 | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 19 | #include "libANGLE/renderer/vulkan/vk_format_utils.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 | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 27 | const vk::Format &GetVkFormatFromConfig(RendererVk *renderer, 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 | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 30 | return renderer->getFormat(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 |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 40 | // similar to triple-buffering. For now we hard-code Mailbox for perf testing. |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 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 | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 144 | const gl::Context * /*context*/, |
Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 145 | GLenum /*binding*/, |
| 146 | const gl::ImageIndex & /*imageIndex*/, |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 147 | FramebufferAttachmentRenderTarget ** /*rtOut*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 148 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 149 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 150 | return gl::InternalError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 153 | gl::Error OffscreenSurfaceVk::initializeContents(const gl::Context *context, |
| 154 | const gl::ImageIndex &imageIndex) |
| 155 | { |
| 156 | UNIMPLEMENTED(); |
| 157 | return gl::NoError(); |
| 158 | } |
| 159 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 160 | WindowSurfaceVk::SwapchainImage::SwapchainImage() = default; |
| 161 | WindowSurfaceVk::SwapchainImage::SwapchainImage(WindowSurfaceVk::SwapchainImage &&other) = default; |
| 162 | WindowSurfaceVk::SwapchainImage::~SwapchainImage() = default; |
| 163 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 164 | WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, |
| 165 | EGLNativeWindowType window, |
| 166 | EGLint width, |
| 167 | EGLint height) |
| 168 | : SurfaceImpl(surfaceState), |
| 169 | mNativeWindowType(window), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 170 | mSurface(VK_NULL_HANDLE), |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 171 | mInstance(VK_NULL_HANDLE), |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 172 | mSwapchain(VK_NULL_HANDLE), |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 173 | mRenderTarget(), |
| 174 | mCurrentSwapchainImageIndex(0) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 175 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 176 | mRenderTarget.extents.width = static_cast<GLint>(width); |
| 177 | mRenderTarget.extents.height = static_cast<GLint>(height); |
| 178 | mRenderTarget.extents.depth = 1; |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 179 | mRenderTarget.resource = this; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | WindowSurfaceVk::~WindowSurfaceVk() |
| 183 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 184 | ASSERT(mSurface == VK_NULL_HANDLE); |
| 185 | ASSERT(mSwapchain == VK_NULL_HANDLE); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 188 | void WindowSurfaceVk::destroy(const egl::Display *display) |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 189 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 190 | const DisplayVk *displayVk = vk::GetImpl(display); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 191 | RendererVk *rendererVk = displayVk->getRenderer(); |
| 192 | VkDevice device = rendererVk->getDevice(); |
| 193 | VkInstance instance = rendererVk->getInstance(); |
| 194 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 195 | rendererVk->finish(display->getProxyContext()); |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 196 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 197 | mAcquireNextImageSemaphore.destroy(device); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 198 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 199 | for (auto &swapchainImage : mSwapchainImages) |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 200 | { |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 201 | // Although we don't own the swapchain image handles, we need to keep our shutdown clean. |
| 202 | swapchainImage.image.reset(); |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 203 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 204 | swapchainImage.imageView.destroy(device); |
| 205 | swapchainImage.framebuffer.destroy(device); |
| 206 | swapchainImage.imageAcquiredSemaphore.destroy(device); |
| 207 | swapchainImage.commandsCompleteSemaphore.destroy(device); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 208 | } |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 209 | |
| 210 | if (mSwapchain) |
| 211 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 212 | vkDestroySwapchainKHR(device, mSwapchain, nullptr); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 213 | mSwapchain = VK_NULL_HANDLE; |
| 214 | } |
| 215 | |
| 216 | if (mSurface) |
| 217 | { |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 218 | vkDestroySurfaceKHR(instance, mSurface, nullptr); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 219 | mSurface = VK_NULL_HANDLE; |
| 220 | } |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 223 | egl::Error WindowSurfaceVk::initialize(const egl::Display *display) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 224 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 225 | const DisplayVk *displayVk = vk::GetImpl(display); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 226 | return initializeImpl(displayVk->getRenderer()).toEGL(EGL_BAD_SURFACE); |
| 227 | } |
| 228 | |
| 229 | vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) |
| 230 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 231 | gl::Extents windowSize; |
| 232 | ANGLE_TRY_RESULT(createSurfaceVk(renderer), windowSize); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 233 | |
| 234 | uint32_t presentQueue = 0; |
| 235 | ANGLE_TRY_RESULT(renderer->selectPresentQueueForSurface(mSurface), presentQueue); |
Frank Henigman | f661686 | 2018-01-15 23:49:14 -0500 | [diff] [blame] | 236 | (void) presentQueue; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 237 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 238 | const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 239 | |
| 240 | VkSurfaceCapabilitiesKHR surfaceCaps; |
| 241 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface, &surfaceCaps)); |
| 242 | |
| 243 | // Adjust width and height to the swapchain if necessary. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 244 | uint32_t width = surfaceCaps.currentExtent.width; |
| 245 | uint32_t height = surfaceCaps.currentExtent.height; |
| 246 | |
| 247 | // TODO(jmadill): Support devices which don't support copy. We use this for ReadPixels. |
| 248 | ANGLE_VK_CHECK((surfaceCaps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) != 0, |
| 249 | VK_ERROR_INITIALIZATION_FAILED); |
| 250 | |
| 251 | if (surfaceCaps.currentExtent.width == 0xFFFFFFFFu) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 252 | { |
| 253 | ASSERT(surfaceCaps.currentExtent.height == 0xFFFFFFFFu); |
| 254 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 255 | if (mRenderTarget.extents.width == 0) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 256 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 257 | width = windowSize.width; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 258 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 259 | if (mRenderTarget.extents.height == 0) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 260 | { |
Frank Henigman | 29f148b | 2016-11-23 21:05:36 -0500 | [diff] [blame] | 261 | height = windowSize.height; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 265 | mRenderTarget.extents.width = static_cast<int>(width); |
| 266 | mRenderTarget.extents.height = static_cast<int>(height); |
| 267 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 268 | uint32_t presentModeCount = 0; |
| 269 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 270 | &presentModeCount, nullptr)); |
| 271 | ASSERT(presentModeCount > 0); |
| 272 | |
| 273 | std::vector<VkPresentModeKHR> presentModes(presentModeCount); |
| 274 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 275 | &presentModeCount, presentModes.data())); |
| 276 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 277 | // Select appropriate present mode based on vsync parameter. |
| 278 | // TODO(jmadill): More complete implementation, which allows for changing and more values. |
| 279 | const EGLint minSwapInterval = mState.config->minSwapInterval; |
| 280 | const EGLint maxSwapInterval = mState.config->maxSwapInterval; |
| 281 | ASSERT(minSwapInterval == 0 || minSwapInterval == 1); |
| 282 | ASSERT(maxSwapInterval == 0 || maxSwapInterval == 1); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 283 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 284 | VkPresentModeKHR swapchainPresentMode = |
| 285 | GetDesiredPresentMode(presentModes, minSwapInterval, maxSwapInterval); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 286 | |
| 287 | // Determine number of swapchain images. Aim for one more than the minimum. |
| 288 | uint32_t minImageCount = surfaceCaps.minImageCount + 1; |
| 289 | if (surfaceCaps.maxImageCount > 0 && minImageCount > surfaceCaps.maxImageCount) |
| 290 | { |
| 291 | minImageCount = surfaceCaps.maxImageCount; |
| 292 | } |
| 293 | |
| 294 | // Default to identity transform. |
| 295 | VkSurfaceTransformFlagBitsKHR preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
| 296 | if ((surfaceCaps.supportedTransforms & preTransform) == 0) |
| 297 | { |
| 298 | preTransform = surfaceCaps.currentTransform; |
| 299 | } |
| 300 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 301 | uint32_t surfaceFormatCount = 0; |
| 302 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
| 303 | nullptr)); |
| 304 | |
| 305 | std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount); |
| 306 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
| 307 | surfaceFormats.data())); |
| 308 | |
Jamie Madill | 1d7be50 | 2017-10-29 18:06:50 -0400 | [diff] [blame] | 309 | mRenderTarget.format = &GetVkFormatFromConfig(renderer, *mState.config); |
| 310 | VkFormat nativeFormat = mRenderTarget.format->vkTextureFormat; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 311 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 312 | if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED) |
| 313 | { |
| 314 | // This is fine. |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | bool foundFormat = false; |
| 319 | for (const auto &surfaceFormat : surfaceFormats) |
| 320 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 321 | if (surfaceFormat.format == nativeFormat) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 322 | { |
| 323 | foundFormat = true; |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | ANGLE_VK_CHECK(foundFormat, VK_ERROR_INITIALIZATION_FAILED); |
| 329 | } |
| 330 | |
| 331 | VkSwapchainCreateInfoKHR swapchainInfo; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 332 | swapchainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 333 | swapchainInfo.pNext = nullptr; |
| 334 | swapchainInfo.flags = 0; |
| 335 | swapchainInfo.surface = mSurface; |
| 336 | swapchainInfo.minImageCount = minImageCount; |
| 337 | swapchainInfo.imageFormat = nativeFormat; |
| 338 | swapchainInfo.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 339 | swapchainInfo.imageExtent.width = width; |
| 340 | swapchainInfo.imageExtent.height = height; |
| 341 | swapchainInfo.imageArrayLayers = 1; |
| 342 | swapchainInfo.imageUsage = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 343 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 344 | swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 345 | swapchainInfo.queueFamilyIndexCount = 0; |
| 346 | swapchainInfo.pQueueFamilyIndices = nullptr; |
| 347 | swapchainInfo.preTransform = preTransform; |
| 348 | swapchainInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 349 | swapchainInfo.presentMode = swapchainPresentMode; |
| 350 | swapchainInfo.clipped = VK_TRUE; |
| 351 | swapchainInfo.oldSwapchain = VK_NULL_HANDLE; |
| 352 | |
Jamie Madill | 6a89d22 | 2017-11-02 11:59:51 -0400 | [diff] [blame] | 353 | VkDevice device = renderer->getDevice(); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 354 | ANGLE_VK_TRY(vkCreateSwapchainKHR(device, &swapchainInfo, nullptr, &mSwapchain)); |
| 355 | |
| 356 | // Intialize the swapchain image views. |
| 357 | uint32_t imageCount = 0; |
| 358 | ANGLE_VK_TRY(vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, nullptr)); |
| 359 | |
| 360 | std::vector<VkImage> swapchainImages(imageCount); |
| 361 | ANGLE_VK_TRY(vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, swapchainImages.data())); |
| 362 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 363 | // Allocate a command buffer for clearing our images to black. |
| 364 | vk::CommandBuffer *commandBuffer = nullptr; |
| 365 | ANGLE_TRY(recordWriteCommands(renderer, &commandBuffer)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 366 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 367 | VkClearColorValue transparentBlack; |
| 368 | transparentBlack.float32[0] = 0.0f; |
| 369 | transparentBlack.float32[1] = 0.0f; |
| 370 | transparentBlack.float32[2] = 0.0f; |
| 371 | transparentBlack.float32[3] = 0.0f; |
| 372 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 373 | mSwapchainImages.resize(imageCount); |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 374 | |
| 375 | ANGLE_TRY(mAcquireNextImageSemaphore.init(device)); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 376 | |
| 377 | for (uint32_t imageIndex = 0; imageIndex < imageCount; ++imageIndex) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 378 | { |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 379 | VkImage swapchainImage = swapchainImages[imageIndex]; |
| 380 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 381 | VkImageViewCreateInfo imageViewInfo; |
| 382 | imageViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 383 | imageViewInfo.pNext = nullptr; |
| 384 | imageViewInfo.flags = 0; |
| 385 | imageViewInfo.image = swapchainImage; |
| 386 | imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 387 | imageViewInfo.format = nativeFormat; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 388 | imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_R; |
| 389 | imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_G; |
| 390 | imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_B; |
| 391 | imageViewInfo.components.a = VK_COMPONENT_SWIZZLE_A; |
| 392 | imageViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 393 | imageViewInfo.subresourceRange.baseMipLevel = 0; |
| 394 | imageViewInfo.subresourceRange.levelCount = 1; |
| 395 | imageViewInfo.subresourceRange.baseArrayLayer = 0; |
| 396 | imageViewInfo.subresourceRange.layerCount = 1; |
| 397 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 398 | auto &member = mSwapchainImages[imageIndex]; |
| 399 | |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 400 | member.image.setHandle(swapchainImage); |
| 401 | ANGLE_TRY(member.imageView.init(device, imageViewInfo)); |
| 402 | |
| 403 | // Set transfer dest layout, and clear the image to black. |
Jamie Madill | d33c77c | 2017-11-09 13:08:30 -0500 | [diff] [blame] | 404 | member.image.changeLayoutWithStages( |
| 405 | VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 406 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer); |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 407 | commandBuffer->clearSingleColorImage(member.image, transparentBlack); |
| 408 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 409 | ANGLE_TRY(member.imageAcquiredSemaphore.init(device)); |
| 410 | ANGLE_TRY(member.commandsCompleteSemaphore.init(device)); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 411 | } |
| 412 | |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 413 | // Get the first available swapchain iamge. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 414 | ANGLE_TRY(nextSwapchainImage(renderer)); |
| 415 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 416 | return vk::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::FramebufferState &state) |
| 420 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 421 | return FramebufferVk::CreateDefaultFBO(state, this); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 422 | } |
| 423 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 424 | egl::Error WindowSurfaceVk::swap(const gl::Context *context) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 425 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 426 | const DisplayVk *displayVk = vk::GetImpl(context->getCurrentDisplay()); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 427 | RendererVk *renderer = displayVk->getRenderer(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 428 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 429 | vk::CommandBuffer *swapCommands = nullptr; |
| 430 | ANGLE_TRY(recordWriteCommands(renderer, &swapCommands)); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 431 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 432 | auto &image = mSwapchainImages[mCurrentSwapchainImageIndex]; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 433 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 434 | image.image.changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, |
| 435 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 436 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, swapCommands); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 437 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 438 | ANGLE_TRY( |
| 439 | renderer->flush(context, image.imageAcquiredSemaphore, image.commandsCompleteSemaphore)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 440 | |
| 441 | VkPresentInfoKHR presentInfo; |
| 442 | presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
| 443 | presentInfo.pNext = nullptr; |
Jamie Madill | e918de2 | 2017-04-12 10:21:11 -0400 | [diff] [blame] | 444 | presentInfo.waitSemaphoreCount = 1; |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 445 | presentInfo.pWaitSemaphores = image.commandsCompleteSemaphore.ptr(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 446 | presentInfo.swapchainCount = 1; |
| 447 | presentInfo.pSwapchains = &mSwapchain; |
| 448 | presentInfo.pImageIndices = &mCurrentSwapchainImageIndex; |
| 449 | presentInfo.pResults = nullptr; |
| 450 | |
| 451 | ANGLE_VK_TRY(vkQueuePresentKHR(renderer->getQueue(), &presentInfo)); |
| 452 | |
Jamie Madill | f0eafe1 | 2017-02-21 15:03:50 -0500 | [diff] [blame] | 453 | // Get the next available swapchain image. |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 454 | ANGLE_TRY(nextSwapchainImage(renderer)); |
| 455 | |
| 456 | return vk::NoError(); |
| 457 | } |
| 458 | |
| 459 | vk::Error WindowSurfaceVk::nextSwapchainImage(RendererVk *renderer) |
| 460 | { |
| 461 | VkDevice device = renderer->getDevice(); |
| 462 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 463 | // Use a timeout of zero for AcquireNextImage so we don't actually block. |
| 464 | // TODO(jmadill): We should handle VK_NOT_READY and block until we can acquire the image. |
| 465 | ANGLE_VK_TRY(vkAcquireNextImageKHR(device, mSwapchain, 0, |
| 466 | mAcquireNextImageSemaphore.getHandle(), VK_NULL_HANDLE, |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 467 | &mCurrentSwapchainImageIndex)); |
| 468 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 469 | auto &image = mSwapchainImages[mCurrentSwapchainImageIndex]; |
| 470 | |
| 471 | // Swap the unused swapchain semaphore and the now active spare semaphore. |
| 472 | std::swap(image.imageAcquiredSemaphore, mAcquireNextImageSemaphore); |
| 473 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 474 | // Update RenderTarget pointers. |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 475 | mRenderTarget.image = &image.image; |
| 476 | mRenderTarget.imageView = &image.imageView; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 477 | |
| 478 | return vk::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 479 | } |
| 480 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 481 | egl::Error WindowSurfaceVk::postSubBuffer(const gl::Context *context, |
| 482 | EGLint x, |
| 483 | EGLint y, |
| 484 | EGLint width, |
| 485 | EGLint height) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 486 | { |
| 487 | // TODO(jmadill) |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 488 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | egl::Error WindowSurfaceVk::querySurfacePointerANGLE(EGLint attribute, void **value) |
| 492 | { |
| 493 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 494 | return egl::EglBadCurrentSurface(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | egl::Error WindowSurfaceVk::bindTexImage(gl::Texture *texture, EGLint buffer) |
| 498 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 499 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | egl::Error WindowSurfaceVk::releaseTexImage(EGLint buffer) |
| 503 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 504 | return egl::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 505 | } |
| 506 | |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 507 | egl::Error WindowSurfaceVk::getSyncValues(EGLuint64KHR * /*ust*/, |
| 508 | EGLuint64KHR * /*msc*/, |
| 509 | EGLuint64KHR * /*sbc*/) |
| 510 | { |
| 511 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 512 | return egl::EglBadAccess(); |
Stanislav Chiknavaryan | ee218f2 | 2017-03-22 15:39:13 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 515 | void WindowSurfaceVk::setSwapInterval(EGLint interval) |
| 516 | { |
| 517 | } |
| 518 | |
| 519 | EGLint WindowSurfaceVk::getWidth() const |
| 520 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 521 | return static_cast<EGLint>(mRenderTarget.extents.width); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | EGLint WindowSurfaceVk::getHeight() const |
| 525 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 526 | return static_cast<EGLint>(mRenderTarget.extents.height); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | EGLint WindowSurfaceVk::isPostSubBufferSupported() const |
| 530 | { |
| 531 | // TODO(jmadill) |
| 532 | return EGL_FALSE; |
| 533 | } |
| 534 | |
| 535 | EGLint WindowSurfaceVk::getSwapBehavior() const |
| 536 | { |
| 537 | // TODO(jmadill) |
| 538 | return EGL_BUFFER_DESTROYED; |
| 539 | } |
| 540 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 541 | gl::Error WindowSurfaceVk::getAttachmentRenderTarget(const gl::Context * /*context*/, |
| 542 | GLenum /*binding*/, |
Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 543 | const gl::ImageIndex & /*target*/, |
| 544 | FramebufferAttachmentRenderTarget **rtOut) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 545 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 546 | *rtOut = &mRenderTarget; |
| 547 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 550 | gl::ErrorOrResult<vk::Framebuffer *> WindowSurfaceVk::getCurrentFramebuffer( |
| 551 | VkDevice device, |
| 552 | const vk::RenderPass &compatibleRenderPass) |
| 553 | { |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 554 | auto ¤tFramebuffer = mSwapchainImages[mCurrentSwapchainImageIndex].framebuffer; |
| 555 | |
| 556 | if (currentFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 557 | { |
| 558 | // Validation layers should detect if the render pass is really compatible. |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 559 | return ¤tFramebuffer; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | VkFramebufferCreateInfo framebufferInfo; |
| 563 | |
| 564 | // TODO(jmadill): Depth/Stencil attachments. |
| 565 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 566 | framebufferInfo.pNext = nullptr; |
| 567 | framebufferInfo.flags = 0; |
| 568 | framebufferInfo.renderPass = compatibleRenderPass.getHandle(); |
| 569 | framebufferInfo.attachmentCount = 1u; |
| 570 | framebufferInfo.pAttachments = nullptr; |
| 571 | framebufferInfo.width = static_cast<uint32_t>(mRenderTarget.extents.width); |
| 572 | framebufferInfo.height = static_cast<uint32_t>(mRenderTarget.extents.height); |
| 573 | framebufferInfo.layers = 1; |
| 574 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 575 | for (auto &swapchainImage : mSwapchainImages) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 576 | { |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 577 | framebufferInfo.pAttachments = swapchainImage.imageView.ptr(); |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 578 | ANGLE_TRY(swapchainImage.framebuffer.init(device, framebufferInfo)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 579 | } |
| 580 | |
Jamie Madill | a9c60e9 | 2017-09-28 19:06:39 -0400 | [diff] [blame] | 581 | ASSERT(currentFramebuffer.valid()); |
| 582 | return ¤tFramebuffer; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 583 | } |
| 584 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 585 | gl::Error WindowSurfaceVk::initializeContents(const gl::Context *context, |
| 586 | const gl::ImageIndex &imageIndex) |
| 587 | { |
| 588 | UNIMPLEMENTED(); |
| 589 | return gl::NoError(); |
| 590 | } |
| 591 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 592 | } // namespace rx |