blob: e2ca46f2d525c3e67d793bd40e8be507fd9936fa [file] [log] [blame]
Jamie Madill7b57b9d2017-01-13 09:33:38 -05001//
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 Madillbcf467f2018-05-23 09:46:00 -040012#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 Madill7b57b9d2017-01-13 09:33:38 -050016namespace rx
17{
Jamie Madill2d03ff42018-09-27 15:04:26 -040018RenderTargetVk::RenderTargetVk(vk::ImageHelper *image, vk::ImageView *imageView, size_t layerIndex)
19 : mImage(image), mImageView(imageView), mLayerIndex(layerIndex)
Jamie Madillb980c562018-11-27 11:34:27 -050020{}
Jamie Madillbcf467f2018-05-23 09:46:00 -040021
Jamie Madillb980c562018-11-27 11:34:27 -050022RenderTargetVk::~RenderTargetVk() {}
Jamie Madillbcf467f2018-05-23 09:46:00 -040023
Jamie Madill71bb0262018-09-12 11:09:42 -040024RenderTargetVk::RenderTargetVk(RenderTargetVk &&other)
Jamie Madillb980c562018-11-27 11:34:27 -050025 : mImage(other.mImage), mImageView(other.mImageView), mLayerIndex(other.mLayerIndex)
26{}
Jamie Madill71bb0262018-09-12 11:09:42 -040027
Jamie Madill193a2842018-10-30 17:28:41 -040028void RenderTargetVk::onColorDraw(vk::FramebufferHelper *framebufferVk,
Jamie Madill316c6062018-05-29 10:49:45 -040029 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040030 vk::RenderPassDesc *renderPassDesc)
31{
Jamie Madill316c6062018-05-29 10:49:45 -040032 ASSERT(commandBuffer->valid());
33 ASSERT(!mImage->getFormat().textureFormat().hasDepthOrStencilBits());
Jamie Madillbcf467f2018-05-23 09:46:00 -040034
35 // Store the attachment info in the renderPassDesc.
Jamie Madill502d2e22018-11-01 11:06:23 -040036 renderPassDesc->packAttachment(mImage->getFormat());
Jamie Madillbcf467f2018-05-23 09:46:00 -040037
38 // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
Jamie Madill316c6062018-05-29 10:49:45 -040039 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 Madillbcf467f2018-05-23 09:46:00 -040043
Jamie Madill316c6062018-05-29 10:49:45 -040044 // Set up dependencies between the RT resource and the Framebuffer.
Jamie Madill2d03ff42018-09-27 15:04:26 -040045 mImage->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040046}
47
Jamie Madill193a2842018-10-30 17:28:41 -040048void RenderTargetVk::onDepthStencilDraw(vk::FramebufferHelper *framebufferVk,
Jamie Madill316c6062018-05-29 10:49:45 -040049 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040050 vk::RenderPassDesc *renderPassDesc)
51{
Jamie Madill316c6062018-05-29 10:49:45 -040052 ASSERT(commandBuffer->valid());
Jamie Madillbcf467f2018-05-23 09:46:00 -040053 ASSERT(mImage->getFormat().textureFormat().hasDepthOrStencilBits());
54
55 // Store the attachment info in the renderPassDesc.
Jamie Madill502d2e22018-11-01 11:06:23 -040056 renderPassDesc->packAttachment(mImage->getFormat());
Jamie Madillbcf467f2018-05-23 09:46:00 -040057
58 // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
59 const angle::Format &format = mImage->getFormat().textureFormat();
Luc Ferron5bdf8bd2018-06-20 09:51:37 -040060 VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
Jamie Madillbcf467f2018-05-23 09:46:00 -040061
62 mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
63 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madill316c6062018-05-29 10:49:45 -040064 VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040065
Jamie Madill316c6062018-05-29 10:49:45 -040066 // Set up dependencies between the RT resource and the Framebuffer.
Jamie Madill2d03ff42018-09-27 15:04:26 -040067 mImage->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040068}
69
Shahbaz Youssefif83a28a2018-12-09 03:48:34 +010070vk::ImageHelper &RenderTargetVk::getImage()
71{
72 ASSERT(mImage && mImage->valid());
73 return *mImage;
74}
75
Jamie Madillbcf467f2018-05-23 09:46:00 -040076const vk::ImageHelper &RenderTargetVk::getImage() const
77{
78 ASSERT(mImage && mImage->valid());
79 return *mImage;
80}
81
Shahbaz Youssefif83a28a2018-12-09 03:48:34 +010082vk::ImageView *RenderTargetVk::getDrawImageView() const
Jamie Madillbcf467f2018-05-23 09:46:00 -040083{
84 ASSERT(mImageView && mImageView->valid());
85 return mImageView;
86}
87
Shahbaz Youssefif83a28a2018-12-09 03:48:34 +010088vk::ImageView *RenderTargetVk::getReadImageView() const
89{
90 return getDrawImageView();
91}
92
Jamie Madillbcf467f2018-05-23 09:46:00 -040093const vk::Format &RenderTargetVk::getImageFormat() const
94{
95 ASSERT(mImage && mImage->valid());
96 return mImage->getFormat();
97}
98
99const gl::Extents &RenderTargetVk::getImageExtents() const
100{
101 ASSERT(mImage && mImage->valid());
102 return mImage->getExtents();
103}
104
105void 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 Madill193a2842018-10-30 17:28:41 -0400112vk::ImageHelper *RenderTargetVk::getImageForRead(vk::RecordableGraphResource *readingResource,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400113 VkImageLayout layout,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400114 vk::CommandBuffer *commandBuffer)
115{
116 ASSERT(mImage && mImage->valid());
117
118 // TODO(jmadill): Better simultaneous resource access. http://anglebug.com/2679
Jamie Madill2d03ff42018-09-27 15:04:26 -0400119 mImage->addWriteDependency(readingResource);
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400120
Luc Ferron1617e692018-07-11 11:08:19 -0400121 mImage->changeLayoutWithStages(mImage->getAspectFlags(), layout,
122 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400123 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
124
125 return mImage;
126}
127
Jamie Madill193a2842018-10-30 17:28:41 -0400128vk::ImageHelper *RenderTargetVk::getImageForWrite(
129 vk::RecordableGraphResource *writingResource) const
Jamie Madillbcf467f2018-05-23 09:46:00 -0400130{
131 ASSERT(mImage && mImage->valid());
Jamie Madill2d03ff42018-09-27 15:04:26 -0400132 mImage->addWriteDependency(writingResource);
Jamie Madillbcf467f2018-05-23 09:46:00 -0400133 return mImage;
134}
135
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500136} // namespace rx