blob: e2170bce443f0e4ff43ba9d0dc0f64644e16520a [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
2* Copyright 2016 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/vk/GrVkFramebuffer.h"
Greg Daniel164a9f02016-02-22 09:56:40 -05009
Greg Daniel38517c22021-03-29 16:01:19 -040010#include "src/gpu/vk/GrVkAttachment.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/vk/GrVkGpu.h"
12#include "src/gpu/vk/GrVkImageView.h"
13#include "src/gpu/vk/GrVkRenderPass.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014
Greg Daniela92d7872021-04-07 11:08:36 -040015GrVkFramebuffer* GrVkFramebuffer::Create(
16 GrVkGpu* gpu,
17 int width, int height,
18 const GrVkRenderPass* renderPass,
19 const GrVkAttachment* colorAttachment,
20 const GrVkAttachment* resolveAttachment,
21 const GrVkAttachment* stencilAttachment,
22 GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle) {
Greg Daniel164a9f02016-02-22 09:56:40 -050023 // At the very least we need a renderPass and a colorAttachment
24 SkASSERT(renderPass);
25 SkASSERT(colorAttachment);
halcanary9d524f22016-03-29 09:03:52 -070026
Greg Daniel164a9f02016-02-22 09:56:40 -050027 VkImageView attachments[3];
Greg Daniel38517c22021-03-29 16:01:19 -040028 attachments[0] = colorAttachment->framebufferView()->imageView();
Greg Daniel164a9f02016-02-22 09:56:40 -050029 int numAttachments = 1;
Greg Daniel7acddf52020-12-16 15:15:51 -050030 if (resolveAttachment) {
Greg Daniel38517c22021-03-29 16:01:19 -040031 attachments[numAttachments++] = resolveAttachment->framebufferView()->imageView();
Greg Daniel7acddf52020-12-16 15:15:51 -050032 }
Greg Daniel164a9f02016-02-22 09:56:40 -050033 if (stencilAttachment) {
Greg Daniel38517c22021-03-29 16:01:19 -040034 attachments[numAttachments++] = stencilAttachment->framebufferView()->imageView();
Greg Daniel164a9f02016-02-22 09:56:40 -050035 }
halcanary9d524f22016-03-29 09:03:52 -070036
Greg Daniel164a9f02016-02-22 09:56:40 -050037 VkFramebufferCreateInfo createInfo;
38 memset(&createInfo, 0, sizeof(VkFramebufferCreateInfo));
39 createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
40 createInfo.pNext = nullptr;
41 createInfo.flags = 0;
42 createInfo.renderPass = renderPass->vkRenderPass();
43 createInfo.attachmentCount = numAttachments;
44 createInfo.pAttachments = attachments;
45 createInfo.width = width;
46 createInfo.height = height;
47 createInfo.layers = 1;
halcanary9d524f22016-03-29 09:03:52 -070048
Greg Daniel164a9f02016-02-22 09:56:40 -050049 VkFramebuffer framebuffer;
Greg Danielfa3adf72019-11-07 09:53:41 -050050 VkResult err;
51 GR_VK_CALL_RESULT(gpu, err, CreateFramebuffer(gpu->device(), &createInfo, nullptr,
52 &framebuffer));
Greg Daniel164a9f02016-02-22 09:56:40 -050053 if (err) {
54 return nullptr;
55 }
56
Greg Daniel38517c22021-03-29 16:01:19 -040057 return new GrVkFramebuffer(gpu, framebuffer, sk_ref_sp(colorAttachment),
Greg Daniela92d7872021-04-07 11:08:36 -040058 sk_ref_sp(resolveAttachment), sk_ref_sp(stencilAttachment),
59 compatibleRenderPassHandle);
Greg Daniel164a9f02016-02-22 09:56:40 -050060}
61
Greg Daniel38517c22021-03-29 16:01:19 -040062GrVkFramebuffer::~GrVkFramebuffer() {}
63
Jim Van Verth5082df12020-03-11 16:14:51 -040064void GrVkFramebuffer::freeGPUData() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050065 SkASSERT(fFramebuffer);
Jim Van Verth5082df12020-03-11 16:14:51 -040066 GR_VK_CALL(fGpu->vkInterface(), DestroyFramebuffer(fGpu->device(), fFramebuffer, nullptr));
Greg Daniel164a9f02016-02-22 09:56:40 -050067}