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

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

Issue 1765923002: Add DescriptorPool and set manager to GrVkProgram (Closed) Base URL: https://skia.googlesource.com/skia.git@samplerDesc
Patch Set: rebase Created 4 years, 9 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/GrVkDescriptorPool.h ('k') | src/gpu/vk/GrVkProgram.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "GrVkDescriptorPool.h" 8 #include "GrVkDescriptorPool.h"
9 9
10 #include "GrVkGpu.h" 10 #include "GrVkGpu.h"
11 #include "SkTemplates.h" 11 #include "SkTemplates.h"
12 12
13 13
14 GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, const DescriptorTypeC ounts& typeCounts) 14 GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorType type , uint32_t count)
15 : INHERITED() 15 : INHERITED()
16 , fTypeCounts(typeCounts) { 16 , fType (type)
17 int numPools = fTypeCounts.numPoolSizes(); 17 , fCount(count) {
18 SkAutoTDeleteArray<VkDescriptorPoolSize> poolSizes(new VkDescriptorPoolSize[ numPools]); 18 VkDescriptorPoolSize poolSize;
19 int currentPool = 0; 19 memset(&poolSize, 0, sizeof(VkDescriptorPoolSize));
20 for (int i = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; i < VK_DESCRIPTOR_TYPE_END_RANG E; ++i) { 20 poolSize.descriptorCount = count;
21 if (fTypeCounts.fDescriptorTypeCount[i]) { 21 poolSize.type = type;
22 VkDescriptorPoolSize& poolSize = poolSizes.get()[currentPool++];
23 poolSize.type = (VkDescriptorType)i;
24 poolSize.descriptorCount = fTypeCounts.fDescriptorTypeCount[i];
25 }
26 }
27 SkASSERT(currentPool == numPools);
28 22
29 VkDescriptorPoolCreateInfo createInfo; 23 VkDescriptorPoolCreateInfo createInfo;
30 memset(&createInfo, 0, sizeof(VkDescriptorPoolCreateInfo)); 24 memset(&createInfo, 0, sizeof(VkDescriptorPoolCreateInfo));
31 createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; 25 createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
32 createInfo.pNext = nullptr; 26 createInfo.pNext = nullptr;
33 createInfo.flags = 0; 27 createInfo.flags = 0;
34 createInfo.maxSets = 2; // Currently we allow one set for samplers and one set for uniforms 28 // This is an over/conservative estimate since each set may contain more tha n count descriptors.
35 createInfo.poolSizeCount = numPools; 29 createInfo.maxSets = count;
36 createInfo.pPoolSizes = poolSizes.get(); 30 createInfo.poolSizeCount = 1;
31 createInfo.pPoolSizes = &poolSize;
37 32
38 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorPool(gpu->device(), 33 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorPool(gpu->device(),
39 &createInfo, 34 &createInfo,
40 nullptr, 35 nullptr,
41 &fDescPool)); 36 &fDescPool));
42 } 37 }
43 38
44 bool GrVkDescriptorPool::isCompatible(const DescriptorTypeCounts& typeCounts) co nst { 39 bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) con st {
45 return fTypeCounts.isSuperSet(typeCounts); 40 return fType == type && count <= fCount;
46 } 41 }
47 42
48 void GrVkDescriptorPool::reset(const GrVkGpu* gpu) { 43 void GrVkDescriptorPool::reset(const GrVkGpu* gpu) {
49 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), ResetDescriptorPool(gpu->device(), f DescPool, 0)); 44 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), ResetDescriptorPool(gpu->device(), f DescPool, 0));
50 } 45 }
51 46
52 void GrVkDescriptorPool::freeGPUData(const GrVkGpu* gpu) const { 47 void GrVkDescriptorPool::freeGPUData(const GrVkGpu* gpu) const {
53 // Destroying the VkDescriptorPool will automatically free and delete any Vk DescriptorSets 48 // Destroying the VkDescriptorPool will automatically free and delete any Vk DescriptorSets
54 // allocated from the pool. 49 // allocated from the pool.
55 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorPool(gpu->device(), fDescPoo l, nullptr)); 50 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorPool(gpu->device(), fDescPoo l, nullptr));
56 } 51 }
57
58 ///////////////////////////////////////////////////////////////////////////////
59
60 int GrVkDescriptorPool::DescriptorTypeCounts::numPoolSizes() const {
61 int count = 0;
62 for (int i = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; i < VK_DESCRIPTOR_TYPE_END_RANG E; ++i) {
63 count += fDescriptorTypeCount[i] ? 1 : 0;
64 }
65 return count;
66 }
67
68 bool GrVkDescriptorPool::DescriptorTypeCounts::isSuperSet(const DescriptorTypeCo unts& that) const {
69 for (int i = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; i < VK_DESCRIPTOR_TYPE_END_RANG E; ++i) {
70 if (that.fDescriptorTypeCount[i] > fDescriptorTypeCount[i]) {
71 return false;
72 }
73 }
74 return true;
75 }
76
77 void GrVkDescriptorPool::DescriptorTypeCounts::setTypeCount(VkDescriptorType typ e, uint8_t count) {
78 fDescriptorTypeCount[type] = count;
79 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkDescriptorPool.h ('k') | src/gpu/vk/GrVkProgram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698