blob: 781ccf8f36e0d85398dd5402c088a7768a2bd21a [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 Daniel164a9f02016-02-22 09:56:40 -050018 const GrVkImageView* stencilAttachment) {
19 // At the very least we need a renderPass and a colorAttachment
20 SkASSERT(renderPass);
21 SkASSERT(colorAttachment);
halcanary9d524f22016-03-29 09:03:52 -070022
Greg Daniel164a9f02016-02-22 09:56:40 -050023 VkImageView attachments[3];
24 attachments[0] = colorAttachment->imageView();
25 int numAttachments = 1;
Greg Daniel164a9f02016-02-22 09:56:40 -050026 if (stencilAttachment) {
27 attachments[numAttachments++] = stencilAttachment->imageView();
28 }
halcanary9d524f22016-03-29 09:03:52 -070029
Greg Daniel164a9f02016-02-22 09:56:40 -050030 VkFramebufferCreateInfo createInfo;
31 memset(&createInfo, 0, sizeof(VkFramebufferCreateInfo));
32 createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
33 createInfo.pNext = nullptr;
34 createInfo.flags = 0;
35 createInfo.renderPass = renderPass->vkRenderPass();
36 createInfo.attachmentCount = numAttachments;
37 createInfo.pAttachments = attachments;
38 createInfo.width = width;
39 createInfo.height = height;
40 createInfo.layers = 1;
halcanary9d524f22016-03-29 09:03:52 -070041
Greg Daniel164a9f02016-02-22 09:56:40 -050042 VkFramebuffer framebuffer;
Greg Danielfa3adf72019-11-07 09:53:41 -050043 VkResult err;
44 GR_VK_CALL_RESULT(gpu, err, CreateFramebuffer(gpu->device(), &createInfo, nullptr,
45 &framebuffer));
Greg Daniel164a9f02016-02-22 09:56:40 -050046 if (err) {
47 return nullptr;
48 }
49
Jim Van Verth5082df12020-03-11 16:14:51 -040050 return new GrVkFramebuffer(gpu, framebuffer);
Greg Daniel164a9f02016-02-22 09:56:40 -050051}
52
Jim Van Verth5082df12020-03-11 16:14:51 -040053void GrVkFramebuffer::freeGPUData() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050054 SkASSERT(fFramebuffer);
Jim Van Verth5082df12020-03-11 16:14:51 -040055 GR_VK_CALL(fGpu->vkInterface(), DestroyFramebuffer(fGpu->device(), fFramebuffer, nullptr));
Greg Daniel164a9f02016-02-22 09:56:40 -050056}