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" |
Jamie Madill | 3ea463b | 2019-06-19 14:21:33 -0400 | [diff] [blame] | 27 | #include "libANGLE/trace.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 | { |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 34 | // The value to assign an alpha channel that's emulated. The type is unsigned int, though it will |
| 35 | // automatically convert to the actual data type. |
| 36 | constexpr unsigned int kEmulatedAlphaValue = 1; |
| 37 | |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 38 | constexpr size_t kMinReadPixelsBufferSize = 128000; |
Mohan Maiya | 8a43b8c | 2019-08-02 08:47:13 -0700 | [diff] [blame] | 39 | |
| 40 | // Alignment value to accommodate the largest known, for now, uncompressed Vulkan format |
| 41 | // VK_FORMAT_R64G64B64A64_SFLOAT |
| 42 | constexpr size_t kReadPixelsBufferAlignment = 32; |
| 43 | |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 44 | // Clear values are only used when loadOp=Clear is set in clearWithRenderPassOp. When starting a |
| 45 | // new render pass, the clear value is set to an unlikely value (bright pink) to stand out better |
| 46 | // in case of a bug. |
| 47 | constexpr VkClearValue kUninitializedClearValue = {{{0.95, 0.05, 0.95, 0.95}}}; |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 48 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 49 | const gl::InternalFormat &GetReadAttachmentInfo(const gl::Context *context, |
| 50 | RenderTargetVk *renderTarget) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 51 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 52 | GLenum implFormat = |
Jamie Madill | 0631e19 | 2019-04-18 16:09:12 -0400 | [diff] [blame] | 53 | renderTarget->getImageFormat().imageFormat().fboImplementationInternalFormat; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 54 | return gl::GetSizedInternalFormatInfo(implFormat); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 55 | } |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 56 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 57 | bool HasSrcBlitFeature(RendererVk *renderer, RenderTargetVk *srcRenderTarget) |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 58 | { |
Jamie Madill | 0631e19 | 2019-04-18 16:09:12 -0400 | [diff] [blame] | 59 | const VkFormat srcFormat = srcRenderTarget->getImageFormat().vkImageFormat; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 60 | return renderer->hasImageFormatFeatureBits(srcFormat, VK_FORMAT_FEATURE_BLIT_SRC_BIT); |
| 61 | } |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 62 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 63 | bool HasDstBlitFeature(RendererVk *renderer, RenderTargetVk *dstRenderTarget) |
| 64 | { |
| 65 | const VkFormat dstFormat = dstRenderTarget->getImageFormat().vkImageFormat; |
| 66 | return renderer->hasImageFormatFeatureBits(dstFormat, VK_FORMAT_FEATURE_BLIT_DST_BIT); |
| 67 | } |
| 68 | |
| 69 | // Returns false if destination has any channel the source doesn't. This means that channel was |
| 70 | // emulated and using the Vulkan blit command would overwrite that emulated channel. |
| 71 | bool areSrcAndDstColorChannelsBlitCompatible(RenderTargetVk *srcRenderTarget, |
| 72 | RenderTargetVk *dstRenderTarget) |
| 73 | { |
| 74 | const angle::Format &srcFormat = srcRenderTarget->getImageFormat().angleFormat(); |
| 75 | const angle::Format &dstFormat = dstRenderTarget->getImageFormat().angleFormat(); |
| 76 | |
| 77 | // Luminance/alpha formats are not renderable, so they can't have ended up in a framebuffer to |
| 78 | // participate in a blit. |
| 79 | ASSERT(!dstFormat.isLUMA() && !srcFormat.isLUMA()); |
| 80 | |
| 81 | // All color formats have the red channel. |
| 82 | ASSERT(dstFormat.redBits > 0 && srcFormat.redBits > 0); |
| 83 | |
| 84 | return (dstFormat.greenBits > 0 || srcFormat.greenBits == 0) && |
| 85 | (dstFormat.blueBits > 0 || srcFormat.blueBits == 0) && |
| 86 | (dstFormat.alphaBits > 0 || srcFormat.alphaBits == 0); |
| 87 | } |
| 88 | |
| 89 | bool areSrcAndDstDepthStencilChannelsBlitCompatible(RenderTargetVk *srcRenderTarget, |
| 90 | RenderTargetVk *dstRenderTarget) |
| 91 | { |
| 92 | const angle::Format &srcFormat = srcRenderTarget->getImageFormat().angleFormat(); |
| 93 | const angle::Format &dstFormat = dstRenderTarget->getImageFormat().angleFormat(); |
| 94 | |
| 95 | return (dstFormat.depthBits > 0 || srcFormat.depthBits == 0) && |
| 96 | (dstFormat.stencilBits > 0 || srcFormat.stencilBits == 0); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 97 | } |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 98 | |
| 99 | // Special rules apply to VkBufferImageCopy with depth/stencil. The components are tightly packed |
| 100 | // into a depth or stencil section of the destination buffer. See the spec: |
| 101 | // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkBufferImageCopy.html |
| 102 | const angle::Format &GetDepthStencilImageToBufferFormat(const angle::Format &imageFormat, |
| 103 | VkImageAspectFlagBits copyAspect) |
| 104 | { |
| 105 | if (copyAspect == VK_IMAGE_ASPECT_STENCIL_BIT) |
| 106 | { |
| 107 | ASSERT(imageFormat.id == angle::FormatID::D24_UNORM_S8_UINT || |
| 108 | imageFormat.id == angle::FormatID::D32_FLOAT_S8X24_UINT || |
| 109 | imageFormat.id == angle::FormatID::S8_UINT); |
| 110 | return angle::Format::Get(angle::FormatID::S8_UINT); |
| 111 | } |
| 112 | |
| 113 | ASSERT(copyAspect == VK_IMAGE_ASPECT_DEPTH_BIT); |
| 114 | |
| 115 | switch (imageFormat.id) |
| 116 | { |
| 117 | case angle::FormatID::D16_UNORM: |
| 118 | return imageFormat; |
| 119 | case angle::FormatID::D24_UNORM_X8_UINT: |
| 120 | return imageFormat; |
| 121 | case angle::FormatID::D24_UNORM_S8_UINT: |
| 122 | return angle::Format::Get(angle::FormatID::D24_UNORM_X8_UINT); |
| 123 | case angle::FormatID::D32_FLOAT: |
| 124 | return imageFormat; |
| 125 | case angle::FormatID::D32_FLOAT_S8X24_UINT: |
| 126 | return angle::Format::Get(angle::FormatID::D32_FLOAT); |
| 127 | default: |
| 128 | UNREACHABLE(); |
| 129 | return imageFormat; |
| 130 | } |
| 131 | } |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 132 | |
| 133 | void SetEmulatedAlphaValue(const vk::Format &format, VkClearColorValue *value) |
| 134 | { |
| 135 | if (format.vkFormatIsInt) |
| 136 | { |
| 137 | if (format.vkFormatIsUnsigned) |
| 138 | { |
| 139 | value->uint32[3] = kEmulatedAlphaValue; |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | value->int32[3] = kEmulatedAlphaValue; |
| 144 | } |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | value->float32[3] = kEmulatedAlphaValue; |
| 149 | } |
| 150 | } |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 151 | } // anonymous namespace |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 152 | |
| 153 | // static |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 154 | FramebufferVk *FramebufferVk::CreateUserFBO(RendererVk *renderer, const gl::FramebufferState &state) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 155 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 156 | return new FramebufferVk(renderer, state, nullptr); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | // static |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 160 | FramebufferVk *FramebufferVk::CreateDefaultFBO(RendererVk *renderer, |
| 161 | const gl::FramebufferState &state, |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 162 | WindowSurfaceVk *backbuffer) |
| 163 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 164 | return new FramebufferVk(renderer, state, backbuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 167 | FramebufferVk::FramebufferVk(RendererVk *renderer, |
| 168 | const gl::FramebufferState &state, |
| 169 | WindowSurfaceVk *backbuffer) |
Jamie Madill | 7f2520f | 2019-06-26 11:18:33 -0400 | [diff] [blame] | 170 | : FramebufferImpl(state), mBackbuffer(backbuffer), mActiveColorComponents(0) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 171 | { |
Mohan Maiya | 8a43b8c | 2019-08-02 08:47:13 -0700 | [diff] [blame] | 172 | mReadPixelBuffer.init(renderer, VK_BUFFER_USAGE_TRANSFER_DST_BIT, kReadPixelsBufferAlignment, |
| 173 | kMinReadPixelsBufferSize, true); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 176 | FramebufferVk::~FramebufferVk() = default; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 177 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 178 | void FramebufferVk::destroy(const gl::Context *context) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 179 | { |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 180 | ContextVk *contextVk = vk::GetImpl(context); |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 181 | mFramebuffer.release(contextVk); |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 182 | |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 183 | mReadPixelBuffer.release(contextVk); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 186 | angle::Result FramebufferVk::discard(const gl::Context *context, |
| 187 | size_t count, |
| 188 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 189 | { |
Shahbaz Youssefi | 97123e3 | 2019-07-08 15:11:16 -0400 | [diff] [blame] | 190 | return invalidate(context, count, attachments); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 191 | } |
| 192 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 193 | angle::Result FramebufferVk::invalidate(const gl::Context *context, |
| 194 | size_t count, |
| 195 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 196 | { |
Shahbaz Youssefi | da90448 | 2019-07-02 10:49:14 -0400 | [diff] [blame] | 197 | mFramebuffer.updateQueueSerial(vk::GetImpl(context)->getCurrentQueueSerial()); |
| 198 | |
| 199 | if (mFramebuffer.valid() && mFramebuffer.hasStartedRenderPass()) |
| 200 | { |
| 201 | invalidateImpl(vk::GetImpl(context), count, attachments); |
| 202 | } |
| 203 | |
| 204 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 205 | } |
| 206 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 207 | angle::Result FramebufferVk::invalidateSub(const gl::Context *context, |
| 208 | size_t count, |
| 209 | const GLenum *attachments, |
| 210 | const gl::Rectangle &area) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 211 | { |
Shahbaz Youssefi | da90448 | 2019-07-02 10:49:14 -0400 | [diff] [blame] | 212 | mFramebuffer.updateQueueSerial(vk::GetImpl(context)->getCurrentQueueSerial()); |
| 213 | |
| 214 | // RenderPass' storeOp cannot be made conditional to a specific region, so we only apply this |
| 215 | // hint if the requested area encompasses the render area. |
| 216 | if (mFramebuffer.valid() && mFramebuffer.hasStartedRenderPass() && |
| 217 | area.encloses(mFramebuffer.getRenderPassRenderArea())) |
| 218 | { |
| 219 | invalidateImpl(vk::GetImpl(context), count, attachments); |
| 220 | } |
| 221 | |
| 222 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 223 | } |
| 224 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 225 | angle::Result FramebufferVk::clear(const gl::Context *context, GLbitfield mask) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 226 | { |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 227 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 228 | |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 229 | bool clearColor = IsMaskFlagSet(mask, static_cast<GLbitfield>(GL_COLOR_BUFFER_BIT)); |
| 230 | bool clearDepth = IsMaskFlagSet(mask, static_cast<GLbitfield>(GL_DEPTH_BUFFER_BIT)); |
| 231 | bool clearStencil = IsMaskFlagSet(mask, static_cast<GLbitfield>(GL_STENCIL_BUFFER_BIT)); |
| 232 | gl::DrawBufferMask clearColorBuffers; |
| 233 | if (clearColor) |
| 234 | { |
| 235 | clearColorBuffers = mState.getEnabledDrawBuffers(); |
| 236 | } |
| 237 | |
| 238 | const VkClearColorValue &clearColorValue = contextVk->getClearColorValue().color; |
| 239 | const VkClearDepthStencilValue &clearDepthStencilValue = |
| 240 | contextVk->getClearDepthStencilValue().depthStencil; |
| 241 | |
| 242 | return clearImpl(context, clearColorBuffers, clearDepth, clearStencil, clearColorValue, |
| 243 | clearDepthStencilValue); |
| 244 | } |
| 245 | |
| 246 | angle::Result FramebufferVk::clearImpl(const gl::Context *context, |
| 247 | gl::DrawBufferMask clearColorBuffers, |
| 248 | bool clearDepth, |
| 249 | bool clearStencil, |
| 250 | const VkClearColorValue &clearColorValue, |
| 251 | const VkClearDepthStencilValue &clearDepthStencilValue) |
| 252 | { |
| 253 | ContextVk *contextVk = vk::GetImpl(context); |
| 254 | |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 255 | const gl::Rectangle scissoredRenderArea = getScissoredRenderArea(contextVk); |
| 256 | |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 257 | // Discard clear altogether if scissor has 0 width or height. |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 258 | if (scissoredRenderArea.width == 0 || scissoredRenderArea.height == 0) |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 259 | { |
| 260 | return angle::Result::Continue; |
| 261 | } |
| 262 | |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 263 | mFramebuffer.updateQueueSerial(contextVk->getCurrentQueueSerial()); |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 264 | |
| 265 | // This function assumes that only enabled attachments are asked to be cleared. |
| 266 | ASSERT((clearColorBuffers & mState.getEnabledDrawBuffers()) == clearColorBuffers); |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 267 | |
Shahbaz Youssefi | edef895 | 2019-04-04 10:03:09 -0400 | [diff] [blame] | 268 | // Adjust clear behavior based on whether the respective attachments are present; if asked to |
| 269 | // clear a non-existent attachment, don't attempt to clear it. |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 270 | |
| 271 | VkColorComponentFlags colorMaskFlags = contextVk->getClearColorMask(); |
| 272 | bool clearColor = clearColorBuffers.any(); |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 273 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 274 | const gl::FramebufferAttachment *depthAttachment = mState.getDepthAttachment(); |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 275 | clearDepth = clearDepth && depthAttachment; |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 276 | ASSERT(!clearDepth || depthAttachment->isAttached()); |
| 277 | |
| 278 | const gl::FramebufferAttachment *stencilAttachment = mState.getStencilAttachment(); |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 279 | clearStencil = clearStencil && stencilAttachment; |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 280 | ASSERT(!clearStencil || stencilAttachment->isAttached()); |
| 281 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 282 | uint8_t stencilMask = |
| 283 | static_cast<uint8_t>(contextVk->getState().getDepthStencilState().stencilWritemask); |
| 284 | |
| 285 | // The front-end should ensure we don't attempt to clear color if all channels are masked. |
| 286 | ASSERT(!clearColor || colorMaskFlags != 0); |
| 287 | // The front-end should ensure we don't attempt to clear depth if depth write is disabled. |
| 288 | ASSERT(!clearDepth || contextVk->getState().getDepthStencilState().depthMask); |
| 289 | // The front-end should ensure we don't attempt to clear stencil if all bits are masked. |
| 290 | ASSERT(!clearStencil || stencilMask != 0); |
| 291 | |
| 292 | // If there is nothing to clear, return right away (for example, if asked to clear depth, but |
| 293 | // there is no depth attachment). |
Shahbaz Youssefi | 02a579e | 2019-03-27 14:21:20 -0400 | [diff] [blame] | 294 | if (!clearColor && !clearDepth && !clearStencil) |
| 295 | { |
| 296 | return angle::Result::Continue; |
| 297 | } |
| 298 | |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 299 | VkClearDepthStencilValue modifiedDepthStencilValue = clearDepthStencilValue; |
Shahbaz Youssefi | d856ca4 | 2018-10-31 16:55:12 -0400 | [diff] [blame] | 300 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 301 | // We can use render pass load ops if clearing depth, unmasked color or unmasked stencil. If |
| 302 | // there's a depth mask, depth clearing is already disabled. |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 303 | bool maskedClearColor = |
| 304 | clearColor && (mActiveColorComponents & colorMaskFlags) != mActiveColorComponents; |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 305 | bool maskedClearStencil = stencilMask != 0xFF; |
| 306 | |
| 307 | bool clearColorWithRenderPassLoadOp = clearColor && !maskedClearColor; |
| 308 | bool clearStencilWithRenderPassLoadOp = clearStencil && !maskedClearStencil; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 309 | |
| 310 | // At least one of color, depth or stencil should be clearable with render pass loadOp for us |
| 311 | // to use this clear path. |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 312 | bool clearAnyWithRenderPassLoadOp = |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 313 | clearColorWithRenderPassLoadOp || clearDepth || clearStencilWithRenderPassLoadOp; |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 314 | |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 315 | if (clearAnyWithRenderPassLoadOp) |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 316 | { |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 317 | // Clearing color is indicated by the set bits in this mask. If not clearing colors with |
| 318 | // render pass loadOp, the default value of all-zeros means the clear is not done in |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 319 | // clearWithRenderPassOp below. In that case, only clear depth/stencil with render pass |
| 320 | // loadOp. |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 321 | gl::DrawBufferMask clearBuffersWithRenderPassLoadOp; |
| 322 | if (clearColorWithRenderPassLoadOp) |
| 323 | { |
| 324 | clearBuffersWithRenderPassLoadOp = clearColorBuffers; |
| 325 | } |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 326 | ANGLE_TRY(clearWithRenderPassOp( |
| 327 | contextVk, scissoredRenderArea, clearBuffersWithRenderPassLoadOp, clearDepth, |
| 328 | clearStencilWithRenderPassLoadOp, clearColorValue, modifiedDepthStencilValue)); |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 329 | |
Shahbaz Youssefi | 27f115a | 2019-04-01 10:33:21 -0400 | [diff] [blame] | 330 | // On some hardware, having inline commands at this point results in corrupted output. In |
| 331 | // that case, end the render pass immediately. http://anglebug.com/2361 |
Jonah Ryan-Davis | 776694c | 2019-05-08 10:28:55 -0400 | [diff] [blame] | 332 | if (contextVk->getRenderer()->getFeatures().restartRenderPassAfterLoadOpClear.enabled) |
Shahbaz Youssefi | 27f115a | 2019-04-01 10:33:21 -0400 | [diff] [blame] | 333 | { |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 334 | mFramebuffer.finishCurrentCommands(contextVk); |
Shahbaz Youssefi | 27f115a | 2019-04-01 10:33:21 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 337 | // Fallback to other methods for whatever isn't cleared here. |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 338 | clearDepth = false; |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 339 | if (clearColorWithRenderPassLoadOp) |
| 340 | { |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 341 | clearColorBuffers.reset(); |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 342 | clearColor = false; |
| 343 | } |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 344 | if (clearStencilWithRenderPassLoadOp) |
| 345 | { |
| 346 | clearStencil = false; |
| 347 | } |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 348 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 349 | // If nothing left to clear, early out. |
| 350 | if (!clearColor && !clearStencil) |
Shahbaz Youssefi | f1153b0 | 2019-03-27 11:22:54 -0400 | [diff] [blame] | 351 | { |
| 352 | return angle::Result::Continue; |
| 353 | } |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 354 | } |
| 355 | |
Shahbaz Youssefi | 2249d4a | 2019-04-05 16:48:55 -0400 | [diff] [blame] | 356 | // Note: depth clear is always done through render pass loadOp. |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 357 | ASSERT(clearDepth == false); |
| 358 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 359 | // The most costly clear mode is when we need to mask out specific color channels or stencil |
Shahbaz Youssefi | 2249d4a | 2019-04-05 16:48:55 -0400 | [diff] [blame] | 360 | // bits. This can only be done with a draw call. |
| 361 | return clearWithDraw(contextVk, scissoredRenderArea, clearColorBuffers, clearStencil, |
| 362 | colorMaskFlags, stencilMask, clearColorValue, |
| 363 | static_cast<uint8_t>(modifiedDepthStencilValue.stencil)); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 364 | } |
| 365 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 366 | angle::Result FramebufferVk::clearBufferfv(const gl::Context *context, |
| 367 | GLenum buffer, |
| 368 | GLint drawbuffer, |
| 369 | const GLfloat *values) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 370 | { |
Shahbaz Youssefi | edef895 | 2019-04-04 10:03:09 -0400 | [diff] [blame] | 371 | VkClearValue clearValue = {}; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 372 | |
| 373 | bool clearDepth = false; |
| 374 | gl::DrawBufferMask clearColorBuffers; |
| 375 | |
| 376 | if (buffer == GL_DEPTH) |
| 377 | { |
| 378 | clearDepth = true; |
| 379 | clearValue.depthStencil.depth = values[0]; |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | clearColorBuffers.set(drawbuffer); |
| 384 | clearValue.color.float32[0] = values[0]; |
| 385 | clearValue.color.float32[1] = values[1]; |
| 386 | clearValue.color.float32[2] = values[2]; |
| 387 | clearValue.color.float32[3] = values[3]; |
| 388 | } |
| 389 | |
| 390 | return clearImpl(context, clearColorBuffers, clearDepth, false, clearValue.color, |
| 391 | clearValue.depthStencil); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 394 | angle::Result FramebufferVk::clearBufferuiv(const gl::Context *context, |
| 395 | GLenum buffer, |
| 396 | GLint drawbuffer, |
| 397 | const GLuint *values) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 398 | { |
Shahbaz Youssefi | edef895 | 2019-04-04 10:03:09 -0400 | [diff] [blame] | 399 | VkClearValue clearValue = {}; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 400 | |
| 401 | gl::DrawBufferMask clearColorBuffers; |
| 402 | clearColorBuffers.set(drawbuffer); |
| 403 | |
| 404 | clearValue.color.uint32[0] = values[0]; |
| 405 | clearValue.color.uint32[1] = values[1]; |
| 406 | clearValue.color.uint32[2] = values[2]; |
| 407 | clearValue.color.uint32[3] = values[3]; |
| 408 | |
| 409 | return clearImpl(context, clearColorBuffers, false, false, clearValue.color, |
| 410 | clearValue.depthStencil); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 411 | } |
| 412 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 413 | angle::Result FramebufferVk::clearBufferiv(const gl::Context *context, |
| 414 | GLenum buffer, |
| 415 | GLint drawbuffer, |
| 416 | const GLint *values) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 417 | { |
Shahbaz Youssefi | edef895 | 2019-04-04 10:03:09 -0400 | [diff] [blame] | 418 | VkClearValue clearValue = {}; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 419 | |
| 420 | bool clearStencil = false; |
| 421 | gl::DrawBufferMask clearColorBuffers; |
| 422 | |
| 423 | if (buffer == GL_STENCIL) |
| 424 | { |
| 425 | clearStencil = true; |
| 426 | clearValue.depthStencil.stencil = |
| 427 | gl::clamp(values[0], 0, std::numeric_limits<uint8_t>::max()); |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | clearColorBuffers.set(drawbuffer); |
| 432 | clearValue.color.int32[0] = values[0]; |
| 433 | clearValue.color.int32[1] = values[1]; |
| 434 | clearValue.color.int32[2] = values[2]; |
| 435 | clearValue.color.int32[3] = values[3]; |
| 436 | } |
| 437 | |
| 438 | return clearImpl(context, clearColorBuffers, false, clearStencil, clearValue.color, |
| 439 | clearValue.depthStencil); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 440 | } |
| 441 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 442 | angle::Result FramebufferVk::clearBufferfi(const gl::Context *context, |
| 443 | GLenum buffer, |
| 444 | GLint drawbuffer, |
| 445 | GLfloat depth, |
| 446 | GLint stencil) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 447 | { |
Shahbaz Youssefi | edef895 | 2019-04-04 10:03:09 -0400 | [diff] [blame] | 448 | VkClearValue clearValue = {}; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 449 | |
| 450 | clearValue.depthStencil.depth = depth; |
| 451 | clearValue.depthStencil.stencil = gl::clamp(stencil, 0, std::numeric_limits<uint8_t>::max()); |
| 452 | |
| 453 | return clearImpl(context, gl::DrawBufferMask(), true, true, clearValue.color, |
| 454 | clearValue.depthStencil); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 457 | GLenum FramebufferVk::getImplementationColorReadFormat(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 458 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 459 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).format; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 460 | } |
| 461 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 462 | GLenum FramebufferVk::getImplementationColorReadType(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 463 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 464 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).type; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 467 | angle::Result FramebufferVk::readPixels(const gl::Context *context, |
| 468 | const gl::Rectangle &area, |
| 469 | GLenum format, |
| 470 | GLenum type, |
| 471 | void *pixels) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 472 | { |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 473 | // Clip read area to framebuffer. |
| 474 | const gl::Extents &fbSize = getState().getReadAttachment()->getSize(); |
| 475 | const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 476 | ContextVk *contextVk = vk::GetImpl(context); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 477 | |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 478 | gl::Rectangle clippedArea; |
| 479 | if (!ClipRectangle(area, fbRect, &clippedArea)) |
| 480 | { |
| 481 | // nothing to read |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 482 | return angle::Result::Continue; |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 483 | } |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 484 | gl::Rectangle flippedArea = clippedArea; |
Geoff Lang | e076a23 | 2018-07-16 15:34:05 -0400 | [diff] [blame] | 485 | if (contextVk->isViewportFlipEnabledForReadFBO()) |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 486 | { |
| 487 | flippedArea.y = fbRect.height - flippedArea.y - flippedArea.height; |
| 488 | } |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 489 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 490 | const gl::State &glState = context->getState(); |
Frank Henigman | 1ffad84 | 2018-09-24 23:40:45 -0400 | [diff] [blame] | 491 | const gl::PixelPackState &packState = glState.getPackState(); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 492 | |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 493 | const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type); |
| 494 | |
| 495 | GLuint outputPitch = 0; |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 496 | ANGLE_VK_CHECK_MATH(contextVk, |
| 497 | sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, |
| 498 | packState.rowLength, &outputPitch)); |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 499 | GLuint outputSkipBytes = 0; |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 500 | ANGLE_VK_CHECK_MATH(contextVk, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState, |
| 501 | false, &outputSkipBytes)); |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 502 | |
| 503 | outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + |
| 504 | (clippedArea.y - area.y) * outputPitch; |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 505 | |
Jamie Madill | db9c69e | 2018-07-18 17:23:47 -0400 | [diff] [blame] | 506 | const angle::Format &angleFormat = GetFormatFromFormatType(format, type); |
| 507 | |
Frank Henigman | 1ffad84 | 2018-09-24 23:40:45 -0400 | [diff] [blame] | 508 | PackPixelsParams params(flippedArea, angleFormat, outputPitch, packState.reverseRowOrder, |
Jamie Madill | db9c69e | 2018-07-18 17:23:47 -0400 | [diff] [blame] | 509 | glState.getTargetBuffer(gl::BufferBinding::PixelPack), 0); |
Frank Henigman | 1ffad84 | 2018-09-24 23:40:45 -0400 | [diff] [blame] | 510 | if (contextVk->isViewportFlipEnabledForReadFBO()) |
| 511 | { |
| 512 | params.reverseRowOrder = !params.reverseRowOrder; |
| 513 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 514 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 515 | ANGLE_TRY(readPixelsImpl(contextVk, flippedArea, params, VK_IMAGE_ASPECT_COLOR_BIT, |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 516 | getColorReadRenderTarget(), |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 517 | static_cast<uint8_t *>(pixels) + outputSkipBytes)); |
Jamie Madill | c773ab9 | 2019-06-25 17:11:58 -0400 | [diff] [blame] | 518 | mReadPixelBuffer.releaseInFlightBuffers(contextVk); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 519 | return angle::Result::Continue; |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 520 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 521 | |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 522 | RenderTargetVk *FramebufferVk::getDepthStencilRenderTarget() const |
| 523 | { |
| 524 | return mRenderTargetCache.getDepthStencil(); |
| 525 | } |
| 526 | |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 527 | RenderTargetVk *FramebufferVk::getColorReadRenderTarget() const |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 528 | { |
| 529 | RenderTargetVk *renderTarget = mRenderTargetCache.getColorRead(mState); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 530 | ASSERT(renderTarget && renderTarget->getImage().valid()); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 531 | return renderTarget; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 532 | } |
| 533 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 534 | angle::Result FramebufferVk::blitWithCommand(ContextVk *contextVk, |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 535 | const gl::Rectangle &sourceArea, |
| 536 | const gl::Rectangle &destArea, |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 537 | RenderTargetVk *readRenderTarget, |
| 538 | RenderTargetVk *drawRenderTarget, |
| 539 | GLenum filter, |
| 540 | bool colorBlit, |
| 541 | bool depthBlit, |
| 542 | bool stencilBlit, |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 543 | bool flipX, |
| 544 | bool flipY) |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 545 | { |
| 546 | // Since blitRenderbufferRect is called for each render buffer that needs to be blitted, |
| 547 | // it should never be the case that both color and depth/stencil need to be blitted at |
| 548 | // at the same time. |
| 549 | ASSERT(colorBlit != (depthBlit || stencilBlit)); |
| 550 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 551 | vk::ImageHelper *srcImage = &readRenderTarget->getImage(); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 552 | vk::ImageHelper *dstImage = drawRenderTarget->getImageForWrite(&mFramebuffer); |
| 553 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 554 | VkImageAspectFlags imageAspectMask = srcImage->getAspectFlags(); |
| 555 | VkImageAspectFlags blitAspectMask = imageAspectMask; |
| 556 | |
| 557 | // Remove depth or stencil aspects if they are not requested to be blitted. |
| 558 | if (!depthBlit) |
| 559 | { |
| 560 | blitAspectMask &= ~VK_IMAGE_ASPECT_DEPTH_BIT; |
| 561 | } |
| 562 | if (!stencilBlit) |
| 563 | { |
| 564 | blitAspectMask &= ~VK_IMAGE_ASPECT_STENCIL_BIT; |
| 565 | } |
| 566 | |
| 567 | if (srcImage->isLayoutChangeNecessary(vk::ImageLayout::TransferSrc)) |
| 568 | { |
| 569 | vk::CommandBuffer *srcLayoutChange; |
| 570 | ANGLE_TRY(srcImage->recordCommands(contextVk, &srcLayoutChange)); |
| 571 | srcImage->changeLayout(imageAspectMask, vk::ImageLayout::TransferSrc, srcLayoutChange); |
| 572 | } |
| 573 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 574 | vk::CommandBuffer *commandBuffer = nullptr; |
| 575 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
| 576 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 577 | srcImage->addReadDependency(&mFramebuffer); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 578 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 579 | VkImageBlit blit = {}; |
| 580 | blit.srcSubresource.aspectMask = blitAspectMask; |
| 581 | blit.srcSubresource.mipLevel = readRenderTarget->getLevelIndex(); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 582 | blit.srcSubresource.baseArrayLayer = readRenderTarget->getLayerIndex(); |
| 583 | blit.srcSubresource.layerCount = 1; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 584 | blit.srcOffsets[0] = {sourceArea.x0(), sourceArea.y0(), 0}; |
| 585 | blit.srcOffsets[1] = {sourceArea.x1(), sourceArea.y1(), 1}; |
| 586 | blit.dstSubresource.aspectMask = blitAspectMask; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 587 | blit.dstSubresource.mipLevel = drawRenderTarget->getLevelIndex(); |
| 588 | blit.dstSubresource.baseArrayLayer = drawRenderTarget->getLayerIndex(); |
| 589 | blit.dstSubresource.layerCount = 1; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 590 | blit.dstOffsets[0] = {destArea.x0(), destArea.y0(), 0}; |
| 591 | blit.dstOffsets[1] = {destArea.x1(), destArea.y1(), 1}; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 592 | |
| 593 | // Requirement of the copyImageToBuffer, the dst image must be in |
| 594 | // VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL layout. |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 595 | dstImage->changeLayout(imageAspectMask, vk::ImageLayout::TransferDst, commandBuffer); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 596 | |
| 597 | commandBuffer->blitImage(srcImage->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 598 | dstImage->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, |
| 599 | gl_vk::GetFilter(filter)); |
| 600 | |
| 601 | return angle::Result::Continue; |
| 602 | } |
| 603 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 604 | angle::Result FramebufferVk::blit(const gl::Context *context, |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 605 | const gl::Rectangle &sourceAreaIn, |
| 606 | const gl::Rectangle &destAreaIn, |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 607 | GLbitfield mask, |
| 608 | GLenum filter) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 609 | { |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 610 | ContextVk *contextVk = vk::GetImpl(context); |
| 611 | RendererVk *renderer = contextVk->getRenderer(); |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 612 | UtilsVk &utilsVk = contextVk->getUtils(); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 613 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 614 | const gl::State &glState = contextVk->getState(); |
| 615 | const gl::Framebuffer *srcFramebuffer = glState.getReadFramebuffer(); |
| 616 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 617 | const bool blitColorBuffer = (mask & GL_COLOR_BUFFER_BIT) != 0; |
| 618 | const bool blitDepthBuffer = (mask & GL_DEPTH_BUFFER_BIT) != 0; |
| 619 | const bool blitStencilBuffer = (mask & GL_STENCIL_BUFFER_BIT) != 0; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 620 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 621 | const bool isResolve = srcFramebuffer->getCachedSamples(context) > 1; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 622 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 623 | FramebufferVk *srcFramebufferVk = vk::GetImpl(srcFramebuffer); |
| 624 | const bool srcFramebufferFlippedY = contextVk->isViewportFlipEnabledForReadFBO(); |
| 625 | const bool destFramebufferFlippedY = contextVk->isViewportFlipEnabledForDrawFBO(); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 626 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 627 | gl::Rectangle sourceArea = sourceAreaIn; |
| 628 | gl::Rectangle destArea = destAreaIn; |
| 629 | |
| 630 | // Note: GLES (all 3.x versions) require source and dest area to be identical when |
| 631 | // resolving. |
| 632 | ASSERT(!isResolve || |
| 633 | (sourceArea.x == destArea.x && sourceArea.y == destArea.y && |
| 634 | sourceArea.width == destArea.width && sourceArea.height == destArea.height)); |
| 635 | |
| 636 | const gl::Rectangle srcFramebufferDimensions = |
| 637 | srcFramebufferVk->mState.getDimensions().toRect(); |
| 638 | |
| 639 | // If the destination is flipped in either direction, we will flip the source instead so that |
| 640 | // the destination area is always unflipped. |
| 641 | sourceArea = sourceArea.flip(destArea.isReversedX(), destArea.isReversedY()); |
| 642 | destArea = destArea.removeReversal(); |
| 643 | |
| 644 | // Calculate the stretch factor prior to any clipping, as it needs to remain constant. |
| 645 | const float stretch[2] = { |
| 646 | std::abs(sourceArea.width / static_cast<float>(destArea.width)), |
| 647 | std::abs(sourceArea.height / static_cast<float>(destArea.height)), |
| 648 | }; |
| 649 | |
| 650 | // First, clip the source area to framebuffer. That requires transforming the dest area to |
| 651 | // match the clipped source. |
| 652 | gl::Rectangle absSourceArea = sourceArea.removeReversal(); |
| 653 | gl::Rectangle clippedSourceArea; |
| 654 | if (!gl::ClipRectangle(srcFramebufferDimensions, absSourceArea, &clippedSourceArea)) |
| 655 | { |
| 656 | return angle::Result::Continue; |
| 657 | } |
| 658 | |
| 659 | // Resize the destination area based on the new size of source. Note again that stretch is |
| 660 | // calculated as SrcDimension/DestDimension. |
| 661 | gl::Rectangle srcClippedDestArea; |
| 662 | if (isResolve) |
| 663 | { |
| 664 | // Source and dest areas are identical in resolve. |
| 665 | srcClippedDestArea = clippedSourceArea; |
| 666 | } |
| 667 | else if (clippedSourceArea == absSourceArea) |
| 668 | { |
| 669 | // If there was no clipping, keep dest area as is. |
| 670 | srcClippedDestArea = destArea; |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | // Shift dest area's x0,y0,x1,y1 by as much as the source area's got shifted (taking |
| 675 | // stretching into account) |
| 676 | float x0Shift = std::round((clippedSourceArea.x - absSourceArea.x) / stretch[0]); |
| 677 | float y0Shift = std::round((clippedSourceArea.y - absSourceArea.y) / stretch[1]); |
| 678 | float x1Shift = std::round((absSourceArea.x1() - clippedSourceArea.x1()) / stretch[0]); |
| 679 | float y1Shift = std::round((absSourceArea.y1() - clippedSourceArea.y1()) / stretch[1]); |
| 680 | |
| 681 | // If the source area was reversed in any direction, the shift should be applied in the |
| 682 | // opposite direction as well. |
| 683 | if (sourceArea.isReversedX()) |
| 684 | { |
| 685 | std::swap(x0Shift, x1Shift); |
| 686 | } |
| 687 | |
| 688 | if (sourceArea.isReversedY()) |
| 689 | { |
| 690 | std::swap(y0Shift, y1Shift); |
| 691 | } |
| 692 | |
| 693 | srcClippedDestArea.x = destArea.x0() + static_cast<int>(x0Shift); |
| 694 | srcClippedDestArea.y = destArea.y0() + static_cast<int>(y0Shift); |
| 695 | int x1 = destArea.x1() - static_cast<int>(x1Shift); |
| 696 | int y1 = destArea.y1() - static_cast<int>(y1Shift); |
| 697 | |
| 698 | srcClippedDestArea.width = x1 - srcClippedDestArea.x; |
| 699 | srcClippedDestArea.height = y1 - srcClippedDestArea.y; |
| 700 | } |
| 701 | |
| 702 | // If framebuffers are flipped in Y, flip the source and dest area (which define the |
| 703 | // transformation regardless of clipping), as well as the blit area (which is the clipped |
| 704 | // dest area). |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 705 | if (srcFramebufferFlippedY) |
| 706 | { |
| 707 | sourceArea.y = srcFramebufferDimensions.height - sourceArea.y; |
| 708 | sourceArea.height = -sourceArea.height; |
| 709 | } |
| 710 | if (destFramebufferFlippedY) |
| 711 | { |
| 712 | destArea.y = mState.getDimensions().height - destArea.y; |
| 713 | destArea.height = -destArea.height; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 714 | |
| 715 | srcClippedDestArea.y = |
| 716 | mState.getDimensions().height - srcClippedDestArea.y - srcClippedDestArea.height; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 717 | } |
| 718 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 719 | const bool flipX = sourceArea.isReversedX() != destArea.isReversedX(); |
| 720 | const bool flipY = sourceArea.isReversedY() != destArea.isReversedY(); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 721 | |
| 722 | // GLES doesn't allow flipping the parameters of glBlitFramebuffer if performing a resolve. |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 723 | ASSERT(!isResolve || |
| 724 | (flipX == false && flipY == (srcFramebufferFlippedY != destFramebufferFlippedY))); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 725 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 726 | // Again, transfer the destination flip to source, so dest is unflipped. Note that destArea |
| 727 | // was not reversed until the final possible Y-flip. |
| 728 | ASSERT(!destArea.isReversedX()); |
| 729 | sourceArea = sourceArea.flip(false, destArea.isReversedY()); |
| 730 | destArea = destArea.removeReversal(); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 731 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 732 | // Clip the destination area to the framebuffer size and scissor. Note that we don't care |
| 733 | // about the source area anymore. The offset translation is done based on the original source |
| 734 | // and destination rectangles. The stretch factor is already calculated as well. |
| 735 | gl::Rectangle blitArea; |
| 736 | if (!gl::ClipRectangle(getScissoredRenderArea(contextVk), srcClippedDestArea, &blitArea)) |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 737 | { |
| 738 | return angle::Result::Continue; |
| 739 | } |
| 740 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 741 | bool noClip = blitArea == destArea && stretch[0] == 1.0f && stretch[1] == 1.0f; |
| 742 | bool noFlip = !flipX && !flipY; |
| 743 | bool disableFlippingBlitWithCommand = |
| 744 | contextVk->getRenderer()->getFeatures().disableFlippingBlitWithCommand.enabled; |
| 745 | |
Shahbaz Youssefi | de70a71 | 2019-06-03 17:05:16 -0400 | [diff] [blame] | 746 | UtilsVk::BlitResolveParameters params; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 747 | params.srcOffset[0] = sourceArea.x; |
| 748 | params.srcOffset[1] = sourceArea.y; |
| 749 | params.destOffset[0] = destArea.x; |
| 750 | params.destOffset[1] = destArea.y; |
| 751 | params.stretch[0] = stretch[0]; |
| 752 | params.stretch[1] = stretch[1]; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 753 | params.srcExtents[0] = srcFramebufferDimensions.width; |
| 754 | params.srcExtents[1] = srcFramebufferDimensions.height; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 755 | params.blitArea = blitArea; |
| 756 | params.linear = filter == GL_LINEAR; |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 757 | params.flipX = flipX; |
| 758 | params.flipY = flipY; |
| 759 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 760 | if (blitColorBuffer) |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 761 | { |
| 762 | RenderTargetVk *readRenderTarget = srcFramebufferVk->getColorReadRenderTarget(); |
| 763 | params.srcLayer = readRenderTarget->getLayerIndex(); |
| 764 | |
| 765 | // Multisampled images are not allowed to have mips. |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 766 | ASSERT(!isResolve || readRenderTarget->getLevelIndex() == 0); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 767 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 768 | // If there was no clipping and the format capabilities allow us, use Vulkan's builtin blit. |
| 769 | // The reason clipping is prohibited in this path is that due to rounding errors, it would |
| 770 | // be hard to guarantee the image stretching remains perfect. That also allows us not to |
| 771 | // have to transform back the dest clipping to source. |
| 772 | // |
| 773 | // For simplicity, we either blit all render targets with a Vulkan command, or none. |
| 774 | bool canBlitWithCommand = !isResolve && noClip && |
| 775 | (noFlip || !disableFlippingBlitWithCommand) && |
| 776 | HasSrcBlitFeature(renderer, readRenderTarget); |
| 777 | bool areChannelsBlitCompatible = true; |
| 778 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
| 779 | { |
| 780 | RenderTargetVk *drawRenderTarget = mRenderTargetCache.getColors()[colorIndexGL]; |
| 781 | canBlitWithCommand = |
| 782 | canBlitWithCommand && HasDstBlitFeature(renderer, drawRenderTarget); |
| 783 | areChannelsBlitCompatible = |
| 784 | areChannelsBlitCompatible && |
| 785 | areSrcAndDstColorChannelsBlitCompatible(readRenderTarget, drawRenderTarget); |
| 786 | } |
| 787 | |
| 788 | if (canBlitWithCommand && areChannelsBlitCompatible) |
| 789 | { |
| 790 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
| 791 | { |
| 792 | RenderTargetVk *drawRenderTarget = mRenderTargetCache.getColors()[colorIndexGL]; |
| 793 | ANGLE_TRY(blitWithCommand(contextVk, sourceArea, destArea, readRenderTarget, |
| 794 | drawRenderTarget, filter, true, false, false, flipX, |
| 795 | flipY)); |
| 796 | } |
| 797 | } |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 798 | // If we're not flipping, use Vulkan's builtin resolve. |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 799 | else if (isResolve && !flipX && !flipY && areChannelsBlitCompatible) |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 800 | { |
| 801 | ANGLE_TRY(resolveColorWithCommand(contextVk, params, &readRenderTarget->getImage())); |
| 802 | } |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 803 | // Otherwise use a shader to do blit or resolve. |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 804 | else |
| 805 | { |
Shahbaz Youssefi | de70a71 | 2019-06-03 17:05:16 -0400 | [diff] [blame] | 806 | ANGLE_TRY(utilsVk.colorBlitResolve(contextVk, this, &readRenderTarget->getImage(), |
| 807 | readRenderTarget->getFetchImageView(), params)); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 811 | if (blitDepthBuffer || blitStencilBuffer) |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 812 | { |
| 813 | RenderTargetVk *readRenderTarget = srcFramebufferVk->getDepthStencilRenderTarget(); |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 814 | RenderTargetVk *drawRenderTarget = mRenderTargetCache.getDepthStencil(); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 815 | params.srcLayer = readRenderTarget->getLayerIndex(); |
| 816 | |
| 817 | // Multisampled images are not allowed to have mips. |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 818 | ASSERT(!isResolve || readRenderTarget->getLevelIndex() == 0); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 819 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 820 | // Similarly, only blit if there's been no clipping. |
| 821 | bool canBlitWithCommand = !isResolve && noClip && |
| 822 | (noFlip || !disableFlippingBlitWithCommand) && |
| 823 | HasSrcBlitFeature(renderer, readRenderTarget) && |
| 824 | HasDstBlitFeature(renderer, drawRenderTarget); |
| 825 | bool areChannelsBlitCompatible = |
| 826 | areSrcAndDstDepthStencilChannelsBlitCompatible(readRenderTarget, drawRenderTarget); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 827 | |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 828 | if (canBlitWithCommand && areChannelsBlitCompatible) |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 829 | { |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 830 | ANGLE_TRY(blitWithCommand(contextVk, sourceArea, destArea, readRenderTarget, |
| 831 | drawRenderTarget, filter, false, blitDepthBuffer, |
| 832 | blitStencilBuffer, flipX, flipY)); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 833 | } |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 834 | else |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 835 | { |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 836 | // Create depth- and stencil-only views for reading. |
| 837 | vk::Scoped<vk::ImageView> depthView(contextVk->getDevice()); |
| 838 | vk::Scoped<vk::ImageView> stencilView(contextVk->getDevice()); |
| 839 | |
| 840 | vk::ImageHelper *depthStencilImage = &readRenderTarget->getImage(); |
| 841 | uint32_t levelIndex = readRenderTarget->getLevelIndex(); |
| 842 | uint32_t layerIndex = readRenderTarget->getLayerIndex(); |
| 843 | gl::TextureType textureType = vk::Get2DTextureType(depthStencilImage->getLayerCount(), |
| 844 | depthStencilImage->getSamples()); |
| 845 | |
| 846 | if (blitDepthBuffer) |
| 847 | { |
| 848 | ANGLE_TRY(depthStencilImage->initLayerImageView( |
| 849 | contextVk, textureType, VK_IMAGE_ASPECT_DEPTH_BIT, gl::SwizzleState(), |
| 850 | &depthView.get(), levelIndex, 1, layerIndex, 1)); |
| 851 | } |
| 852 | |
| 853 | if (blitStencilBuffer) |
| 854 | { |
| 855 | ANGLE_TRY(depthStencilImage->initLayerImageView( |
| 856 | contextVk, textureType, VK_IMAGE_ASPECT_STENCIL_BIT, gl::SwizzleState(), |
| 857 | &stencilView.get(), levelIndex, 1, layerIndex, 1)); |
| 858 | } |
| 859 | |
| 860 | // If shader stencil export is not possible, defer stencil blit/stencil to another pass. |
| 861 | bool hasShaderStencilExport = |
| 862 | contextVk->getRenderer()->getFeatures().supportsShaderStencilExport.enabled; |
| 863 | |
| 864 | // Blit depth. If shader stencil export is present, blit stencil as well. |
| 865 | if (blitDepthBuffer || (blitStencilBuffer && hasShaderStencilExport)) |
| 866 | { |
| 867 | vk::ImageView *depth = blitDepthBuffer ? &depthView.get() : nullptr; |
| 868 | vk::ImageView *stencil = |
| 869 | blitStencilBuffer && hasShaderStencilExport ? &stencilView.get() : nullptr; |
| 870 | |
| 871 | ANGLE_TRY(utilsVk.depthStencilBlitResolve(contextVk, this, depthStencilImage, depth, |
| 872 | stencil, params)); |
| 873 | } |
| 874 | |
| 875 | // If shader stencil export is not present, blit stencil through a different path. |
| 876 | if (blitStencilBuffer && !hasShaderStencilExport) |
| 877 | { |
| 878 | ANGLE_TRY(utilsVk.stencilBlitResolveNoShaderExport( |
| 879 | contextVk, this, depthStencilImage, &stencilView.get(), params)); |
| 880 | } |
| 881 | |
| 882 | vk::ImageView depthViewObject = depthView.release(); |
| 883 | vk::ImageView stencilViewObject = stencilView.release(); |
| 884 | |
| 885 | contextVk->releaseObject(contextVk->getCurrentQueueSerial(), &depthViewObject); |
| 886 | contextVk->releaseObject(contextVk->getCurrentQueueSerial(), &stencilViewObject); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 887 | } |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | return angle::Result::Continue; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 891 | } // namespace rx |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 892 | |
| 893 | angle::Result FramebufferVk::resolveColorWithCommand(ContextVk *contextVk, |
Shahbaz Youssefi | de70a71 | 2019-06-03 17:05:16 -0400 | [diff] [blame] | 894 | const UtilsVk::BlitResolveParameters ¶ms, |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 895 | vk::ImageHelper *srcImage) |
| 896 | { |
| 897 | if (srcImage->isLayoutChangeNecessary(vk::ImageLayout::TransferSrc)) |
| 898 | { |
| 899 | vk::CommandBuffer *srcLayoutChange; |
| 900 | ANGLE_TRY(srcImage->recordCommands(contextVk, &srcLayoutChange)); |
| 901 | srcImage->changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferSrc, |
| 902 | srcLayoutChange); |
| 903 | } |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 904 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 905 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 16c2014 | 2018-10-01 13:58:19 -0400 | [diff] [blame] | 906 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
| 907 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 908 | // Source's layout change should happen before rendering |
| 909 | srcImage->addReadDependency(&mFramebuffer); |
Luc Ferron | 2658111 | 2018-06-21 09:43:08 -0400 | [diff] [blame] | 910 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 911 | VkImageResolve resolveRegion = {}; |
| 912 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 913 | resolveRegion.srcSubresource.mipLevel = 0; |
| 914 | resolveRegion.srcSubresource.baseArrayLayer = params.srcLayer; |
| 915 | resolveRegion.srcSubresource.layerCount = 1; |
| 916 | resolveRegion.srcOffset.x = params.srcOffset[0]; |
| 917 | resolveRegion.srcOffset.y = params.srcOffset[1]; |
| 918 | resolveRegion.srcOffset.z = 0; |
| 919 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 920 | resolveRegion.dstSubresource.layerCount = 1; |
| 921 | resolveRegion.dstOffset.x = params.destOffset[0]; |
| 922 | resolveRegion.dstOffset.y = params.destOffset[1]; |
| 923 | resolveRegion.dstOffset.z = 0; |
| 924 | resolveRegion.extent.width = params.srcExtents[0]; |
| 925 | resolveRegion.extent.height = params.srcExtents[1]; |
| 926 | resolveRegion.extent.depth = 1; |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 927 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 928 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 929 | { |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 930 | RenderTargetVk *drawRenderTarget = mRenderTargetCache.getColors()[colorIndexGL]; |
Shahbaz Youssefi | b407e1a | 2019-06-03 17:15:51 -0400 | [diff] [blame] | 931 | vk::ImageHelper *drawImage = drawRenderTarget->getImageForWrite(&mFramebuffer); |
| 932 | drawImage->changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferDst, |
| 933 | commandBuffer); |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 934 | |
| 935 | resolveRegion.dstSubresource.mipLevel = drawRenderTarget->getLevelIndex(); |
| 936 | resolveRegion.dstSubresource.baseArrayLayer = drawRenderTarget->getLayerIndex(); |
| 937 | |
| 938 | srcImage->resolve(&drawRenderTarget->getImage(), resolveRegion, commandBuffer); |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 941 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 944 | bool FramebufferVk::checkStatus(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 945 | { |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 946 | // if we have both a depth and stencil buffer, they must refer to the same object |
| 947 | // since we only support packed_depth_stencil and not separate depth and stencil |
| 948 | if (mState.hasSeparateDepthAndStencilAttachments()) |
| 949 | { |
| 950 | return false; |
| 951 | } |
| 952 | |
Jamie Madill | b79e7bb | 2017-10-24 13:55:50 -0400 | [diff] [blame] | 953 | return true; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 954 | } |
| 955 | |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 956 | angle::Result FramebufferVk::updateColorAttachment(const gl::Context *context, size_t colorIndexGL) |
| 957 | { |
| 958 | ContextVk *contextVk = vk::GetImpl(context); |
| 959 | |
| 960 | ANGLE_TRY(mRenderTargetCache.updateColorRenderTarget(context, mState, colorIndexGL)); |
| 961 | |
| 962 | // Update cached masks for masked clears. |
| 963 | RenderTargetVk *renderTarget = mRenderTargetCache.getColors()[colorIndexGL]; |
| 964 | if (renderTarget) |
| 965 | { |
| 966 | const angle::Format &emulatedFormat = renderTarget->getImageFormat().imageFormat(); |
| 967 | updateActiveColorMasks(colorIndexGL, emulatedFormat.redBits > 0, |
| 968 | emulatedFormat.greenBits > 0, emulatedFormat.blueBits > 0, |
| 969 | emulatedFormat.alphaBits > 0); |
| 970 | |
| 971 | const angle::Format &sourceFormat = renderTarget->getImageFormat().angleFormat(); |
| 972 | mEmulatedAlphaAttachmentMask.set( |
| 973 | colorIndexGL, sourceFormat.alphaBits == 0 && emulatedFormat.alphaBits > 0); |
| 974 | |
| 975 | contextVk->updateColorMask(context->getState().getBlendState()); |
| 976 | } |
| 977 | else |
| 978 | { |
| 979 | updateActiveColorMasks(colorIndexGL, false, false, false, false); |
| 980 | } |
| 981 | |
| 982 | return angle::Result::Continue; |
| 983 | } |
| 984 | |
Shahbaz Youssefi | da90448 | 2019-07-02 10:49:14 -0400 | [diff] [blame] | 985 | void FramebufferVk::invalidateImpl(ContextVk *contextVk, size_t count, const GLenum *attachments) |
| 986 | { |
| 987 | ASSERT(mFramebuffer.hasStartedRenderPass()); |
| 988 | |
| 989 | gl::DrawBufferMask invalidateColorBuffers; |
| 990 | bool invalidateDepthBuffer = false; |
| 991 | bool invalidateStencilBuffer = false; |
| 992 | |
| 993 | for (size_t i = 0; i < count; ++i) |
| 994 | { |
| 995 | const GLenum attachment = attachments[i]; |
| 996 | |
| 997 | switch (attachment) |
| 998 | { |
| 999 | case GL_DEPTH: |
| 1000 | case GL_DEPTH_ATTACHMENT: |
| 1001 | invalidateDepthBuffer = true; |
| 1002 | break; |
| 1003 | case GL_STENCIL: |
| 1004 | case GL_STENCIL_ATTACHMENT: |
| 1005 | invalidateStencilBuffer = true; |
| 1006 | break; |
| 1007 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1008 | invalidateDepthBuffer = true; |
| 1009 | invalidateStencilBuffer = true; |
| 1010 | break; |
| 1011 | default: |
| 1012 | ASSERT( |
| 1013 | (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15) || |
| 1014 | (attachment == GL_COLOR)); |
| 1015 | |
| 1016 | invalidateColorBuffers.set( |
| 1017 | attachment == GL_COLOR ? 0u : (attachment - GL_COLOR_ATTACHMENT0)); |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | // Set the appropriate storeOp for attachments. |
| 1022 | size_t attachmentIndexVk = 0; |
| 1023 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
| 1024 | { |
| 1025 | if (invalidateColorBuffers.test(colorIndexGL)) |
| 1026 | { |
| 1027 | mFramebuffer.invalidateRenderPassColorAttachment(attachmentIndexVk); |
| 1028 | } |
| 1029 | ++attachmentIndexVk; |
| 1030 | } |
| 1031 | |
| 1032 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 1033 | if (depthStencilRenderTarget) |
| 1034 | { |
| 1035 | if (invalidateDepthBuffer) |
| 1036 | { |
| 1037 | mFramebuffer.invalidateRenderPassDepthAttachment(attachmentIndexVk); |
| 1038 | } |
| 1039 | |
| 1040 | if (invalidateStencilBuffer) |
| 1041 | { |
| 1042 | mFramebuffer.invalidateRenderPassStencilAttachment(attachmentIndexVk); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | // NOTE: Possible future optimization is to delay setting the storeOp and only do so if the |
| 1047 | // render pass is closed by itself before another draw call. Otherwise, in a situation like |
| 1048 | // this: |
| 1049 | // |
| 1050 | // draw() |
| 1051 | // invalidate() |
| 1052 | // draw() |
| 1053 | // |
| 1054 | // We would be discarding the attachments only to load them for the next draw (which is less |
| 1055 | // efficient than keeping the render pass open and not do the discard at all). While dEQP tests |
| 1056 | // this pattern, this optimization may not be necessary if no application does this. It is |
| 1057 | // expected that an application would invalidate() when it's done with the framebuffer, so the |
| 1058 | // render pass would have closed either way. |
| 1059 | mFramebuffer.finishCurrentCommands(contextVk); |
| 1060 | } |
| 1061 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 1062 | angle::Result FramebufferVk::syncState(const gl::Context *context, |
| 1063 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1064 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 1065 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1066 | |
| 1067 | ASSERT(dirtyBits.any()); |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 1068 | for (size_t dirtyBit : dirtyBits) |
| 1069 | { |
| 1070 | switch (dirtyBit) |
| 1071 | { |
| 1072 | case gl::Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: |
| 1073 | case gl::Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: |
| 1074 | ANGLE_TRY(mRenderTargetCache.updateDepthStencilRenderTarget(context, mState)); |
| 1075 | break; |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1076 | case gl::Framebuffer::DIRTY_BIT_DEPTH_BUFFER_CONTENTS: |
| 1077 | case gl::Framebuffer::DIRTY_BIT_STENCIL_BUFFER_CONTENTS: |
| 1078 | ANGLE_TRY(mRenderTargetCache.getDepthStencil()->flushStagedUpdates(contextVk)); |
| 1079 | break; |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 1080 | case gl::Framebuffer::DIRTY_BIT_DRAW_BUFFERS: |
| 1081 | case gl::Framebuffer::DIRTY_BIT_READ_BUFFER: |
| 1082 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_WIDTH: |
| 1083 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_HEIGHT: |
| 1084 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_SAMPLES: |
| 1085 | case gl::Framebuffer::DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1086 | break; |
| 1087 | default: |
| 1088 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1089 | static_assert(gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0, "FB dirty bits"); |
| 1090 | if (dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1091 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1092 | size_t colorIndexGL = static_cast<size_t>( |
| 1093 | dirtyBit - gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 1094 | ANGLE_TRY(updateColorAttachment(context, colorIndexGL)); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1095 | } |
| 1096 | else |
| 1097 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1098 | ASSERT(dirtyBit >= gl::Framebuffer::DIRTY_BIT_COLOR_BUFFER_CONTENTS_0 && |
| 1099 | dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_BUFFER_CONTENTS_MAX); |
| 1100 | size_t colorIndexGL = static_cast<size_t>( |
| 1101 | dirtyBit - gl::Framebuffer::DIRTY_BIT_COLOR_BUFFER_CONTENTS_0); |
| 1102 | ANGLE_TRY(mRenderTargetCache.getColors()[colorIndexGL]->flushStagedUpdates( |
| 1103 | contextVk)); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1104 | } |
Jamie Madill | 57d9cbb | 2018-04-27 11:45:04 -0400 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | } |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1108 | |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1109 | // The FBOs new attachment may have changed the renderable area |
| 1110 | const gl::State &glState = context->getState(); |
| 1111 | contextVk->updateScissor(glState); |
| 1112 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1113 | mActiveColorComponents = gl_vk::GetColorComponentFlags( |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 1114 | mActiveColorComponentMasksForClear[0].any(), mActiveColorComponentMasksForClear[1].any(), |
| 1115 | mActiveColorComponentMasksForClear[2].any(), mActiveColorComponentMasksForClear[3].any()); |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1116 | |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1117 | mFramebuffer.release(contextVk); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1118 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 1119 | // 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] | 1120 | // create a new entry in the command graph. |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1121 | mFramebuffer.finishCurrentCommands(contextVk); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 1122 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1123 | // Notify the ContextVk to update the pipeline desc. |
| 1124 | updateRenderPassDesc(); |
Shahbaz Youssefi | da90448 | 2019-07-02 10:49:14 -0400 | [diff] [blame] | 1125 | |
| 1126 | FramebufferVk *currentDrawFramebuffer = vk::GetImpl(context->getState().getDrawFramebuffer()); |
| 1127 | if (currentDrawFramebuffer == this) |
| 1128 | { |
| 1129 | contextVk->onDrawFramebufferChange(this); |
| 1130 | } |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 1131 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1132 | return angle::Result::Continue; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1133 | } |
| 1134 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1135 | void FramebufferVk::updateRenderPassDesc() |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1136 | { |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1137 | mRenderPassDesc = {}; |
| 1138 | mRenderPassDesc.setSamples(getSamples()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1139 | |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1140 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 1141 | const gl::DrawBufferMask enabledDrawBuffers = mState.getEnabledDrawBuffers(); |
| 1142 | for (size_t colorIndexGL = 0; colorIndexGL < enabledDrawBuffers.size(); ++colorIndexGL) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1143 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1144 | if (enabledDrawBuffers[colorIndexGL]) |
| 1145 | { |
| 1146 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndexGL]; |
| 1147 | ASSERT(colorRenderTarget); |
| 1148 | mRenderPassDesc.packColorAttachment( |
| 1149 | colorIndexGL, colorRenderTarget->getImage().getFormat().angleFormatID); |
| 1150 | } |
| 1151 | else |
| 1152 | { |
| 1153 | mRenderPassDesc.packColorAttachmentGap(colorIndexGL); |
| 1154 | } |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1155 | } |
| 1156 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1157 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 1158 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1159 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1160 | mRenderPassDesc.packDepthStencilAttachment( |
| 1161 | depthStencilRenderTarget->getImage().getFormat().angleFormatID); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1162 | } |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1163 | } |
| 1164 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1165 | angle::Result FramebufferVk::getFramebuffer(ContextVk *contextVk, vk::Framebuffer **framebufferOut) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1166 | { |
| 1167 | // If we've already created our cached Framebuffer, return it. |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1168 | if (mFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1169 | { |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1170 | *framebufferOut = &mFramebuffer.getFramebuffer(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1171 | return angle::Result::Continue; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1172 | } |
| 1173 | |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1174 | vk::RenderPass *compatibleRenderPass = nullptr; |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1175 | ANGLE_TRY(contextVk->getCompatibleRenderPass(mRenderPassDesc, &compatibleRenderPass)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1176 | |
| 1177 | // If we've a Framebuffer provided by a Surface (default FBO/backbuffer), query it. |
| 1178 | if (mBackbuffer) |
| 1179 | { |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1180 | return mBackbuffer->getCurrentFramebuffer(contextVk, *compatibleRenderPass, framebufferOut); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | // Gather VkImageViews over all FBO attachments, also size of attached region. |
| 1184 | std::vector<VkImageView> attachments; |
| 1185 | gl::Extents attachmentsSize; |
| 1186 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1187 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1188 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1189 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1190 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndexGL]; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1191 | ASSERT(colorRenderTarget); |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 1192 | attachments.push_back(colorRenderTarget->getDrawImageView()->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1193 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 1194 | ASSERT(attachmentsSize.empty() || attachmentsSize == colorRenderTarget->getExtents()); |
| 1195 | attachmentsSize = colorRenderTarget->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1196 | } |
| 1197 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1198 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 1199 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1200 | { |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 1201 | attachments.push_back(depthStencilRenderTarget->getDrawImageView()->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1202 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 1203 | ASSERT(attachmentsSize.empty() || |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 1204 | attachmentsSize == depthStencilRenderTarget->getExtents()); |
| 1205 | attachmentsSize = depthStencilRenderTarget->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1206 | } |
| 1207 | |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1208 | if (attachmentsSize.empty()) |
| 1209 | { |
| 1210 | // No attachments, so use the default values. |
| 1211 | attachmentsSize.height = mState.getDefaultHeight(); |
| 1212 | attachmentsSize.width = mState.getDefaultWidth(); |
| 1213 | attachmentsSize.depth = 0; |
| 1214 | } |
| 1215 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 1216 | VkFramebufferCreateInfo framebufferInfo = {}; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1217 | |
| 1218 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1219 | framebufferInfo.flags = 0; |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1220 | framebufferInfo.renderPass = compatibleRenderPass->getHandle(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 1221 | framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); |
| 1222 | framebufferInfo.pAttachments = attachments.data(); |
| 1223 | framebufferInfo.width = static_cast<uint32_t>(attachmentsSize.width); |
| 1224 | framebufferInfo.height = static_cast<uint32_t>(attachmentsSize.height); |
| 1225 | framebufferInfo.layers = 1; |
| 1226 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1227 | ANGLE_TRY(mFramebuffer.init(contextVk, framebufferInfo)); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 1228 | |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1229 | *framebufferOut = &mFramebuffer.getFramebuffer(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1230 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1233 | angle::Result FramebufferVk::clearWithRenderPassOp( |
| 1234 | ContextVk *contextVk, |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1235 | const gl::Rectangle &clearArea, |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1236 | gl::DrawBufferMask clearColorBuffers, |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1237 | bool clearDepth, |
| 1238 | bool clearStencil, |
| 1239 | const VkClearColorValue &clearColorValue, |
| 1240 | const VkClearDepthStencilValue &clearDepthStencilValue) |
| 1241 | { |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1242 | // Start a new render pass if: |
| 1243 | // |
| 1244 | // - no render pass has started, |
| 1245 | // - there is a render pass started but it contains commands; we cannot modify its ops, so new |
| 1246 | // render pass is needed, |
| 1247 | // - the current render area doesn't match the clear area. We need the render area to be |
| 1248 | // exactly as specified by the scissor for the loadOp to clear only that area. See |
| 1249 | // onScissorChange for more information. |
| 1250 | |
| 1251 | if (!mFramebuffer.valid() || !mFramebuffer.renderPassStartedButEmpty() || |
| 1252 | mFramebuffer.getRenderPassRenderArea() != clearArea) |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1253 | { |
| 1254 | vk::CommandBuffer *commandBuffer; |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1255 | ANGLE_TRY(startNewRenderPass(contextVk, clearArea, &commandBuffer)); |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1258 | size_t attachmentIndexVk = 0; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1259 | |
| 1260 | // Go through clearColorBuffers and set the appropriate loadOp and clear values. |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1261 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1262 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1263 | if (clearColorBuffers.test(colorIndexGL)) |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1264 | { |
| 1265 | RenderTargetVk *renderTarget = getColorReadRenderTarget(); |
| 1266 | |
| 1267 | // If the render target doesn't have alpha, but its emulated format has it, clear the |
| 1268 | // alpha to 1. |
| 1269 | VkClearColorValue value = clearColorValue; |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1270 | if (mEmulatedAlphaAttachmentMask[colorIndexGL]) |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1271 | { |
| 1272 | SetEmulatedAlphaValue(renderTarget->getImageFormat(), &value); |
| 1273 | } |
| 1274 | |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1275 | mFramebuffer.clearRenderPassColorAttachment(attachmentIndexVk, value); |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1276 | } |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1277 | ++attachmentIndexVk; |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | // Set the appropriate loadOp and clear values for depth and stencil. |
| 1281 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 1282 | if (depthStencilRenderTarget) |
| 1283 | { |
| 1284 | if (clearDepth) |
| 1285 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1286 | mFramebuffer.clearRenderPassDepthAttachment(attachmentIndexVk, |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1287 | clearDepthStencilValue.depth); |
| 1288 | } |
| 1289 | |
| 1290 | if (clearStencil) |
| 1291 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1292 | mFramebuffer.clearRenderPassStencilAttachment(attachmentIndexVk, |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1293 | clearDepthStencilValue.stencil); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | return angle::Result::Continue; |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1298 | } |
| 1299 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1300 | angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk, |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1301 | const gl::Rectangle &clearArea, |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1302 | gl::DrawBufferMask clearColorBuffers, |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1303 | bool clearStencil, |
| 1304 | VkColorComponentFlags colorMaskFlags, |
| 1305 | uint8_t stencilMask, |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1306 | const VkClearColorValue &clearColorValue, |
Shahbaz Youssefi | 2249d4a | 2019-04-05 16:48:55 -0400 | [diff] [blame] | 1307 | uint8_t clearStencilValue) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1308 | { |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1309 | UtilsVk::ClearFramebufferParameters params = {}; |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1310 | params.clearArea = clearArea; |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1311 | params.colorClearValue = clearColorValue; |
Shahbaz Youssefi | 2249d4a | 2019-04-05 16:48:55 -0400 | [diff] [blame] | 1312 | params.stencilClearValue = clearStencilValue; |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1313 | params.stencilMask = stencilMask; |
| 1314 | |
| 1315 | params.clearColor = true; |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1316 | params.clearStencil = clearStencil; |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1317 | |
Shahbaz Youssefi | 4399701 | 2019-03-30 23:24:01 -0400 | [diff] [blame] | 1318 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1319 | for (size_t colorIndexGL : clearColorBuffers) |
Shahbaz Youssefi | 4399701 | 2019-03-30 23:24:01 -0400 | [diff] [blame] | 1320 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1321 | const RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndexGL]; |
Shahbaz Youssefi | 4399701 | 2019-03-30 23:24:01 -0400 | [diff] [blame] | 1322 | ASSERT(colorRenderTarget); |
| 1323 | |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1324 | params.colorFormat = &colorRenderTarget->getImage().getFormat().imageFormat(); |
James Darpinian | 7e48c9e | 2019-08-06 17:17:19 -0700 | [diff] [blame^] | 1325 | params.colorAttachmentIndexGL = static_cast<uint32_t>(colorIndexGL); |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1326 | params.colorMaskFlags = colorMaskFlags; |
| 1327 | if (mEmulatedAlphaAttachmentMask[colorIndexGL]) |
Shahbaz Youssefi | 4399701 | 2019-03-30 23:24:01 -0400 | [diff] [blame] | 1328 | { |
| 1329 | params.colorMaskFlags &= ~VK_COLOR_COMPONENT_A_BIT; |
| 1330 | } |
| 1331 | |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1332 | ANGLE_TRY(contextVk->getUtils().clearFramebuffer(contextVk, this, params)); |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1333 | |
Shahbaz Youssefi | 2249d4a | 2019-04-05 16:48:55 -0400 | [diff] [blame] | 1334 | // Clear stencil only once! |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1335 | params.clearStencil = false; |
| 1336 | } |
| 1337 | |
Shahbaz Youssefi | 2249d4a | 2019-04-05 16:48:55 -0400 | [diff] [blame] | 1338 | // If there was no color clear, clear stencil alone. |
| 1339 | if (params.clearStencil) |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1340 | { |
| 1341 | params.clearColor = false; |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1342 | ANGLE_TRY(contextVk->getUtils().clearFramebuffer(contextVk, this, params)); |
Shahbaz Youssefi | 4399701 | 2019-03-30 23:24:01 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | return angle::Result::Continue; |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1348 | angle::Result FramebufferVk::getSamplePosition(const gl::Context *context, |
| 1349 | size_t index, |
| 1350 | GLfloat *xy) const |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1351 | { |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1352 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1353 | return angle::Result::Stop; |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Jamie Madill | d1249de | 2018-08-28 16:58:53 -0400 | [diff] [blame] | 1356 | angle::Result FramebufferVk::startNewRenderPass(ContextVk *contextVk, |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1357 | const gl::Rectangle &renderArea, |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1358 | vk::CommandBuffer **commandBufferOut) |
Jamie Madill | d1249de | 2018-08-28 16:58:53 -0400 | [diff] [blame] | 1359 | { |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1360 | vk::Framebuffer *framebuffer = nullptr; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1361 | ANGLE_TRY(getFramebuffer(contextVk, &framebuffer)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1362 | |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1363 | vk::AttachmentOpsArray renderPassAttachmentOps; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1364 | std::vector<VkClearValue> attachmentClearValues; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1365 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1366 | vk::CommandBuffer *writeCommands = nullptr; |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1367 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &writeCommands)); |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 1368 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1369 | // Initialize RenderPass info. |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1370 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1371 | for (size_t colorIndexGL : mState.getEnabledDrawBuffers()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 1372 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1373 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndexGL]; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1374 | ASSERT(colorRenderTarget); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1375 | |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1376 | ANGLE_TRY(colorRenderTarget->onColorDraw(contextVk, &mFramebuffer, writeCommands)); |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1377 | |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1378 | renderPassAttachmentOps.initWithLoadStore(attachmentClearValues.size(), |
| 1379 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 1380 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); |
| 1381 | attachmentClearValues.emplace_back(kUninitializedClearValue); |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 1385 | if (depthStencilRenderTarget) |
| 1386 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1387 | ANGLE_TRY( |
| 1388 | depthStencilRenderTarget->onDepthStencilDraw(contextVk, &mFramebuffer, writeCommands)); |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1389 | |
Shahbaz Youssefi | db4ed31 | 2019-03-29 00:32:45 -0400 | [diff] [blame] | 1390 | renderPassAttachmentOps.initWithLoadStore(attachmentClearValues.size(), |
| 1391 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
| 1392 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); |
| 1393 | attachmentClearValues.emplace_back(kUninitializedClearValue); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 1394 | } |
| 1395 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1396 | return mFramebuffer.beginRenderPass(contextVk, *framebuffer, renderArea, mRenderPassDesc, |
Shahbaz Youssefi | 0c128e1 | 2019-03-25 23:50:14 -0400 | [diff] [blame] | 1397 | renderPassAttachmentOps, attachmentClearValues, |
| 1398 | commandBufferOut); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1401 | void FramebufferVk::updateActiveColorMasks(size_t colorIndexGL, bool r, bool g, bool b, bool a) |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1402 | { |
Shahbaz Youssefi | 9fa248e | 2019-05-06 14:55:18 -0400 | [diff] [blame] | 1403 | mActiveColorComponentMasksForClear[0].set(colorIndexGL, r); |
| 1404 | mActiveColorComponentMasksForClear[1].set(colorIndexGL, g); |
| 1405 | mActiveColorComponentMasksForClear[2].set(colorIndexGL, b); |
| 1406 | mActiveColorComponentMasksForClear[3].set(colorIndexGL, a); |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 1407 | } |
| 1408 | |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 1409 | const gl::DrawBufferMask &FramebufferVk::getEmulatedAlphaAttachmentMask() const |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 1410 | { |
| 1411 | return mEmulatedAlphaAttachmentMask; |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1412 | } |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1413 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1414 | angle::Result FramebufferVk::readPixelsImpl(ContextVk *contextVk, |
| 1415 | const gl::Rectangle &area, |
| 1416 | const PackPixelsParams &packPixelsParams, |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1417 | VkImageAspectFlagBits copyAspectFlags, |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1418 | RenderTargetVk *renderTarget, |
| 1419 | void *pixels) |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1420 | { |
Jamie Madill | 3ea463b | 2019-06-19 14:21:33 -0400 | [diff] [blame] | 1421 | ANGLE_TRACE_EVENT0("gpu.angle", "FramebufferVk::readPixelsImpl"); |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1422 | |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1423 | RendererVk *renderer = contextVk->getRenderer(); |
| 1424 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1425 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | e8dd079 | 2018-09-27 15:04:27 -0400 | [diff] [blame] | 1426 | ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer)); |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1427 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1428 | // Note that although we're reading from the image, we need to update the layout below. |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 1429 | vk::ImageHelper *srcImage = |
| 1430 | renderTarget->getImageForRead(&mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1431 | |
Jamie Madill | 0631e19 | 2019-04-18 16:09:12 -0400 | [diff] [blame] | 1432 | const angle::Format *readFormat = &srcImage->getFormat().imageFormat(); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1433 | |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1434 | if (copyAspectFlags != VK_IMAGE_ASPECT_COLOR_BIT) |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1435 | { |
Jamie Madill | b436aac | 2018-07-18 17:23:48 -0400 | [diff] [blame] | 1436 | readFormat = &GetDepthStencilImageToBufferFormat(*readFormat, copyAspectFlags); |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
James Darpinian | 7e48c9e | 2019-08-06 17:17:19 -0700 | [diff] [blame^] | 1439 | uint32_t level = renderTarget->getLevelIndex(); |
| 1440 | uint32_t layer = renderTarget->getLayerIndex(); |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1441 | VkOffset3D srcOffset = {area.x, area.y, 0}; |
Cody Northrop | eb0479e | 2019-07-24 14:15:56 -0600 | [diff] [blame] | 1442 | |
| 1443 | VkImageSubresourceLayers srcSubresource = {}; |
| 1444 | srcSubresource.aspectMask = copyAspectFlags; |
| 1445 | srcSubresource.mipLevel = level; |
| 1446 | srcSubresource.baseArrayLayer = layer; |
| 1447 | srcSubresource.layerCount = 1; |
| 1448 | |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1449 | VkExtent3D srcExtent = {static_cast<uint32_t>(area.width), static_cast<uint32_t>(area.height), |
| 1450 | 1}; |
| 1451 | |
Cody Northrop | eb0479e | 2019-07-24 14:15:56 -0600 | [diff] [blame] | 1452 | if (srcImage->getExtents().depth > 1) |
| 1453 | { |
| 1454 | // Depth > 1 means this is a 3D texture and we need special handling |
| 1455 | srcOffset.z = layer; |
| 1456 | srcSubresource.baseArrayLayer = 0; |
| 1457 | } |
| 1458 | |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1459 | // If the source image is multisampled, we need to resolve it into a temporary image before |
| 1460 | // performing a readback. |
| 1461 | bool isMultisampled = srcImage->getSamples() > 1; |
| 1462 | vk::Scoped<vk::ImageHelper> resolvedImage(contextVk->getDevice()); |
| 1463 | if (isMultisampled) |
| 1464 | { |
| 1465 | ANGLE_TRY(resolvedImage.get().init2DStaging( |
| 1466 | contextVk, renderer->getMemoryProperties(), gl::Extents(area.width, area.height, 1), |
| 1467 | srcImage->getFormat(), |
| 1468 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 1)); |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1469 | resolvedImage.get().updateQueueSerial(contextVk->getCurrentQueueSerial()); |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1470 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 1471 | // Note: resolve only works on color images (not depth/stencil). |
| 1472 | // |
| 1473 | // TODO: Currently, depth/stencil blit can perform a depth/stencil readback, but that code |
| 1474 | // path will be optimized away. http://anglebug.com/3200 |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1475 | ASSERT(copyAspectFlags == VK_IMAGE_ASPECT_COLOR_BIT); |
| 1476 | |
| 1477 | VkImageResolve resolveRegion = {}; |
Cody Northrop | eb0479e | 2019-07-24 14:15:56 -0600 | [diff] [blame] | 1478 | resolveRegion.srcSubresource = srcSubresource; |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1479 | resolveRegion.srcOffset = srcOffset; |
| 1480 | resolveRegion.dstSubresource.aspectMask = copyAspectFlags; |
| 1481 | resolveRegion.dstSubresource.mipLevel = 0; |
| 1482 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 1483 | resolveRegion.dstSubresource.layerCount = 1; |
| 1484 | resolveRegion.dstOffset = {}; |
| 1485 | resolveRegion.extent = srcExtent; |
| 1486 | |
| 1487 | srcImage->resolve(&resolvedImage.get(), resolveRegion, commandBuffer); |
| 1488 | |
| 1489 | resolvedImage.get().changeLayout(copyAspectFlags, vk::ImageLayout::TransferSrc, |
| 1490 | commandBuffer); |
| 1491 | |
| 1492 | // Make the resolved image the target of buffer copy. |
| 1493 | srcImage = &resolvedImage.get(); |
| 1494 | level = 0; |
| 1495 | layer = 0; |
| 1496 | srcOffset = {0, 0, 0}; |
Cody Northrop | eb0479e | 2019-07-24 14:15:56 -0600 | [diff] [blame] | 1497 | srcSubresource.baseArrayLayer = 0; |
| 1498 | srcSubresource.layerCount = 1; |
| 1499 | srcSubresource.mipLevel = 0; |
Shahbaz Youssefi | b16d69c | 2019-05-13 16:28:27 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 1502 | VkBuffer bufferHandle = VK_NULL_HANDLE; |
| 1503 | uint8_t *readPixelBuffer = nullptr; |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 1504 | VkDeviceSize stagingOffset = 0; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 1505 | size_t allocationSize = readFormat->pixelBytes * area.width * area.height; |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1506 | |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 1507 | ANGLE_TRY(mReadPixelBuffer.allocate(contextVk, allocationSize, &readPixelBuffer, &bufferHandle, |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 1508 | &stagingOffset, nullptr)); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1509 | |
Cody Northrop | eb0479e | 2019-07-24 14:15:56 -0600 | [diff] [blame] | 1510 | VkBufferImageCopy region = {}; |
| 1511 | region.bufferImageHeight = srcExtent.height; |
| 1512 | region.bufferOffset = stagingOffset; |
| 1513 | region.bufferRowLength = srcExtent.width; |
| 1514 | region.imageExtent = srcExtent; |
| 1515 | region.imageOffset = srcOffset; |
| 1516 | region.imageSubresource = srcSubresource; |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1517 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 1518 | commandBuffer->copyImageToBuffer(srcImage->getImage(), srcImage->getCurrentLayout(), |
| 1519 | bufferHandle, 1, ®ion); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1520 | |
| 1521 | // Triggers a full finish. |
| 1522 | // TODO(jmadill): Don't block on asynchronous readback. |
Geoff Lang | 892d180 | 2019-03-27 14:21:34 -0400 | [diff] [blame] | 1523 | ANGLE_TRY(contextVk->finishImpl()); |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1524 | |
Luc Ferron | 534b00d | 2018-05-18 08:16:53 -0400 | [diff] [blame] | 1525 | // The buffer we copied to needs to be invalidated before we read from it because its not been |
| 1526 | // created with the host coherent bit. |
Jamie Madill | d754eb5 | 2018-07-19 14:55:03 -0400 | [diff] [blame] | 1527 | ANGLE_TRY(mReadPixelBuffer.invalidate(contextVk)); |
Yuly Novikov | 6c6c76c | 2018-05-17 18:45:06 +0000 | [diff] [blame] | 1528 | |
Ian Elliott | dc2c5c5 | 2019-08-02 09:32:18 -0600 | [diff] [blame] | 1529 | const gl::State &glState = contextVk->getState(); |
| 1530 | gl::Buffer *packBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelPack); |
| 1531 | if (packBuffer != nullptr) |
| 1532 | { |
| 1533 | // Must map the PBO in order to read its contents (and then unmap it later) |
| 1534 | BufferVk *packBufferVk = vk::GetImpl(packBuffer); |
| 1535 | void *mapPtr = nullptr; |
| 1536 | ANGLE_TRY(packBufferVk->mapImpl(contextVk, &mapPtr)); |
| 1537 | uint8_t *dest = static_cast<uint8_t *>(mapPtr) + reinterpret_cast<ptrdiff_t>(pixels); |
| 1538 | PackPixels(packPixelsParams, *readFormat, area.width * readFormat->pixelBytes, |
| 1539 | readPixelBuffer, static_cast<uint8_t *>(dest)); |
| 1540 | packBufferVk->unmapImpl(contextVk); |
| 1541 | } |
| 1542 | else |
| 1543 | { |
| 1544 | PackPixels(packPixelsParams, *readFormat, area.width * readFormat->pixelBytes, |
| 1545 | readPixelBuffer, static_cast<uint8_t *>(pixels)); |
| 1546 | } |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1547 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1548 | return angle::Result::Continue; |
Luc Ferron | 018709f | 2018-05-10 13:53:11 -0400 | [diff] [blame] | 1549 | } |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1550 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 1551 | gl::Extents FramebufferVk::getReadImageExtents() const |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1552 | { |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1553 | ASSERT(getColorReadRenderTarget()->getExtents().width == mState.getDimensions().width); |
| 1554 | ASSERT(getColorReadRenderTarget()->getExtents().height == mState.getDimensions().height); |
| 1555 | |
Shahbaz Youssefi | 6854940 | 2019-03-25 23:30:49 -0400 | [diff] [blame] | 1556 | return getColorReadRenderTarget()->getExtents(); |
Jamie Madill | 5867501 | 2018-05-22 14:54:07 -0400 | [diff] [blame] | 1557 | } |
Jamie Madill | 502d2e2 | 2018-11-01 11:06:23 -0400 | [diff] [blame] | 1558 | |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1559 | gl::Rectangle FramebufferVk::getCompleteRenderArea() const |
| 1560 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1561 | const gl::Box &dimensions = mState.getDimensions(); |
| 1562 | return gl::Rectangle(0, 0, dimensions.width, dimensions.height); |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | gl::Rectangle FramebufferVk::getScissoredRenderArea(ContextVk *contextVk) const |
| 1566 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1567 | const gl::Box &dimensions = mState.getDimensions(); |
| 1568 | const gl::Rectangle renderArea(0, 0, dimensions.width, dimensions.height); |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1569 | bool invertViewport = contextVk->isViewportFlipEnabledForDrawFBO(); |
| 1570 | |
| 1571 | return ClipRectToScissor(contextVk->getState(), renderArea, invertViewport); |
| 1572 | } |
| 1573 | |
| 1574 | void FramebufferVk::onScissorChange(ContextVk *contextVk) |
| 1575 | { |
| 1576 | gl::Rectangle scissoredRenderArea = getScissoredRenderArea(contextVk); |
| 1577 | |
| 1578 | // If the scissor has grown beyond the previous scissoredRenderArea, make sure the render pass |
| 1579 | // is restarted. Otherwise, we can continue using the same renderpass area. |
| 1580 | // |
| 1581 | // Without a scissor, the render pass area covers the whole of the framebuffer. With a |
| 1582 | // scissored clear, the render pass area could be smaller than the framebuffer size. When the |
| 1583 | // scissor changes, if the scissor area is completely encompassed by the render pass area, it's |
| 1584 | // possible to continue using the same render pass. However, if the current render pass area |
| 1585 | // is too small, we need to start a new one. The latter can happen if a scissored clear starts |
| 1586 | // a render pass, the scissor is disabled and a draw call is issued to affect the whole |
| 1587 | // framebuffer. |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1588 | mFramebuffer.updateQueueSerial(contextVk->getCurrentQueueSerial()); |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1589 | if (mFramebuffer.hasStartedRenderPass() && |
| 1590 | !mFramebuffer.getRenderPassRenderArea().encloses(scissoredRenderArea)) |
| 1591 | { |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 1592 | mFramebuffer.finishCurrentCommands(contextVk); |
Shahbaz Youssefi | 127990f | 2019-04-04 13:52:04 -0400 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | |
Jamie Madill | 502d2e2 | 2018-11-01 11:06:23 -0400 | [diff] [blame] | 1596 | RenderTargetVk *FramebufferVk::getFirstRenderTarget() const |
| 1597 | { |
| 1598 | for (auto *renderTarget : mRenderTargetCache.getColors()) |
| 1599 | { |
| 1600 | if (renderTarget) |
| 1601 | { |
| 1602 | return renderTarget; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | return mRenderTargetCache.getDepthStencil(); |
| 1607 | } |
| 1608 | |
| 1609 | GLint FramebufferVk::getSamples() const |
| 1610 | { |
| 1611 | RenderTargetVk *firstRT = getFirstRenderTarget(); |
| 1612 | return firstRT ? firstRT->getImage().getSamples() : 0; |
| 1613 | } |
| 1614 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1615 | } // namespace rx |