| /* |
| * Copyright 2023 Google LLC |
| * |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| |
| #include "src/gpu/graphite/vk/VulkanDescriptorSet.h" |
| |
| #include "src/gpu/graphite/vk/VulkanDescriptorPool.h" |
| #include "src/gpu/graphite/vk/VulkanSharedContext.h" |
| |
| namespace skgpu::graphite { |
| |
| sk_sp<VulkanDescriptorSet> VulkanDescriptorSet::Make(const VulkanSharedContext* ctxt, |
| sk_sp<VulkanDescriptorPool> pool, |
| const VkDescriptorSetLayout* layout) { |
| VkDescriptorSet descSet; |
| |
| VkDescriptorSetAllocateInfo dsAllocateInfo; |
| memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo)); |
| dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| dsAllocateInfo.pNext = nullptr; |
| dsAllocateInfo.descriptorPool = *(pool->descPool()); |
| dsAllocateInfo.descriptorSetCount = VulkanDescriptorPool::kMaxNumSets; |
| dsAllocateInfo.pSetLayouts = layout; |
| |
| VkResult result; |
| VULKAN_CALL_RESULT(ctxt->interface(), |
| result, |
| AllocateDescriptorSets(ctxt->device(), |
| &dsAllocateInfo, |
| &descSet)); |
| if (result != VK_SUCCESS) { |
| return nullptr; |
| } |
| return sk_sp<VulkanDescriptorSet>(new VulkanDescriptorSet(ctxt, descSet, pool)); |
| } |
| |
| VkDescriptorType VulkanDescriptorSet::DsTypeEnumToVkDs(DescriptorType type) { |
| switch (type) { |
| case DescriptorType::kUniformBuffer: |
| return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| case DescriptorType::kTextureSampler: |
| return VK_DESCRIPTOR_TYPE_SAMPLER; |
| case DescriptorType::kTexture: |
| return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| case DescriptorType::kCombinedTextureSampler: |
| return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| case DescriptorType::kStorageBuffer: |
| return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; |
| case DescriptorType::kInputAttachment: |
| return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| } |
| SkUNREACHABLE; |
| } |
| |
| VulkanDescriptorSet::VulkanDescriptorSet(const VulkanSharedContext* ctxt, |
| VkDescriptorSet set, |
| sk_sp<VulkanDescriptorPool> pool) |
| : Resource(ctxt, Ownership::kOwned, skgpu::Budgeted::kNo, /*gpuMemorySize=*/0) |
| , fDescSet (set) |
| , fPool (pool) { |
| fPool->ref(); |
| } |
| |
| void VulkanDescriptorSet::freeGpuData() { |
| fPool->unref(); |
| } |
| |
| } // namespace skgpu::graphite |