| 1 |
/* |
| 2 |
* Copyright 2023 Google LLC |
| 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 "src/gpu/graphite/vk/VulkanFramebuffer.h" |
| 9 |
|
| 10 |
#include "src/gpu/graphite/vk/VulkanGraphiteUtils.h" |
| 11 |
#include "src/gpu/graphite/vk/VulkanSharedContext.h" |
| 12 |
#include "src/gpu/graphite/vk/VulkanTexture.h" |
| 13 |
|
| 14 |
namespace skgpu::graphite { |
| 15 |
|
| 16 |
sk_sp<VulkanFramebuffer> VulkanFramebuffer::Make(const VulkanSharedContext* context, |
| 17 |
const VkFramebufferCreateInfo& framebufferInfo, |
| 18 |
const RenderPassDesc& renderPassDesc, |
| 19 |
sk_sp<VulkanTexture> msaaTexture, |
| 20 |
sk_sp<VulkanTexture> depthStencilTexture) { |
| 21 |
VkFramebuffer framebuffer; |
| 22 |
VkResult result; |
| 23 |
VULKAN_CALL_RESULT( |
| 24 |
context, |
| 25 |
result, |
| 26 |
CreateFramebuffer(context->device(), &framebufferInfo, nullptr, &framebuffer)); |
| 27 |
if (result != VK_SUCCESS) { |
| 28 |
return nullptr; |
| 29 |
} |
| 30 |
|
| 31 |
bool loadMSAAFromResolve = RenderPassDescWillLoadMSAAFromResolve(renderPassDesc); |
| 32 |
|
| 33 |
return sk_sp<VulkanFramebuffer>(new VulkanFramebuffer(context, |
| 34 |
framebuffer, |
| 35 |
std::move(msaaTexture), |
| 36 |
std::move(depthStencilTexture), |
| 37 |
loadMSAAFromResolve)); |
| 38 |
} |
| 39 |
|
| 40 |
VulkanFramebuffer::VulkanFramebuffer(const VulkanSharedContext* context, |
| 41 |
VkFramebuffer framebuffer, |
| 42 |
sk_sp<VulkanTexture> msaaTexture, |
| 43 |
sk_sp<VulkanTexture> depthStencilTexture, |
| 44 |
bool loadMSAAFromResolve) |
| 45 |
: Resource(context, |
| 46 |
Ownership::kOwned, |
| 47 |
/*gpuMemorySize=*/0) |
| 48 |
, fSharedContext(context) |
| 49 |
, fFramebuffer(framebuffer) |
| 50 |
, fMsaaTexture(std::move(msaaTexture)) |
| 51 |
, fDepthStencilTexture(std::move(depthStencilTexture)) |
| 52 |
, fLoadMSAAFromResolve(loadMSAAFromResolve) {} |
| 53 |
|
| 54 |
bool VulkanFramebuffer::compatible(const RenderPassDesc& renderPassDesc, |
| 55 |
const VulkanTexture* msaaTexture, |
| 56 |
const VulkanTexture* depthStencilTexture) { |
| 57 |
auto compatibleTextures = [](const VulkanTexture* tex1, const VulkanTexture* tex2) { |
| 58 |
if (tex1 && tex2) { |
| 59 |
return tex1->uniqueID() == tex2->uniqueID(); |
| 60 |
} else if (!tex1 && !tex2){ |
| 61 |
return true; |
| 62 |
} |
| 63 |
return false; |
| 64 |
}; |
| 65 |
|
| 66 |
bool loadMSAAFromResolve = RenderPassDescWillLoadMSAAFromResolve(renderPassDesc); |
| 67 |
|
| 68 |
return fLoadMSAAFromResolve == loadMSAAFromResolve && |
| 69 |
compatibleTextures(msaaTexture, fMsaaTexture.get()) && |
| 70 |
compatibleTextures(depthStencilTexture, fDepthStencilTexture.get()); |
| 71 |
} |
| 72 |
|
| 73 |
void VulkanFramebuffer::freeGpuData() { |
| 74 |
VULKAN_CALL(fSharedContext->interface(), |
| 75 |
DestroyFramebuffer(fSharedContext->device(), fFramebuffer, nullptr)); |
| 76 |
} |
| 77 |
|
| 78 |
} // namespace skgpu::graphite |