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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/vk/GrVkFramebuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 9 | |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 10 | #include "src/gpu/vk/GrVkAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/vk/GrVkGpu.h" |
| 12 | #include "src/gpu/vk/GrVkImageView.h" |
| 13 | #include "src/gpu/vk/GrVkRenderPass.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | |
| 15 | GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu, |
| 16 | int width, int height, |
| 17 | const GrVkRenderPass* renderPass, |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 18 | const GrVkAttachment* colorAttachment, |
| 19 | const GrVkAttachment* resolveAttachment, |
| 20 | const GrVkAttachment* stencilAttachment) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 21 | // At the very least we need a renderPass and a colorAttachment |
| 22 | SkASSERT(renderPass); |
| 23 | SkASSERT(colorAttachment); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 24 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 25 | VkImageView attachments[3]; |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 26 | attachments[0] = colorAttachment->framebufferView()->imageView(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 27 | int numAttachments = 1; |
Greg Daniel | 7acddf5 | 2020-12-16 15:15:51 -0500 | [diff] [blame] | 28 | if (resolveAttachment) { |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 29 | attachments[numAttachments++] = resolveAttachment->framebufferView()->imageView(); |
Greg Daniel | 7acddf5 | 2020-12-16 15:15:51 -0500 | [diff] [blame] | 30 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 31 | if (stencilAttachment) { |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 32 | attachments[numAttachments++] = stencilAttachment->framebufferView()->imageView(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 33 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 34 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 35 | 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; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 46 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 47 | VkFramebuffer framebuffer; |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 48 | VkResult err; |
| 49 | GR_VK_CALL_RESULT(gpu, err, CreateFramebuffer(gpu->device(), &createInfo, nullptr, |
| 50 | &framebuffer)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 51 | if (err) { |
| 52 | return nullptr; |
| 53 | } |
| 54 | |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 55 | return new GrVkFramebuffer(gpu, framebuffer, sk_ref_sp(colorAttachment), |
| 56 | sk_ref_sp(resolveAttachment), sk_ref_sp(stencilAttachment)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Greg Daniel | 38517c2 | 2021-03-29 16:01:19 -0400 | [diff] [blame] | 59 | GrVkFramebuffer::~GrVkFramebuffer() {} |
| 60 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 61 | void GrVkFramebuffer::freeGPUData() const { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 62 | SkASSERT(fFramebuffer); |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 63 | GR_VK_CALL(fGpu->vkInterface(), DestroyFramebuffer(fGpu->device(), fFramebuffer, nullptr)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 64 | } |