Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu, |
| 15 | int width, int height, |
| 16 | const GrVkRenderPass* renderPass, |
| 17 | const GrVkImageView* colorAttachment, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 18 | const GrVkImageView* stencilAttachment) { |
| 19 | // At the very least we need a renderPass and a colorAttachment |
| 20 | SkASSERT(renderPass); |
| 21 | SkASSERT(colorAttachment); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 22 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 23 | VkImageView attachments[3]; |
| 24 | attachments[0] = colorAttachment->imageView(); |
| 25 | int numAttachments = 1; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 26 | if (stencilAttachment) { |
| 27 | attachments[numAttachments++] = stencilAttachment->imageView(); |
| 28 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 29 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 30 | 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; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 41 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 42 | VkFramebuffer framebuffer; |
| 43 | VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateFramebuffer(gpu->device(), |
| 44 | &createInfo, |
| 45 | nullptr, |
| 46 | &framebuffer)); |
| 47 | if (err) { |
| 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | return new GrVkFramebuffer(framebuffer); |
| 52 | } |
| 53 | |
| 54 | void GrVkFramebuffer::freeGPUData(const GrVkGpu* gpu) const { |
| 55 | SkASSERT(fFramebuffer); |
| 56 | GR_VK_CALL(gpu->vkInterface(), DestroyFramebuffer(gpu->device(), fFramebuffer, nullptr)); |
| 57 | } |