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 #ifndef skgpu_graphite_VulkanDescriptorSet_DEFINED 9 #define skgpu_graphite_VulkanDescriptorSet_DEFINED 10 11 #include "src/gpu/graphite/Resource.h" 12 13 #include "src/gpu/graphite/DescriptorData.h" 14 #include "src/gpu/graphite/vk/VulkanGraphiteUtilsPriv.h" 15 16 namespace skgpu::graphite { 17 18 class VulkanDescriptorPool; 19 class VulkanSharedContext; 20 21 /** 22 * Wrapper around VkDescriptorSet which maintains a reference to its descriptor pool. Once the ref 23 * count on that pool is 0, it will be destroyed. 24 */ 25 class VulkanDescriptorSet : public Resource { 26 public: 27 static sk_sp<VulkanDescriptorSet> Make(const VulkanSharedContext*, 28 const sk_sp<VulkanDescriptorPool>&); 29 30 VulkanDescriptorSet(const VulkanSharedContext*, 31 VkDescriptorSet, 32 sk_sp<VulkanDescriptorPool>); 33 descriptorSet()34 const VkDescriptorSet* descriptorSet() { return &fDescSet; } 35 getResourceType()36 const char* getResourceType() const override { return "Vulkan Descriptor Set"; } 37 38 private: 39 void freeGpuData() override; 40 41 VkDescriptorSet fDescSet; 42 // Have this class hold on to a reference of the descriptor pool. When a pool's reference count 43 // is 0, that means all the descriptor sets that came from that pool are no longer needed, so 44 // the pool can safely be destroyed. 45 sk_sp<VulkanDescriptorPool> fPool; 46 }; 47 } // namespace skgpu::graphite 48 49 #endif // skgpu_graphite_VulkanDescriptorSet_DEFINED 50