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 | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 13 | #include "libANGLE/Surface.h" |
| 14 | #include "libANGLE/renderer/vulkan/DisplayVk.h" |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 15 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 16 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 17 | #include "libANGLE/renderer/vulkan/formatutilsvk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 18 | |
| 19 | namespace rx |
| 20 | { |
| 21 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 22 | namespace |
| 23 | { |
| 24 | |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 25 | const vk::Format &GetVkFormatFromConfig(const egl::Config &config) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 26 | { |
| 27 | // TODO(jmadill): Properly handle format interpretation. |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 28 | return vk::Format::Get(GL_BGRA8_EXT); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | } // namespace |
| 32 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 33 | OffscreenSurfaceVk::OffscreenSurfaceVk(const egl::SurfaceState &surfaceState, |
| 34 | EGLint width, |
| 35 | EGLint height) |
| 36 | : SurfaceImpl(surfaceState), mWidth(width), mHeight(height) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 40 | OffscreenSurfaceVk::~OffscreenSurfaceVk() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 44 | egl::Error OffscreenSurfaceVk::initialize(const DisplayImpl *displayImpl) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 45 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 46 | return egl::Error(EGL_SUCCESS); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 49 | FramebufferImpl *OffscreenSurfaceVk::createDefaultFramebuffer(const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 50 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 51 | return new FramebufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 54 | egl::Error OffscreenSurfaceVk::swap(const DisplayImpl *displayImpl) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 55 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 56 | return egl::Error(EGL_SUCCESS); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 59 | egl::Error OffscreenSurfaceVk::postSubBuffer(EGLint /*x*/, |
| 60 | EGLint /*y*/, |
| 61 | EGLint /*width*/, |
| 62 | EGLint /*height*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 63 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 64 | return egl::Error(EGL_SUCCESS); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 67 | egl::Error OffscreenSurfaceVk::querySurfacePointerANGLE(EGLint /*attribute*/, void ** /*value*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 68 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 69 | UNREACHABLE(); |
| 70 | return egl::Error(EGL_BAD_CURRENT_SURFACE); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 73 | egl::Error OffscreenSurfaceVk::bindTexImage(gl::Texture * /*texture*/, EGLint /*buffer*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 74 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 75 | return egl::Error(EGL_SUCCESS); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 78 | egl::Error OffscreenSurfaceVk::releaseTexImage(EGLint /*buffer*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 79 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 80 | return egl::Error(EGL_SUCCESS); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 83 | void OffscreenSurfaceVk::setSwapInterval(EGLint /*interval*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 84 | { |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 87 | EGLint OffscreenSurfaceVk::getWidth() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 88 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 89 | return mWidth; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 92 | EGLint OffscreenSurfaceVk::getHeight() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 93 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 94 | return mHeight; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 97 | EGLint OffscreenSurfaceVk::isPostSubBufferSupported() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 98 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 99 | return EGL_FALSE; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 102 | EGLint OffscreenSurfaceVk::getSwapBehavior() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 103 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 104 | return EGL_BUFFER_PRESERVED; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 107 | gl::Error OffscreenSurfaceVk::getAttachmentRenderTarget( |
| 108 | const gl::FramebufferAttachment::Target & /*target*/, |
| 109 | FramebufferAttachmentRenderTarget ** /*rtOut*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 110 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 111 | UNREACHABLE(); |
| 112 | return gl::Error(GL_INVALID_OPERATION); |
| 113 | } |
| 114 | |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 115 | WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, |
| 116 | EGLNativeWindowType window, |
| 117 | EGLint width, |
| 118 | EGLint height) |
| 119 | : SurfaceImpl(surfaceState), |
| 120 | mNativeWindowType(window), |
| 121 | mWidth(width), |
| 122 | mHeight(height), |
| 123 | mSurface(VK_NULL_HANDLE), |
| 124 | mSwapchain(VK_NULL_HANDLE), |
| 125 | mDevice(VK_NULL_HANDLE), |
| 126 | mInstance(VK_NULL_HANDLE) |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 127 | { |
| 128 | } |
| 129 | |
| 130 | WindowSurfaceVk::~WindowSurfaceVk() |
| 131 | { |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 132 | mSwapchainImages.clear(); |
| 133 | |
| 134 | if (mSwapchain) |
| 135 | { |
| 136 | vkDestroySwapchainKHR(mDevice, mSwapchain, nullptr); |
| 137 | mSwapchain = VK_NULL_HANDLE; |
| 138 | } |
| 139 | |
| 140 | if (mSurface) |
| 141 | { |
| 142 | vkDestroySurfaceKHR(mInstance, mSurface, nullptr); |
| 143 | mSurface = VK_NULL_HANDLE; |
| 144 | } |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | egl::Error WindowSurfaceVk::initialize(const DisplayImpl *displayImpl) |
| 148 | { |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 149 | const DisplayVk *displayVk = GetAs<DisplayVk>(displayImpl); |
| 150 | return initializeImpl(displayVk->getRenderer()).toEGL(EGL_BAD_SURFACE); |
| 151 | } |
| 152 | |
| 153 | vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) |
| 154 | { |
| 155 | // These are needed for resource deallocation. |
| 156 | // TODO(jmadill): Don't cache these. |
| 157 | mDevice = renderer->getDevice(); |
| 158 | mInstance = renderer->getInstance(); |
| 159 | |
| 160 | // TODO(jmadill): Make this platform-specific. |
| 161 | VkWin32SurfaceCreateInfoKHR createInfo; |
| 162 | |
| 163 | createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; |
| 164 | createInfo.pNext = nullptr; |
| 165 | createInfo.flags = 0; |
| 166 | createInfo.hinstance = GetModuleHandle(nullptr); |
| 167 | createInfo.hwnd = mNativeWindowType; |
| 168 | ANGLE_VK_TRY(vkCreateWin32SurfaceKHR(renderer->getInstance(), &createInfo, nullptr, &mSurface)); |
| 169 | |
| 170 | uint32_t presentQueue = 0; |
| 171 | ANGLE_TRY_RESULT(renderer->selectPresentQueueForSurface(mSurface), presentQueue); |
| 172 | |
| 173 | const auto &physicalDevice = renderer->getPhysicalDevice(); |
| 174 | |
| 175 | VkSurfaceCapabilitiesKHR surfaceCaps; |
| 176 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface, &surfaceCaps)); |
| 177 | |
| 178 | // Adjust width and height to the swapchain if necessary. |
| 179 | if (surfaceCaps.currentExtent.width != 0xFFFFFFFFu) |
| 180 | { |
| 181 | ASSERT(surfaceCaps.currentExtent.height != 0xFFFFFFFFu); |
| 182 | mWidth = static_cast<EGLint>(surfaceCaps.currentExtent.width); |
| 183 | mHeight = static_cast<EGLint>(surfaceCaps.currentExtent.height); |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | ASSERT(surfaceCaps.currentExtent.height == 0xFFFFFFFFu); |
| 188 | |
| 189 | RECT rect; |
| 190 | ANGLE_VK_CHECK(GetClientRect(mNativeWindowType, &rect) == TRUE, |
| 191 | VK_ERROR_INITIALIZATION_FAILED); |
| 192 | if (mWidth == 0) |
| 193 | { |
| 194 | mWidth = static_cast<EGLint>(rect.right - rect.left); |
| 195 | } |
| 196 | if (mHeight == 0) |
| 197 | { |
| 198 | mHeight = static_cast<EGLint>(rect.bottom - rect.top); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | uint32_t presentModeCount = 0; |
| 203 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 204 | &presentModeCount, nullptr)); |
| 205 | ASSERT(presentModeCount > 0); |
| 206 | |
| 207 | std::vector<VkPresentModeKHR> presentModes(presentModeCount); |
| 208 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, |
| 209 | &presentModeCount, presentModes.data())); |
| 210 | |
| 211 | // Use FIFO mode if available, since it throttles you to the display rate. Mailbox can lead |
| 212 | // to rendering frames which are never seen by the user, wasting power. |
| 213 | VkPresentModeKHR swapchainPresentMode = presentModes[0]; |
| 214 | for (auto presentMode : presentModes) |
| 215 | { |
| 216 | if (presentMode == VK_PRESENT_MODE_FIFO_KHR) |
| 217 | { |
| 218 | swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR; |
| 219 | break; |
| 220 | } |
| 221 | |
| 222 | // Fallback to immediate mode if FIFO is unavailable. |
| 223 | if (presentMode == VK_PRESENT_MODE_IMMEDIATE_KHR) |
| 224 | { |
| 225 | swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Determine number of swapchain images. Aim for one more than the minimum. |
| 230 | uint32_t minImageCount = surfaceCaps.minImageCount + 1; |
| 231 | if (surfaceCaps.maxImageCount > 0 && minImageCount > surfaceCaps.maxImageCount) |
| 232 | { |
| 233 | minImageCount = surfaceCaps.maxImageCount; |
| 234 | } |
| 235 | |
| 236 | // Default to identity transform. |
| 237 | VkSurfaceTransformFlagBitsKHR preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
| 238 | if ((surfaceCaps.supportedTransforms & preTransform) == 0) |
| 239 | { |
| 240 | preTransform = surfaceCaps.currentTransform; |
| 241 | } |
| 242 | |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 243 | const vk::Format &configSurfaceFormat = GetVkFormatFromConfig(*mState.config); |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 244 | |
| 245 | uint32_t surfaceFormatCount = 0; |
| 246 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
| 247 | nullptr)); |
| 248 | |
| 249 | std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount); |
| 250 | ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, |
| 251 | surfaceFormats.data())); |
| 252 | |
| 253 | if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED) |
| 254 | { |
| 255 | // This is fine. |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | bool foundFormat = false; |
| 260 | for (const auto &surfaceFormat : surfaceFormats) |
| 261 | { |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 262 | if (surfaceFormat.format == configSurfaceFormat.native) |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 263 | { |
| 264 | foundFormat = true; |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | ANGLE_VK_CHECK(foundFormat, VK_ERROR_INITIALIZATION_FAILED); |
| 270 | } |
| 271 | |
| 272 | VkSwapchainCreateInfoKHR swapchainInfo; |
| 273 | swapchainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 274 | swapchainInfo.pNext = nullptr; |
| 275 | swapchainInfo.flags = 0; |
| 276 | swapchainInfo.surface = mSurface; |
| 277 | swapchainInfo.minImageCount = minImageCount; |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 278 | swapchainInfo.imageFormat = configSurfaceFormat.native; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 279 | swapchainInfo.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 280 | swapchainInfo.imageExtent.width = mWidth; |
| 281 | swapchainInfo.imageExtent.height = mHeight; |
| 282 | swapchainInfo.imageArrayLayers = 1; |
| 283 | swapchainInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 284 | swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 285 | swapchainInfo.queueFamilyIndexCount = 0; |
| 286 | swapchainInfo.pQueueFamilyIndices = nullptr; |
| 287 | swapchainInfo.preTransform = preTransform; |
| 288 | swapchainInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 289 | swapchainInfo.presentMode = swapchainPresentMode; |
| 290 | swapchainInfo.clipped = VK_TRUE; |
| 291 | swapchainInfo.oldSwapchain = VK_NULL_HANDLE; |
| 292 | |
| 293 | const auto &device = renderer->getDevice(); |
| 294 | ANGLE_VK_TRY(vkCreateSwapchainKHR(device, &swapchainInfo, nullptr, &mSwapchain)); |
| 295 | |
| 296 | // Intialize the swapchain image views. |
| 297 | uint32_t imageCount = 0; |
| 298 | ANGLE_VK_TRY(vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, nullptr)); |
| 299 | |
| 300 | std::vector<VkImage> swapchainImages(imageCount); |
| 301 | ANGLE_VK_TRY(vkGetSwapchainImagesKHR(device, mSwapchain, &imageCount, swapchainImages.data())); |
| 302 | |
| 303 | // CommandBuffer is a singleton in the Renderer. |
| 304 | vk::CommandBuffer *commandBuffer = renderer->getCommandBuffer(); |
| 305 | ANGLE_TRY(commandBuffer->begin()); |
| 306 | |
| 307 | for (auto swapchainImage : swapchainImages) |
| 308 | { |
| 309 | VkImageViewCreateInfo imageViewInfo; |
| 310 | imageViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 311 | imageViewInfo.pNext = nullptr; |
| 312 | imageViewInfo.flags = 0; |
| 313 | imageViewInfo.image = swapchainImage; |
| 314 | imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame^] | 315 | imageViewInfo.format = configSurfaceFormat.native; |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 316 | imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_R; |
| 317 | imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_G; |
| 318 | imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_B; |
| 319 | imageViewInfo.components.a = VK_COMPONENT_SWIZZLE_A; |
| 320 | imageViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 321 | imageViewInfo.subresourceRange.baseMipLevel = 0; |
| 322 | imageViewInfo.subresourceRange.levelCount = 1; |
| 323 | imageViewInfo.subresourceRange.baseArrayLayer = 0; |
| 324 | imageViewInfo.subresourceRange.layerCount = 1; |
| 325 | |
| 326 | vk::Image image(swapchainImage); |
| 327 | vk::ImageView imageView(device); |
| 328 | ANGLE_TRY(imageView.init(imageViewInfo)); |
| 329 | |
| 330 | // Set optimal color layout for the image. |
| 331 | image.changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 332 | commandBuffer); |
| 333 | |
| 334 | mSwapchainImages.push_back(std::move(image)); |
| 335 | mSwapchainImageViews.push_back(std::move(imageView)); |
| 336 | } |
| 337 | |
| 338 | ANGLE_TRY(commandBuffer->end()); |
| 339 | ANGLE_TRY(renderer->submitAndFinishCommandBuffer(*commandBuffer)); |
| 340 | |
| 341 | return vk::NoError(); |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::FramebufferState &state) |
| 345 | { |
| 346 | return new FramebufferVk(state); |
| 347 | } |
| 348 | |
| 349 | egl::Error WindowSurfaceVk::swap(const DisplayImpl *displayImpl) |
| 350 | { |
| 351 | // TODO(jmadill) |
| 352 | return egl::Error(EGL_SUCCESS); |
| 353 | } |
| 354 | |
| 355 | egl::Error WindowSurfaceVk::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height) |
| 356 | { |
| 357 | // TODO(jmadill) |
| 358 | return egl::Error(EGL_SUCCESS); |
| 359 | } |
| 360 | |
| 361 | egl::Error WindowSurfaceVk::querySurfacePointerANGLE(EGLint attribute, void **value) |
| 362 | { |
| 363 | UNREACHABLE(); |
| 364 | return egl::Error(EGL_BAD_CURRENT_SURFACE); |
| 365 | } |
| 366 | |
| 367 | egl::Error WindowSurfaceVk::bindTexImage(gl::Texture *texture, EGLint buffer) |
| 368 | { |
| 369 | return egl::Error(EGL_SUCCESS); |
| 370 | } |
| 371 | |
| 372 | egl::Error WindowSurfaceVk::releaseTexImage(EGLint buffer) |
| 373 | { |
| 374 | return egl::Error(EGL_SUCCESS); |
| 375 | } |
| 376 | |
| 377 | void WindowSurfaceVk::setSwapInterval(EGLint interval) |
| 378 | { |
| 379 | } |
| 380 | |
| 381 | EGLint WindowSurfaceVk::getWidth() const |
| 382 | { |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 383 | return mWidth; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | EGLint WindowSurfaceVk::getHeight() const |
| 387 | { |
Jamie Madill | 4d0bf55 | 2016-12-28 15:45:24 -0500 | [diff] [blame] | 388 | return mHeight; |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | EGLint WindowSurfaceVk::isPostSubBufferSupported() const |
| 392 | { |
| 393 | // TODO(jmadill) |
| 394 | return EGL_FALSE; |
| 395 | } |
| 396 | |
| 397 | EGLint WindowSurfaceVk::getSwapBehavior() const |
| 398 | { |
| 399 | // TODO(jmadill) |
| 400 | return EGL_BUFFER_DESTROYED; |
| 401 | } |
| 402 | |
| 403 | gl::Error WindowSurfaceVk::getAttachmentRenderTarget( |
| 404 | const gl::FramebufferAttachment::Target &target, |
| 405 | FramebufferAttachmentRenderTarget **rtOut) |
| 406 | { |
| 407 | UNREACHABLE(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 408 | return gl::Error(GL_INVALID_OPERATION); |
| 409 | } |
| 410 | |
| 411 | } // namespace rx |