GrVkDescriptorSetManager.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef GrVkDescriptorSetManager_DEFINED
  8. #define GrVkDescriptorSetManager_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/gpu/vk/GrVkTypes.h"
  11. #include "include/private/SkTArray.h"
  12. #include "src/gpu/GrResourceHandle.h"
  13. #include "src/gpu/vk/GrVkDescriptorPool.h"
  14. #include "src/gpu/vk/GrVkSampler.h"
  15. class GrVkDescriptorSet;
  16. class GrVkGpu;
  17. class GrVkUniformHandler;
  18. /**
  19. * This class handles the allocation of descriptor sets for a given VkDescriptorSetLayout. It will
  20. * try to reuse previously allocated descriptor sets if they are no longer in use by other objects.
  21. */
  22. class GrVkDescriptorSetManager {
  23. public:
  24. GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle);
  25. static GrVkDescriptorSetManager* CreateUniformManager(GrVkGpu* gpu);
  26. static GrVkDescriptorSetManager* CreateSamplerManager(GrVkGpu* gpu, VkDescriptorType type,
  27. const GrVkUniformHandler&);
  28. static GrVkDescriptorSetManager* CreateSamplerManager(GrVkGpu* gpu, VkDescriptorType type,
  29. const SkTArray<uint32_t>& visibilities);
  30. ~GrVkDescriptorSetManager() {}
  31. void abandon();
  32. void release(GrVkGpu* gpu);
  33. VkDescriptorSetLayout layout() const { return fPoolManager.fDescLayout; }
  34. const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle);
  35. void recycleDescriptorSet(const GrVkDescriptorSet*);
  36. bool isCompatible(VkDescriptorType type, const GrVkUniformHandler*) const;
  37. bool isCompatible(VkDescriptorType type,
  38. const SkTArray<uint32_t>& visibilities) const;
  39. private:
  40. struct DescriptorPoolManager {
  41. DescriptorPoolManager(VkDescriptorType type, GrVkGpu* gpu,
  42. const SkTArray<uint32_t>& visibilities,
  43. const SkTArray<const GrVkSampler*>& immutableSamplers);
  44. ~DescriptorPoolManager() {
  45. SkASSERT(!fDescLayout);
  46. SkASSERT(!fPool);
  47. }
  48. void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds);
  49. void freeGPUResources(GrVkGpu* gpu);
  50. void abandonGPUResources();
  51. VkDescriptorSetLayout fDescLayout;
  52. VkDescriptorType fDescType;
  53. uint32_t fDescCountPerSet;
  54. uint32_t fMaxDescriptors;
  55. uint32_t fCurrentDescriptorCount;
  56. GrVkDescriptorPool* fPool;
  57. private:
  58. enum {
  59. kUniformDescPerSet = 2,
  60. kMaxDescriptors = 1024,
  61. kStartNumDescriptors = 16, // must be less than kMaxUniformDescriptors
  62. };
  63. void getNewPool(GrVkGpu* gpu);
  64. };
  65. GrVkDescriptorSetManager(GrVkGpu* gpu,
  66. VkDescriptorType,
  67. const SkTArray<uint32_t>& visibilities,
  68. const SkTArray<const GrVkSampler*>& immutableSamplers);
  69. DescriptorPoolManager fPoolManager;
  70. SkTArray<const GrVkDescriptorSet*, true> fFreeSets;
  71. SkSTArray<4, uint32_t> fBindingVisibilities;
  72. SkSTArray<4, const GrVkSampler*> fImmutableSamplers;
  73. };
  74. #endif