blob: 807dccf7be45e9aca52df06769edc4889b597c64 [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
29void 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
48void 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
72const vk::ImageHelper &RenderTargetVk::getImage() const
73{
74 ASSERT(mImage && mImage->valid());
75 return *mImage;
76}
77
78vk::ImageView *RenderTargetVk::getImageView() const
79{
80 ASSERT(mImageView && mImageView->valid());
81 return mImageView;
82}
83
84vk::CommandGraphResource *RenderTargetVk::getResource() const
85{
86 return mResource;
87}
88
89const vk::Format &RenderTargetVk::getImageFormat() const
90{
91 ASSERT(mImage && mImage->valid());
92 return mImage->getFormat();
93}
94
95const gl::Extents &RenderTargetVk::getImageExtents() const
96{
97 ASSERT(mImage && mImage->valid());
98 return mImage->getExtents();
99}
100
101void 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
108vk::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 Madill7b57b9d2017-01-13 09:33:38 -0500116} // namespace rx