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