blob: 18dd86d5b86838f0b6cb231b246d837dcbf377a0 [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 Madillbcf467f2018-05-23 09:46:00 -040018RenderTargetVk::RenderTargetVk(vk::ImageHelper *image,
19 vk::ImageView *imageView,
Jamie Madill3f3b3582018-09-14 10:38:44 -040020 vk::CommandGraphResource *resource,
21 size_t layerIndex)
22 : mImage(image), mImageView(imageView), mResource(resource), mLayerIndex(layerIndex)
Jamie Madill7b57b9d2017-01-13 09:33:38 -050023{
Geoff Langbd6ae4a2018-01-29 15:51:18 -050024}
Jamie Madillbcf467f2018-05-23 09:46:00 -040025
26RenderTargetVk::~RenderTargetVk()
27{
28}
29
Jamie Madill71bb0262018-09-12 11:09:42 -040030RenderTargetVk::RenderTargetVk(RenderTargetVk &&other)
Jamie Madill3f3b3582018-09-14 10:38:44 -040031 : mImage(other.mImage),
32 mImageView(other.mImageView),
33 mResource(other.mResource),
34 mLayerIndex(other.mLayerIndex)
Jamie Madill71bb0262018-09-12 11:09:42 -040035{
36}
37
Jamie Madill316c6062018-05-29 10:49:45 -040038void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk,
39 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040040 vk::RenderPassDesc *renderPassDesc)
41{
Jamie Madill316c6062018-05-29 10:49:45 -040042 ASSERT(commandBuffer->valid());
43 ASSERT(!mImage->getFormat().textureFormat().hasDepthOrStencilBits());
Jamie Madillbcf467f2018-05-23 09:46:00 -040044
45 // Store the attachment info in the renderPassDesc.
46 renderPassDesc->packColorAttachment(*mImage);
47
48 // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
Jamie Madill316c6062018-05-29 10:49:45 -040049 mImage->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT,
50 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
51 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
52 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040053
Jamie Madill316c6062018-05-29 10:49:45 -040054 // Set up dependencies between the RT resource and the Framebuffer.
55 mResource->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040056}
57
Jamie Madill316c6062018-05-29 10:49:45 -040058void RenderTargetVk::onDepthStencilDraw(vk::CommandGraphResource *framebufferVk,
59 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040060 vk::RenderPassDesc *renderPassDesc)
61{
Jamie Madill316c6062018-05-29 10:49:45 -040062 ASSERT(commandBuffer->valid());
Jamie Madillbcf467f2018-05-23 09:46:00 -040063 ASSERT(mImage->getFormat().textureFormat().hasDepthOrStencilBits());
64
65 // Store the attachment info in the renderPassDesc.
66 renderPassDesc->packDepthStencilAttachment(*mImage);
67
68 // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
69 const angle::Format &format = mImage->getFormat().textureFormat();
Luc Ferron5bdf8bd2018-06-20 09:51:37 -040070 VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
Jamie Madillbcf467f2018-05-23 09:46:00 -040071
72 mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
73 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madill316c6062018-05-29 10:49:45 -040074 VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040075
Jamie Madill316c6062018-05-29 10:49:45 -040076 // Set up dependencies between the RT resource and the Framebuffer.
77 mResource->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040078}
79
80const vk::ImageHelper &RenderTargetVk::getImage() const
81{
82 ASSERT(mImage && mImage->valid());
83 return *mImage;
84}
85
86vk::ImageView *RenderTargetVk::getImageView() const
87{
88 ASSERT(mImageView && mImageView->valid());
89 return mImageView;
90}
91
92vk::CommandGraphResource *RenderTargetVk::getResource() const
93{
94 return mResource;
95}
96
97const vk::Format &RenderTargetVk::getImageFormat() const
98{
99 ASSERT(mImage && mImage->valid());
100 return mImage->getFormat();
101}
102
103const gl::Extents &RenderTargetVk::getImageExtents() const
104{
105 ASSERT(mImage && mImage->valid());
106 return mImage->getExtents();
107}
108
109void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView *imageView)
110{
111 ASSERT(image && image->valid() && imageView && imageView->valid());
112 mImage = image;
113 mImageView = imageView;
114}
115
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400116vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readingResource,
117 VkImageLayout layout,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400118 vk::CommandBuffer *commandBuffer)
119{
120 ASSERT(mImage && mImage->valid());
121
122 // TODO(jmadill): Better simultaneous resource access. http://anglebug.com/2679
123 mResource->addWriteDependency(readingResource);
124
Luc Ferron1617e692018-07-11 11:08:19 -0400125 mImage->changeLayoutWithStages(mImage->getAspectFlags(), layout,
126 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madille4e2d0c2018-06-22 08:25:05 -0400127 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
128
129 return mImage;
130}
131
132vk::ImageHelper *RenderTargetVk::getImageForWrite(vk::CommandGraphResource *writingResource) const
Jamie Madillbcf467f2018-05-23 09:46:00 -0400133{
134 ASSERT(mImage && mImage->valid());
Jamie Madill316c6062018-05-29 10:49:45 -0400135 mResource->addWriteDependency(writingResource);
Jamie Madillbcf467f2018-05-23 09:46:00 -0400136 return mImage;
137}
138
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500139} // namespace rx