blob: 1531214f933c4a686a1a4cfc66cc87c51713cd9c [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/vk/GrVkGpu.h"
11#include "src/gpu/vk/GrVkImageView.h"
12#include "src/gpu/vk/GrVkRenderPass.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050013
14GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu,
15 int width, int height,
16 const GrVkRenderPass* renderPass,
17 const GrVkImageView* colorAttachment,
Greg Daniel7acddf52020-12-16 15:15:51 -050018 const GrVkImageView* resolveAttachment,
Greg Daniel164a9f02016-02-22 09:56:40 -050019 const GrVkImageView* stencilAttachment) {
20 // At the very least we need a renderPass and a colorAttachment
21 SkASSERT(renderPass);
22 SkASSERT(colorAttachment);
halcanary9d524f22016-03-29 09:03:52 -070023
Greg Daniel164a9f02016-02-22 09:56:40 -050024 VkImageView attachments[3];
25 attachments[0] = colorAttachment->imageView();
26 int numAttachments = 1;
Greg Daniel7acddf52020-12-16 15:15:51 -050027 if (resolveAttachment) {
28 attachments[numAttachments++] = resolveAttachment->imageView();
29 }
Greg Daniel164a9f02016-02-22 09:56:40 -050030 if (stencilAttachment) {
31 attachments[numAttachments++] = stencilAttachment->imageView();
32 }
halcanary9d524f22016-03-29 09:03:52 -070033
Greg Daniel164a9f02016-02-22 09:56:40 -050034 VkFramebufferCreateInfo createInfo;
35 memset(&createInfo, 0, sizeof(VkFramebufferCreateInfo));
36 createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
37 createInfo.pNext = nullptr;
38 createInfo.flags = 0;
39 createInfo.renderPass = renderPass->vkRenderPass();
40 createInfo.attachmentCount = numAttachments;
41 createInfo.pAttachments = attachments;
42 createInfo.width = width;
43 createInfo.height = height;
44 createInfo.layers = 1;
halcanary9d524f22016-03-29 09:03:52 -070045
Greg Daniel164a9f02016-02-22 09:56:40 -050046 VkFramebuffer framebuffer;
Greg Danielfa3adf72019-11-07 09:53:41 -050047 VkResult err;
48 GR_VK_CALL_RESULT(gpu, err, CreateFramebuffer(gpu->device(), &createInfo, nullptr,
49 &framebuffer));
Greg Daniel164a9f02016-02-22 09:56:40 -050050 if (err) {
51 return nullptr;
52 }
53
Jim Van Verth5082df12020-03-11 16:14:51 -040054 return new GrVkFramebuffer(gpu, framebuffer);
Greg Daniel164a9f02016-02-22 09:56:40 -050055}
56
Jim Van Verth5082df12020-03-11 16:14:51 -040057void GrVkFramebuffer::freeGPUData() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050058 SkASSERT(fFramebuffer);
Jim Van Verth5082df12020-03-11 16:14:51 -040059 GR_VK_CALL(fGpu->vkInterface(), DestroyFramebuffer(fGpu->device(), fFramebuffer, nullptr));
Greg Daniel164a9f02016-02-22 09:56:40 -050060}