Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // FramebufferVk.cpp: |
| 7 | // Implements the class methods for FramebufferVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 11 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 12 | #include <vulkan/vulkan.h> |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 13 | #include <array> |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 14 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 15 | #include "common/debug.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 16 | #include "image_util/imageformats.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 17 | #include "libANGLE/Context.h" |
| 18 | #include "libANGLE/Display.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 19 | #include "libANGLE/formatutils.h" |
| 20 | #include "libANGLE/renderer/renderer_utils.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 21 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 22 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 23 | #include "libANGLE/renderer/vulkan/DisplayVk.h" |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/vulkan/RenderTargetVk.h" |
| 25 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 26 | #include "libANGLE/renderer/vulkan/SurfaceVk.h" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 27 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 28 | |
| 29 | namespace rx |
| 30 | { |
| 31 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 32 | namespace |
| 33 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 34 | const gl::InternalFormat &GetReadAttachmentInfo(const gl::Context *context, |
| 35 | RenderTargetVk *renderTarget) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 36 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 37 | GLenum implFormat = |
| 38 | renderTarget->image->getFormat().textureFormat().fboImplementationInternalFormat; |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 39 | return gl::GetSizedInternalFormatInfo(implFormat); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 40 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 41 | } // anonymous namespace |
| 42 | |
| 43 | // static |
| 44 | FramebufferVk *FramebufferVk::CreateUserFBO(const gl::FramebufferState &state) |
| 45 | { |
| 46 | return new FramebufferVk(state); |
| 47 | } |
| 48 | |
| 49 | // static |
| 50 | FramebufferVk *FramebufferVk::CreateDefaultFBO(const gl::FramebufferState &state, |
| 51 | WindowSurfaceVk *backbuffer) |
| 52 | { |
| 53 | return new FramebufferVk(state, backbuffer); |
| 54 | } |
| 55 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 56 | FramebufferVk::FramebufferVk(const gl::FramebufferState &state) |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 57 | : FramebufferImpl(state), mBackbuffer(nullptr), mRenderPassDesc(), mFramebuffer() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 58 | { |
| 59 | } |
| 60 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 61 | FramebufferVk::FramebufferVk(const gl::FramebufferState &state, WindowSurfaceVk *backbuffer) |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 62 | : FramebufferImpl(state), mBackbuffer(backbuffer), mRenderPassDesc(), mFramebuffer() |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 66 | FramebufferVk::~FramebufferVk() |
| 67 | { |
| 68 | } |
| 69 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 70 | void FramebufferVk::destroy(const gl::Context *context) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 71 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 72 | RendererVk *renderer = vk::GetImpl(context)->getRenderer(); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 73 | |
Jamie Madill | 526543c | 2017-10-28 10:59:16 -0400 | [diff] [blame] | 74 | renderer->releaseResource(*this, &mFramebuffer); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 77 | void FramebufferVk::destroyDefault(const egl::Display *display) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 78 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 79 | VkDevice device = vk::GetImpl(display)->getRenderer()->getDevice(); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 80 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 81 | mFramebuffer.destroy(device); |
| 82 | } |
| 83 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 84 | gl::Error FramebufferVk::discard(const gl::Context *context, |
| 85 | size_t count, |
| 86 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 87 | { |
| 88 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 89 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 92 | gl::Error FramebufferVk::invalidate(const gl::Context *context, |
| 93 | size_t count, |
| 94 | const GLenum *attachments) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 95 | { |
| 96 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 97 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 100 | gl::Error FramebufferVk::invalidateSub(const gl::Context *context, |
| 101 | size_t count, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 102 | const GLenum *attachments, |
| 103 | const gl::Rectangle &area) |
| 104 | { |
| 105 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 106 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 109 | gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 110 | { |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 111 | ContextVk *contextVk = vk::GetImpl(context); |
| 112 | RendererVk *renderer = contextVk->getRenderer(); |
| 113 | Serial currentSerial = renderer->getCurrentQueueSerial(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 114 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 115 | // This command buffer is only started once. |
| 116 | vk::CommandBuffer *commandBuffer = nullptr; |
| 117 | vk::CommandGraphNode *writingNode = nullptr; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 118 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 119 | const gl::FramebufferAttachment *depthAttachment = mState.getDepthAttachment(); |
| 120 | bool clearDepth = (depthAttachment && (mask & GL_DEPTH_BUFFER_BIT) != 0); |
| 121 | ASSERT(!clearDepth || depthAttachment->isAttached()); |
| 122 | |
| 123 | const gl::FramebufferAttachment *stencilAttachment = mState.getStencilAttachment(); |
| 124 | bool clearStencil = (stencilAttachment && (mask & GL_STENCIL_BUFFER_BIT) != 0); |
| 125 | ASSERT(!clearStencil || stencilAttachment->isAttached()); |
| 126 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 127 | bool clearColor = IsMaskFlagSet(static_cast<int>(mask), GL_COLOR_BUFFER_BIT); |
| 128 | |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 129 | const gl::FramebufferAttachment *depthStencilAttachment = mState.getDepthStencilAttachment(); |
| 130 | |
| 131 | // If we clear the depth OR the stencil but not both, and we have a packed depth stencil |
| 132 | // attachment, we need to use clearAttachment instead of clearDepthStencil since Vulkan won't |
| 133 | // allow us to clear one or the other separately. |
| 134 | bool isSingleClearOnPackedDepthStencilAttachment = |
| 135 | depthStencilAttachment && (clearDepth != clearStencil); |
| 136 | if (context->getGLState().isScissorTestEnabled() || isSingleClearOnPackedDepthStencilAttachment) |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 137 | { |
| 138 | // With scissor test enabled, we clear very differently and we don't need to access |
| 139 | // the image inside each attachment we can just use clearCmdAttachments with our |
| 140 | // scissor region instead. |
| 141 | ANGLE_TRY(clearAttachmentsWithScissorRegion(context, clearColor, clearDepth, clearStencil)); |
| 142 | return gl::NoError(); |
| 143 | } |
| 144 | |
| 145 | // Standard Depth/stencil clear without scissor. |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 146 | if (clearDepth || clearStencil) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 147 | { |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 148 | ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 149 | writingNode = getCurrentWritingNode(); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 150 | |
| 151 | const VkClearDepthStencilValue &clearDepthStencilValue = |
| 152 | contextVk->getClearDepthStencilValue().depthStencil; |
| 153 | |
| 154 | // We only support packed depth/stencil, not separate. |
Luc Ferron | 8836f63 | 2018-04-05 07:26:53 -0400 | [diff] [blame] | 155 | ASSERT(!(clearDepth && clearStencil) || depthStencilAttachment); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 156 | |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 157 | const VkImageAspectFlags aspectFlags = |
| 158 | (depthAttachment ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) | |
| 159 | (stencilAttachment ? VK_IMAGE_ASPECT_STENCIL_BIT : 0); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 160 | |
| 161 | RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil(); |
| 162 | renderTarget->resource->onWriteResource(writingNode, currentSerial); |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 163 | renderTarget->image->clearDepthStencil(aspectFlags, clearDepthStencilValue, commandBuffer); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 164 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 165 | if (!clearColor) |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 166 | { |
| 167 | return gl::NoError(); |
| 168 | } |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 171 | ASSERT(clearColor); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 172 | const auto *attachment = mState.getFirstNonNullAttachment(); |
| 173 | ASSERT(attachment && attachment->isAttached()); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 174 | |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 175 | if (!commandBuffer) |
| 176 | { |
| 177 | ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 178 | writingNode = getCurrentWritingNode(); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 179 | } |
Jamie Madill | efb5a5c | 2018-01-29 15:56:59 -0500 | [diff] [blame] | 180 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 181 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 182 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 183 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 184 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 185 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 186 | ASSERT(colorRenderTarget); |
Jamie Madill | 0cec82a | 2018-03-14 09:21:07 -0400 | [diff] [blame] | 187 | colorRenderTarget->resource->onWriteResource(writingNode, currentSerial); |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 188 | colorRenderTarget->image->clearColor(contextVk->getClearColorValue().color, commandBuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 191 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 194 | gl::Error FramebufferVk::clearBufferfv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 195 | GLenum buffer, |
| 196 | GLint drawbuffer, |
| 197 | const GLfloat *values) |
| 198 | { |
| 199 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 200 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 203 | gl::Error FramebufferVk::clearBufferuiv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 204 | GLenum buffer, |
| 205 | GLint drawbuffer, |
| 206 | const GLuint *values) |
| 207 | { |
| 208 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 209 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 212 | gl::Error FramebufferVk::clearBufferiv(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 213 | GLenum buffer, |
| 214 | GLint drawbuffer, |
| 215 | const GLint *values) |
| 216 | { |
| 217 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 218 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 221 | gl::Error FramebufferVk::clearBufferfi(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 222 | GLenum buffer, |
| 223 | GLint drawbuffer, |
| 224 | GLfloat depth, |
| 225 | GLint stencil) |
| 226 | { |
| 227 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 228 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 231 | GLenum FramebufferVk::getImplementationColorReadFormat(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 232 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 233 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).format; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 236 | GLenum FramebufferVk::getImplementationColorReadType(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 237 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 238 | return GetReadAttachmentInfo(context, mRenderTargetCache.getColorRead(mState)).type; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 241 | gl::Error FramebufferVk::readPixels(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 242 | const gl::Rectangle &area, |
| 243 | GLenum format, |
| 244 | GLenum type, |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 245 | void *pixels) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 246 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 247 | const gl::State &glState = context->getGLState(); |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 248 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 249 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 250 | VkDevice device = renderer->getDevice(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 251 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 252 | RenderTargetVk *renderTarget = mRenderTargetCache.getColorRead(mState); |
| 253 | ASSERT(renderTarget); |
| 254 | |
Jamie Madill | 93edca1 | 2018-03-30 10:43:18 -0400 | [diff] [blame] | 255 | vk::ImageHelper stagingImage; |
| 256 | ANGLE_TRY(stagingImage.init2DStaging( |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 257 | device, renderer->getMemoryProperties(), renderTarget->image->getFormat(), |
Jamie Madill | 93edca1 | 2018-03-30 10:43:18 -0400 | [diff] [blame] | 258 | gl::Extents(area.width, area.height, 1), vk::StagingUsage::Read)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 259 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 260 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 261 | ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 262 | |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 263 | stagingImage.changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, |
| 264 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 265 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 266 | |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 267 | vk::ImageHelper::Copy(renderTarget->image, &stagingImage, gl::Offset(area.x, area.y, 0), |
| 268 | gl::Offset(), gl::Extents(area.width, area.height, 1), |
| 269 | VK_IMAGE_ASPECT_COLOR_BIT, commandBuffer); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 270 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 271 | // Triggers a full finish. |
| 272 | // TODO(jmadill): Don't block on asynchronous readback. |
| 273 | ANGLE_TRY(renderer->finish(context)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 274 | |
| 275 | // TODO(jmadill): parameters |
| 276 | uint8_t *mapPointer = nullptr; |
Jamie Madill | 93edca1 | 2018-03-30 10:43:18 -0400 | [diff] [blame] | 277 | ANGLE_TRY(stagingImage.getDeviceMemory().map(device, 0, stagingImage.getAllocatedMemorySize(), |
| 278 | 0, &mapPointer)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 279 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 280 | const angle::Format &angleFormat = renderTarget->image->getFormat().textureFormat(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 281 | |
| 282 | // TODO(jmadill): Use pixel bytes from the ANGLE format directly. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 283 | const auto &glFormat = gl::GetSizedInternalFormatInfo(angleFormat.glInternalFormat); |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 284 | int outputPitch = glFormat.pixelBytes * area.width; |
| 285 | |
| 286 | // Get the staging image pitch and use it to pack the pixels later. |
| 287 | VkSubresourceLayout subresourceLayout; |
| 288 | stagingImage.getImage().getSubresourceLayout(device, VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, |
| 289 | &subresourceLayout); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 290 | |
| 291 | PackPixelsParams params; |
| 292 | params.area = area; |
| 293 | params.format = format; |
| 294 | params.type = type; |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 295 | params.outputPitch = outputPitch; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 296 | params.packBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelPack); |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 297 | params.pack = glState.getPackState(); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 298 | |
Luc Ferron | 6028422 | 2018-03-20 16:01:44 -0400 | [diff] [blame] | 299 | PackPixels(params, angleFormat, static_cast<int>(subresourceLayout.rowPitch), mapPointer, |
| 300 | reinterpret_cast<uint8_t *>(pixels)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 301 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 302 | stagingImage.getDeviceMemory().unmap(device); |
Jamie Madill | e88ec8e | 2017-10-31 17:18:14 -0400 | [diff] [blame] | 303 | renderer->releaseObject(renderer->getCurrentQueueSerial(), &stagingImage); |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 304 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 305 | return vk::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 308 | gl::Error FramebufferVk::blit(const gl::Context *context, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 309 | const gl::Rectangle &sourceArea, |
| 310 | const gl::Rectangle &destArea, |
| 311 | GLbitfield mask, |
| 312 | GLenum filter) |
| 313 | { |
| 314 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 315 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 318 | bool FramebufferVk::checkStatus(const gl::Context *context) const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 319 | { |
Jamie Madill | b79e7bb | 2017-10-24 13:55:50 -0400 | [diff] [blame] | 320 | return true; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 321 | } |
| 322 | |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 323 | gl::Error FramebufferVk::syncState(const gl::Context *context, |
| 324 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 325 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 326 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 327 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 328 | |
| 329 | ASSERT(dirtyBits.any()); |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 330 | ANGLE_TRY(mRenderTargetCache.update(context, mState, dirtyBits)); |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 331 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 332 | mRenderPassDesc.reset(); |
Jamie Madill | 7bd1666 | 2017-10-28 19:40:50 -0400 | [diff] [blame] | 333 | renderer->releaseResource(*this, &mFramebuffer); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 334 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 335 | // Trigger a new set of secondary commands next time we render to this FBO. |
| 336 | getNewWritingNode(renderer); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 337 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 338 | contextVk->invalidateCurrentPipeline(); |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 339 | |
| 340 | return gl::NoError(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 341 | } |
| 342 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 343 | const vk::RenderPassDesc &FramebufferVk::getRenderPassDesc(const gl::Context *context) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 344 | { |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 345 | if (mRenderPassDesc.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 346 | { |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 347 | return mRenderPassDesc.value(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 348 | } |
| 349 | |
Jamie Madill | 0b684ce | 2017-11-23 12:57:39 -0500 | [diff] [blame] | 350 | vk::RenderPassDesc desc; |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 351 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 352 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 353 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 354 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 355 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 356 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 357 | ASSERT(colorRenderTarget); |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 358 | desc.packColorAttachment(*colorRenderTarget->image); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 359 | } |
| 360 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 361 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 362 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 363 | { |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 364 | desc.packDepthStencilAttachment(*depthStencilRenderTarget->image); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 365 | } |
| 366 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 367 | mRenderPassDesc = desc; |
| 368 | return mRenderPassDesc.value(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 369 | } |
| 370 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 371 | gl::ErrorOrResult<vk::Framebuffer *> FramebufferVk::getFramebuffer(const gl::Context *context, |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 372 | RendererVk *rendererVk) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 373 | { |
| 374 | // If we've already created our cached Framebuffer, return it. |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 375 | if (mFramebuffer.valid()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 376 | { |
| 377 | return &mFramebuffer; |
| 378 | } |
| 379 | |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 380 | const vk::RenderPassDesc &desc = getRenderPassDesc(context); |
| 381 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 382 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 383 | ANGLE_TRY(rendererVk->getCompatibleRenderPass(desc, &renderPass)); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 384 | |
| 385 | // If we've a Framebuffer provided by a Surface (default FBO/backbuffer), query it. |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 386 | VkDevice device = rendererVk->getDevice(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 387 | if (mBackbuffer) |
| 388 | { |
| 389 | return mBackbuffer->getCurrentFramebuffer(device, *renderPass); |
| 390 | } |
| 391 | |
| 392 | // Gather VkImageViews over all FBO attachments, also size of attached region. |
| 393 | std::vector<VkImageView> attachments; |
| 394 | gl::Extents attachmentsSize; |
| 395 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 396 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 397 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 398 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 399 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 400 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 401 | ASSERT(colorRenderTarget); |
| 402 | attachments.push_back(colorRenderTarget->imageView->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 403 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 404 | ASSERT(attachmentsSize.empty() || |
| 405 | attachmentsSize == colorRenderTarget->image->getExtents()); |
| 406 | attachmentsSize = colorRenderTarget->image->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 407 | } |
| 408 | |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 409 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 410 | if (depthStencilRenderTarget) |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 411 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 412 | attachments.push_back(depthStencilRenderTarget->imageView->getHandle()); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 413 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 414 | ASSERT(attachmentsSize.empty() || |
| 415 | attachmentsSize == depthStencilRenderTarget->image->getExtents()); |
| 416 | attachmentsSize = depthStencilRenderTarget->image->getExtents(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | ASSERT(!attachments.empty()); |
| 420 | |
| 421 | VkFramebufferCreateInfo framebufferInfo; |
| 422 | |
| 423 | framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 424 | framebufferInfo.pNext = nullptr; |
| 425 | framebufferInfo.flags = 0; |
Jamie Madill | 9f2a861 | 2017-11-30 12:43:09 -0500 | [diff] [blame] | 426 | framebufferInfo.renderPass = renderPass->getHandle(); |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 427 | framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); |
| 428 | framebufferInfo.pAttachments = attachments.data(); |
| 429 | framebufferInfo.width = static_cast<uint32_t>(attachmentsSize.width); |
| 430 | framebufferInfo.height = static_cast<uint32_t>(attachmentsSize.height); |
| 431 | framebufferInfo.layers = 1; |
| 432 | |
Jamie Madill | 25301b6 | 2017-10-28 20:59:31 -0400 | [diff] [blame] | 433 | ANGLE_TRY(mFramebuffer.init(device, framebufferInfo)); |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 434 | |
Jamie Madill | ab9f9c3 | 2017-01-17 17:47:34 -0500 | [diff] [blame] | 435 | return &mFramebuffer; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 438 | gl::Error FramebufferVk::clearAttachmentsWithScissorRegion(const gl::Context *context, |
| 439 | bool clearColor, |
| 440 | bool clearDepth, |
| 441 | bool clearStencil) |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 442 | { |
| 443 | ContextVk *contextVk = vk::GetImpl(context); |
| 444 | RendererVk *renderer = contextVk->getRenderer(); |
| 445 | |
| 446 | // This command can only happen inside a render pass, so obtain one if its already happening |
| 447 | // or create a new one if not. |
| 448 | vk::CommandGraphNode *node = nullptr; |
| 449 | vk::CommandBuffer *commandBuffer = nullptr; |
| 450 | ANGLE_TRY(getCommandGraphNodeForDraw(context, &node)); |
| 451 | if (node->getInsideRenderPassCommands()->valid()) |
| 452 | { |
| 453 | commandBuffer = node->getInsideRenderPassCommands(); |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | ANGLE_TRY(node->beginInsideRenderPassRecording(renderer, &commandBuffer)); |
| 458 | } |
| 459 | |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 460 | gl::AttachmentArray<VkClearAttachment> clearAttachments; |
| 461 | int clearAttachmentIndex = 0; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 462 | |
| 463 | if (clearColor) |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 464 | { |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 465 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 466 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
| 467 | { |
| 468 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 469 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 470 | clearAttachment.colorAttachment = static_cast<uint32_t>(colorIndex); |
| 471 | clearAttachment.clearValue = contextVk->getClearColorValue(); |
| 472 | ++clearAttachmentIndex; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | if (clearDepth && clearStencil && mState.getDepthStencilAttachment() != nullptr) |
| 477 | { |
| 478 | // When we have a packed depth/stencil attachment we can do 1 clear for both when it |
| 479 | // applies. |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 480 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 481 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 482 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
| 483 | clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 484 | ++clearAttachmentIndex; |
| 485 | } |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 486 | else |
| 487 | { |
| 488 | if (clearDepth) |
| 489 | { |
| 490 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 491 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 492 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
| 493 | clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); |
| 494 | ++clearAttachmentIndex; |
| 495 | } |
| 496 | |
| 497 | if (clearStencil) |
| 498 | { |
| 499 | VkClearAttachment &clearAttachment = clearAttachments[clearAttachmentIndex]; |
| 500 | clearAttachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 501 | clearAttachment.colorAttachment = VK_ATTACHMENT_UNUSED; |
| 502 | clearAttachment.clearValue = contextVk->getClearDepthStencilValue(); |
| 503 | ++clearAttachmentIndex; |
| 504 | } |
| 505 | } |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 506 | |
| 507 | // We assume for now that we always need to clear only 1 layer starting at the |
| 508 | // baseArrayLayer 0, this might need to change depending how we'll implement |
| 509 | // cube maps, 3d textures and array textures. |
| 510 | VkClearRect clearRect; |
| 511 | clearRect.baseArrayLayer = 0; |
| 512 | clearRect.layerCount = 1; |
| 513 | clearRect.rect = contextVk->getScissor(); |
| 514 | |
Luc Ferron | a8af3a6 | 2018-03-29 14:44:24 -0400 | [diff] [blame] | 515 | commandBuffer->clearAttachments(static_cast<uint32_t>(clearAttachmentIndex), |
Luc Ferron | 5242d5b | 2018-02-15 07:14:35 -0500 | [diff] [blame] | 516 | clearAttachments.data(), 1, &clearRect); |
| 517 | return gl::NoError(); |
| 518 | } |
| 519 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 520 | gl::Error FramebufferVk::getSamplePosition(size_t index, GLfloat *xy) const |
| 521 | { |
| 522 | UNIMPLEMENTED(); |
| 523 | return gl::InternalError() << "getSamplePosition is unimplemented."; |
| 524 | } |
| 525 | |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 526 | gl::Error FramebufferVk::getCommandGraphNodeForDraw(const gl::Context *context, |
| 527 | vk::CommandGraphNode **nodeOut) |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 528 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 529 | ContextVk *contextVk = vk::GetImpl(context); |
| 530 | RendererVk *renderer = contextVk->getRenderer(); |
| 531 | Serial currentSerial = renderer->getCurrentQueueSerial(); |
Jamie Madill | bef918c | 2017-12-13 13:11:30 -0500 | [diff] [blame] | 532 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 533 | // This will reset the current writing node if it has been completed. |
| 534 | updateQueueSerial(currentSerial); |
| 535 | |
| 536 | if (hasChildlessWritingNode()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 537 | { |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 538 | *nodeOut = getCurrentWritingNode(); |
| 539 | } |
| 540 | else |
| 541 | { |
| 542 | *nodeOut = getNewWritingNode(renderer); |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 543 | } |
| 544 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 545 | if ((*nodeOut)->getInsideRenderPassCommands()->valid()) |
| 546 | { |
| 547 | return gl::NoError(); |
| 548 | } |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 549 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 550 | vk::Framebuffer *framebuffer = nullptr; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 551 | ANGLE_TRY_RESULT(getFramebuffer(context, renderer), framebuffer); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 552 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 553 | std::vector<VkClearValue> attachmentClearValues; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 554 | |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 555 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 556 | if (!(*nodeOut)->getOutsideRenderPassCommands()->valid()) |
| 557 | { |
| 558 | ANGLE_TRY((*nodeOut)->beginOutsideRenderPassRecording( |
| 559 | renderer->getDevice(), renderer->getCommandPool(), &commandBuffer)); |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | commandBuffer = (*nodeOut)->getOutsideRenderPassCommands(); |
| 564 | } |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 565 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 566 | // Initialize RenderPass info. |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 567 | // TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394 |
| 568 | const auto &colorRenderTargets = mRenderTargetCache.getColors(); |
| 569 | for (size_t colorIndex : mState.getEnabledDrawBuffers()) |
Jamie Madill | 4c26fc2 | 2017-02-24 11:04:10 -0500 | [diff] [blame] | 570 | { |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 571 | RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex]; |
| 572 | ASSERT(colorRenderTarget); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 573 | |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 574 | // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361 |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 575 | colorRenderTarget->image->changeLayoutWithStages( |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 576 | VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 577 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 578 | commandBuffer); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 579 | (*nodeOut)->appendColorRenderTarget(currentSerial, colorRenderTarget); |
Jamie Madill | 66546be | 2018-03-08 09:47:20 -0500 | [diff] [blame] | 580 | attachmentClearValues.emplace_back(contextVk->getClearColorValue()); |
| 581 | } |
| 582 | |
| 583 | RenderTargetVk *depthStencilRenderTarget = mRenderTargetCache.getDepthStencil(); |
| 584 | if (depthStencilRenderTarget) |
| 585 | { |
| 586 | // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361 |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 587 | const angle::Format &format = depthStencilRenderTarget->image->getFormat().textureFormat(); |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 588 | VkImageAspectFlags aspectFlags = (format.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) | |
| 589 | (format.stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0); |
| 590 | |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 591 | depthStencilRenderTarget->image->changeLayoutWithStages( |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 592 | aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
| 593 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, |
| 594 | commandBuffer); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 595 | (*nodeOut)->appendDepthStencilRenderTarget(currentSerial, depthStencilRenderTarget); |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 596 | attachmentClearValues.emplace_back(contextVk->getClearDepthStencilValue()); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 597 | } |
| 598 | |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 599 | // Hard-code RenderPass to clear the first render target to the current clear value. |
| 600 | // TODO(jmadill): Proper clear value implementation. http://anglebug.com/2361 |
| 601 | const gl::State &glState = context->getGLState(); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame^] | 602 | (*nodeOut)->storeRenderPassInfo(*framebuffer, glState.getViewport(), attachmentClearValues); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 603 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 604 | return gl::NoError(); |
| 605 | } |
| 606 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 607 | } // namespace rx |