Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [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 | // RenderTargetVk: |
| 7 | // Wrapper around a Vulkan renderable resource, using an ImageView. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/RenderTargetVk.h" |
| 11 | |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 12 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
| 13 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
| 14 | #include "libANGLE/renderer/vulkan/vk_helpers.h" |
| 15 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 16 | namespace rx |
| 17 | { |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 18 | RenderTargetVk::RenderTargetVk(vk::ImageHelper *image, |
| 19 | vk::ImageView *imageView, |
Jamie Madill | 3f3b358 | 2018-09-14 10:38:44 -0400 | [diff] [blame^] | 20 | vk::CommandGraphResource *resource, |
| 21 | size_t layerIndex) |
| 22 | : mImage(image), mImageView(imageView), mResource(resource), mLayerIndex(layerIndex) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 23 | { |
Geoff Lang | bd6ae4a | 2018-01-29 15:51:18 -0500 | [diff] [blame] | 24 | } |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 25 | |
| 26 | RenderTargetVk::~RenderTargetVk() |
| 27 | { |
| 28 | } |
| 29 | |
Jamie Madill | 71bb026 | 2018-09-12 11:09:42 -0400 | [diff] [blame] | 30 | RenderTargetVk::RenderTargetVk(RenderTargetVk &&other) |
Jamie Madill | 3f3b358 | 2018-09-14 10:38:44 -0400 | [diff] [blame^] | 31 | : mImage(other.mImage), |
| 32 | mImageView(other.mImageView), |
| 33 | mResource(other.mResource), |
| 34 | mLayerIndex(other.mLayerIndex) |
Jamie Madill | 71bb026 | 2018-09-12 11:09:42 -0400 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 38 | void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk, |
| 39 | vk::CommandBuffer *commandBuffer, |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 40 | vk::RenderPassDesc *renderPassDesc) |
| 41 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 42 | ASSERT(commandBuffer->valid()); |
| 43 | ASSERT(!mImage->getFormat().textureFormat().hasDepthOrStencilBits()); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 44 | |
| 45 | // Store the attachment info in the renderPassDesc. |
| 46 | renderPassDesc->packColorAttachment(*mImage); |
| 47 | |
| 48 | // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361 |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 49 | mImage->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, |
| 50 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 51 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 52 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, commandBuffer); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 53 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 54 | // Set up dependencies between the RT resource and the Framebuffer. |
| 55 | mResource->addWriteDependency(framebufferVk); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 58 | void RenderTargetVk::onDepthStencilDraw(vk::CommandGraphResource *framebufferVk, |
| 59 | vk::CommandBuffer *commandBuffer, |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 60 | vk::RenderPassDesc *renderPassDesc) |
| 61 | { |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 62 | ASSERT(commandBuffer->valid()); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 63 | ASSERT(mImage->getFormat().textureFormat().hasDepthOrStencilBits()); |
| 64 | |
| 65 | // Store the attachment info in the renderPassDesc. |
| 66 | renderPassDesc->packDepthStencilAttachment(*mImage); |
| 67 | |
| 68 | // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361 |
| 69 | const angle::Format &format = mImage->getFormat().textureFormat(); |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 70 | VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 71 | |
| 72 | mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
| 73 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 74 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 75 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 76 | // Set up dependencies between the RT resource and the Framebuffer. |
| 77 | mResource->addWriteDependency(framebufferVk); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | const vk::ImageHelper &RenderTargetVk::getImage() const |
| 81 | { |
| 82 | ASSERT(mImage && mImage->valid()); |
| 83 | return *mImage; |
| 84 | } |
| 85 | |
| 86 | vk::ImageView *RenderTargetVk::getImageView() const |
| 87 | { |
| 88 | ASSERT(mImageView && mImageView->valid()); |
| 89 | return mImageView; |
| 90 | } |
| 91 | |
| 92 | vk::CommandGraphResource *RenderTargetVk::getResource() const |
| 93 | { |
| 94 | return mResource; |
| 95 | } |
| 96 | |
| 97 | const vk::Format &RenderTargetVk::getImageFormat() const |
| 98 | { |
| 99 | ASSERT(mImage && mImage->valid()); |
| 100 | return mImage->getFormat(); |
| 101 | } |
| 102 | |
| 103 | const gl::Extents &RenderTargetVk::getImageExtents() const |
| 104 | { |
| 105 | ASSERT(mImage && mImage->valid()); |
| 106 | return mImage->getExtents(); |
| 107 | } |
| 108 | |
| 109 | void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView *imageView) |
| 110 | { |
| 111 | ASSERT(image && image->valid() && imageView && imageView->valid()); |
| 112 | mImage = image; |
| 113 | mImageView = imageView; |
| 114 | } |
| 115 | |
Jamie Madill | e4e2d0c | 2018-06-22 08:25:05 -0400 | [diff] [blame] | 116 | vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readingResource, |
| 117 | VkImageLayout layout, |
Jamie Madill | e4e2d0c | 2018-06-22 08:25:05 -0400 | [diff] [blame] | 118 | vk::CommandBuffer *commandBuffer) |
| 119 | { |
| 120 | ASSERT(mImage && mImage->valid()); |
| 121 | |
| 122 | // TODO(jmadill): Better simultaneous resource access. http://anglebug.com/2679 |
| 123 | mResource->addWriteDependency(readingResource); |
| 124 | |
Luc Ferron | 1617e69 | 2018-07-11 11:08:19 -0400 | [diff] [blame] | 125 | mImage->changeLayoutWithStages(mImage->getAspectFlags(), layout, |
| 126 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
Jamie Madill | e4e2d0c | 2018-06-22 08:25:05 -0400 | [diff] [blame] | 127 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer); |
| 128 | |
| 129 | return mImage; |
| 130 | } |
| 131 | |
| 132 | vk::ImageHelper *RenderTargetVk::getImageForWrite(vk::CommandGraphResource *writingResource) const |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 133 | { |
| 134 | ASSERT(mImage && mImage->valid()); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 135 | mResource->addWriteDependency(writingResource); |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 136 | return mImage; |
| 137 | } |
| 138 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 139 | } // namespace rx |