Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: src/gpu/vk/GrVkDescriptorSetManager.h

Issue 2172873003: Reuse sampler descriptor set allocations in Vulkan (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrVkDescriptorSetManager_DEFINED 8 #ifndef GrVkDescriptorSetManager_DEFINED
9 #define GrVkDescriptorSetManager_DEFINED 9 #define GrVkDescriptorSetManager_DEFINED
10 10
11 #include "GrResourceHandle.h" 11 #include "GrResourceHandle.h"
12 #include "GrVkDescriptorPool.h" 12 #include "GrVkDescriptorPool.h"
13 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
14 #include "SkTArray.h" 14 #include "SkTArray.h"
15 #include "vk/GrVkDefines.h" 15 #include "vk/GrVkDefines.h"
16 16
17 class GrVkDescriptorSet; 17 class GrVkDescriptorSet;
18 class GrVkGpu; 18 class GrVkGpu;
19 class GrVkUniformHandler;
19 20
20 /** 21 /**
21 * This class handles the allocation of descriptor sets for a given VkDescriptor SetLayout. It will 22 * This class handles the allocation of descriptor sets for a given VkDescriptor SetLayout. It will
22 * try to reuse previously allocated descriptor sets if they are no longer in us e by other objects. 23 * try to reuse previously allocated descriptor sets if they are no longer in us e by other objects.
23 */ 24 */
24 class GrVkDescriptorSetManager { 25 class GrVkDescriptorSetManager {
25 public: 26 public:
26 GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle); 27 GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle);
27 28
28 GrVkDescriptorSetManager(GrVkGpu* gpu, 29 GrVkDescriptorSetManager(GrVkGpu* gpu,
29 VkDescriptorSetLayout layout, 30 VkDescriptorSetLayout layout,
30 VkDescriptorType, 31 VkDescriptorType,
31 uint32_t samplerCount); 32 uint32_t descCountPerSet,
33 const GrVkUniformHandler* handler = nullptr);
32 ~GrVkDescriptorSetManager() {} 34 ~GrVkDescriptorSetManager() {}
33 35
34 void abandon(); 36 void abandon();
35 void release(const GrVkGpu* gpu); 37 void release(const GrVkGpu* gpu);
36 38
39 VkDescriptorSetLayout layout() const;
40
37 const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle ); 41 const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle );
38 42
39 void recycleDescriptorSet(const GrVkDescriptorSet*); 43 void recycleDescriptorSet(const GrVkDescriptorSet*);
40 44
41 int isCompatible(uint32_t numSamplers) const { return numSamplers == fNumSam plerBindings; } 45 bool isCompatible(VkDescriptorType type, const GrVkUniformHandler*) const;
42 46
43 private: 47 private:
44 struct DescriptorPoolManager { 48 struct DescriptorPoolManager {
45 DescriptorPoolManager(VkDescriptorSetLayout layout, VkDescriptorType typ e, 49 DescriptorPoolManager(VkDescriptorSetLayout layout, VkDescriptorType typ e,
46 uint32_t samplerCount, GrVkGpu* gpu) 50 uint32_t descCountPerSet, GrVkGpu* gpu)
47 : fDescLayout(layout) 51 : fDescLayout(layout)
48 , fDescType(type) 52 , fDescType(type)
53 , fDescCountPerSet(descCountPerSet)
49 , fCurrentDescriptorCount(0) 54 , fCurrentDescriptorCount(0)
50 , fPool(nullptr) { 55 , fPool(nullptr) {
51 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type) {
52 fDescCountPerSet = kNumUniformDescPerSet;
53 } else {
54 SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
55 fDescCountPerSet = samplerCount;
56 }
57
58 SkASSERT(fDescCountPerSet < kStartNumDescriptors); 56 SkASSERT(fDescCountPerSet < kStartNumDescriptors);
59 fMaxDescriptors = kStartNumDescriptors; 57 fMaxDescriptors = kStartNumDescriptors;
60 SkASSERT(fMaxDescriptors > 0); 58 SkASSERT(fMaxDescriptors > 0);
61 this->getNewPool(gpu); 59 this->getNewPool(gpu);
62 } 60 }
63 61
64 ~DescriptorPoolManager() { 62 ~DescriptorPoolManager() {
65 SkASSERT(!fDescLayout); 63 SkASSERT(!fDescLayout);
66 SkASSERT(!fPool); 64 SkASSERT(!fPool);
67 } 65 }
68 66
69 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds); 67 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds);
70 68
71 void freeGPUResources(const GrVkGpu* gpu); 69 void freeGPUResources(const GrVkGpu* gpu);
72 void abandonGPUResources(); 70 void abandonGPUResources();
73 71
74 VkDescriptorSetLayout fDescLayout; // Not owned by this class 72 VkDescriptorSetLayout fDescLayout;
75 VkDescriptorType fDescType; 73 VkDescriptorType fDescType;
76 uint32_t fDescCountPerSet; 74 uint32_t fDescCountPerSet;
77 uint32_t fMaxDescriptors; 75 uint32_t fMaxDescriptors;
78 uint32_t fCurrentDescriptorCount; 76 uint32_t fCurrentDescriptorCount;
79 GrVkDescriptorPool* fPool; 77 GrVkDescriptorPool* fPool;
80 78
81 private: 79 private:
82 enum { 80 enum {
83 kNumUniformDescPerSet = 2,
84 kMaxDescriptors = 1024, 81 kMaxDescriptors = 1024,
85 kStartNumDescriptors = 16, // must be less than kMaxUniformDescripto rs 82 kStartNumDescriptors = 16, // must be less than kMaxUniformDescripto rs
86 }; 83 };
87 84
88 void getNewPool(GrVkGpu* gpu); 85 void getNewPool(GrVkGpu* gpu);
89 }; 86 };
90 87
91 DescriptorPoolManager fPoolManager; 88 DescriptorPoolManager fPoolManager;
92 SkTArray<const GrVkDescriptorSet*> fFreeSets; 89 SkTArray<const GrVkDescriptorSet*, true> fFreeSets;
93 // If the number of bindings is 0 we assume this is for uniform buffers 90 SkSTArray<4, uint32_t> fBindingVisibilities;
94 uint32_t fNumSamplerBindings;
95 }; 91 };
96 92
97 #endif 93 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/vk/GrVkDescriptorSetManager.cpp » ('j') | src/gpu/vk/GrVkDescriptorSetManager.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698