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

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

Issue 1816153002: Set up cache in vulkan to reuse GrVkPrograms (aka VkPipelines) (Closed) Base URL: https://skia.googlesource.com/skia.git@progSamplers
Patch Set: cleanup 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
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 GrVkResourceProvider_DEFINED 8 #ifndef GrVkResourceProvider_DEFINED
9 #define GrVkResourceProvider_DEFINED 9 #define GrVkResourceProvider_DEFINED
10 10
11 #include "GrGpu.h"
11 #include "GrVkDescriptorPool.h" 12 #include "GrVkDescriptorPool.h"
13 #include "GrVkProgram.h"
12 #include "GrVkResource.h" 14 #include "GrVkResource.h"
13 #include "GrVkUtil.h" 15 #include "GrVkUtil.h"
14 #include "SkTArray.h" 16 #include "SkTArray.h"
15 #include "SkTDynamicHash.h" 17 #include "SkTDynamicHash.h"
16 18
17 #include "vulkan/vulkan.h" 19 #include "vulkan/vulkan.h"
18 20
19 class GrPipeline; 21 class GrPipeline;
20 class GrPrimitiveProcessor; 22 class GrPrimitiveProcessor;
21 class GrTextureParams; 23 class GrTextureParams;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // TODO: Currently this will just create a descriptor pool without holding o nto a ref itself 56 // TODO: Currently this will just create a descriptor pool without holding o nto a ref itself
55 // so we currently do not reuse them. Rquires knowing if another draw is currently using 57 // so we currently do not reuse them. Rquires knowing if another draw is currently using
56 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out 58 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out
57 // of our cache of GrVkDescriptorPools. 59 // of our cache of GrVkDescriptorPools.
58 GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool(VkDescriptorType ty pe, uint32_t count); 60 GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool(VkDescriptorType ty pe, uint32_t count);
59 61
60 // Finds or creates a compatible GrVkSampler based on the GrTextureParams. 62 // Finds or creates a compatible GrVkSampler based on the GrTextureParams.
61 // The refcount is incremented and a pointer returned. 63 // The refcount is incremented and a pointer returned.
62 GrVkSampler* findOrCreateCompatibleSampler(const GrTextureParams&); 64 GrVkSampler* findOrCreateCompatibleSampler(const GrTextureParams&);
63 65
66 GrVkProgram* findOrCreateCompatibleProgram(const GrPipeline&,
67 const GrPrimitiveProcessor&,
68 GrPrimitiveType,
69 const GrVkRenderPass& renderPass) ;
70
64 // Destroy any cached resources. To be called before destroying the VkDevice . 71 // Destroy any cached resources. To be called before destroying the VkDevice .
65 // The assumption is that all queues are idle and all command buffers are fi nished. 72 // The assumption is that all queues are idle and all command buffers are fi nished.
66 // For resource tracing to work properly, this should be called after unrefi ng all other 73 // For resource tracing to work properly, this should be called after unrefi ng all other
67 // resource usages. 74 // resource usages.
68 void destroyResources(); 75 void destroyResources();
69 76
70 // Abandon any cached resources. To be used when the context/VkDevice is los t. 77 // Abandon any cached resources. To be used when the context/VkDevice is los t.
71 // For resource tracing to work properly, this should be called after unrefi ng all other 78 // For resource tracing to work properly, this should be called after unrefi ng all other
72 // resource usages. 79 // resource usages.
73 void abandonResources(); 80 void abandonResources();
74 81
75 private: 82 private:
83 class ProgramCache : public ::SkNoncopyable {
84 public:
85 // typedef GrGpu::DrawArgs DrawArgs;
jvanverth1 2016/03/21 21:16:16 Still need this?
egdaniel 2016/03/22 20:06:14 deleted
86
87 ProgramCache(GrVkGpu* gpu);
88 ~ProgramCache();
89
90 void abandon();
91 void release();
92 GrVkProgram* refProgram(const GrPipeline&,
93 const GrPrimitiveProcessor&,
94 GrPrimitiveType,
95 const GrVkRenderPass& renderPass);
96
97 private:
98 enum {
99 // We may actually have kMaxEntries+1 shaders in the GL context beca use we create a new
jvanverth1 2016/03/21 21:16:16 GL? And are these values good for Vulkan?
egdaniel 2016/03/21 22:23:52 When I previously looked at the cache stats we wer
bsalomon 2016/03/22 14:00:33 At various times in the past this was tuned to imp
egdaniel 2016/03/22 20:06:14 Fixed comment. For now my rough testing shows dece
100 // shader before evicting from the cache.
101 kMaxEntries = 128,
102 kHashBits = 6,
103 };
104
105 struct Entry;
106
107 struct PipelineDescLess;
108
109 void reset();
110
111 // binary search for entry matching desc. returns index into fEntries th at matches desc or ~
112 // of the index of where it should be inserted.
113 int search(const GrVkProgram::PipelineDesc& desc) const;
114
115 // sorted array of all the entries
116 Entry* fEntries[kMaxEntries];
117 // hash table based on lowest kHashBits bits of the program key. Used to avoid binary
118 // searching fEntries.
119 Entry* fHashTable[1 << kHashBits];
120
121 int fCount;
122 unsigned int fCurrLRUStamp;
123 GrVkGpu* fGpu;
124 #ifdef PROGRAM_CACHE_STATS
125 int fTotalRequests;
126 int fCacheMisses;
127 int fHashMisses; // cache hit but hash table mis sed
128 #endif
129 };
130
76 GrVkGpu* fGpu; 131 GrVkGpu* fGpu;
77 132
78 // Central cache for creating pipelines 133 // Central cache for creating pipelines
79 VkPipelineCache fPipelineCache; 134 VkPipelineCache fPipelineCache;
80 135
81 // Array of RenderPasses that only have a single color attachment, optional stencil attachment, 136 // Array of RenderPasses that only have a single color attachment, optional stencil attachment,
82 // optional resolve attachment, and only one subpass 137 // optional resolve attachment, and only one subpass
83 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses; 138 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses;
84 139
85 // Array of CommandBuffers that are currently in flight 140 // Array of CommandBuffers that are currently in flight
86 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; 141 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers;
87 142
88 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple 143 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple
89 // programs 144 // programs
90 SkTDynamicHash<GrVkSampler, uint8_t> fSamplers; 145 SkTDynamicHash<GrVkSampler, uint8_t> fSamplers;
146
147 // Cache of GrVkPrograms
148 ProgramCache* fProgramCache;
91 }; 149 };
92 150
93 #endif 151 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698