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 | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
| 17 | #include "libANGLE/Display.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 18 | #include "libANGLE/formatutils.h" |
| 19 | #include "libANGLE/renderer/renderer_utils.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 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" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 26 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Tobin Ehlis | 4a41914 | 2019-02-05 08:50:30 -0700 | [diff] [blame] | 27 | #include "third_party/trace_event/trace_event.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 | { |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 34 | constexpr size_t kMinReadPixelsBufferSize = 128000; |
| 35 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 36 | const gl::InternalFormat &GetReadAttachmentInfo(const gl::Context *context, |
| 37 | RenderTargetVk *renderTarget) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 38 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 39 | GLenum implFormat = |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 40 | renderTarget->getImageFormat().textureFormat().fboImplementationInternalFormat; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 41 | return gl::GetSizedInternalFormatInfo(implFormat); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 42 | } |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 43 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 44 | bool ClipToRenderTarget(const gl::Rectangle &area, |
| 45 | RenderTargetVk *renderTarget, |
| 46 | gl::Rectangle *rectOut) |
| 47 | { |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 48 | const gl::Extents renderTargetExtents = renderTarget->getExtents(); |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 49 | gl::Rectangle renderTargetRect(0, 0, renderTargetExtents.width, renderTargetExtents.height); |
| 50 | return ClipRectangle(area, renderTargetRect, rectOut); |
| 51 | } |
| 52 | |
Shahbaz Youssefi | 96bd8fd | 2018-11-30 14:30:18 -0500 | [diff] [blame] | 53 | bool HasSrcAndDstBlitProperties(RendererVk *renderer, |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 54 | RenderTargetVk *srcRenderTarget, |
| 55 | RenderTargetVk *dstRenderTarget) |
| 56 | { |
Shahbaz Youssefi | 96bd8fd | 2018-11-30 14:30:18 -0500 | [diff] [blame] | 57 | const VkFormat srcFormat = srcRenderTarget->getImageFormat().vkTextureFormat; |
| 58 | const VkFormat dstFormat = dstRenderTarget->getImageFormat().vkTextureFormat; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 59 | |
| 60 | // Verifies if the draw and read images have the necessary prerequisites for blitting. |
Shahbaz Youssefi | 96bd8fd | 2018-11-30 14:30:18 -0500 | [diff] [blame] | 61 | return renderer->hasTextureFormatFeatureBits(srcFormat, VK_FORMAT_FEATURE_BLIT_SRC_BIT) && |
| 62 | renderer->hasTextureFormatFeatureBits(dstFormat, VK_FORMAT_FEATURE_BLIT_DST_BIT); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 63 | } |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 64 | |
| 65 | // Special rules apply to VkBufferImageCopy with depth/stencil. The components are tightly packed |
| 66 | // into a depth or stencil section of the destination buffer. See the spec: |
| 67 | // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkBufferImageCopy.html |
| 68 | const angle::Format &GetDepthStencilImageToBufferFormat(const angle::Format &imageFormat, |
| 69 | VkImageAspectFlagBits copyAspect) |
| 70 | { |
| 71 | if (copyAspect == VK_IMAGE_ASPECT_STENCIL_BIT) |
| 72 | { |
| 73 | ASSERT(imageFormat.id == angle::FormatID::D24_UNORM_S8_UINT || |
| 74 | imageFormat.id == angle::FormatID::D32_FLOAT_S8X24_UINT || |
| 75 | imageFormat.id == angle::FormatID::S8_UINT); |
| 76 | return angle::Format::Get(angle::FormatID::S8_UINT); |
| 77 | } |
| 78 | |
| 79 | ASSERT(copyAspect == VK_IMAGE_ASPECT_DEPTH_BIT); |
| 80 | |
| 81 | switch (imageFormat.id) |
| 82 | { |
| 83 | case angle::FormatID::D16_UNORM: |
| 84 | return imageFormat; |
| 85 | case angle::FormatID::D24_UNORM_X8_UINT: |
| 86 | return imageFormat; |
| 87 | case angle::FormatID::D24_UNORM_S8_UINT: |
| 88 | return angle::Format::Get(angle::FormatID::D24_UNORM_X8_UINT); |
| 89 | case angle::FormatID::D32_FLOAT: |
| 90 | return imageFormat; |
| 91 | case angle::FormatID::D32_FLOAT_S8X24_UINT: |
| 92 | return angle::Format::Get(angle::FormatID::D32_FLOAT); |
| 93 | default: |
| 94 | UNREACHABLE(); |
| 95 | return imageFormat; |
| 96 | } |
| 97 | } |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 98 | } // anonymous namespace |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 99 | |
| 100 | // static |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 101 | FramebufferVk *FramebufferVk::CreateUserFBO(RendererVk *renderer, const gl::FramebufferState &state) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 102 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 103 | return new FramebufferVk(renderer, state, nullptr); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // static |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 107 | FramebufferVk *FramebufferVk::CreateDefaultFBO(RendererVk *renderer, |
| 108 | const gl::FramebufferState &state, |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 109 | WindowSurfaceVk *backbuffer) |
| 110 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 111 | return new FramebufferVk(renderer, state, backbuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 112 | } |
| 113 | |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 114 | FramebufferVk::FramebufferVk(RendererVk *renderer, |
| 115 | const gl::FramebufferState &state, |
| 116 | WindowSurfaceVk *backbuffer) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 117 | : FramebufferImpl(state), |
| 118 | mBackbuffer(backbuffer), |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 119 | mActiveColorComponents(0), |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 120 | mReadPixelBuffer(VK_BUFFER_USAGE_TRANSFER_DST_BIT, kMinReadPixelsBufferSize, true), |
| 121 | mBlitPixelBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, kMinReadPixelsBufferSize, true) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 122 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 123 | mBlitPixelBuffer.init(1, renderer); |
Frank Henigman | 49b0f6e | 2018-10-03 23:15:29 -0400 | [diff] [blame] | 124 | mReadPixelBuffer.init(4, renderer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 127 | FramebufferVk::~FramebufferVk() = default; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 128 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 129 | void FramebufferVk::destroy(const gl::Context *context) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 130 | { |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 131 | ContextVk *contextVk = vk::GetImpl(context); |
| 132 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 133 | mFramebuffer.release(renderer); |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 134 | |
Shahbaz Youssefi | fca8fd6 | 2018-11-13 13:55:48 -0500 | [diff] [blame] | 135 | mReadPixelBuffer.release(renderer); |
| 136 | mBlitPixelBuffer.release(renderer); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 137 | } |
| 138 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 139 | angle::Result FramebufferVk::discard(const gl::Context *context, |
| 140 | size_t count, |
| 141 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 142 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 143 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 144 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 147 | angle::Result FramebufferVk::invalidate(const gl::Context *context, |
| 148 | size_t count, |
| 149 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 150 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 151 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 152 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 155 | angle::Result FramebufferVk::invalidateSub(const gl::Context *context, |
| 156 | size_t count, |
| 157 | const GLenum *attachments, |
| 158 | const gl::Rectangle &area) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 159 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 160 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 161 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 164 | angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 165 | { |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 166 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 167 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 168 | // This command buffer is only started once. |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 169 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 170 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 171 | const gl::FramebufferAttachment *depthAttachment = mState.getDepthAttachment(); |
| 172 | bool clearDepth = (depthAttachment && (mask & GL_DEPTH_BUFFER_BIT) != 0); |
| 173 | ASSERT(!clearDepth || depthAttachment->isAttached()); |
| 174 | |
Shahbaz Youssefi | 2197dc5 | 2018-10-30 11:29:58 -0400 | [diff] [blame] | 175 | // If depth write is disabled, pretend that GL_DEPTH_BUFFER_BIT is not specified altogether. |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 176 | clearDepth = clearDepth && contextVk->getState().getDepthStencilState().depthMask; |
Shahbaz Youssefi | 2197dc5 | 2018-10-30 11:29:58 -0400 | [diff] [blame] | 177 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 178 | const gl::FramebufferAttachment *stencilAttachment = mState.getStencilAttachment(); |
| 179 | bool clearStencil = (stencilAttachment && (mask & GL_STENCIL_BUFFER_BIT) != 0); |
| 180 | ASSERT(!clearStencil || stencilAttachment->isAttached()); |
| 181 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 182 | bool clearColor = IsMaskFlagSet(static_cast<int>(mask), GL_COLOR_BUFFER_BIT); |
| 183 | |
Shahbaz Youssefi | 02a579e | 2019-03-27 14:21:20 -0400 | [diff] [blame^] | 184 | // If the only thing to be cleared was depth and it's masked, there's nothing to do. |
| 185 | if (!clearColor && !clearDepth && !clearStencil) |
| 186 | { |
| 187 | return angle::Result::Continue; |
| 188 | } |
| 189 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 190 | const gl::State &glState = context->getState(); |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 191 | |
| 192 | VkClearDepthStencilValue clearDepthStencilValue = |
| 193 | contextVk->getClearDepthStencilValue().depthStencil; |
| 194 | |
| 195 | // Apply the stencil mask to the clear value. |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 196 | clearDepthStencilValue.stencil &= contextVk->getState().getDepthStencilState().stencilWritemask; |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 197 | |
| 198 | // If the depth or stencil is being cleared, and the image was originally requested to have a |
| 199 | // single aspect, but it's emulated with a depth/stencil format, clear both aspects, setting the |
| 200 | // other aspect to 0. |
| 201 | if (clearStencil || clearDepth) |
| 202 | { |
| 203 | RenderTargetVk *depthStencil = mRenderTargetCache.getDepthStencil(); |
| 204 | const vk::Format &format = depthStencil->getImageFormat(); |
| 205 | |
| 206 | // GL_DEPTH_COMPONENT24 is always emulated with a format that has stencil. |
| 207 | if (format.angleFormat().stencilBits == 0) |
| 208 | { |
| 209 | clearStencil = true; |
| 210 | clearDepthStencilValue.stencil = 0; |
| 211 | } |
| 212 | // GL_STENCIL_INDEX8 may or may not be emulated. |
| 213 | else if (format.angleFormat().depthBits == 0 && format.vkTextureFormat != VK_FORMAT_S8_UINT) |
| 214 | { |
| 215 | clearDepth = true; |
| 216 | clearDepthStencilValue.depth = 0; |
| 217 | } |
| 218 | } |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 219 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 220 | // The most costly clear mode is when we need to mask out specific color channels. This can |
| 221 | // only be done with a draw call. The scissor region however can easily be integrated with |
| 222 | // this method. Similarly for depth/stencil clear. |
| 223 | VkColorComponentFlags colorMaskFlags = contextVk->getClearColorMask(); |
| 224 | if (clearColor && (mActiveColorComponents & colorMaskFlags) != mActiveColorComponents) |
| 225 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 226 | ANGLE_TRY(clearWithDraw(contextVk, colorMaskFlags)); |
Jamie Madill | 78cd940 | 2018-05-10 16:49:58 -0400 | [diff] [blame] | 227 | |
| 228 | // Stencil clears must be handled separately. The only way to write out a stencil value from |
| 229 | // a fragment shader in Vulkan is with VK_EXT_shader_stencil_export. Support for this |
| 230 | // extension is sparse. Hence, we call into the RenderPass clear path. We similarly clear |
| 231 | // depth to keep the code simple, but depth clears could be combined with the masked color |
| 232 | // clears as an optimization. |
| 233 | |
| 234 | if (clearDepth || clearStencil) |
| 235 | { |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 236 | ANGLE_TRY(clearWithClearAttachments(contextVk, false, clearDepth, clearStencil, |
| 237 | clearDepthStencilValue)); |
Jamie Madill | 78cd940 | 2018-05-10 16:49:58 -0400 | [diff] [blame] | 238 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 239 | return angle::Result::Continue; |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 240 | } |
| 241 | |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 242 | if (glState.isScissorTestEnabled()) |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 243 | { |
| 244 | // With scissor test enabled, we clear very differently and we don't need to access |
| 245 | // the image inside each attachment we can just use clearCmdAttachments with our |
| 246 | // scissor region instead. |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 247 | ANGLE_TRY(clearWithClearAttachments(contextVk, clearColor, clearDepth, clearStencil, |
| 248 | clearDepthStencilValue)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 249 | return angle::Result::Continue; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // Standard Depth/stencil clear without scissor. |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 253 | if (clearDepth || clearStencil) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 254 | { |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 255 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 256 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 257 | RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil(); |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 258 | const angle::Format &format = renderTarget->getImageFormat().textureFormat(); |
| 259 | const VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format); |
| 260 | |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 261 | VkImageAspectFlags clearAspects = aspectFlags; |
| 262 | if (!clearDepth) |
| 263 | { |
| 264 | clearAspects &= ~VK_IMAGE_ASPECT_DEPTH_BIT; |
| 265 | } |
| 266 | if (!clearStencil) |
| 267 | { |
| 268 | clearAspects &= ~VK_IMAGE_ASPECT_STENCIL_BIT; |
| 269 | } |
| 270 | |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 271 | vk::ImageHelper *image = renderTarget->getImageForWrite(&mFramebuffer); |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 272 | image->clearDepthStencil(aspectFlags, clearAspects, clearDepthStencilValue, commandBuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 273 | } |
| 274 | |
Luc Ferron | d3ab307 | 2018-06-19 09:55:04 -0400 | [diff] [blame] | 275 | if (!clearColor) |
| 276 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 277 | return angle::Result::Continue; |
Luc Ferron | d3ab307 | 2018-06-19 09:55:04 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 280 | const auto *attachment = mState.getFirstNonNullAttachment(); |
| 281 | ASSERT(attachment && attachment->isAttached()); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 282 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 283 | if (!commandBuffer) |
| 284 | { |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 285 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 286 | } |
Jamie Madill | efb5a5c | 2018-01-29 15:56:59 -0500 | [diff] [blame] | 287 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 288 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame] | 289 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 290 | const VkClearColorValue &clearColorValue = contextVk->getClearColorValue().color; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 291 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 292 | { |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 293 | VkClearColorValue modifiedClearColorValue = clearColorValue; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 294 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 295 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 296 | // It's possible we're clearing a render target that has no alpha channel but we represent |
| 297 | // it with a texture that has one. We must not affect its alpha channel no matter what the |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 298 | // clear value is in that case. |
| 299 | if (mEmulatedAlphaAttachmentMask[colorIndex]) |
| 300 | { |
| 301 | modifiedClearColorValue.float32[3] = 1.0; |
| 302 | } |
| 303 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 304 | ASSERT(colorRenderTarget); |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 305 | vk::ImageHelper *image = colorRenderTarget->getImageForWrite(&mFramebuffer); |
Jamie Madill | 3f3b358 | 2018-09-14 10:38:44 -0400 | [diff] [blame] | 306 | |
| 307 | // If we're clearing a cube map face ensure we only clear the selected layer. |
Geoff Lang | 4a29870 | 2019-01-18 10:49:36 -0500 | [diff] [blame] | 308 | image->clearColorLayer(modifiedClearColorValue, colorRenderTarget->getLevelIndex(), 1, |
Jamie Madill | 3f3b358 | 2018-09-14 10:38:44 -0400 | [diff] [blame] | 309 | colorRenderTarget->getLayerIndex(), 1, commandBuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 310 | } |
| 311 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 312 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 315 | angle::Result FramebufferVk::clearBufferfv(const gl::Context *context, |
| 316 | GLenum buffer, |
| 317 | GLint drawbuffer, |
| 318 | const GLfloat *values) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 319 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 320 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 321 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 324 | angle::Result FramebufferVk::clearBufferuiv(const gl::Context *context, |
| 325 | GLenum buffer, |
| 326 | GLint drawbuffer, |
| 327 | const GLuint *values) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 328 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 329 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 330 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 333 | angle::Result FramebufferVk::clearBufferiv(const gl::Context *context, |
| 334 | GLenum buffer, |
| 335 | GLint drawbuffer, |
| 336 | const GLint *values) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 337 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 338 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 339 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 340 | } |
| 341 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 342 | angle::Result FramebufferVk::clearBufferfi(const gl::Context *context, |
| 343 | GLenum buffer, |
| 344 | GLint drawbuffer, |
| 345 | GLfloat depth, |
| 346 | GLint stencil) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 347 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 348 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 349 | return angle::Result::Stop; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 352 | GLenum FramebufferVk::getImplementationColorReadFormat(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 353 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 354 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).format; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 357 | GLenum FramebufferVk::getImplementationColorReadType(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 358 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 359 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).type; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 360 | } |
| 361 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 362 | angle::Result FramebufferVk::readPixels(const gl::Context *context, |
| 363 | const gl::Rectangle &area, |
| 364 | GLenum format, |
| 365 | GLenum type, |
| 366 | void *pixels) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 367 | { |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 368 | // Clip read area to framebuffer. |
| 369 | const gl::Extents &fbSize = getState().getReadAttachment()->getSize(); |
| 370 | const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 371 | ContextVk *contextVk = vk::GetImpl(context); |
| 372 | RendererVk *renderer = contextVk->getRenderer(); |
| 373 | |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 374 | gl::Rectangle clippedArea; |
| 375 | if (!ClipRectangle(area, fbRect, &clippedArea)) |
| 376 | { |
| 377 | // nothing to read |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 378 | return angle::Result::Continue; |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 379 | } |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 380 | gl::Rectangle flippedArea = clippedArea; |
Geoff Lang | e076a23 | 2018-07-16 15:34:05 -0400 | [diff] [blame] | 381 | if (contextVk->isViewportFlipEnabledForReadFBO()) |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 382 | { |
| 383 | flippedArea.y = fbRect.height - flippedArea.y - flippedArea.height; |
| 384 | } |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 385 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 386 | const gl::State &glState = context->getState(); |
Frank Henigman | 1ffad84 | 2018-09-24 23:40:45 -0400 | [diff] [blame] | 387 | const gl::PixelPackState &packState = glState.getPackState(); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 388 | |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 389 | const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type); |
| 390 | |
| 391 | GLuint outputPitch = 0; |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 392 | ANGLE_VK_CHECK_MATH(contextVk, |
| 393 | sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, |
| 394 | packState.rowLength, &outputPitch)); |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 395 | GLuint outputSkipBytes = 0; |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 396 | ANGLE_VK_CHECK_MATH(contextVk, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState, |
| 397 | false, &outputSkipBytes)); |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 398 | |
| 399 | outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + |
| 400 | (clippedArea.y - area.y) * outputPitch; |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 401 | |
Jamie Madill | db9c69e | 2018-07-18 17:23:47 -0400 | [diff] [blame] | 402 | const angle::Format &angleFormat = GetFormatFromFormatType(format, type); |
| 403 | |
Frank Henigman | 1ffad84 | 2018-09-24 23:40:45 -0400 | [diff] [blame] | 404 | PackPixelsParams params(flippedArea, angleFormat, outputPitch, packState.reverseRowOrder, |
Jamie Madill | db9c69e | 2018-07-18 17:23:47 -0400 | [diff] [blame] | 405 | glState.getTargetBuffer(gl::BufferBinding::PixelPack), 0); |
Frank Henigman | 1ffad84 | 2018-09-24 23:40:45 -0400 | [diff] [blame] | 406 | if (contextVk->isViewportFlipEnabledForReadFBO()) |
| 407 | { |
| 408 | params.reverseRowOrder = !params.reverseRowOrder; |
| 409 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 410 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 411 | ANGLE_TRY(readPixelsImpl(contextVk, flippedArea, params, VK_IMAGE_ASPECT_COLOR_BIT, |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 412 | getColorReadRenderTarget(), |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 413 | static_cast<uint8_t *>(pixels) + outputSkipBytes)); |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 414 | mReadPixelBuffer.releaseRetainedBuffers(renderer); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 415 | return angle::Result::Continue; |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 416 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 417 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 418 | RenderTargetVk *FramebufferVk::getDepthStencilRenderTarget() const |
| 419 | { |
| 420 | return mRenderTargetCache.getDepthStencil(); |
| 421 | } |
| 422 | |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 423 | angle::Result FramebufferVk::blitWithCopy(ContextVk *contextVk, |
| 424 | const gl::Rectangle ©Area, |
| 425 | RenderTargetVk *readRenderTarget, |
| 426 | RenderTargetVk *drawRenderTarget, |
| 427 | bool blitDepthBuffer, |
| 428 | bool blitStencilBuffer) |
Luc Ferron | be30c4f | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 429 | { |
Shahbaz Youssefi | 028df5f | 2019-02-13 12:57:10 -0500 | [diff] [blame] | 430 | VkImageAspectFlags aspectMask = |
| 431 | vk::GetDepthStencilAspectFlagsForCopy(blitDepthBuffer, blitStencilBuffer); |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 432 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 433 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 434 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
| 435 | |
Shahbaz Youssefi | 028df5f | 2019-02-13 12:57:10 -0500 | [diff] [blame] | 436 | vk::ImageHelper *writeImage = drawRenderTarget->getImageForWrite(&mFramebuffer); |
| 437 | writeImage->changeLayout(writeImage->getAspectFlags(), vk::ImageLayout::TransferDst, |
| 438 | commandBuffer); |
| 439 | |
Luc Ferron | be30c4f | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 440 | vk::ImageHelper *readImage = readRenderTarget->getImageForRead( |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 441 | &mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 442 | |
Shahbaz Youssefi | 028df5f | 2019-02-13 12:57:10 -0500 | [diff] [blame] | 443 | VkImageSubresourceLayers readSubresource = {}; |
| 444 | readSubresource.aspectMask = aspectMask; |
| 445 | readSubresource.mipLevel = 0; |
| 446 | readSubresource.baseArrayLayer = 0; |
| 447 | readSubresource.layerCount = 1; |
| 448 | |
| 449 | VkImageSubresourceLayers writeSubresource = readSubresource; |
| 450 | |
Luc Ferron | be30c4f | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 451 | vk::ImageHelper::Copy(readImage, writeImage, gl::Offset(), gl::Offset(), |
Shahbaz Youssefi | 028df5f | 2019-02-13 12:57:10 -0500 | [diff] [blame] | 452 | gl::Extents(copyArea.width, copyArea.height, 1), readSubresource, |
| 453 | writeSubresource, commandBuffer); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 454 | return angle::Result::Continue; |
Luc Ferron | be30c4f | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 457 | RenderTargetVk *FramebufferVk::getColorReadRenderTarget() const |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 458 | { |
| 459 | RenderTargetVk *renderTarget = mRenderTargetCache.getColorRead(mState); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 460 | ASSERT(renderTarget && renderTarget->getImage().valid()); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 461 | return renderTarget; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 462 | } |
| 463 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 464 | angle::Result FramebufferVk::blitWithReadback(ContextVk *contextVk, |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 465 | const gl::Rectangle ©Area, |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 466 | VkImageAspectFlagBits aspect, |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 467 | RenderTargetVk *readRenderTarget, |
| 468 | RenderTargetVk *drawRenderTarget) |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 469 | { |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 470 | RendererVk *renderer = contextVk->getRenderer(); |
| 471 | const angle::Format &readFormat = readRenderTarget->getImageFormat().textureFormat(); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 472 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 473 | ASSERT(aspect == VK_IMAGE_ASPECT_DEPTH_BIT || aspect == VK_IMAGE_ASPECT_STENCIL_BIT); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 474 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 475 | // This path is only currently used for y-flipping depth/stencil blits. |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 476 | PackPixelsParams packPixelsParams; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 477 | packPixelsParams.reverseRowOrder = true; |
| 478 | packPixelsParams.area.width = copyArea.width; |
| 479 | packPixelsParams.area.height = copyArea.height; |
| 480 | packPixelsParams.area.x = copyArea.x; |
| 481 | packPixelsParams.area.y = copyArea.y; |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 482 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 483 | // Read back depth values into the destination buffer. |
| 484 | const angle::Format ©Format = GetDepthStencilImageToBufferFormat(readFormat, aspect); |
| 485 | packPixelsParams.destFormat = ©Format; |
| 486 | packPixelsParams.outputPitch = copyFormat.pixelBytes * copyArea.width; |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 487 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 488 | // Allocate a space in the destination buffer to write to. |
| 489 | size_t blitAllocationSize = copyFormat.pixelBytes * copyArea.width * copyArea.height; |
| 490 | uint8_t *destPtr = nullptr; |
| 491 | VkBuffer destBufferHandle = VK_NULL_HANDLE; |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 492 | VkDeviceSize destOffset = 0; |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 493 | ANGLE_TRY(mBlitPixelBuffer.allocate(contextVk, blitAllocationSize, &destPtr, &destBufferHandle, |
| 494 | &destOffset, nullptr)); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 495 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 496 | ANGLE_TRY( |
| 497 | readPixelsImpl(contextVk, copyArea, packPixelsParams, aspect, readRenderTarget, destPtr)); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 498 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 499 | VkBufferImageCopy copyRegion = {}; |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 500 | copyRegion.bufferOffset = destOffset; |
| 501 | copyRegion.bufferImageHeight = copyArea.height; |
| 502 | copyRegion.bufferRowLength = copyArea.width; |
| 503 | copyRegion.imageExtent.width = copyArea.width; |
| 504 | copyRegion.imageExtent.height = copyArea.height; |
| 505 | copyRegion.imageExtent.depth = 1; |
| 506 | copyRegion.imageSubresource.mipLevel = 0; |
| 507 | copyRegion.imageSubresource.aspectMask = aspect; |
| 508 | copyRegion.imageSubresource.baseArrayLayer = 0; |
| 509 | copyRegion.imageSubresource.layerCount = 1; |
| 510 | copyRegion.imageOffset.x = copyArea.x; |
| 511 | copyRegion.imageOffset.y = copyArea.y; |
| 512 | copyRegion.imageOffset.z = 0; |
| 513 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 514 | ANGLE_TRY(mBlitPixelBuffer.flush(contextVk)); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 515 | |
| 516 | // Reinitialize the commandBuffer after a read pixels because it calls |
| 517 | // renderer->finish which makes command buffers obsolete. |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 518 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 519 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 520 | |
| 521 | // We read the bytes of the image in a buffer, now we have to copy them into the |
| 522 | // destination target. |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 523 | vk::ImageHelper *imageForWrite = drawRenderTarget->getImageForWrite(&mFramebuffer); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 524 | |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 525 | imageForWrite->changeLayout(imageForWrite->getAspectFlags(), vk::ImageLayout::TransferDst, |
| 526 | commandBuffer); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 527 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 528 | commandBuffer->copyBufferToImage(destBufferHandle, imageForWrite->getImage(), |
| 529 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©Region); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 530 | |
| 531 | mBlitPixelBuffer.releaseRetainedBuffers(renderer); |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 532 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 533 | return angle::Result::Continue; |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 536 | angle::Result FramebufferVk::blit(const gl::Context *context, |
| 537 | const gl::Rectangle &sourceArea, |
| 538 | const gl::Rectangle &destArea, |
| 539 | GLbitfield mask, |
| 540 | GLenum filter) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 541 | { |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 542 | ContextVk *contextVk = vk::GetImpl(context); |
| 543 | RendererVk *renderer = contextVk->getRenderer(); |
| 544 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 545 | const gl::State &glState = context->getState(); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 546 | const gl::Framebuffer *sourceFramebuffer = glState.getReadFramebuffer(); |
Jamie Madill | ba36593 | 2018-07-18 17:23:46 -0400 | [diff] [blame] | 547 | bool blitColorBuffer = (mask & GL_COLOR_BUFFER_BIT) != 0; |
| 548 | bool blitDepthBuffer = (mask & GL_DEPTH_BUFFER_BIT) != 0; |
| 549 | bool blitStencilBuffer = (mask & GL_STENCIL_BUFFER_BIT) != 0; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 550 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 551 | FramebufferVk *sourceFramebufferVk = vk::GetImpl(sourceFramebuffer); |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 552 | bool flipSource = contextVk->isViewportFlipEnabledForReadFBO(); |
| 553 | bool flipDest = contextVk->isViewportFlipEnabledForDrawFBO(); |
| 554 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 555 | gl::Rectangle readRect = sourceArea; |
| 556 | gl::Rectangle drawRect = destArea; |
| 557 | |
| 558 | if (glState.isScissorTestEnabled()) |
| 559 | { |
| 560 | const gl::Rectangle scissorRect = glState.getScissor(); |
| 561 | if (!ClipRectangle(sourceArea, scissorRect, &readRect)) |
| 562 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 563 | return angle::Result::Continue; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | if (!ClipRectangle(destArea, scissorRect, &drawRect)) |
| 567 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 568 | return angle::Result::Continue; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | // After cropping for the scissor, we also want to crop for the size of the buffers. |
| 573 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 574 | if (blitColorBuffer) |
| 575 | { |
| 576 | RenderTargetVk *readRenderTarget = sourceFramebufferVk->getColorReadRenderTarget(); |
| 577 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 578 | gl::Rectangle readRenderTargetRect; |
| 579 | if (!ClipToRenderTarget(readRect, readRenderTarget, &readRenderTargetRect)) |
| 580 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 581 | return angle::Result::Continue; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 582 | } |
| 583 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 584 | for (size_t colorAttachment : mState.getEnabledDrawBuffers()) |
| 585 | { |
| 586 | RenderTargetVk *drawRenderTarget = mRenderTargetCache.getColors()[colorAttachment]; |
| 587 | ASSERT(drawRenderTarget); |
Shahbaz Youssefi | 96bd8fd | 2018-11-30 14:30:18 -0500 | [diff] [blame] | 588 | ASSERT(HasSrcAndDstBlitProperties(renderer, readRenderTarget, drawRenderTarget)); |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 589 | |
| 590 | gl::Rectangle drawRenderTargetRect; |
| 591 | if (!ClipToRenderTarget(drawRect, drawRenderTarget, &drawRenderTargetRect)) |
| 592 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 593 | return angle::Result::Continue; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 594 | } |
| 595 | |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 596 | ANGLE_TRY(blitWithCommand(contextVk, readRenderTargetRect, drawRenderTargetRect, |
| 597 | readRenderTarget, drawRenderTarget, filter, true, false, |
| 598 | false, flipSource, flipDest)); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
| 602 | if (blitDepthBuffer || blitStencilBuffer) |
| 603 | { |
| 604 | RenderTargetVk *readRenderTarget = sourceFramebufferVk->getDepthStencilRenderTarget(); |
| 605 | ASSERT(readRenderTarget); |
| 606 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 607 | gl::Rectangle readRenderTargetRect; |
| 608 | if (!ClipToRenderTarget(readRect, readRenderTarget, &readRenderTargetRect)) |
| 609 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 610 | return angle::Result::Continue; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 611 | } |
| 612 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 613 | RenderTargetVk *drawRenderTarget = mRenderTargetCache.getDepthStencil(); |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 614 | ASSERT(drawRenderTarget); |
| 615 | |
| 616 | gl::Rectangle drawRenderTargetRect; |
| 617 | if (!ClipToRenderTarget(drawRect, drawRenderTarget, &drawRenderTargetRect)) |
| 618 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 619 | return angle::Result::Continue; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | ASSERT(readRenderTargetRect == drawRenderTargetRect); |
| 623 | ASSERT(filter == GL_NEAREST); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 624 | |
Shahbaz Youssefi | 96bd8fd | 2018-11-30 14:30:18 -0500 | [diff] [blame] | 625 | if (HasSrcAndDstBlitProperties(renderer, readRenderTarget, drawRenderTarget)) |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 626 | { |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 627 | ANGLE_TRY(blitWithCommand(contextVk, readRenderTargetRect, drawRenderTargetRect, |
| 628 | readRenderTarget, drawRenderTarget, filter, false, |
| 629 | blitDepthBuffer, blitStencilBuffer, flipSource, flipDest)); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 630 | } |
| 631 | else |
| 632 | { |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 633 | if (flipSource || flipDest) |
| 634 | { |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 635 | if (blitDepthBuffer) |
| 636 | { |
| 637 | ANGLE_TRY(blitWithReadback(contextVk, readRenderTargetRect, |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 638 | VK_IMAGE_ASPECT_DEPTH_BIT, readRenderTarget, |
| 639 | drawRenderTarget)); |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 640 | } |
| 641 | if (blitStencilBuffer) |
| 642 | { |
| 643 | ANGLE_TRY(blitWithReadback(contextVk, readRenderTargetRect, |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 644 | VK_IMAGE_ASPECT_STENCIL_BIT, readRenderTarget, |
| 645 | drawRenderTarget)); |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 646 | } |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 647 | } |
| 648 | else |
| 649 | { |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 650 | ANGLE_TRY(blitWithCopy(contextVk, readRenderTargetRect, readRenderTarget, |
| 651 | drawRenderTarget, blitDepthBuffer, blitStencilBuffer)); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 652 | } |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 656 | return angle::Result::Continue; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 657 | } |
| 658 | |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 659 | angle::Result FramebufferVk::blitWithCommand(ContextVk *contextVk, |
| 660 | const gl::Rectangle &readRectIn, |
| 661 | const gl::Rectangle &drawRectIn, |
| 662 | RenderTargetVk *readRenderTarget, |
| 663 | RenderTargetVk *drawRenderTarget, |
| 664 | GLenum filter, |
| 665 | bool colorBlit, |
| 666 | bool depthBlit, |
| 667 | bool stencilBlit, |
| 668 | bool flipSource, |
| 669 | bool flipDest) |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 670 | { |
| 671 | // Since blitRenderbufferRect is called for each render buffer that needs to be blitted, |
| 672 | // it should never be the case that both color and depth/stencil need to be blitted at |
| 673 | // at the same time. |
| 674 | ASSERT(colorBlit != (depthBlit || stencilBlit)); |
| 675 | |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 676 | vk::ImageHelper *dstImage = drawRenderTarget->getImageForWrite(&mFramebuffer); |
| 677 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 678 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 679 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
| 680 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 681 | const vk::Format &readImageFormat = readRenderTarget->getImageFormat(); |
| 682 | VkImageAspectFlags aspectMask = |
| 683 | colorBlit ? VK_IMAGE_ASPECT_COLOR_BIT |
| 684 | : vk::GetDepthStencilAspectFlags(readImageFormat.textureFormat()); |
| 685 | vk::ImageHelper *srcImage = readRenderTarget->getImageForRead( |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 686 | &mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 687 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 688 | const gl::Extents sourceFrameBufferExtents = readRenderTarget->getExtents(); |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 689 | gl::Rectangle readRect = readRectIn; |
| 690 | |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 691 | if (flipSource) |
| 692 | { |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 693 | readRect.y = sourceFrameBufferExtents.height - readRect.y - readRect.height; |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 694 | } |
| 695 | |
Jamie Madill | ba36593 | 2018-07-18 17:23:46 -0400 | [diff] [blame] | 696 | VkImageBlit blit = {}; |
| 697 | blit.srcOffsets[0] = {readRect.x0(), flipSource ? readRect.y1() : readRect.y0(), 0}; |
| 698 | blit.srcOffsets[1] = {readRect.x1(), flipSource ? readRect.y0() : readRect.y1(), 1}; |
| 699 | blit.srcSubresource.aspectMask = aspectMask; |
| 700 | blit.srcSubresource.mipLevel = 0; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 701 | blit.srcSubresource.baseArrayLayer = 0; |
| 702 | blit.srcSubresource.layerCount = 1; |
| 703 | blit.dstSubresource.aspectMask = aspectMask; |
| 704 | blit.dstSubresource.mipLevel = 0; |
| 705 | blit.dstSubresource.baseArrayLayer = 0; |
| 706 | blit.dstSubresource.layerCount = 1; |
| 707 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 708 | const gl::Extents drawFrameBufferExtents = drawRenderTarget->getExtents(); |
| 709 | gl::Rectangle drawRect = drawRectIn; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 710 | |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 711 | if (flipDest) |
| 712 | { |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 713 | drawRect.y = drawFrameBufferExtents.height - drawRect.y - drawRect.height; |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 716 | blit.dstOffsets[0] = {drawRect.x0(), flipDest ? drawRect.y1() : drawRect.y0(), 0}; |
| 717 | blit.dstOffsets[1] = {drawRect.x1(), flipDest ? drawRect.y0() : drawRect.y1(), 1}; |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 718 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 719 | // Requirement of the copyImageToBuffer, the dst image must be in |
| 720 | // VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL layout. |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 721 | dstImage->changeLayout(aspectMask, vk::ImageLayout::TransferDst, commandBuffer); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 722 | |
| 723 | commandBuffer->blitImage(srcImage->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 724 | dstImage->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, |
| 725 | gl_vk::GetFilter(filter)); |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 726 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 727 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 730 | bool FramebufferVk::checkStatus(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 731 | { |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 732 | // if we have both a depth and stencil buffer, they must refer to the same object |
| 733 | // since we only support packed_depth_stencil and not separate depth and stencil |
| 734 | if (mState.hasSeparateDepthAndStencilAttachments()) |
| 735 | { |
| 736 | return false; |
| 737 | } |
| 738 | |
Jamie Madill | b79e7bb | 2017-10-24 13:55:50 -0400 | [diff] [blame] | 739 | return true; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 740 | } |
| 741 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 742 | angle::Result FramebufferVk::syncState(const gl::Context *context, |
| 743 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 744 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 745 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 746 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 747 | |
| 748 | ASSERT(dirtyBits.any()); |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 749 | for (size_t dirtyBit : dirtyBits) |
| 750 | { |
| 751 | switch (dirtyBit) |
| 752 | { |
| 753 | case gl::Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: |
| 754 | case gl::Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: |
| 755 | ANGLE_TRY(mRenderTargetCache.updateDepthStencilRenderTarget(context, mState)); |
| 756 | break; |
| 757 | case gl::Framebuffer::DIRTY_BIT_DRAW_BUFFERS: |
| 758 | case gl::Framebuffer::DIRTY_BIT_READ_BUFFER: |
| 759 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_WIDTH: |
| 760 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_HEIGHT: |
| 761 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_SAMPLES: |
| 762 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 763 | break; |
| 764 | default: |
| 765 | { |
| 766 | ASSERT(gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 && |
| 767 | dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX); |
| 768 | size_t colorIndex = |
| 769 | static_cast<size_t>(dirtyBit - gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 770 | ANGLE_TRY(mRenderTargetCache.updateColorRenderTarget(context, mState, colorIndex)); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 771 | |
| 772 | // Update cached masks for masked clears. |
| 773 | RenderTargetVk *renderTarget = mRenderTargetCache.getColors()[colorIndex]; |
| 774 | if (renderTarget) |
| 775 | { |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 776 | const angle::Format &emulatedFormat = |
| 777 | renderTarget->getImageFormat().textureFormat(); |
| 778 | updateActiveColorMasks( |
| 779 | colorIndex, emulatedFormat.redBits > 0, emulatedFormat.greenBits > 0, |
| 780 | emulatedFormat.blueBits > 0, emulatedFormat.alphaBits > 0); |
| 781 | |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 782 | const angle::Format &sourceFormat = |
| 783 | renderTarget->getImageFormat().angleFormat(); |
| 784 | mEmulatedAlphaAttachmentMask.set( |
| 785 | colorIndex, sourceFormat.alphaBits == 0 && emulatedFormat.alphaBits > 0); |
Luc Ferron | 0bb940a | 2018-06-22 09:59:34 -0400 | [diff] [blame] | 786 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 787 | contextVk->updateColorMask(context->getState().getBlendState()); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 788 | } |
| 789 | else |
| 790 | { |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 791 | updateActiveColorMasks(colorIndex, false, false, false, false); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 792 | } |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 793 | break; |
| 794 | } |
| 795 | } |
| 796 | } |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 797 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 798 | mActiveColorComponents = gl_vk::GetColorComponentFlags( |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 799 | mActiveColorComponentMasksForClear[0].any(), mActiveColorComponentMasksForClear[1].any(), |
| 800 | mActiveColorComponentMasksForClear[2].any(), mActiveColorComponentMasksForClear[3].any()); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 801 | |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 802 | mFramebuffer.release(renderer); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 803 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 804 | // Will freeze the current set of dependencies on this FBO. The next time we render we will |
Jamie Madill | a5e0607 | 2018-05-18 14:36:05 -0400 | [diff] [blame] | 805 | // create a new entry in the command graph. |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 806 | mFramebuffer.finishCurrentCommands(renderer); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 807 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 808 | // Notify the ContextVk to update the pipeline desc. |
| 809 | updateRenderPassDesc(); |
| 810 | contextVk->onFramebufferChange(mRenderPassDesc); |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 811 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 812 | return angle::Result::Continue; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 813 | } |
| 814 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 815 | void FramebufferVk::updateRenderPassDesc() |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 816 | { |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 817 | mRenderPassDesc = {}; |
| 818 | mRenderPassDesc.setSamples(getSamples()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 819 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 820 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 821 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 822 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 823 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 824 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 825 | ASSERT(colorRenderTarget); |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 826 | mRenderPassDesc.packAttachment(colorRenderTarget->getImage().getFormat()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 827 | } |
| 828 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 829 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 830 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 831 | { |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 832 | mRenderPassDesc.packAttachment(depthStencilRenderTarget->getImage().getFormat()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 833 | } |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 834 | } |
| 835 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 836 | angle::Result FramebufferVk::getFramebuffer(ContextVk *contextVk, vk::Framebuffer **framebufferOut) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 837 | { |
| 838 | // If we've already created our cached Framebuffer, return it. |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 839 | if (mFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 840 | { |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 841 | *framebufferOut = &mFramebuffer.getFramebuffer(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 842 | return angle::Result::Continue; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 846 | ANGLE_TRY( |
| 847 | contextVk->getRenderer()->getCompatibleRenderPass(contextVk, mRenderPassDesc, &renderPass)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 848 | |
| 849 | // If we've a Framebuffer provided by a Surface (default FBO/backbuffer), query it. |
| 850 | if (mBackbuffer) |
| 851 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 852 | return mBackbuffer->getCurrentFramebuffer(contextVk, *renderPass, framebufferOut); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | // Gather VkImageViews over all FBO attachments, also size of attached region. |
| 856 | std::vector<VkImageView> attachments; |
| 857 | gl::Extents attachmentsSize; |
| 858 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 859 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 860 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 861 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 862 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 863 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 864 | ASSERT(colorRenderTarget); |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 865 | attachments.push_back(colorRenderTarget->getDrawImageView()->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 866 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 867 | ASSERT(attachmentsSize.empty() || attachmentsSize == colorRenderTarget->getExtents()); |
| 868 | attachmentsSize = colorRenderTarget->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 869 | } |
| 870 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 871 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 872 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 873 | { |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 874 | attachments.push_back(depthStencilRenderTarget->getDrawImageView()->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 875 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 876 | ASSERT(attachmentsSize.empty() || |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 877 | attachmentsSize == depthStencilRenderTarget->getExtents()); |
| 878 | attachmentsSize = depthStencilRenderTarget->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | ASSERT(!attachments.empty()); |
| 882 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 883 | VkFramebufferCreateInfo framebufferInfo = {}; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 884 | |
| 885 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 886 | framebufferInfo.flags = 0; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 887 | framebufferInfo.renderPass = renderPass->getHandle(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 888 | framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); |
| 889 | framebufferInfo.pAttachments = attachments.data(); |
| 890 | framebufferInfo.width = static_cast<uint32_t>(attachmentsSize.width); |
| 891 | framebufferInfo.height = static_cast<uint32_t>(attachmentsSize.height); |
| 892 | framebufferInfo.layers = 1; |
| 893 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 894 | ANGLE_TRY(mFramebuffer.init(contextVk, framebufferInfo)); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 895 | |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 896 | *framebufferOut = &mFramebuffer.getFramebuffer(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 897 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 898 | } |
| 899 | |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 900 | angle::Result FramebufferVk::clearWithClearAttachments( |
| 901 | ContextVk *contextVk, |
| 902 | bool clearColor, |
| 903 | bool clearDepth, |
| 904 | bool clearStencil, |
| 905 | const VkClearDepthStencilValue &clearDepthStencilValue) |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 906 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 907 | // Trigger a new command node to ensure overlapping writes happen sequentially. |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 908 | mFramebuffer.finishCurrentCommands(contextVk->getRenderer()); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 909 | |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 910 | // This command can only happen inside a render pass, so obtain one if its already happening |
| 911 | // or create a new one if not. |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 912 | vk::CommandBuffer *commandBuffer = nullptr; |
| 913 | vk::RecordingMode mode = vk::RecordingMode::Start; |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 914 | ANGLE_TRY(getCommandBufferForDraw(contextVk, &commandBuffer, &mode)); |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 915 | |
Jamie Madill | 3f3b358 | 2018-09-14 10:38:44 -0400 | [diff] [blame] | 916 | // The array layer is offset by the ImageView. So we shouldn't need to set a base array layer. |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 917 | VkClearRect clearRect = {}; |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 918 | clearRect.baseArrayLayer = 0; |
| 919 | clearRect.layerCount = 1; |
| 920 | |
| 921 | // When clearing, the scissor region must be clipped to the renderArea per the validation rules |
| 922 | // in Vulkan. |
| 923 | gl::Rectangle intersection; |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 924 | if (!gl::ClipRectangle(contextVk->getState().getScissor(), |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 925 | mFramebuffer.getRenderPassRenderArea(), &intersection)) |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 926 | { |
| 927 | // There is nothing to clear since the scissor is outside of the render area. |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 928 | return angle::Result::Continue; |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 929 | } |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 930 | |
Luc Ferron | e4c38be | 2018-04-17 11:09:16 -0400 | [diff] [blame] | 931 | clearRect.rect = gl_vk::GetRect(intersection); |
| 932 | |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 933 | if (contextVk->isViewportFlipEnabledForDrawFBO()) |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 934 | { |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 935 | clearRect.rect.offset.y = mFramebuffer.getRenderPassRenderArea().height - |
| 936 | clearRect.rect.offset.y - clearRect.rect.extent.height; |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 939 | gl::AttachmentArray<VkClearAttachment> clearAttachments; |
| 940 | int clearAttachmentIndex = 0; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 941 | |
| 942 | if (clearColor) |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 943 | { |
Luc Ferron | f6e160f | 2018-06-12 10:13:57 -0400 | [diff] [blame] | 944 | RenderTargetVk *renderTarget = getColorReadRenderTarget(); |
| 945 | const vk::Format &format = renderTarget->getImageFormat(); |
| 946 | VkClearValue modifiedClear = contextVk->getClearColorValue(); |
| 947 | |
| 948 | // We need to make sure we are not clearing the alpha channel if we are using a buffer |
| 949 | // format that doesn't have an alpha channel. |
| 950 | if (format.angleFormat().alphaBits == 0) |
| 951 | { |
| 952 | modifiedClear.color.float32[3] = 1.0; |
| 953 | } |
| 954 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 955 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 956 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
| 957 | { |
| 958 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 959 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 960 | clearAttachment.colorAttachment = static_cast<uint32_t>(colorIndex); |
Luc Ferron | f6e160f | 2018-06-12 10:13:57 -0400 | [diff] [blame] | 961 | clearAttachment.clearValue = modifiedClear; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 962 | ++clearAttachmentIndex; |
| 963 | } |
| 964 | } |
| 965 | |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 966 | VkClearValue depthStencilClearValue = {}; |
| 967 | depthStencilClearValue.depthStencil = clearDepthStencilValue; |
Shahbaz Youssefi | 2197dc5 | 2018-10-30 11:29:58 -0400 | [diff] [blame] | 968 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 969 | if (clearDepth && clearStencil && mState.getDepthStencilAttachment() != nullptr) |
| 970 | { |
| 971 | // When we have a packed depth/stencil attachment we can do 1 clear for both when it |
| 972 | // applies. |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 973 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 974 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 975 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 976 | clearAttachment.clearValue = depthStencilClearValue; |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 977 | ++clearAttachmentIndex; |
| 978 | } |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 979 | else |
| 980 | { |
| 981 | if (clearDepth) |
| 982 | { |
| 983 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 984 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 985 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
Shahbaz Youssefi | 2197dc5 | 2018-10-30 11:29:58 -0400 | [diff] [blame] | 986 | clearAttachment.clearValue = depthStencilClearValue; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 987 | ++clearAttachmentIndex; |
| 988 | } |
| 989 | |
| 990 | if (clearStencil) |
| 991 | { |
| 992 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 993 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 994 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
Shahbaz Youssefi | 2197dc5 | 2018-10-30 11:29:58 -0400 | [diff] [blame] | 995 | clearAttachment.clearValue = depthStencilClearValue; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 996 | ++clearAttachmentIndex; |
| 997 | } |
| 998 | } |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 999 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 1000 | commandBuffer->clearAttachments(static_cast<uint32_t>(clearAttachmentIndex), |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 1001 | clearAttachments.data(), 1, &clearRect); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1002 | return angle::Result::Continue; |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 1003 | } |
| 1004 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1005 | angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk, |
| 1006 | VkColorComponentFlags colorMaskFlags) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1007 | { |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 1008 | RendererVk *renderer = contextVk->getRenderer(); |
| 1009 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1010 | // If the format of the framebuffer does not have an alpha channel, we need to make sure we do |
Luc Ferron | 66c2f4a | 2018-06-19 10:27:57 -0400 | [diff] [blame] | 1011 | // not affect the alpha channel of the type we're using to emulate the format. |
| 1012 | // TODO(jmadill): Implement EXT_draw_buffers http://anglebug.com/2394 |
| 1013 | RenderTargetVk *renderTarget = mRenderTargetCache.getColors()[0]; |
| 1014 | ASSERT(renderTarget); |
| 1015 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1016 | UtilsVk::ClearImageParameters params = {}; |
| 1017 | params.colorMaskFlags = colorMaskFlags; |
| 1018 | params.alphaMask = &getEmulatedAlphaAttachmentMask(); |
| 1019 | params.renderPassDesc = &getRenderPassDesc(); |
| 1020 | |
| 1021 | const vk::Format &imageFormat = renderTarget->getImageFormat(); |
| 1022 | params.clearValue = contextVk->getClearColorValue().color; |
Luc Ferron | 66c2f4a | 2018-06-19 10:27:57 -0400 | [diff] [blame] | 1023 | bool overrideAlphaWithOne = |
| 1024 | imageFormat.textureFormat().alphaBits > 0 && imageFormat.angleFormat().alphaBits == 0; |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1025 | params.clearValue.float32[3] = overrideAlphaWithOne ? 1.0f : params.clearValue.float32[3]; |
Luc Ferron | 66c2f4a | 2018-06-19 10:27:57 -0400 | [diff] [blame] | 1026 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1027 | params.renderAreaHeight = mState.getDimensions().height; |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1028 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1029 | return renderer->getUtils().clearImage(contextVk, this, params); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1032 | angle::Result FramebufferVk::getSamplePosition(const gl::Context *context, |
| 1033 | size_t index, |
| 1034 | GLfloat *xy) const |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1035 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1036 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1037 | return angle::Result::Stop; |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1040 | angle::Result FramebufferVk::getCommandBufferForDraw(ContextVk *contextVk, |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1041 | vk::CommandBuffer **commandBufferOut, |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1042 | vk::RecordingMode *modeOut) |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1043 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1044 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | bef918c | 2017-12-13 13:11:30 -0500 | [diff] [blame] | 1045 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 1046 | // This will clear the current write operation if it is complete. |
Jamie Madill | c759b8b | 2019-01-03 15:16:50 -0500 | [diff] [blame] | 1047 | if (appendToStartedRenderPass(renderer->getCurrentQueueSerial(), commandBufferOut)) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 1048 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 1049 | *modeOut = vk::RecordingMode::Append; |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1050 | return angle::Result::Continue; |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 1051 | } |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 1052 | |
Jamie Madill | d1249de | 2018-08-28 16:58:53 -0400 | [diff] [blame] | 1053 | return startNewRenderPass(contextVk, commandBufferOut); |
| 1054 | } |
| 1055 | |
| 1056 | angle::Result FramebufferVk::startNewRenderPass(ContextVk *contextVk, |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1057 | vk::CommandBuffer **commandBufferOut) |
Jamie Madill | d1249de | 2018-08-28 16:58:53 -0400 | [diff] [blame] | 1058 | { |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1059 | vk::Framebuffer *framebuffer = nullptr; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1060 | ANGLE_TRY(getFramebuffer(contextVk, &framebuffer)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1061 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 1062 | // TODO(jmadill): Proper clear value implementation. http://anglebug.com/2361 |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1063 | std::vector<VkClearValue> attachmentClearValues; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1064 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1065 | vk::CommandBuffer *writeCommands = nullptr; |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1066 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &writeCommands)); |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 1067 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1068 | vk::RenderPassDesc renderPassDesc; |
| 1069 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1070 | // Initialize RenderPass info. |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1071 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 1072 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 1073 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 1074 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1075 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 1076 | ASSERT(colorRenderTarget); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1077 | |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1078 | colorRenderTarget->onColorDraw(&mFramebuffer, writeCommands, &renderPassDesc); |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1079 | attachmentClearValues.emplace_back(contextVk->getClearColorValue()); |
| 1080 | } |
| 1081 | |
| 1082 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 1083 | if (depthStencilRenderTarget) |
| 1084 | { |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1085 | depthStencilRenderTarget->onDepthStencilDraw(&mFramebuffer, writeCommands, &renderPassDesc); |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 1086 | attachmentClearValues.emplace_back(contextVk->getClearDepthStencilValue()); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1087 | } |
| 1088 | |
Luc Ferron | d17bdfe | 2018-04-05 13:50:10 -0400 | [diff] [blame] | 1089 | gl::Rectangle renderArea = |
| 1090 | gl::Rectangle(0, 0, mState.getDimensions().width, mState.getDimensions().height); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1091 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1092 | return mFramebuffer.beginRenderPass(contextVk, *framebuffer, renderArea, mRenderPassDesc, |
| 1093 | attachmentClearValues, commandBufferOut); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1094 | } |
| 1095 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1096 | void FramebufferVk::updateActiveColorMasks(size_t colorIndex, bool r, bool g, bool b, bool a) |
| 1097 | { |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 1098 | mActiveColorComponentMasksForClear[0].set(colorIndex, r); |
| 1099 | mActiveColorComponentMasksForClear[1].set(colorIndex, g); |
| 1100 | mActiveColorComponentMasksForClear[2].set(colorIndex, b); |
| 1101 | mActiveColorComponentMasksForClear[3].set(colorIndex, a); |
| 1102 | } |
| 1103 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1104 | const gl::DrawBufferMask &FramebufferVk::getEmulatedAlphaAttachmentMask() const |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 1105 | { |
| 1106 | return mEmulatedAlphaAttachmentMask; |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1107 | } |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1108 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1109 | angle::Result FramebufferVk::readPixelsImpl(ContextVk *contextVk, |
| 1110 | const gl::Rectangle &area, |
| 1111 | const PackPixelsParams &packPixelsParams, |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1112 | VkImageAspectFlagBits copyAspectFlags, |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1113 | RenderTargetVk *renderTarget, |
| 1114 | void *pixels) |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1115 | { |
Tobin Ehlis | 4a41914 | 2019-02-05 08:50:30 -0700 | [diff] [blame] | 1116 | TRACE_EVENT0("gpu.angle", "FramebufferVk::readPixelsImpl"); |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1117 | RendererVk *renderer = contextVk->getRenderer(); |
| 1118 | |
Shahbaz Youssefi | 29b4941 | 2019-01-07 14:03:06 -0500 | [diff] [blame] | 1119 | ANGLE_TRY(renderTarget->ensureImageInitialized(contextVk)); |
| 1120 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1121 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1122 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1123 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1124 | // Note that although we're reading from the image, we need to update the layout below. |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1125 | |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 1126 | vk::ImageHelper *srcImage = |
| 1127 | renderTarget->getImageForRead(&mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1128 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1129 | const angle::Format *readFormat = &srcImage->getFormat().textureFormat(); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1130 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1131 | if (copyAspectFlags != VK_IMAGE_ASPECT_COLOR_BIT) |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1132 | { |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1133 | readFormat = &GetDepthStencilImageToBufferFormat(*readFormat, copyAspectFlags); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1134 | } |
| 1135 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 1136 | VkBuffer bufferHandle = VK_NULL_HANDLE; |
| 1137 | uint8_t *readPixelBuffer = nullptr; |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 1138 | VkDeviceSize stagingOffset = 0; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 1139 | size_t allocationSize = readFormat->pixelBytes * area.width * area.height; |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1140 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 1141 | ANGLE_TRY(mReadPixelBuffer.allocate(contextVk, allocationSize, &readPixelBuffer, &bufferHandle, |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 1142 | &stagingOffset, nullptr)); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1143 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 1144 | VkBufferImageCopy region = {}; |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1145 | region.bufferImageHeight = area.height; |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 1146 | region.bufferOffset = stagingOffset; |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1147 | region.bufferRowLength = area.width; |
| 1148 | region.imageExtent.width = area.width; |
| 1149 | region.imageExtent.height = area.height; |
| 1150 | region.imageExtent.depth = 1; |
| 1151 | region.imageOffset.x = area.x; |
| 1152 | region.imageOffset.y = area.y; |
| 1153 | region.imageOffset.z = 0; |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1154 | region.imageSubresource.aspectMask = copyAspectFlags; |
Jamie Madill | 3f3b358 | 2018-09-14 10:38:44 -0400 | [diff] [blame] | 1155 | region.imageSubresource.baseArrayLayer = renderTarget->getLayerIndex(); |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1156 | region.imageSubresource.layerCount = 1; |
Geoff Lang | 4a29870 | 2019-01-18 10:49:36 -0500 | [diff] [blame] | 1157 | region.imageSubresource.mipLevel = renderTarget->getLevelIndex(); |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1158 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1159 | commandBuffer->copyImageToBuffer(srcImage->getImage(), srcImage->getCurrentLayout(), |
| 1160 | bufferHandle, 1, ®ion); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1161 | |
| 1162 | // Triggers a full finish. |
| 1163 | // TODO(jmadill): Don't block on asynchronous readback. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1164 | ANGLE_TRY(renderer->finish(contextVk)); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1165 | |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1166 | // The buffer we copied to needs to be invalidated before we read from it because its not been |
| 1167 | // created with the host coherent bit. |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 1168 | ANGLE_TRY(mReadPixelBuffer.invalidate(contextVk)); |
Yuly Novikov | 6c6c76c | 2018-05-17 18:45:06 +0000 | [diff] [blame] | 1169 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1170 | PackPixels(packPixelsParams, *readFormat, area.width * readFormat->pixelBytes, readPixelBuffer, |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 1171 | static_cast<uint8_t *>(pixels)); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1172 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1173 | return angle::Result::Continue; |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1174 | } |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1175 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 1176 | gl::Extents FramebufferVk::getReadImageExtents() const |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1177 | { |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 1178 | return getColorReadRenderTarget()->getExtents(); |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1179 | } |
Jamie Madill | 502d2e2 | 2018-11-01 11:06:23 -0400 | [diff] [blame] | 1180 | |
| 1181 | RenderTargetVk *FramebufferVk::getFirstRenderTarget() const |
| 1182 | { |
| 1183 | for (auto *renderTarget : mRenderTargetCache.getColors()) |
| 1184 | { |
| 1185 | if (renderTarget) |
| 1186 | { |
| 1187 | return renderTarget; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | return mRenderTargetCache.getDepthStencil(); |
| 1192 | } |
| 1193 | |
| 1194 | GLint FramebufferVk::getSamples() const |
| 1195 | { |
| 1196 | RenderTargetVk *firstRT = getFirstRenderTarget(); |
| 1197 | return firstRT ? firstRT->getImage().getSamples() : 0; |
| 1198 | } |
| 1199 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1200 | } // namespace rx |