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 | // RenderbufferVk.cpp: |
| 7 | // Implements the class methods for RenderbufferVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/RenderbufferVk.h" |
| 11 | |
Jamie Madill | 12eb3d7 | 2018-02-14 12:34:45 -0500 | [diff] [blame] | 12 | #include "libANGLE/Context.h" |
| 13 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 14 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 15 | |
| 16 | namespace rx |
| 17 | { |
| 18 | |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 19 | namespace |
| 20 | { |
| 21 | constexpr VkClearDepthStencilValue kDefaultClearDepthStencilValue = {0.0f, 1}; |
| 22 | constexpr VkClearColorValue kBlackClearColorValue = {{0}}; |
| 23 | |
| 24 | } // anonymous namespace |
| 25 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 26 | RenderbufferVk::RenderbufferVk(const gl::RenderbufferState &state) |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 27 | : RenderbufferImpl(state), mRenderTarget(&mImage, &mImageView, 0) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 28 | { |
| 29 | } |
| 30 | |
| 31 | RenderbufferVk::~RenderbufferVk() |
| 32 | { |
| 33 | } |
| 34 | |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 35 | void RenderbufferVk::onDestroy(const gl::Context *context) |
Jamie Madill | 12eb3d7 | 2018-02-14 12:34:45 -0500 | [diff] [blame] | 36 | { |
| 37 | ContextVk *contextVk = vk::GetImpl(context); |
| 38 | RendererVk *renderer = contextVk->getRenderer(); |
| 39 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 40 | mImage.release(renderer); |
| 41 | renderer->releaseObject(renderer->getCurrentQueueSerial(), &mImageView); |
Jamie Madill | 12eb3d7 | 2018-02-14 12:34:45 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 44 | angle::Result RenderbufferVk::setStorage(const gl::Context *context, |
| 45 | GLenum internalformat, |
| 46 | size_t width, |
| 47 | size_t height) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 48 | { |
Jamie Madill | 12eb3d7 | 2018-02-14 12:34:45 -0500 | [diff] [blame] | 49 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | 57fbfd8 | 2018-02-14 12:45:34 -0500 | [diff] [blame] | 50 | RendererVk *renderer = contextVk->getRenderer(); |
| 51 | const vk::Format &vkFormat = renderer->getFormat(internalformat); |
Jamie Madill | 12eb3d7 | 2018-02-14 12:34:45 -0500 | [diff] [blame] | 52 | |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 53 | if (mImage.valid()) |
| 54 | { |
| 55 | // Check against the state if we need to recreate the storage. |
| 56 | if (internalformat != mState.getFormat().info->internalFormat || |
| 57 | static_cast<GLsizei>(width) != mState.getWidth() || |
| 58 | static_cast<GLsizei>(height) != mState.getHeight()) |
| 59 | { |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 60 | mImage.release(renderer); |
| 61 | renderer->releaseObject(renderer->getCurrentQueueSerial(), &mImageView); |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 62 | } |
| 63 | } |
Jamie Madill | 0cbfa58 | 2018-02-15 14:45:41 -0500 | [diff] [blame] | 64 | |
Shahbaz Youssefi | 3d86e89 | 2018-11-02 16:29:44 -0400 | [diff] [blame^] | 65 | if (!mImage.valid() && (width != 0 && height != 0)) |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 66 | { |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 67 | const angle::Format &textureFormat = vkFormat.textureFormat(); |
| 68 | bool isDepthOrStencilFormat = textureFormat.depthBits > 0 || textureFormat.stencilBits > 0; |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 69 | const VkImageUsageFlags usage = |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 70 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 71 | VK_IMAGE_USAGE_SAMPLED_BIT | |
| 72 | (textureFormat.redBits > 0 ? VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT : 0) | |
| 73 | (isDepthOrStencilFormat ? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT : 0); |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 74 | |
Jamie Madill | bc54342 | 2018-03-30 10:43:19 -0400 | [diff] [blame] | 75 | gl::Extents extents(static_cast<int>(width), static_cast<int>(height), 1); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 76 | ANGLE_TRY(mImage.init(contextVk, gl::TextureType::_2D, extents, vkFormat, 1, usage, 1)); |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 77 | |
| 78 | VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 79 | ANGLE_TRY(mImage.initMemory(contextVk, renderer->getMemoryProperties(), flags)); |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 80 | |
Geoff Lang | 9e14164 | 2018-06-27 11:43:18 -0400 | [diff] [blame] | 81 | VkImageAspectFlags aspect = vk::GetFormatAspectFlags(textureFormat); |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 82 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 83 | ANGLE_TRY(mImage.initImageView(contextVk, gl::TextureType::_2D, aspect, gl::SwizzleState(), |
Luc Ferron | 6641053 | 2018-04-20 12:47:45 -0400 | [diff] [blame] | 84 | &mImageView, 1)); |
Jamie Madill | e4c5a23 | 2018-03-02 21:00:31 -0500 | [diff] [blame] | 85 | |
| 86 | // TODO(jmadill): Fold this into the RenderPass load/store ops. http://anglebug.com/2361 |
| 87 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 88 | ANGLE_TRY(mImage.recordCommands(contextVk, &commandBuffer)); |
Jamie Madill | 93edca1 | 2018-03-30 10:43:18 -0400 | [diff] [blame] | 89 | |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 90 | if (isDepthOrStencilFormat) |
| 91 | { |
Jamie Madill | 858c1cc | 2018-03-31 14:19:13 -0400 | [diff] [blame] | 92 | mImage.clearDepthStencil(aspect, kDefaultClearDepthStencilValue, commandBuffer); |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 93 | } |
| 94 | else |
| 95 | { |
Luc Ferron | c20b950 | 2018-05-24 09:30:17 -0400 | [diff] [blame] | 96 | mImage.clearColor(kBlackClearColorValue, 0, 1, commandBuffer); |
Luc Ferron | e6a40d0 | 2018-03-22 10:30:57 -0400 | [diff] [blame] | 97 | } |
Jamie Madill | 7b21381 | 2018-03-06 10:13:13 -0500 | [diff] [blame] | 98 | } |
| 99 | |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 100 | return angle::Result::Continue(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 103 | angle::Result RenderbufferVk::setStorageMultisample(const gl::Context *context, |
| 104 | size_t samples, |
| 105 | GLenum internalformat, |
| 106 | size_t width, |
| 107 | size_t height) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 108 | { |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 109 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
| 110 | return angle::Result::Stop(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 113 | angle::Result RenderbufferVk::setStorageEGLImageTarget(const gl::Context *context, |
| 114 | egl::Image *image) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 115 | { |
Jamie Madill | c2328a1 | 2018-10-18 15:00:29 -0400 | [diff] [blame] | 116 | ANGLE_VK_UNREACHABLE(vk::GetImpl(context)); |
| 117 | return angle::Result::Stop(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 118 | } |
| 119 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 120 | angle::Result RenderbufferVk::getAttachmentRenderTarget(const gl::Context *context, |
| 121 | GLenum binding, |
| 122 | const gl::ImageIndex &imageIndex, |
| 123 | FramebufferAttachmentRenderTarget **rtOut) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 124 | { |
Jamie Madill | 0cbfa58 | 2018-02-15 14:45:41 -0500 | [diff] [blame] | 125 | ASSERT(mImage.valid()); |
| 126 | *rtOut = &mRenderTarget; |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 127 | return angle::Result::Continue(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 128 | } |
| 129 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 130 | angle::Result RenderbufferVk::initializeContents(const gl::Context *context, |
| 131 | const gl::ImageIndex &imageIndex) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 132 | { |
| 133 | UNIMPLEMENTED(); |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 134 | return angle::Result::Continue(); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 135 | } |
| 136 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 137 | } // namespace rx |