| 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/VulkanDescriptorSet.h" |
| 9 |
|
| 10 |
#include "src/gpu/graphite/vk/VulkanDescriptorPool.h" |
| 11 |
#include "src/gpu/graphite/vk/VulkanGraphiteUtils.h" |
| 12 |
#include "src/gpu/graphite/vk/VulkanSharedContext.h" |
| 13 |
|
| 14 |
namespace skgpu::graphite { |
| 15 |
|
| 16 |
sk_sp<VulkanDescriptorSet> VulkanDescriptorSet::Make(const VulkanSharedContext* ctxt, |
| 17 |
const sk_sp<VulkanDescriptorPool>& pool) { |
| 18 |
VkDescriptorSet descSet; |
| 19 |
VkDescriptorSetAllocateInfo dsAllocateInfo = {}; |
| 20 |
dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 21 |
dsAllocateInfo.descriptorPool = pool->descPool(); |
| 22 |
dsAllocateInfo.descriptorSetCount = 1; |
| 23 |
dsAllocateInfo.pSetLayouts = pool->descSetLayout(); |
| 24 |
|
| 25 |
VkResult result; |
| 26 |
VULKAN_CALL_RESULT( |
| 27 |
ctxt, result, AllocateDescriptorSets(ctxt->device(), &dsAllocateInfo, &descSet)); |
| 28 |
if (result != VK_SUCCESS) { |
| 29 |
return nullptr; |
| 30 |
} |
| 31 |
return sk_sp<VulkanDescriptorSet>(new VulkanDescriptorSet(ctxt, descSet, pool)); |
| 32 |
} |
| 33 |
|
| 34 |
VulkanDescriptorSet::VulkanDescriptorSet(const VulkanSharedContext* ctxt, |
| 35 |
VkDescriptorSet set, |
| 36 |
sk_sp<VulkanDescriptorPool> pool) |
| 37 |
: Resource(ctxt, |
| 38 |
Ownership::kOwned, |
| 39 |
/*gpuMemorySize=*/0, |
| 40 |
// Explicitly set reusableRequiresPurgeable because this object may be modified |
| 41 |
// by VulkanCommandBuffer immediately during Skia API calls, outside of the flow |
| 42 |
// of command buffer command execution. |
| 43 |
/*reusableRequiresPurgeable=*/true) |
| 44 |
, fDescSet(set) |
| 45 |
, fPool(pool) { |
| 46 |
fPool->ref(); |
| 47 |
} |
| 48 |
|
| 49 |
void VulkanDescriptorSet::freeGpuData() { |
| 50 |
fPool->unref(); |
| 51 |
} |
| 52 |
|
| 53 |
} // namespace skgpu::graphite |