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