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

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

Issue 2163673002: Setup system in Vulkan to reuse VkDescriptorSet allocations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit 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
« no previous file with comments | « src/gpu/vk/GrVkDescriptorSetManager.h ('k') | src/gpu/vk/GrVkImage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
8 #include "GrVkDescriptorSetManager.h"
9
10 #include "GrVkDescriptorPool.h"
11 #include "GrVkDescriptorSet.h"
12 #include "GrVkGpu.h"
13
14 GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu,
15 VkDescriptorSetLayout layout,
16 VkDescriptorType type,
17 uint32_t samplerCount)
18 : fPoolManager(layout, type, samplerCount, gpu)
19 , fNumSamplerBindings(samplerCount) {
20 }
21
22 const GrVkDescriptorSet* GrVkDescriptorSetManager::getDescriptorSet(GrVkGpu* gpu ,
23 const Handle & handle) {
24 const GrVkDescriptorSet* ds = nullptr;
25 int count = fFreeSets.count();
26 if (count > 0) {
27 ds = fFreeSets[count - 1];
28 fFreeSets.removeShuffle(count - 1);
29 } else {
30 VkDescriptorSet vkDS;
31 fPoolManager.getNewDescriptorSet(gpu, &vkDS);
32
33 ds = new GrVkDescriptorSet(vkDS, fPoolManager.fPool, handle);
34 }
35 SkASSERT(ds);
36 return ds;
37 }
38
39 void GrVkDescriptorSetManager::recycleDescriptorSet(const GrVkDescriptorSet* des cSet) {
40 SkASSERT(descSet);
41 fFreeSets.push_back(descSet);
42 }
43
44 void GrVkDescriptorSetManager::release(const GrVkGpu* gpu) {
45 fPoolManager.freeGPUResources(gpu);
46
47 for (int i = 0; i < fFreeSets.count(); ++i) {
48 fFreeSets[i]->unref(gpu);
49 }
50 fFreeSets.reset();
51 }
52
53 void GrVkDescriptorSetManager::abandon() {
54 fPoolManager.abandonGPUResources();
55
56 for (int i = 0; i < fFreeSets.count(); ++i) {
57 fFreeSets[i]->unrefAndAbandon();
58 }
59 fFreeSets.reset();
60 }
61
62 ////////////////////////////////////////////////////////////////////////////////
63
64 void GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(GrVkGpu* gpu) {
65 if (fPool) {
66 fPool->unref(gpu);
67 uint32_t newPoolSize = fMaxDescriptors + ((fMaxDescriptors + 1) >> 1);
68 if (newPoolSize < kMaxDescriptors) {
69 fMaxDescriptors = newPoolSize;
70 } else {
71 fMaxDescriptors = kMaxDescriptors;
72 }
73
74 }
75 fPool = gpu->resourceProvider().findOrCreateCompatibleDescriptorPool(fDescTy pe,
76 fMaxDes criptors);
77 SkASSERT(fPool);
78 }
79
80 void GrVkDescriptorSetManager::DescriptorPoolManager::getNewDescriptorSet(GrVkGp u* gpu,
81 VkDesc riptorSet* ds) {
82 if (!fMaxDescriptors) {
83 return;
84 }
85 fCurrentDescriptorCount += fDescCountPerSet;
86 if (fCurrentDescriptorCount > fMaxDescriptors) {
87 this->getNewPool(gpu);
88 fCurrentDescriptorCount = fDescCountPerSet;
89 }
90
91 VkDescriptorSetAllocateInfo dsAllocateInfo;
92 memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo));
93 dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
94 dsAllocateInfo.pNext = nullptr;
95 dsAllocateInfo.descriptorPool = fPool->descPool();
96 dsAllocateInfo.descriptorSetCount = 1;
97 dsAllocateInfo.pSetLayouts = &fDescLayout;
98 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device() ,
99 &dsAllocateIn fo,
100 ds));
101 }
102
103 void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(const GrV kGpu* gpu) {
104 // The layout should be owned by the class which owns the DescriptorSetManag er so it will
105 // take care of destroying it.
106 fDescLayout = VK_NULL_HANDLE;
107
108 if (fPool) {
109 fPool->unref(gpu);
110 fPool = nullptr;
111 }
112 }
113
114 void GrVkDescriptorSetManager::DescriptorPoolManager::abandonGPUResources() {
115 fDescLayout = VK_NULL_HANDLE;
116 if (fPool) {
117 fPool->unrefAndAbandon();
118 fPool = nullptr;
119 }
120 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkDescriptorSetManager.h ('k') | src/gpu/vk/GrVkImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698