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 | |
| 29 | void RenderTargetVk::onColorDraw(Serial currentSerial, |
| 30 | vk::CommandGraphNode *writingNode, |
| 31 | vk::RenderPassDesc *renderPassDesc) |
| 32 | { |
| 33 | ASSERT(writingNode->getOutsideRenderPassCommands()->valid()); |
| 34 | |
| 35 | // Store the attachment info in the renderPassDesc. |
| 36 | renderPassDesc->packColorAttachment(*mImage); |
| 37 | |
| 38 | // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361 |
| 39 | mImage->changeLayoutWithStages( |
| 40 | VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 41 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 42 | writingNode->getOutsideRenderPassCommands()); |
| 43 | |
| 44 | // Set up dependencies between the new graph node and other current nodes in the resource. |
| 45 | mResource->onWriteResource(writingNode, currentSerial); |
| 46 | } |
| 47 | |
| 48 | void RenderTargetVk::onDepthStencilDraw(Serial currentSerial, |
| 49 | vk::CommandGraphNode *writingNode, |
| 50 | vk::RenderPassDesc *renderPassDesc) |
| 51 | { |
| 52 | ASSERT(writingNode->getOutsideRenderPassCommands()->valid()); |
| 53 | ASSERT(mImage->getFormat().textureFormat().hasDepthOrStencilBits()); |
| 54 | |
| 55 | // Store the attachment info in the renderPassDesc. |
| 56 | renderPassDesc->packDepthStencilAttachment(*mImage); |
| 57 | |
| 58 | // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361 |
| 59 | const angle::Format &format = mImage->getFormat().textureFormat(); |
| 60 | VkImageAspectFlags aspectFlags = (format.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) | |
| 61 | (format.stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0); |
| 62 | |
| 63 | mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
| 64 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 65 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, |
| 66 | writingNode->getOutsideRenderPassCommands()); |
| 67 | |
| 68 | // Set up dependencies between the new graph node and other current nodes in the resource. |
| 69 | mResource->onWriteResource(writingNode, currentSerial); |
| 70 | } |
| 71 | |
| 72 | const vk::ImageHelper &RenderTargetVk::getImage() const |
| 73 | { |
| 74 | ASSERT(mImage && mImage->valid()); |
| 75 | return *mImage; |
| 76 | } |
| 77 | |
| 78 | vk::ImageView *RenderTargetVk::getImageView() const |
| 79 | { |
| 80 | ASSERT(mImageView && mImageView->valid()); |
| 81 | return mImageView; |
| 82 | } |
| 83 | |
| 84 | vk::CommandGraphResource *RenderTargetVk::getResource() const |
| 85 | { |
| 86 | return mResource; |
| 87 | } |
| 88 | |
| 89 | const vk::Format &RenderTargetVk::getImageFormat() const |
| 90 | { |
| 91 | ASSERT(mImage && mImage->valid()); |
| 92 | return mImage->getFormat(); |
| 93 | } |
| 94 | |
| 95 | const gl::Extents &RenderTargetVk::getImageExtents() const |
| 96 | { |
| 97 | ASSERT(mImage && mImage->valid()); |
| 98 | return mImage->getExtents(); |
| 99 | } |
| 100 | |
| 101 | void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView *imageView) |
| 102 | { |
| 103 | ASSERT(image && image->valid() && imageView && imageView->valid()); |
| 104 | mImage = image; |
| 105 | mImageView = imageView; |
| 106 | } |
| 107 | |
| 108 | vk::ImageHelper *RenderTargetVk::getImageForWrite(Serial currentSerial, |
| 109 | vk::CommandGraphNode *writingNode) const |
| 110 | { |
| 111 | ASSERT(mImage && mImage->valid()); |
| 112 | mResource->onWriteResource(writingNode, currentSerial); |
| 113 | return mImage; |
| 114 | } |
| 115 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 116 | } // namespace rx |