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 | // FramebufferVk.cpp: |
| 7 | // Implements the class methods for FramebufferVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 11 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 12 | #include <vulkan/vulkan.h> |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 13 | #include <array> |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 14 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 15 | #include "common/debug.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 16 | #include "image_util/imageformats.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 17 | #include "libANGLE/Context.h" |
| 18 | #include "libANGLE/Display.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 19 | #include "libANGLE/formatutils.h" |
| 20 | #include "libANGLE/renderer/renderer_utils.h" |
| 21 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 22 | #include "libANGLE/renderer/vulkan/DisplayVk.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 23 | #include "libANGLE/renderer/vulkan/RenderTargetVk.h" |
| 24 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 25 | #include "libANGLE/renderer/vulkan/SurfaceVk.h" |
| 26 | #include "libANGLE/renderer/vulkan/formatutilsvk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 27 | |
| 28 | namespace rx |
| 29 | { |
| 30 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 31 | namespace |
| 32 | { |
| 33 | |
| 34 | gl::ErrorOrResult<const gl::InternalFormat *> GetReadAttachmentInfo( |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 35 | const gl::Context *context, |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 36 | const gl::FramebufferAttachment *readAttachment) |
| 37 | { |
| 38 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 39 | ANGLE_TRY(readAttachment->getRenderTarget(context, &renderTarget)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 40 | |
Jamie Madill | 1d7be50 | 2017-10-29 18:06:50 -0400 | [diff] [blame] | 41 | GLenum implFormat = renderTarget->format->textureFormat().fboImplementationInternalFormat; |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 42 | return &gl::GetSizedInternalFormatInfo(implFormat); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 45 | VkSampleCountFlagBits ConvertSamples(GLint sampleCount) |
| 46 | { |
| 47 | switch (sampleCount) |
| 48 | { |
| 49 | case 0: |
| 50 | case 1: |
| 51 | return VK_SAMPLE_COUNT_1_BIT; |
| 52 | case 2: |
| 53 | return VK_SAMPLE_COUNT_2_BIT; |
| 54 | case 4: |
| 55 | return VK_SAMPLE_COUNT_4_BIT; |
| 56 | case 8: |
| 57 | return VK_SAMPLE_COUNT_8_BIT; |
| 58 | case 16: |
| 59 | return VK_SAMPLE_COUNT_16_BIT; |
| 60 | case 32: |
| 61 | return VK_SAMPLE_COUNT_32_BIT; |
| 62 | default: |
| 63 | UNREACHABLE(); |
| 64 | return VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM; |
| 65 | } |
| 66 | } |
| 67 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 68 | } // anonymous namespace |
| 69 | |
| 70 | // static |
| 71 | FramebufferVk *FramebufferVk::CreateUserFBO(const gl::FramebufferState &state) |
| 72 | { |
| 73 | return new FramebufferVk(state); |
| 74 | } |
| 75 | |
| 76 | // static |
| 77 | FramebufferVk *FramebufferVk::CreateDefaultFBO(const gl::FramebufferState &state, |
| 78 | WindowSurfaceVk *backbuffer) |
| 79 | { |
| 80 | return new FramebufferVk(state, backbuffer); |
| 81 | } |
| 82 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 83 | FramebufferVk::FramebufferVk(const gl::FramebufferState &state) |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 84 | : FramebufferImpl(state), mBackbuffer(nullptr), mRenderPassDesc(), mFramebuffer() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 85 | { |
| 86 | } |
| 87 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 88 | FramebufferVk::FramebufferVk(const gl::FramebufferState &state, WindowSurfaceVk *backbuffer) |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 89 | : FramebufferImpl(state), mBackbuffer(backbuffer), mRenderPassDesc(), mFramebuffer() |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 90 | { |
| 91 | } |
| 92 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 93 | FramebufferVk::~FramebufferVk() |
| 94 | { |
| 95 | } |
| 96 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 97 | void FramebufferVk::destroy(const gl::Context *context) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 98 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 99 | RendererVk *renderer = vk::GetImpl(context)->getRenderer(); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 100 | |
Jamie Madill | 526543c | 2017-10-28 10:59:16 -0400 | [diff] [blame] | 101 | renderer->releaseResource(*this, &mFramebuffer); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 104 | void FramebufferVk::destroyDefault(const egl::Display *display) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 105 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 106 | VkDevice device = vk::GetImpl(display)->getRenderer()->getDevice(); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 107 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 108 | mFramebuffer.destroy(device); |
| 109 | } |
| 110 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 111 | gl::Error FramebufferVk::discard(const gl::Context *context, |
| 112 | size_t count, |
| 113 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 114 | { |
| 115 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 116 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 119 | gl::Error FramebufferVk::invalidate(const gl::Context *context, |
| 120 | size_t count, |
| 121 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 122 | { |
| 123 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 124 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 127 | gl::Error FramebufferVk::invalidateSub(const gl::Context *context, |
| 128 | size_t count, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 129 | const GLenum *attachments, |
| 130 | const gl::Rectangle &area) |
| 131 | { |
| 132 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 133 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 136 | gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 137 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 138 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 139 | |
| 140 | if (mState.getDepthAttachment() && (mask & GL_DEPTH_BUFFER_BIT) != 0) |
| 141 | { |
| 142 | // TODO(jmadill): Depth clear |
| 143 | UNIMPLEMENTED(); |
| 144 | } |
| 145 | |
| 146 | if (mState.getStencilAttachment() && (mask & GL_STENCIL_BUFFER_BIT) != 0) |
| 147 | { |
| 148 | // TODO(jmadill): Stencil clear |
| 149 | UNIMPLEMENTED(); |
| 150 | } |
| 151 | |
| 152 | if ((mask & GL_COLOR_BUFFER_BIT) == 0) |
| 153 | { |
| 154 | return gl::NoError(); |
| 155 | } |
| 156 | |
| 157 | const auto &glState = context->getGLState(); |
| 158 | const auto &clearColor = glState.getColorClearValue(); |
| 159 | VkClearColorValue clearColorValue; |
| 160 | clearColorValue.float32[0] = clearColor.red; |
| 161 | clearColorValue.float32[1] = clearColor.green; |
| 162 | clearColorValue.float32[2] = clearColor.blue; |
| 163 | clearColorValue.float32[3] = clearColor.alpha; |
| 164 | |
| 165 | // TODO(jmadill): Scissored clears. |
| 166 | const auto *attachment = mState.getFirstNonNullAttachment(); |
| 167 | ASSERT(attachment && attachment->isAttached()); |
| 168 | const auto &size = attachment->getSize(); |
| 169 | const gl::Rectangle renderArea(0, 0, size.width, size.height); |
| 170 | |
Jamie Madill | 7f738d4 | 2017-11-20 17:06:27 -0500 | [diff] [blame] | 171 | vk::CommandBufferAndState *commandBuffer = nullptr; |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 172 | ANGLE_TRY(contextVk->getStartedCommandBuffer(&commandBuffer)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 173 | |
| 174 | for (const auto &colorAttachment : mState.getColorAttachments()) |
| 175 | { |
| 176 | if (colorAttachment.isAttached()) |
| 177 | { |
| 178 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 179 | ANGLE_TRY(colorAttachment.getRenderTarget(context, &renderTarget)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 180 | renderTarget->image->changeLayoutTop( |
| 181 | VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, commandBuffer); |
| 182 | commandBuffer->clearSingleColorImage(*renderTarget->image, clearColorValue); |
| 183 | } |
| 184 | } |
| 185 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 186 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 189 | gl::Error FramebufferVk::clearBufferfv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 190 | GLenum buffer, |
| 191 | GLint drawbuffer, |
| 192 | const GLfloat *values) |
| 193 | { |
| 194 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 195 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 198 | gl::Error FramebufferVk::clearBufferuiv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 199 | GLenum buffer, |
| 200 | GLint drawbuffer, |
| 201 | const GLuint *values) |
| 202 | { |
| 203 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 204 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 205 | } |
| 206 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 207 | gl::Error FramebufferVk::clearBufferiv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 208 | GLenum buffer, |
| 209 | GLint drawbuffer, |
| 210 | const GLint *values) |
| 211 | { |
| 212 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 213 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 216 | gl::Error FramebufferVk::clearBufferfi(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 217 | GLenum buffer, |
| 218 | GLint drawbuffer, |
| 219 | GLfloat depth, |
| 220 | GLint stencil) |
| 221 | { |
| 222 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 223 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 226 | GLenum FramebufferVk::getImplementationColorReadFormat(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 227 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 228 | auto errOrResult = GetReadAttachmentInfo(context, mState.getReadAttachment()); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 229 | |
| 230 | // TODO(jmadill): Handle getRenderTarget error. |
| 231 | if (errOrResult.isError()) |
| 232 | { |
Yuly Novikov | d73f852 | 2017-01-13 17:48:57 -0500 | [diff] [blame] | 233 | ERR() << "Internal error in FramebufferVk::getImplementationColorReadFormat."; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 234 | return GL_NONE; |
| 235 | } |
| 236 | |
| 237 | return errOrResult.getResult()->format; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 240 | GLenum FramebufferVk::getImplementationColorReadType(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 241 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 242 | auto errOrResult = GetReadAttachmentInfo(context, mState.getReadAttachment()); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 243 | |
| 244 | // TODO(jmadill): Handle getRenderTarget error. |
| 245 | if (errOrResult.isError()) |
| 246 | { |
Yuly Novikov | d73f852 | 2017-01-13 17:48:57 -0500 | [diff] [blame] | 247 | ERR() << "Internal error in FramebufferVk::getImplementationColorReadFormat."; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 248 | return GL_NONE; |
| 249 | } |
| 250 | |
| 251 | return errOrResult.getResult()->type; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 254 | gl::Error FramebufferVk::readPixels(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 255 | const gl::Rectangle &area, |
| 256 | GLenum format, |
| 257 | GLenum type, |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 258 | void *pixels) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 259 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 260 | const auto &glState = context->getGLState(); |
| 261 | const auto *readFramebuffer = glState.getReadFramebuffer(); |
| 262 | const auto *readAttachment = readFramebuffer->getReadColorbuffer(); |
| 263 | |
| 264 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 265 | ANGLE_TRY(readAttachment->getRenderTarget(context, &renderTarget)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 266 | |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 267 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 268 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 269 | VkDevice device = renderer->getDevice(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 270 | |
| 271 | vk::Image *readImage = renderTarget->image; |
| 272 | vk::StagingImage stagingImage; |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 273 | ANGLE_TRY(renderer->createStagingImage(TextureDimension::TEX_2D, *renderTarget->format, |
Jamie Madill | 035fd6b | 2017-10-03 15:43:22 -0400 | [diff] [blame] | 274 | renderTarget->extents, vk::StagingUsage::Read, |
| 275 | &stagingImage)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 276 | |
Jamie Madill | 7f738d4 | 2017-11-20 17:06:27 -0500 | [diff] [blame] | 277 | vk::CommandBufferAndState *commandBuffer = nullptr; |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 278 | ANGLE_TRY(contextVk->getStartedCommandBuffer(&commandBuffer)); |
| 279 | |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 280 | // End render pass if we're in one. |
Jamie Madill | 1b03824 | 2017-11-01 15:14:36 -0400 | [diff] [blame] | 281 | renderer->endRenderPass(); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 282 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 283 | stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, |
| 284 | commandBuffer); |
| 285 | |
Jamie Madill | d33c77c | 2017-11-09 13:08:30 -0500 | [diff] [blame] | 286 | readImage->changeLayoutWithStages( |
| 287 | VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 288 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer); |
Jamie Madill | 815a6c9 | 2017-10-21 14:33:04 -0400 | [diff] [blame] | 289 | |
| 290 | VkImageCopy region; |
| 291 | region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 292 | region.srcSubresource.mipLevel = 0; |
| 293 | region.srcSubresource.baseArrayLayer = 0; |
| 294 | region.srcSubresource.layerCount = 1; |
| 295 | region.srcOffset.x = area.x; |
| 296 | region.srcOffset.y = area.y; |
| 297 | region.srcOffset.z = 0; |
| 298 | region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 299 | region.dstSubresource.mipLevel = 0; |
| 300 | region.dstSubresource.baseArrayLayer = 0; |
| 301 | region.dstSubresource.layerCount = 1; |
| 302 | region.dstOffset.x = 0; |
| 303 | region.dstOffset.y = 0; |
| 304 | region.dstOffset.z = 0; |
| 305 | region.extent.width = area.width; |
| 306 | region.extent.height = area.height; |
| 307 | region.extent.depth = 1; |
| 308 | |
| 309 | commandBuffer->copyImage(*readImage, stagingImage.getImage(), 1, ®ion); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 310 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 311 | ANGLE_TRY(renderer->submitAndFinishCommandBuffer(commandBuffer)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 312 | |
| 313 | // TODO(jmadill): parameters |
| 314 | uint8_t *mapPointer = nullptr; |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 315 | ANGLE_TRY( |
| 316 | stagingImage.getDeviceMemory().map(device, 0, stagingImage.getSize(), 0, &mapPointer)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 317 | |
Jamie Madill | 1d7be50 | 2017-10-29 18:06:50 -0400 | [diff] [blame] | 318 | const auto &angleFormat = renderTarget->format->textureFormat(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 319 | |
| 320 | // TODO(jmadill): Use pixel bytes from the ANGLE format directly. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 321 | const auto &glFormat = gl::GetSizedInternalFormatInfo(angleFormat.glInternalFormat); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 322 | int inputPitch = glFormat.pixelBytes * area.width; |
| 323 | |
| 324 | PackPixelsParams params; |
| 325 | params.area = area; |
| 326 | params.format = format; |
| 327 | params.type = type; |
| 328 | params.outputPitch = inputPitch; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 329 | params.packBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelPack); |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 330 | params.pack = glState.getPackState(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 331 | |
| 332 | PackPixels(params, angleFormat, inputPitch, mapPointer, reinterpret_cast<uint8_t *>(pixels)); |
| 333 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 334 | stagingImage.getDeviceMemory().unmap(device); |
Jamie Madill | e88ec8e | 2017-10-31 17:18:14 -0400 | [diff] [blame] | 335 | renderer->releaseObject(renderer->getCurrentQueueSerial(), &stagingImage); |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 336 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 337 | return vk::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 340 | gl::Error FramebufferVk::blit(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 341 | const gl::Rectangle &sourceArea, |
| 342 | const gl::Rectangle &destArea, |
| 343 | GLbitfield mask, |
| 344 | GLenum filter) |
| 345 | { |
| 346 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 347 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 350 | bool FramebufferVk::checkStatus(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 351 | { |
Jamie Madill | b79e7bb | 2017-10-24 13:55:50 -0400 | [diff] [blame] | 352 | return true; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 355 | void FramebufferVk::syncState(const gl::Context *context, |
| 356 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 357 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 358 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 359 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 360 | |
| 361 | ASSERT(dirtyBits.any()); |
| 362 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 363 | // TODO(jmadill): Smarter update. |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 364 | mRenderPassDesc.reset(); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 365 | renderer->releaseResource(*this, &mFramebuffer); |
| 366 | renderer->onReleaseRenderPass(this); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 367 | |
| 368 | // TODO(jmadill): Use pipeline cache. |
| 369 | contextVk->invalidateCurrentPipeline(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 370 | } |
| 371 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 372 | const vk::RenderPassDesc &FramebufferVk::getRenderPassDesc(const gl::Context *context) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 373 | { |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 374 | if (mRenderPassDesc.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 375 | { |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 376 | return mRenderPassDesc.value(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 377 | } |
| 378 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 379 | vk::RenderPassDesc desc; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 380 | |
| 381 | const auto &colorAttachments = mState.getColorAttachments(); |
| 382 | for (size_t attachmentIndex = 0; attachmentIndex < colorAttachments.size(); ++attachmentIndex) |
| 383 | { |
| 384 | const auto &colorAttachment = colorAttachments[attachmentIndex]; |
| 385 | if (colorAttachment.isAttached()) |
| 386 | { |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 387 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 388 | ANGLE_SWALLOW_ERR(colorAttachment.getRenderTarget(context, &renderTarget)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 389 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 390 | VkAttachmentDescription *colorDesc = desc.nextColorAttachment(); |
| 391 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 392 | // TODO(jmadill): We would only need this flag for duplicated attachments. |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 393 | colorDesc->flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT; |
| 394 | colorDesc->format = renderTarget->format->vkTextureFormat; |
| 395 | colorDesc->samples = ConvertSamples(colorAttachment.getSamples()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 396 | |
| 397 | // The load op controls the prior existing depth/color attachment data. |
| 398 | // TODO(jmadill): Proper load ops. Should not be hard coded to clear. |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 399 | colorDesc->loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 400 | colorDesc->storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 401 | colorDesc->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 402 | colorDesc->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 403 | colorDesc->initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 404 | |
| 405 | // We might want to transition directly to PRESENT_SRC for Surface attachments. |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 406 | colorDesc->finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | const auto *depthStencilAttachment = mState.getDepthStencilAttachment(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 411 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 412 | if (depthStencilAttachment && depthStencilAttachment->isAttached()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 413 | { |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 414 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 415 | ANGLE_SWALLOW_ERR(depthStencilAttachment->getRenderTarget(context, &renderTarget)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 416 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 417 | VkAttachmentDescription *depthStencilDesc = desc.nextDepthStencilAttachment(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 418 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 419 | depthStencilDesc->flags = 0; |
| 420 | depthStencilDesc->format = renderTarget->format->vkTextureFormat; |
| 421 | depthStencilDesc->samples = ConvertSamples(depthStencilAttachment->getSamples()); |
| 422 | depthStencilDesc->loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 423 | depthStencilDesc->storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 424 | depthStencilDesc->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 425 | depthStencilDesc->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 426 | depthStencilDesc->initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 427 | depthStencilDesc->finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 428 | } |
| 429 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 430 | mRenderPassDesc = desc; |
| 431 | return mRenderPassDesc.value(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 432 | } |
| 433 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 434 | gl::ErrorOrResult<vk::Framebuffer *> FramebufferVk::getFramebuffer(const gl::Context *context, |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 435 | RendererVk *rendererVk) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 436 | { |
| 437 | // If we've already created our cached Framebuffer, return it. |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 438 | if (mFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 439 | { |
| 440 | return &mFramebuffer; |
| 441 | } |
| 442 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 443 | const vk::RenderPassDesc &desc = getRenderPassDesc(context); |
| 444 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 445 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 446 | ANGLE_TRY(rendererVk->getCompatibleRenderPass(desc, &renderPass)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 447 | |
| 448 | // If we've a Framebuffer provided by a Surface (default FBO/backbuffer), query it. |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 449 | VkDevice device = rendererVk->getDevice(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 450 | if (mBackbuffer) |
| 451 | { |
| 452 | return mBackbuffer->getCurrentFramebuffer(device, *renderPass); |
| 453 | } |
| 454 | |
| 455 | // Gather VkImageViews over all FBO attachments, also size of attached region. |
| 456 | std::vector<VkImageView> attachments; |
| 457 | gl::Extents attachmentsSize; |
| 458 | |
| 459 | const auto &colorAttachments = mState.getColorAttachments(); |
| 460 | for (size_t attachmentIndex = 0; attachmentIndex < colorAttachments.size(); ++attachmentIndex) |
| 461 | { |
| 462 | const auto &colorAttachment = colorAttachments[attachmentIndex]; |
| 463 | if (colorAttachment.isAttached()) |
| 464 | { |
| 465 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 466 | ANGLE_TRY(colorAttachment.getRenderTarget<RenderTargetVk>(context, &renderTarget)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 467 | attachments.push_back(renderTarget->imageView->getHandle()); |
| 468 | |
| 469 | ASSERT(attachmentsSize.empty() || attachmentsSize == colorAttachment.getSize()); |
| 470 | attachmentsSize = colorAttachment.getSize(); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | const auto *depthStencilAttachment = mState.getDepthStencilAttachment(); |
| 475 | if (depthStencilAttachment && depthStencilAttachment->isAttached()) |
| 476 | { |
| 477 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 478 | ANGLE_TRY(depthStencilAttachment->getRenderTarget<RenderTargetVk>(context, &renderTarget)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 479 | attachments.push_back(renderTarget->imageView->getHandle()); |
| 480 | |
| 481 | ASSERT(attachmentsSize.empty() || attachmentsSize == depthStencilAttachment->getSize()); |
| 482 | attachmentsSize = depthStencilAttachment->getSize(); |
| 483 | } |
| 484 | |
| 485 | ASSERT(!attachments.empty()); |
| 486 | |
| 487 | VkFramebufferCreateInfo framebufferInfo; |
| 488 | |
| 489 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 490 | framebufferInfo.pNext = nullptr; |
| 491 | framebufferInfo.flags = 0; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 492 | framebufferInfo.renderPass = renderPass->getHandle(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 493 | framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); |
| 494 | framebufferInfo.pAttachments = attachments.data(); |
| 495 | framebufferInfo.width = static_cast<uint32_t>(attachmentsSize.width); |
| 496 | framebufferInfo.height = static_cast<uint32_t>(attachmentsSize.height); |
| 497 | framebufferInfo.layers = 1; |
| 498 | |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 499 | ANGLE_TRY(mFramebuffer.init(device, framebufferInfo)); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 500 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 501 | return &mFramebuffer; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 502 | } |
| 503 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 504 | gl::Error FramebufferVk::getSamplePosition(size_t index, GLfloat *xy) const |
| 505 | { |
| 506 | UNIMPLEMENTED(); |
| 507 | return gl::InternalError() << "getSamplePosition is unimplemented."; |
| 508 | } |
| 509 | |
Jamie Madill | 1b03824 | 2017-11-01 15:14:36 -0400 | [diff] [blame] | 510 | gl::Error FramebufferVk::beginRenderPass(const gl::Context *context, |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 511 | RendererVk *rendererVk, |
Jamie Madill | 1b03824 | 2017-11-01 15:14:36 -0400 | [diff] [blame] | 512 | vk::CommandBuffer *commandBuffer, |
| 513 | Serial queueSerial) |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 514 | { |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 515 | // TODO(jmadill): Cache render targets. |
| 516 | for (const auto &colorAttachment : mState.getColorAttachments()) |
| 517 | { |
| 518 | if (colorAttachment.isAttached()) |
| 519 | { |
| 520 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 521 | ANGLE_TRY(colorAttachment.getRenderTarget<RenderTargetVk>(context, &renderTarget)); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 522 | renderTarget->resource->setQueueSerial(queueSerial); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | const auto *depthStencilAttachment = mState.getDepthStencilAttachment(); |
| 527 | if (depthStencilAttachment && depthStencilAttachment->isAttached()) |
| 528 | { |
| 529 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 530 | ANGLE_TRY(depthStencilAttachment->getRenderTarget<RenderTargetVk>(context, &renderTarget)); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 531 | renderTarget->resource->setQueueSerial(queueSerial); |
| 532 | } |
| 533 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 534 | vk::Framebuffer *framebuffer = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 535 | ANGLE_TRY_RESULT(getFramebuffer(context, rendererVk), framebuffer); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 536 | ASSERT(framebuffer && framebuffer->valid()); |
| 537 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 538 | const vk::RenderPassDesc &desc = getRenderPassDesc(context); |
| 539 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 540 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame^] | 541 | ANGLE_TRY(rendererVk->getMatchingRenderPass(desc, &renderPass)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 542 | ASSERT(renderPass && renderPass->valid()); |
| 543 | |
| 544 | // TODO(jmadill): Proper clear value implementation. |
Jamie Madill | 1b03824 | 2017-11-01 15:14:36 -0400 | [diff] [blame] | 545 | const gl::State &glState = context->getGLState(); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 546 | VkClearColorValue colorClear; |
| 547 | memset(&colorClear, 0, sizeof(VkClearColorValue)); |
| 548 | colorClear.float32[0] = glState.getColorClearValue().red; |
| 549 | colorClear.float32[1] = glState.getColorClearValue().green; |
| 550 | colorClear.float32[2] = glState.getColorClearValue().blue; |
| 551 | colorClear.float32[3] = glState.getColorClearValue().alpha; |
| 552 | |
| 553 | std::vector<VkClearValue> attachmentClearValues; |
| 554 | attachmentClearValues.push_back({colorClear}); |
| 555 | |
| 556 | // Updated the cached image layout of the attachments in this FBO. |
| 557 | // For a default FBO, we need to call through to the WindowSurfaceVk |
| 558 | // TODO(jmadill): Iterate over all attachments. |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 559 | RenderTargetVk *renderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 560 | ANGLE_TRY(mState.getFirstColorAttachment()->getRenderTarget(context, &renderTarget)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 561 | renderTarget->image->updateLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); |
| 562 | |
Jamie Madill | e218f15 | 2017-11-30 12:38:50 -0500 | [diff] [blame] | 563 | commandBuffer->beginRenderPass(*renderPass, *framebuffer, glState.getViewport(), 1, |
| 564 | attachmentClearValues.data()); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 565 | |
| 566 | setQueueSerial(queueSerial); |
| 567 | if (mBackbuffer) |
| 568 | { |
| 569 | mBackbuffer->setQueueSerial(queueSerial); |
| 570 | } |
| 571 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 572 | return gl::NoError(); |
| 573 | } |
| 574 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 575 | } // namespace rx |