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" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 21 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 22 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 23 | #include "libANGLE/renderer/vulkan/DisplayVk.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/vulkan/RenderTargetVk.h" |
| 25 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 26 | #include "libANGLE/renderer/vulkan/SurfaceVk.h" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 27 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 28 | |
| 29 | namespace rx |
| 30 | { |
| 31 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 32 | namespace |
| 33 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 34 | const gl::InternalFormat &GetReadAttachmentInfo(const gl::Context *context, |
| 35 | RenderTargetVk *renderTarget) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 36 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 37 | GLenum implFormat = |
| 38 | renderTarget->image->getFormat().textureFormat().fboImplementationInternalFormat; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 39 | return gl::GetSizedInternalFormatInfo(implFormat); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 40 | } |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 41 | } // anonymous namespace< |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 42 | |
| 43 | // static |
| 44 | FramebufferVk *FramebufferVk::CreateUserFBO(const gl::FramebufferState &state) |
| 45 | { |
| 46 | return new FramebufferVk(state); |
| 47 | } |
| 48 | |
| 49 | // static |
| 50 | FramebufferVk *FramebufferVk::CreateDefaultFBO(const gl::FramebufferState &state, |
| 51 | WindowSurfaceVk *backbuffer) |
| 52 | { |
| 53 | return new FramebufferVk(state, backbuffer); |
| 54 | } |
| 55 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 56 | FramebufferVk::FramebufferVk(const gl::FramebufferState &state) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 57 | : FramebufferImpl(state), |
| 58 | mBackbuffer(nullptr), |
| 59 | mRenderPassDesc(), |
| 60 | mFramebuffer(), |
| 61 | mActiveColorComponents(0), |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 62 | mMaskedClearDescriptorSet(VK_NULL_HANDLE) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 66 | FramebufferVk::FramebufferVk(const gl::FramebufferState &state, WindowSurfaceVk *backbuffer) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 67 | : FramebufferImpl(state), |
| 68 | mBackbuffer(backbuffer), |
| 69 | mRenderPassDesc(), |
| 70 | mFramebuffer(), |
| 71 | mActiveColorComponents(0), |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 72 | mMaskedClearDescriptorSet(VK_NULL_HANDLE) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 73 | { |
| 74 | } |
| 75 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 76 | FramebufferVk::~FramebufferVk() |
| 77 | { |
| 78 | } |
| 79 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 80 | void FramebufferVk::destroy(const gl::Context *context) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 81 | { |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 82 | RendererVk *renderer = vk::GetImpl(context)->getRenderer(); |
Jamie Madill | 526543c | 2017-10-28 10:59:16 -0400 | [diff] [blame] | 83 | renderer->releaseResource(*this, &mFramebuffer); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 84 | renderer->releaseResource(*this, &mMaskedClearUniformBuffer.buffer); |
| 85 | renderer->releaseResource(*this, &mMaskedClearUniformBuffer.memory); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 86 | } |
| 87 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 88 | gl::Error FramebufferVk::discard(const gl::Context *context, |
| 89 | size_t count, |
| 90 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 91 | { |
| 92 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 93 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 96 | gl::Error FramebufferVk::invalidate(const gl::Context *context, |
| 97 | size_t count, |
| 98 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 99 | { |
| 100 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 101 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 104 | gl::Error FramebufferVk::invalidateSub(const gl::Context *context, |
| 105 | size_t count, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 106 | const GLenum *attachments, |
| 107 | const gl::Rectangle &area) |
| 108 | { |
| 109 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 110 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 113 | gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 114 | { |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 115 | ContextVk *contextVk = vk::GetImpl(context); |
| 116 | RendererVk *renderer = contextVk->getRenderer(); |
| 117 | Serial currentSerial = renderer->getCurrentQueueSerial(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 118 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 119 | // This command buffer is only started once. |
| 120 | vk::CommandBuffer *commandBuffer = nullptr; |
| 121 | vk::CommandGraphNode *writingNode = nullptr; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 122 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 123 | const gl::FramebufferAttachment *depthAttachment = mState.getDepthAttachment(); |
| 124 | bool clearDepth = (depthAttachment && (mask & GL_DEPTH_BUFFER_BIT) != 0); |
| 125 | ASSERT(!clearDepth || depthAttachment->isAttached()); |
| 126 | |
| 127 | const gl::FramebufferAttachment *stencilAttachment = mState.getStencilAttachment(); |
| 128 | bool clearStencil = (stencilAttachment && (mask & GL_STENCIL_BUFFER_BIT) != 0); |
| 129 | ASSERT(!clearStencil || stencilAttachment->isAttached()); |
| 130 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 131 | bool clearColor = IsMaskFlagSet(static_cast<int>(mask), GL_COLOR_BUFFER_BIT); |
| 132 | |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 133 | const gl::FramebufferAttachment *depthStencilAttachment = mState.getDepthStencilAttachment(); |
Jamie Madill | d47044a | 2018-04-27 11:45:03 -0400 | [diff] [blame] | 134 | const gl::State &glState = context->getGLState(); |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 135 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 136 | // The most costly clear mode is when we need to mask out specific color channels. This can |
| 137 | // only be done with a draw call. The scissor region however can easily be integrated with |
| 138 | // this method. Similarly for depth/stencil clear. |
| 139 | VkColorComponentFlags colorMaskFlags = contextVk->getClearColorMask(); |
| 140 | if (clearColor && (mActiveColorComponents & colorMaskFlags) != mActiveColorComponents) |
| 141 | { |
Jamie Madill | 78cd940 | 2018-05-10 16:49:58 -0400 | [diff] [blame] | 142 | ANGLE_TRY(clearWithDraw(contextVk, colorMaskFlags)); |
| 143 | |
| 144 | // Stencil clears must be handled separately. The only way to write out a stencil value from |
| 145 | // a fragment shader in Vulkan is with VK_EXT_shader_stencil_export. Support for this |
| 146 | // extension is sparse. Hence, we call into the RenderPass clear path. We similarly clear |
| 147 | // depth to keep the code simple, but depth clears could be combined with the masked color |
| 148 | // clears as an optimization. |
| 149 | |
| 150 | if (clearDepth || clearStencil) |
| 151 | { |
| 152 | // Masked stencil clears are currently not implemented. |
| 153 | // TODO(jmadill): Masked stencil clear. http://anglebug.com/2540 |
| 154 | ANGLE_TRY(clearWithClearAttachments(contextVk, false, clearDepth, clearStencil)); |
| 155 | } |
| 156 | return gl::NoError(); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 159 | // If we clear the depth OR the stencil but not both, and we have a packed depth stencil |
| 160 | // attachment, we need to use clearAttachment instead of clearDepthStencil since Vulkan won't |
| 161 | // allow us to clear one or the other separately. |
| 162 | bool isSingleClearOnPackedDepthStencilAttachment = |
| 163 | depthStencilAttachment && (clearDepth != clearStencil); |
Jamie Madill | d47044a | 2018-04-27 11:45:03 -0400 | [diff] [blame] | 164 | if (glState.isScissorTestEnabled() || isSingleClearOnPackedDepthStencilAttachment) |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 165 | { |
| 166 | // With scissor test enabled, we clear very differently and we don't need to access |
| 167 | // the image inside each attachment we can just use clearCmdAttachments with our |
| 168 | // scissor region instead. |
Jamie Madill | 78cd940 | 2018-05-10 16:49:58 -0400 | [diff] [blame] | 169 | |
| 170 | // Masked stencil clears are currently not implemented. |
| 171 | // TODO(jmadill): Masked stencil clear. http://anglebug.com/2540 |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 172 | ANGLE_TRY(clearWithClearAttachments(contextVk, clearColor, clearDepth, clearStencil)); |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 173 | return gl::NoError(); |
| 174 | } |
| 175 | |
| 176 | // Standard Depth/stencil clear without scissor. |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 177 | if (clearDepth || clearStencil) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 178 | { |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 179 | ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 180 | writingNode = getCurrentWritingNode(); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 181 | |
| 182 | const VkClearDepthStencilValue &clearDepthStencilValue = |
| 183 | contextVk->getClearDepthStencilValue().depthStencil; |
| 184 | |
| 185 | // We only support packed depth/stencil, not separate. |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 186 | ASSERT(!(clearDepth && clearStencil) || depthStencilAttachment); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 187 | |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 188 | const VkImageAspectFlags aspectFlags = |
| 189 | (depthAttachment ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) | |
| 190 | (stencilAttachment ? VK_IMAGE_ASPECT_STENCIL_BIT : 0); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 191 | |
| 192 | RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil(); |
| 193 | renderTarget->resource->onWriteResource(writingNode, currentSerial); |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 194 | renderTarget->image->clearDepthStencil(aspectFlags, clearDepthStencilValue, commandBuffer); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 195 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 196 | if (!clearColor) |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 197 | { |
| 198 | return gl::NoError(); |
| 199 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 202 | ASSERT(clearColor); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 203 | const auto *attachment = mState.getFirstNonNullAttachment(); |
| 204 | ASSERT(attachment && attachment->isAttached()); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 205 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 206 | if (!commandBuffer) |
| 207 | { |
| 208 | ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 209 | writingNode = getCurrentWritingNode(); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 210 | } |
Jamie Madill | efb5a5c | 2018-01-29 15:56:59 -0500 | [diff] [blame] | 211 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 212 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 213 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 214 | const VkClearColorValue &clearColorValue = contextVk->getClearColorValue().color; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 215 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 216 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 217 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 218 | ASSERT(colorRenderTarget); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 219 | colorRenderTarget->resource->onWriteResource(writingNode, currentSerial); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 220 | colorRenderTarget->image->clearColor(clearColorValue, commandBuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 223 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 226 | gl::Error FramebufferVk::clearBufferfv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 227 | GLenum buffer, |
| 228 | GLint drawbuffer, |
| 229 | const GLfloat *values) |
| 230 | { |
| 231 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 232 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 233 | } |
| 234 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 235 | gl::Error FramebufferVk::clearBufferuiv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 236 | GLenum buffer, |
| 237 | GLint drawbuffer, |
| 238 | const GLuint *values) |
| 239 | { |
| 240 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 241 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 244 | gl::Error FramebufferVk::clearBufferiv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 245 | GLenum buffer, |
| 246 | GLint drawbuffer, |
| 247 | const GLint *values) |
| 248 | { |
| 249 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 250 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 253 | gl::Error FramebufferVk::clearBufferfi(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 254 | GLenum buffer, |
| 255 | GLint drawbuffer, |
| 256 | GLfloat depth, |
| 257 | GLint stencil) |
| 258 | { |
| 259 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 260 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 263 | GLenum FramebufferVk::getImplementationColorReadFormat(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 264 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 265 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).format; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 268 | GLenum FramebufferVk::getImplementationColorReadType(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 269 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 270 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).type; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 273 | gl::Error FramebufferVk::readPixels(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 274 | const gl::Rectangle &area, |
| 275 | GLenum format, |
| 276 | GLenum type, |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 277 | void *pixels) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 278 | { |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 279 | // Clip read area to framebuffer. |
| 280 | const gl::Extents &fbSize = getState().getReadAttachment()->getSize(); |
| 281 | const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height); |
| 282 | gl::Rectangle clippedArea; |
| 283 | if (!ClipRectangle(area, fbRect, &clippedArea)) |
| 284 | { |
| 285 | // nothing to read |
| 286 | return gl::NoError(); |
| 287 | } |
| 288 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 289 | const gl::State &glState = context->getGLState(); |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 290 | RenderTargetVk *renderTarget = getColorReadRenderTarget(); |
| 291 | ASSERT(renderTarget); |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 292 | |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 293 | const gl::PixelPackState &packState = context->getGLState().getPackState(); |
| 294 | const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type); |
| 295 | |
| 296 | GLuint outputPitch = 0; |
| 297 | ANGLE_TRY_RESULT( |
| 298 | sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, packState.rowLength), |
| 299 | outputPitch); |
| 300 | GLuint outputSkipBytes = 0; |
| 301 | ANGLE_TRY_RESULT(sizedFormatInfo.computeSkipBytes(outputPitch, 0, packState, false), |
| 302 | outputSkipBytes); |
| 303 | |
| 304 | outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + |
| 305 | (clippedArea.y - area.y) * outputPitch; |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 306 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 307 | PackPixelsParams params; |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 308 | params.area = area; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 309 | params.format = format; |
| 310 | params.type = type; |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 311 | params.outputPitch = outputPitch; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 312 | params.packBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelPack); |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 313 | params.pack = glState.getPackState(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 314 | |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 315 | vk::CommandBuffer *commandBuffer = nullptr; |
| 316 | ANGLE_TRY(beginWriteResource(vk::GetImpl(context)->getRenderer(), &commandBuffer)); |
| 317 | return ReadPixelsFromRenderTarget(context, clippedArea, params, renderTarget, commandBuffer, |
| 318 | reinterpret_cast<uint8_t *>(pixels) + outputSkipBytes); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 319 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 320 | |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 321 | RenderTargetVk *FramebufferVk::getColorReadRenderTarget() |
| 322 | { |
| 323 | RenderTargetVk *renderTarget = mRenderTargetCache.getColorRead(mState); |
| 324 | ASSERT(renderTarget && renderTarget->image->valid()); |
| 325 | return renderTarget; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 326 | } |
| 327 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 328 | gl::Error FramebufferVk::blit(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 329 | const gl::Rectangle &sourceArea, |
| 330 | const gl::Rectangle &destArea, |
| 331 | GLbitfield mask, |
| 332 | GLenum filter) |
| 333 | { |
| 334 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 335 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 338 | bool FramebufferVk::checkStatus(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 339 | { |
Jamie Madill | b79e7bb | 2017-10-24 13:55:50 -0400 | [diff] [blame] | 340 | return true; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 343 | gl::Error FramebufferVk::syncState(const gl::Context *context, |
| 344 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 345 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 346 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 347 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 348 | |
| 349 | ASSERT(dirtyBits.any()); |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 350 | for (size_t dirtyBit : dirtyBits) |
| 351 | { |
| 352 | switch (dirtyBit) |
| 353 | { |
| 354 | case gl::Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: |
| 355 | case gl::Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: |
| 356 | ANGLE_TRY(mRenderTargetCache.updateDepthStencilRenderTarget(context, mState)); |
| 357 | break; |
| 358 | case gl::Framebuffer::DIRTY_BIT_DRAW_BUFFERS: |
| 359 | case gl::Framebuffer::DIRTY_BIT_READ_BUFFER: |
| 360 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_WIDTH: |
| 361 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_HEIGHT: |
| 362 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_SAMPLES: |
| 363 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 364 | break; |
| 365 | default: |
| 366 | { |
| 367 | ASSERT(gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 && |
| 368 | dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX); |
| 369 | size_t colorIndex = |
| 370 | static_cast<size_t>(dirtyBit - gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 371 | ANGLE_TRY(mRenderTargetCache.updateColorRenderTarget(context, mState, colorIndex)); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 372 | |
| 373 | // Update cached masks for masked clears. |
| 374 | RenderTargetVk *renderTarget = mRenderTargetCache.getColors()[colorIndex]; |
| 375 | if (renderTarget) |
| 376 | { |
| 377 | const angle::Format &format = renderTarget->image->getFormat().textureFormat(); |
| 378 | updateActiveColorMasks(colorIndex, format.redBits > 0, format.greenBits > 0, |
| 379 | format.blueBits > 0, format.alphaBits > 0); |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | updateActiveColorMasks(colorIndex, 0, 0, 0, 0); |
| 384 | } |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 385 | break; |
| 386 | } |
| 387 | } |
| 388 | } |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 389 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 390 | mActiveColorComponents = gl_vk::GetColorComponentFlags( |
| 391 | mActiveColorComponentMasks[0].any(), mActiveColorComponentMasks[1].any(), |
| 392 | mActiveColorComponentMasks[2].any(), mActiveColorComponentMasks[3].any()); |
| 393 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 394 | mRenderPassDesc.reset(); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 395 | renderer->releaseResource(*this, &mFramebuffer); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 396 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 397 | // Trigger a new set of secondary commands next time we render to this FBO. |
| 398 | getNewWritingNode(renderer); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 399 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 400 | contextVk->invalidateCurrentPipeline(); |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 401 | |
| 402 | return gl::NoError(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 405 | const vk::RenderPassDesc &FramebufferVk::getRenderPassDesc() |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 406 | { |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 407 | if (mRenderPassDesc.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 408 | { |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 409 | return mRenderPassDesc.value(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 410 | } |
| 411 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 412 | vk::RenderPassDesc desc; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 413 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 414 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 415 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 416 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 417 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 418 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 419 | ASSERT(colorRenderTarget); |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 420 | desc.packColorAttachment(*colorRenderTarget->image); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 421 | } |
| 422 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 423 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 424 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 425 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 426 | desc.packDepthStencilAttachment(*depthStencilRenderTarget->image); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 427 | } |
| 428 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 429 | mRenderPassDesc = desc; |
| 430 | return mRenderPassDesc.value(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 431 | } |
| 432 | |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 433 | gl::ErrorOrResult<vk::Framebuffer *> FramebufferVk::getFramebuffer(RendererVk *rendererVk) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 434 | { |
| 435 | // If we've already created our cached Framebuffer, return it. |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 436 | if (mFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 437 | { |
| 438 | return &mFramebuffer; |
| 439 | } |
| 440 | |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 441 | const vk::RenderPassDesc &desc = getRenderPassDesc(); |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 442 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 443 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 444 | ANGLE_TRY(rendererVk->getCompatibleRenderPass(desc, &renderPass)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 445 | |
| 446 | // 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] | 447 | VkDevice device = rendererVk->getDevice(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 448 | if (mBackbuffer) |
| 449 | { |
| 450 | return mBackbuffer->getCurrentFramebuffer(device, *renderPass); |
| 451 | } |
| 452 | |
| 453 | // Gather VkImageViews over all FBO attachments, also size of attached region. |
| 454 | std::vector<VkImageView> attachments; |
| 455 | gl::Extents attachmentsSize; |
| 456 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 457 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 458 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 459 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 460 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 461 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 462 | ASSERT(colorRenderTarget); |
| 463 | attachments.push_back(colorRenderTarget->imageView->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 464 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 465 | ASSERT(attachmentsSize.empty() || |
| 466 | attachmentsSize == colorRenderTarget->image->getExtents()); |
| 467 | attachmentsSize = colorRenderTarget->image->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 468 | } |
| 469 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 470 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 471 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 472 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 473 | attachments.push_back(depthStencilRenderTarget->imageView->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 474 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 475 | ASSERT(attachmentsSize.empty() || |
| 476 | attachmentsSize == depthStencilRenderTarget->image->getExtents()); |
| 477 | attachmentsSize = depthStencilRenderTarget->image->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | ASSERT(!attachments.empty()); |
| 481 | |
| 482 | VkFramebufferCreateInfo framebufferInfo; |
| 483 | |
| 484 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 485 | framebufferInfo.pNext = nullptr; |
| 486 | framebufferInfo.flags = 0; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 487 | framebufferInfo.renderPass = renderPass->getHandle(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 488 | framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); |
| 489 | framebufferInfo.pAttachments = attachments.data(); |
| 490 | framebufferInfo.width = static_cast<uint32_t>(attachmentsSize.width); |
| 491 | framebufferInfo.height = static_cast<uint32_t>(attachmentsSize.height); |
| 492 | framebufferInfo.layers = 1; |
| 493 | |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 494 | ANGLE_TRY(mFramebuffer.init(device, framebufferInfo)); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 495 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 496 | return &mFramebuffer; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 499 | gl::Error FramebufferVk::clearWithClearAttachments(ContextVk *contextVk, |
| 500 | bool clearColor, |
| 501 | bool clearDepth, |
| 502 | bool clearStencil) |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 503 | { |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 504 | RendererVk *renderer = contextVk->getRenderer(); |
| 505 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 506 | getNewWritingNode(renderer); |
| 507 | |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 508 | // This command can only happen inside a render pass, so obtain one if its already happening |
| 509 | // or create a new one if not. |
| 510 | vk::CommandGraphNode *node = nullptr; |
| 511 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 512 | ANGLE_TRY(getCommandGraphNodeForDraw(contextVk, &node)); |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 513 | if (node->getInsideRenderPassCommands()->valid()) |
| 514 | { |
| 515 | commandBuffer = node->getInsideRenderPassCommands(); |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | ANGLE_TRY(node->beginInsideRenderPassRecording(renderer, &commandBuffer)); |
| 520 | } |
| 521 | |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 522 | // TODO(jmadill): Cube map attachments. http://anglebug.com/2470 |
| 523 | // We assume for now that we always need to clear only 1 layer starting at the |
| 524 | // baseArrayLayer 0, this might need to change depending how we'll implement |
| 525 | // cube maps, 3d textures and array textures. |
| 526 | VkClearRect clearRect; |
| 527 | clearRect.baseArrayLayer = 0; |
| 528 | clearRect.layerCount = 1; |
| 529 | |
| 530 | // When clearing, the scissor region must be clipped to the renderArea per the validation rules |
| 531 | // in Vulkan. |
| 532 | gl::Rectangle intersection; |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 533 | if (!gl::ClipRectangle(contextVk->getGLState().getScissor(), node->getRenderPassRenderArea(), |
| 534 | &intersection)) |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 535 | { |
| 536 | // There is nothing to clear since the scissor is outside of the render area. |
| 537 | return gl::NoError(); |
| 538 | } |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 539 | clearRect.rect = gl_vk::GetRect(intersection); |
| 540 | |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 541 | gl::AttachmentArray<VkClearAttachment> clearAttachments; |
| 542 | int clearAttachmentIndex = 0; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 543 | |
| 544 | if (clearColor) |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 545 | { |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 546 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 547 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
| 548 | { |
| 549 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 550 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 551 | clearAttachment.colorAttachment = static_cast<uint32_t>(colorIndex); |
| 552 | clearAttachment.clearValue = contextVk->getClearColorValue(); |
| 553 | ++clearAttachmentIndex; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | if (clearDepth && clearStencil && mState.getDepthStencilAttachment() != nullptr) |
| 558 | { |
| 559 | // When we have a packed depth/stencil attachment we can do 1 clear for both when it |
| 560 | // applies. |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 561 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 562 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 563 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
| 564 | clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 565 | ++clearAttachmentIndex; |
| 566 | } |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 567 | else |
| 568 | { |
| 569 | if (clearDepth) |
| 570 | { |
| 571 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 572 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 573 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
| 574 | clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); |
| 575 | ++clearAttachmentIndex; |
| 576 | } |
| 577 | |
| 578 | if (clearStencil) |
| 579 | { |
| 580 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 581 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 582 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
| 583 | clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); |
| 584 | ++clearAttachmentIndex; |
| 585 | } |
| 586 | } |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 587 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 588 | commandBuffer->clearAttachments(static_cast<uint32_t>(clearAttachmentIndex), |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 589 | clearAttachments.data(), 1, &clearRect); |
| 590 | return gl::NoError(); |
| 591 | } |
| 592 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 593 | gl::Error FramebufferVk::clearWithDraw(ContextVk *contextVk, VkColorComponentFlags colorMaskFlags) |
| 594 | { |
| 595 | RendererVk *renderer = contextVk->getRenderer(); |
| 596 | vk::ShaderLibrary *shaderLibrary = renderer->getShaderLibrary(); |
| 597 | |
| 598 | const vk::ShaderAndSerial *fullScreenQuad = nullptr; |
| 599 | ANGLE_TRY(shaderLibrary->getShader(renderer, vk::InternalShaderID::FullScreenQuad_vert, |
| 600 | &fullScreenQuad)); |
| 601 | |
| 602 | const vk::ShaderAndSerial *uniformColor = nullptr; |
| 603 | ANGLE_TRY( |
| 604 | shaderLibrary->getShader(renderer, vk::InternalShaderID::UniformColor_frag, &uniformColor)); |
| 605 | |
| 606 | const vk::PipelineLayout *pipelineLayout = nullptr; |
| 607 | ANGLE_TRY(renderer->getInternalUniformPipelineLayout(&pipelineLayout)); |
| 608 | |
| 609 | vk::CommandBuffer *commandBuffer = nullptr; |
| 610 | ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); |
| 611 | |
| 612 | vk::CommandGraphNode *node = nullptr; |
| 613 | ANGLE_TRY(getCommandGraphNodeForDraw(contextVk, &node)); |
| 614 | |
| 615 | // This pipeline desc could be cached. |
| 616 | vk::PipelineDesc pipelineDesc; |
| 617 | pipelineDesc.initDefaults(); |
| 618 | pipelineDesc.updateColorWriteMask(colorMaskFlags); |
| 619 | pipelineDesc.updateRenderPassDesc(getRenderPassDesc()); |
| 620 | pipelineDesc.updateShaders(fullScreenQuad->queueSerial(), uniformColor->queueSerial()); |
| 621 | pipelineDesc.updateViewport(node->getRenderPassRenderArea(), 0.0f, 1.0f); |
| 622 | |
| 623 | const gl::State &glState = contextVk->getGLState(); |
| 624 | if (glState.isScissorTestEnabled()) |
| 625 | { |
| 626 | gl::Rectangle intersection; |
| 627 | if (!gl::ClipRectangle(glState.getScissor(), node->getRenderPassRenderArea(), |
| 628 | &intersection)) |
| 629 | { |
| 630 | return gl::NoError(); |
| 631 | } |
| 632 | |
| 633 | pipelineDesc.updateScissor(intersection); |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | pipelineDesc.updateScissor(node->getRenderPassRenderArea()); |
| 638 | } |
| 639 | |
| 640 | vk::PipelineAndSerial *pipeline = nullptr; |
| 641 | ANGLE_TRY(renderer->getInternalPipeline(*fullScreenQuad, *uniformColor, *pipelineLayout, |
| 642 | pipelineDesc, gl::AttributesMask(), &pipeline)); |
| 643 | pipeline->updateSerial(renderer->getCurrentQueueSerial()); |
| 644 | |
| 645 | VkDevice device = renderer->getDevice(); |
| 646 | |
| 647 | if (!mMaskedClearUniformBuffer.buffer.valid()) |
| 648 | { |
| 649 | ASSERT(mMaskedClearDescriptorSet == VK_NULL_HANDLE); |
| 650 | |
| 651 | VkBufferUsageFlags bufferUsage = |
| 652 | (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT); |
| 653 | |
| 654 | VkBufferCreateInfo uniformBufferInfo; |
| 655 | uniformBufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 656 | uniformBufferInfo.pNext = nullptr; |
| 657 | uniformBufferInfo.flags = 0; |
| 658 | uniformBufferInfo.size = sizeof(VkClearColorValue); |
| 659 | uniformBufferInfo.usage = bufferUsage; |
| 660 | uniformBufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 661 | uniformBufferInfo.queueFamilyIndexCount = 0; |
| 662 | uniformBufferInfo.pQueueFamilyIndices = nullptr; |
| 663 | |
| 664 | ANGLE_TRY(mMaskedClearUniformBuffer.buffer.init(device, uniformBufferInfo)); |
| 665 | |
| 666 | VkMemoryPropertyFlags memoryFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 667 | size_t requiredSize = 0; |
| 668 | ANGLE_TRY(vk::AllocateBufferMemory(renderer, memoryFlags, &mMaskedClearUniformBuffer.buffer, |
| 669 | &mMaskedClearUniformBuffer.memory, &requiredSize)); |
| 670 | |
| 671 | const vk::DescriptorSetLayout &descriptorSetLayout = |
| 672 | renderer->getInternalUniformDescriptorSetLayout(); |
| 673 | |
| 674 | // This might confuse the dynamic descriptor pool's counting, but it shouldn't cause |
| 675 | // overflow. |
| 676 | vk::DynamicDescriptorPool *descriptorPool = contextVk->getDynamicDescriptorPool(); |
| 677 | descriptorPool->allocateDescriptorSets(contextVk, descriptorSetLayout.ptr(), 1, |
| 678 | &mMaskedClearDescriptorSet); |
| 679 | |
| 680 | VkDescriptorBufferInfo bufferInfo; |
| 681 | bufferInfo.buffer = mMaskedClearUniformBuffer.buffer.getHandle(); |
| 682 | bufferInfo.offset = 0; |
| 683 | bufferInfo.range = VK_WHOLE_SIZE; |
| 684 | |
| 685 | VkWriteDescriptorSet writeSet; |
| 686 | writeSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 687 | writeSet.pNext = nullptr; |
| 688 | writeSet.dstSet = mMaskedClearDescriptorSet; |
| 689 | writeSet.dstBinding = 1; |
| 690 | writeSet.dstArrayElement = 0; |
| 691 | writeSet.descriptorCount = 1; |
| 692 | writeSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 693 | writeSet.pImageInfo = nullptr; |
| 694 | writeSet.pBufferInfo = &bufferInfo; |
| 695 | writeSet.pTexelBufferView = nullptr; |
| 696 | |
| 697 | vkUpdateDescriptorSets(device, 1, &writeSet, 0, nullptr); |
| 698 | } |
| 699 | |
| 700 | VkClearColorValue clearColorValue = contextVk->getClearColorValue().color; |
| 701 | commandBuffer->updateBuffer(mMaskedClearUniformBuffer.buffer, 0, sizeof(VkClearColorValue), |
| 702 | clearColorValue.float32); |
| 703 | |
| 704 | vk::CommandBuffer *drawCommandBuffer = nullptr; |
| 705 | ANGLE_TRY(node->beginInsideRenderPassRecording(renderer, &drawCommandBuffer)); |
| 706 | |
| 707 | std::array<uint32_t, 2> dynamicOffsets = {{0, 0}}; |
| 708 | drawCommandBuffer->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0, 1, |
| 709 | &mMaskedClearDescriptorSet, 2, dynamicOffsets.data()); |
| 710 | |
| 711 | // TODO(jmadill): Masked combined color and depth/stencil clear. http://anglebug.com/2455 |
| 712 | // Any active queries submitted by the user should also be paused here. |
| 713 | drawCommandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->get()); |
| 714 | drawCommandBuffer->draw(6, 1, 0, 0); |
| 715 | |
| 716 | return gl::NoError(); |
| 717 | } |
| 718 | |
Geoff Lang | 1345507 | 2018-05-09 11:24:43 -0400 | [diff] [blame] | 719 | gl::Error FramebufferVk::getSamplePosition(const gl::Context *context, |
| 720 | size_t index, |
| 721 | GLfloat *xy) const |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 722 | { |
| 723 | UNIMPLEMENTED(); |
| 724 | return gl::InternalError() << "getSamplePosition is unimplemented."; |
| 725 | } |
| 726 | |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 727 | gl::Error FramebufferVk::getCommandGraphNodeForDraw(ContextVk *contextVk, |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 728 | vk::CommandGraphNode **nodeOut) |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 729 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 730 | RendererVk *renderer = contextVk->getRenderer(); |
| 731 | Serial currentSerial = renderer->getCurrentQueueSerial(); |
Jamie Madill | bef918c | 2017-12-13 13:11:30 -0500 | [diff] [blame] | 732 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 733 | // This will reset the current writing node if it has been completed. |
| 734 | updateQueueSerial(currentSerial); |
| 735 | |
| 736 | if (hasChildlessWritingNode()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 737 | { |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 738 | *nodeOut = getCurrentWritingNode(); |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | *nodeOut = getNewWritingNode(renderer); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 743 | } |
| 744 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 745 | if ((*nodeOut)->getInsideRenderPassCommands()->valid()) |
| 746 | { |
| 747 | return gl::NoError(); |
| 748 | } |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 749 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 750 | vk::Framebuffer *framebuffer = nullptr; |
Jamie Madill | b90779e | 2018-04-27 11:45:01 -0400 | [diff] [blame] | 751 | ANGLE_TRY_RESULT(getFramebuffer(renderer), framebuffer); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 752 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 753 | std::vector<VkClearValue> attachmentClearValues; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 754 | |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 755 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 756 | if (!(*nodeOut)->getOutsideRenderPassCommands()->valid()) |
| 757 | { |
| 758 | ANGLE_TRY((*nodeOut)->beginOutsideRenderPassRecording( |
| 759 | renderer->getDevice(), renderer->getCommandPool(), &commandBuffer)); |
| 760 | } |
| 761 | else |
| 762 | { |
| 763 | commandBuffer = (*nodeOut)->getOutsideRenderPassCommands(); |
| 764 | } |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 765 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 766 | // Initialize RenderPass info. |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 767 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 768 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 769 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 770 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 771 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 772 | ASSERT(colorRenderTarget); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 773 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 774 | (*nodeOut)->appendColorRenderTarget(currentSerial, colorRenderTarget); |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 775 | attachmentClearValues.emplace_back(contextVk->getClearColorValue()); |
| 776 | } |
| 777 | |
| 778 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 779 | if (depthStencilRenderTarget) |
| 780 | { |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 781 | (*nodeOut)->appendDepthStencilRenderTarget(currentSerial, depthStencilRenderTarget); |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 782 | attachmentClearValues.emplace_back(contextVk->getClearDepthStencilValue()); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 783 | } |
| 784 | |
Luc Ferron | d17bdfe | 2018-04-05 13:50:10 -0400 | [diff] [blame] | 785 | gl::Rectangle renderArea = |
| 786 | gl::Rectangle(0, 0, mState.getDimensions().width, mState.getDimensions().height); |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 787 | // Hard-code RenderPass to clear the first render target to the current clear value. |
| 788 | // TODO(jmadill): Proper clear value implementation. http://anglebug.com/2361 |
Luc Ferron | d17bdfe | 2018-04-05 13:50:10 -0400 | [diff] [blame] | 789 | (*nodeOut)->storeRenderPassInfo(*framebuffer, renderArea, attachmentClearValues); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 790 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 791 | return gl::NoError(); |
| 792 | } |
| 793 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 794 | void FramebufferVk::updateActiveColorMasks(size_t colorIndex, bool r, bool g, bool b, bool a) |
| 795 | { |
| 796 | mActiveColorComponentMasks[0].set(colorIndex, r); |
| 797 | mActiveColorComponentMasks[1].set(colorIndex, g); |
| 798 | mActiveColorComponentMasks[2].set(colorIndex, b); |
| 799 | mActiveColorComponentMasks[3].set(colorIndex, a); |
| 800 | } |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 801 | |
| 802 | gl::Error ReadPixelsFromRenderTarget(const gl::Context *context, |
| 803 | const gl::Rectangle &area, |
| 804 | const PackPixelsParams &packPixelsParams, |
| 805 | RenderTargetVk *renderTarget, |
| 806 | vk::CommandBuffer *commandBuffer, |
| 807 | void *pixels) |
| 808 | { |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 809 | ContextVk *contextVk = vk::GetImpl(context); |
| 810 | RendererVk *renderer = contextVk->getRenderer(); |
| 811 | VkDevice device = renderer->getDevice(); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 812 | |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 813 | vk::ImageHelper stagingImage; |
| 814 | ANGLE_TRY(stagingImage.init2DStaging( |
| 815 | device, renderer->getMemoryProperties(), renderTarget->image->getFormat(), |
| 816 | gl::Extents(area.width, area.height, 1), vk::StagingUsage::Read)); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 817 | |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 818 | stagingImage.changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, |
| 819 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 820 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 821 | |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 822 | vk::ImageHelper::Copy(renderTarget->image, &stagingImage, gl::Offset(area.x, area.y, 0), |
| 823 | gl::Offset(), gl::Extents(area.width, area.height, 1), |
| 824 | VK_IMAGE_ASPECT_COLOR_BIT, commandBuffer); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 825 | |
| 826 | // Triggers a full finish. |
| 827 | // TODO(jmadill): Don't block on asynchronous readback. |
| 828 | ANGLE_TRY(renderer->finish(context)); |
| 829 | |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 830 | // TODO(jmadill): parameters |
| 831 | uint8_t *mapPointer = nullptr; |
| 832 | ANGLE_TRY(stagingImage.getDeviceMemory().map(device, 0, stagingImage.getAllocatedMemorySize(), |
| 833 | 0, &mapPointer)); |
Yuly Novikov | 6c6c76c | 2018-05-17 18:45:06 +0000 | [diff] [blame] | 834 | |
Luc Ferron | dd56578 | 2018-05-18 11:39:49 -0400 | [diff] [blame] | 835 | const angle::Format &angleFormat = renderTarget->image->getFormat().textureFormat(); |
| 836 | |
| 837 | // Get the staging image pitch and use it to pack the pixels later. |
| 838 | VkSubresourceLayout subresourceLayout; |
| 839 | stagingImage.getImage().getSubresourceLayout(device, VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, |
| 840 | &subresourceLayout); |
| 841 | |
| 842 | PackPixels(packPixelsParams, angleFormat, static_cast<int>(subresourceLayout.rowPitch), |
| 843 | mapPointer, reinterpret_cast<uint8_t *>(pixels)); |
| 844 | |
| 845 | stagingImage.getDeviceMemory().unmap(device); |
| 846 | renderer->releaseObject(renderer->getCurrentQueueSerial(), &stagingImage); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 847 | |
| 848 | return vk::NoError(); |
| 849 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 850 | } // namespace rx |