blob: 5fa289485b2aa3c20f998f09bec748d11bbd6dca [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 Madill7b57b9d2017-01-13 09:33:38 -050020{
Geoff Langbd6ae4a2018-01-29 15:51:18 -050021}
Jamie Madillbcf467f2018-05-23 09:46:00 -040022
23RenderTargetVk::~RenderTargetVk()
24{
25}
26
Jamie Madill71bb0262018-09-12 11:09:42 -040027RenderTargetVk::RenderTargetVk(RenderTargetVk &&other)
Jamie Madill3f3b3582018-09-14 10:38:44 -040028 : mImage(other.mImage),
29 mImageView(other.mImageView),
Jamie Madill3f3b3582018-09-14 10:38:44 -040030 mLayerIndex(other.mLayerIndex)
Jamie Madill71bb0262018-09-12 11:09:42 -040031{
32}
33
Jamie Madill193a2842018-10-30 17:28:41 -040034void RenderTargetVk::onColorDraw(vk::FramebufferHelper *framebufferVk,
Jamie Madill316c6062018-05-29 10:49:45 -040035 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040036 vk::RenderPassDesc *renderPassDesc)
37{
Jamie Madill316c6062018-05-29 10:49:45 -040038 ASSERT(commandBuffer->valid());
39 ASSERT(!mImage->getFormat().textureFormat().hasDepthOrStencilBits());
Jamie Madillbcf467f2018-05-23 09:46:00 -040040
41 // Store the attachment info in the renderPassDesc.
42 renderPassDesc->packColorAttachment(*mImage);
43
44 // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
Jamie Madill316c6062018-05-29 10:49:45 -040045 mImage->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT,
46 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
47 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
48 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040049
Jamie Madill316c6062018-05-29 10:49:45 -040050 // Set up dependencies between the RT resource and the Framebuffer.
Jamie Madill2d03ff42018-09-27 15:04:26 -040051 mImage->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040052}
53
Jamie Madill193a2842018-10-30 17:28:41 -040054void RenderTargetVk::onDepthStencilDraw(vk::FramebufferHelper *framebufferVk,
Jamie Madill316c6062018-05-29 10:49:45 -040055 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040056 vk::RenderPassDesc *renderPassDesc)
57{
Jamie Madill316c6062018-05-29 10:49:45 -040058 ASSERT(commandBuffer->valid());
Jamie Madillbcf467f2018-05-23 09:46:00 -040059 ASSERT(mImage->getFormat().textureFormat().hasDepthOrStencilBits());
60
61 // Store the attachment info in the renderPassDesc.
62 renderPassDesc->packDepthStencilAttachment(*mImage);
63
64 // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
65 const angle::Format &format = mImage->getFormat().textureFormat();
Luc Ferron5bdf8bd2018-06-20 09:51:37 -040066 VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
Jamie Madillbcf467f2018-05-23 09:46:00 -040067
68 mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
69 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madill316c6062018-05-29 10:49:45 -040070 VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040071
Jamie Madill316c6062018-05-29 10:49:45 -040072 // Set up dependencies between the RT resource and the Framebuffer.
Jamie Madill2d03ff42018-09-27 15:04:26 -040073 mImage->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040074}
75
76const vk::ImageHelper &RenderTargetVk::getImage() const
77{
78 ASSERT(mImage && mImage->valid());
79 return *mImage;
80}
81
82vk::ImageView *RenderTargetVk::getImageView() const
83{
84 ASSERT(mImageView && mImageView->valid());
85 return mImageView;
86}
87
Jamie Madillbcf467f2018-05-23 09:46:00 -040088const vk::Format &RenderTargetVk::getImageFormat() const
89{
90 ASSERT(mImage && mImage->valid());
91 return mImage->getFormat();
92}
93
94const gl::Extents &RenderTargetVk::getImageExtents() const
95{
96 ASSERT(mImage && mImage->valid());
97 return mImage->getExtents();
98}
99
100void 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 Madill193a2842018-10-30 17:28:41 -0400107vk::ImageHelper *RenderTargetVk::getImageForRead(vk::RecordableGraphResource *readingResource,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400108 VkImageLayout layout,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400109 vk::CommandBuffer *commandBuffer)
110{
111 ASSERT(mImage && mImage->valid());
112
113 // TODO(jmadill): Better simultaneous resource access. http://anglebug.com/2679
Jamie Madill2d03ff42018-09-27 15:04:26 -0400114 mImage->addWriteDependency(readingResource);
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400115
Luc Ferron1617e692018-07-11 11:08:19 -0400116 mImage->changeLayoutWithStages(mImage->getAspectFlags(), layout,
117 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400118 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
119
120 return mImage;
121}
122
Jamie Madill193a2842018-10-30 17:28:41 -0400123vk::ImageHelper *RenderTargetVk::getImageForWrite(
124 vk::RecordableGraphResource *writingResource) const
Jamie Madillbcf467f2018-05-23 09:46:00 -0400125{
126 ASSERT(mImage && mImage->valid());
Jamie Madill2d03ff42018-09-27 15:04:26 -0400127 mImage->addWriteDependency(writingResource);
Jamie Madillbcf467f2018-05-23 09:46:00 -0400128 return mImage;
129}
130
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500131} // namespace rx