blob: 49c6e414fc110e4d1e5fc5724976d95d749656b6 [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
8#include "GrVkFramebuffer.h"
9
10#include "GrVkGpu.h"
11#include "GrVkImageView.h"
12#include "GrVkRenderPass.h"
13
14GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu,
15 int width, int height,
16 const GrVkRenderPass* renderPass,
17 const GrVkImageView* colorAttachment,
18 const GrVkImageView* resolveAttachment,
19 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;
27 if (resolveAttachment) {
28 attachments[numAttachments++] = resolveAttachment->imageView();
29 }
30 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;
47 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateFramebuffer(gpu->device(),
48 &createInfo,
49 nullptr,
50 &framebuffer));
51 if (err) {
52 return nullptr;
53 }
54
55 return new GrVkFramebuffer(framebuffer);
56}
57
58void GrVkFramebuffer::freeGPUData(const GrVkGpu* gpu) const {
59 SkASSERT(fFramebuffer);
60 GR_VK_CALL(gpu->vkInterface(), DestroyFramebuffer(gpu->device(), fFramebuffer, nullptr));
61}