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