blob: 7a3c1a1e44bbe4a704254cd483480fbb92b2a515 [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
15GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu,
16 int width, int height,
17 const GrVkRenderPass* renderPass,
Greg Daniel38517c22021-03-29 16:01:19 -040018 const GrVkAttachment* colorAttachment,
19 const GrVkAttachment* resolveAttachment,
20 const GrVkAttachment* stencilAttachment) {
Greg Daniel164a9f02016-02-22 09:56:40 -050021 // At the very least we need a renderPass and a colorAttachment
22 SkASSERT(renderPass);
23 SkASSERT(colorAttachment);
halcanary9d524f22016-03-29 09:03:52 -070024
Greg Daniel164a9f02016-02-22 09:56:40 -050025 VkImageView attachments[3];
Greg Daniel38517c22021-03-29 16:01:19 -040026 attachments[0] = colorAttachment->framebufferView()->imageView();
Greg Daniel164a9f02016-02-22 09:56:40 -050027 int numAttachments = 1;
Greg Daniel7acddf52020-12-16 15:15:51 -050028 if (resolveAttachment) {
Greg Daniel38517c22021-03-29 16:01:19 -040029 attachments[numAttachments++] = resolveAttachment->framebufferView()->imageView();
Greg Daniel7acddf52020-12-16 15:15:51 -050030 }
Greg Daniel164a9f02016-02-22 09:56:40 -050031 if (stencilAttachment) {
Greg Daniel38517c22021-03-29 16:01:19 -040032 attachments[numAttachments++] = stencilAttachment->framebufferView()->imageView();
Greg Daniel164a9f02016-02-22 09:56:40 -050033 }
halcanary9d524f22016-03-29 09:03:52 -070034
Greg Daniel164a9f02016-02-22 09:56:40 -050035 VkFramebufferCreateInfo createInfo;
36 memset(&createInfo, 0, sizeof(VkFramebufferCreateInfo));
37 createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
38 createInfo.pNext = nullptr;
39 createInfo.flags = 0;
40 createInfo.renderPass = renderPass->vkRenderPass();
41 createInfo.attachmentCount = numAttachments;
42 createInfo.pAttachments = attachments;
43 createInfo.width = width;
44 createInfo.height = height;
45 createInfo.layers = 1;
halcanary9d524f22016-03-29 09:03:52 -070046
Greg Daniel164a9f02016-02-22 09:56:40 -050047 VkFramebuffer framebuffer;
Greg Danielfa3adf72019-11-07 09:53:41 -050048 VkResult err;
49 GR_VK_CALL_RESULT(gpu, err, CreateFramebuffer(gpu->device(), &createInfo, nullptr,
50 &framebuffer));
Greg Daniel164a9f02016-02-22 09:56:40 -050051 if (err) {
52 return nullptr;
53 }
54
Greg Daniel38517c22021-03-29 16:01:19 -040055 return new GrVkFramebuffer(gpu, framebuffer, sk_ref_sp(colorAttachment),
56 sk_ref_sp(resolveAttachment), sk_ref_sp(stencilAttachment));
Greg Daniel164a9f02016-02-22 09:56:40 -050057}
58
Greg Daniel38517c22021-03-29 16:01:19 -040059GrVkFramebuffer::~GrVkFramebuffer() {}
60
Jim Van Verth5082df12020-03-11 16:14:51 -040061void GrVkFramebuffer::freeGPUData() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050062 SkASSERT(fFramebuffer);
Jim Van Verth5082df12020-03-11 16:14:51 -040063 GR_VK_CALL(fGpu->vkInterface(), DestroyFramebuffer(fGpu->device(), fFramebuffer, nullptr));
Greg Daniel164a9f02016-02-22 09:56:40 -050064}