blob: 282834b4e0a4b783250eb3b449b1cf64210214d9 [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();
61 VkImageAspectFlags aspectFlags = (format.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
62 (format.stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
63
64 mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
65 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
Jamie Madill316c6062018-05-29 10:49:45 -040066 VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
Jamie Madillbcf467f2018-05-23 09:46:00 -040067
Jamie Madill316c6062018-05-29 10:49:45 -040068 // Set up dependencies between the RT resource and the Framebuffer.
69 mResource->addWriteDependency(framebufferVk);
Jamie Madillbcf467f2018-05-23 09:46:00 -040070}
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,
Jamie Madill316c6062018-05-29 10:49:45 -0400109 vk::CommandGraphResource *writingResource) const
Jamie Madillbcf467f2018-05-23 09:46:00 -0400110{
111 ASSERT(mImage && mImage->valid());
Jamie Madill316c6062018-05-29 10:49:45 -0400112 mResource->addWriteDependency(writingResource);
Jamie Madillbcf467f2018-05-23 09:46:00 -0400113 return mImage;
114}
115
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500116} // namespace rx