blob: 48c2c10892c449eaaf01176a0ca44550c42fdf6c [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,
20 vk::CommandGraphResource *resource)
21 : mImage(image), mImageView(imageView), mResource(resource)
Jamie Madill7b57b9d2017-01-13 09:33:38 -050022{
Geoff Langbd6ae4a2018-01-29 15:51:18 -050023}
Jamie Madillbcf467f2018-05-23 09:46:00 -040024
25RenderTargetVk::~RenderTargetVk()
26{
27}
28
Jamie Madill316c6062018-05-29 10:49:45 -040029void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk,
30 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040031 vk::RenderPassDesc *renderPassDesc)
32{
Jamie Madill316c6062018-05-29 10:49:45 -040033 ASSERT(commandBuffer->valid());
34 ASSERT(!mImage->getFormat().textureFormat().hasDepthOrStencilBits());
Jamie Madillbcf467f2018-05-23 09:46:00 -040035
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 Madill316c6062018-05-29 10:49:45 -040040 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 Madillbcf467f2018-05-23 09:46:00 -040044
Jamie Madill316c6062018-05-29 10:49:45 -040045 // Set up dependencies between the RT resource and the Framebuffer.
46 mResource->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040047}
48
Jamie Madill316c6062018-05-29 10:49:45 -040049void RenderTargetVk::onDepthStencilDraw(vk::CommandGraphResource *framebufferVk,
50 vk::CommandBuffer *commandBuffer,
Jamie Madillbcf467f2018-05-23 09:46:00 -040051 vk::RenderPassDesc *renderPassDesc)
52{
Jamie Madill316c6062018-05-29 10:49:45 -040053 ASSERT(commandBuffer->valid());
Jamie Madillbcf467f2018-05-23 09:46:00 -040054 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 Ferron5bdf8bd2018-06-20 09:51:37 -040061 VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
Jamie Madillbcf467f2018-05-23 09:46:00 -040062
63 mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
64 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madill316c6062018-05-29 10:49:45 -040065 VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040066
Jamie Madill316c6062018-05-29 10:49:45 -040067 // Set up dependencies between the RT resource and the Framebuffer.
68 mResource->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040069}
70
71const vk::ImageHelper &RenderTargetVk::getImage() const
72{
73 ASSERT(mImage && mImage->valid());
74 return *mImage;
75}
76
77vk::ImageView *RenderTargetVk::getImageView() const
78{
79 ASSERT(mImageView && mImageView->valid());
80 return mImageView;
81}
82
83vk::CommandGraphResource *RenderTargetVk::getResource() const
84{
85 return mResource;
86}
87
88const 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 Madille4e2d0c2018-06-22 08:25:05 -0400107vk::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
123vk::ImageHelper *RenderTargetVk::getImageForWrite(vk::CommandGraphResource *writingResource) const
Jamie Madillbcf467f2018-05-23 09:46:00 -0400124{
125 ASSERT(mImage && mImage->valid());
Jamie Madill316c6062018-05-29 10:49:45 -0400126 mResource->addWriteDependency(writingResource);
Jamie Madillbcf467f2018-05-23 09:46:00 -0400127 return mImage;
128}
129
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500130} // namespace rx