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

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

Issue 2172873003: Reuse sampler descriptor set allocations in Vulkan (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits Created 4 years, 4 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/GrVkPipelineStateBuilder.cpp ('k') | src/gpu/vk/GrVkResourceProvider.cpp » ('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 #ifndef GrVkResourceProvider_DEFINED 8 #ifndef GrVkResourceProvider_DEFINED
9 #define GrVkResourceProvider_DEFINED 9 #define GrVkResourceProvider_DEFINED
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 class GrPipeline; 26 class GrPipeline;
27 class GrPrimitiveProcessor; 27 class GrPrimitiveProcessor;
28 class GrTextureParams; 28 class GrTextureParams;
29 class GrVkGpu; 29 class GrVkGpu;
30 class GrVkPipeline; 30 class GrVkPipeline;
31 class GrVkPrimaryCommandBuffer; 31 class GrVkPrimaryCommandBuffer;
32 class GrVkRenderTarget; 32 class GrVkRenderTarget;
33 class GrVkSampler; 33 class GrVkSampler;
34 class GrVkSecondaryCommandBuffer; 34 class GrVkSecondaryCommandBuffer;
35 class GrVkUniformHandler;
35 36
36 class GrVkResourceProvider { 37 class GrVkResourceProvider {
37 public: 38 public:
38 GrVkResourceProvider(GrVkGpu* gpu); 39 GrVkResourceProvider(GrVkGpu* gpu);
39 ~GrVkResourceProvider(); 40 ~GrVkResourceProvider();
40 41
41 // Set up any initial vk objects 42 // Set up any initial vk objects
42 void init(); 43 void init();
43 44
44 GrVkPipeline* createPipeline(const GrPipeline& pipeline, 45 GrVkPipeline* createPipeline(const GrPipeline& pipeline,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 // Finds or creates a compatible GrVkSampler based on the GrTextureParams. 96 // Finds or creates a compatible GrVkSampler based on the GrTextureParams.
96 // The refcount is incremented and a pointer returned. 97 // The refcount is incremented and a pointer returned.
97 GrVkSampler* findOrCreateCompatibleSampler(const GrTextureParams&, uint32_t mipLevels); 98 GrVkSampler* findOrCreateCompatibleSampler(const GrTextureParams&, uint32_t mipLevels);
98 99
99 sk_sp<GrVkPipelineState> findOrCreateCompatiblePipelineState(const GrPipelin e&, 100 sk_sp<GrVkPipelineState> findOrCreateCompatiblePipelineState(const GrPipelin e&,
100 const GrPrimiti veProcessor&, 101 const GrPrimiti veProcessor&,
101 GrPrimitiveType , 102 GrPrimitiveType ,
102 const GrVkRende rPass& renderPass); 103 const GrVkRende rPass& renderPass);
103 104
104 // Returns a handle which the GrVkResourceProvider uses to know which compat ible 105 void getSamplerDescriptorSetHandle(const GrVkUniformHandler&,
105 // GrVkDescriptorSetManager to use when getting or recycling a GrVkDescripto rSet. Passing in a 106 GrVkDescriptorSetManager::Handle* handle) ;
106 // value of 0 for numSamplers is used to signal this is for the uniform desc riptor set. 107
107 void getDescSetHandle(uint32_t numSamplers, VkDescriptorSetLayout layout, 108 // Returns the compatible VkDescriptorSetLayout to use for uniform buffers. The caller does not
108 GrVkDescriptorSetManager::Handle* handle); 109 // own the VkDescriptorSetLayout and thus should not delete it. This functio n should be used
110 // when the caller needs the layout to create a VkPipelineLayout.
111 VkDescriptorSetLayout getUniformDSLayout() const;
112
113 // Returns the compatible VkDescriptorSetLayout to use for a specific sample r handle. The caller
114 // does not own the VkDescriptorSetLayout and thus should not delete it. Thi s function should be
115 // used when the caller needs the layout to create a VkPipelineLayout.
116 VkDescriptorSetLayout getSamplerDSLayout(const GrVkDescriptorSetManager::Han dle&) const;
109 117
110 // Returns a GrVkDescriptorSet that can be used for uniform buffers. The GrV kDescriptorSet 118 // Returns a GrVkDescriptorSet that can be used for uniform buffers. The GrV kDescriptorSet
111 // is already reffed for the caller. 119 // is already reffed for the caller.
112 const GrVkDescriptorSet* getUniformDescriptorSet(); 120 const GrVkDescriptorSet* getUniformDescriptorSet();
113 121
114 // Returns a GrVkDescriptorSet that can be used for sampler descriptors that are compatible with 122 // Returns a GrVkDescriptorSet that can be used for sampler descriptors that are compatible with
115 // the GrVkDescriptorSetManager::Handle passed int.. The GrVkDescriptorSet i s already reffed for 123 // the GrVkDescriptorSetManager::Handle passed in. The GrVkDescriptorSet is already reffed for
116 // the caller. 124 // the caller.
117 // TODO: Move samplers in GrVkPipelineState to use the GrVkResourceProvider to allocate
118 // descriptor sets from.
119 const GrVkDescriptorSet* getSamplerDescriptorSet(const GrVkDescriptorSetMana ger::Handle&); 125 const GrVkDescriptorSet* getSamplerDescriptorSet(const GrVkDescriptorSetMana ger::Handle&);
120 126
121 // Returns the compatible VkDescriptorSetLayout to use for uniform buffers. The caller does not
122 // own the VkDescriptorSetLayout and thus should not delete it. This functio n should be used
123 // when the caller needs the layout to create a VkPipelineLayout.
124 VkDescriptorSetLayout getUniDSLayout() const { return fUniformDescLayout; }
125 127
126 // Signals that the descriptor set passed it, which is compatible with the p assed in handle, 128 // Signals that the descriptor set passed it, which is compatible with the p assed in handle,
127 // can be reused by the next allocation request. 129 // can be reused by the next allocation request.
128 void recycleDescriptorSet(const GrVkDescriptorSet* descSet, 130 void recycleDescriptorSet(const GrVkDescriptorSet* descSet,
129 const GrVkDescriptorSetManager::Handle&); 131 const GrVkDescriptorSetManager::Handle&);
130 132
131 // Creates or finds free uniform buffer resources of size GrVkUniformBuffer: :kStandardSize. 133 // Creates or finds free uniform buffer resources of size GrVkUniformBuffer: :kStandardSize.
132 // Anything larger will need to be created and released by the client. 134 // Anything larger will need to be created and released by the client.
133 const GrVkResource* findOrCreateStandardUniformBufferResource(); 135 const GrVkResource* findOrCreateStandardUniformBufferResource();
134 136
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 const GrVkRenderPass::LoadStoreOps& stenci lOps); 211 const GrVkRenderPass::LoadStoreOps& stenci lOps);
210 212
211 void releaseResources(const GrVkGpu* gpu); 213 void releaseResources(const GrVkGpu* gpu);
212 void abandonResources(); 214 void abandonResources();
213 215
214 private: 216 private:
215 SkSTArray<4, GrVkRenderPass*> fRenderPasses; 217 SkSTArray<4, GrVkRenderPass*> fRenderPasses;
216 int fLastReturnedIndex; 218 int fLastReturnedIndex;
217 }; 219 };
218 220
219 // Initialiaze the vkDescriptorSetLayout used for allocating new uniform buf fer descritpor sets.
220 void initUniformDescObjects();
221
222 GrVkGpu* fGpu; 221 GrVkGpu* fGpu;
223 222
224 // Central cache for creating pipelines 223 // Central cache for creating pipelines
225 VkPipelineCache fPipelineCache; 224 VkPipelineCache fPipelineCache;
226 225
227 SkSTArray<4, CompatibleRenderPassSet> fRenderPassArray; 226 SkSTArray<4, CompatibleRenderPassSet> fRenderPassArray;
228 227
229 // Array of PrimaryCommandBuffers that are currently in flight 228 // Array of PrimaryCommandBuffers that are currently in flight
230 SkSTArray<4, GrVkPrimaryCommandBuffer*> fActiveCommandBuffers; 229 SkSTArray<4, GrVkPrimaryCommandBuffer*, true> fActiveCommandBuffers;
231 // Array of available primary command buffers that are not in flight 230 // Array of available primary command buffers that are not in flight
232 SkSTArray<4, GrVkPrimaryCommandBuffer*> fAvailableCommandBuffers; 231 SkSTArray<4, GrVkPrimaryCommandBuffer*, true> fAvailableCommandBuffers;
233 232
234 // Array of available secondary command buffers 233 // Array of available secondary command buffers
235 SkSTArray<16, GrVkSecondaryCommandBuffer*> fAvailableSecondaryCommandBuffers ; 234 SkSTArray<16, GrVkSecondaryCommandBuffer*, true> fAvailableSecondaryCommandB uffers;
236 235
237 // Array of available uniform buffer resources 236 // Array of available uniform buffer resources
238 SkSTArray<16, const GrVkResource*> fAvailableUniformBufferResources; 237 SkSTArray<16, const GrVkResource*, true> fAvailableUniformBufferResources;
239 238
240 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple 239 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple
241 // GrVkPipelineStates 240 // GrVkPipelineStates
242 SkTDynamicHash<GrVkSampler, uint16_t> fSamplers; 241 SkTDynamicHash<GrVkSampler, uint16_t> fSamplers;
243 242
244 // Cache of GrVkPipelineStates 243 // Cache of GrVkPipelineStates
245 PipelineStateCache* fPipelineStateCache; 244 PipelineStateCache* fPipelineStateCache;
246 245
247 SkSTArray<4, GrVkDescriptorSetManager> fDescriptorSetManagers; 246 SkSTArray<4, GrVkDescriptorSetManager, true> fDescriptorSetManagers;
248 247
249 GrVkDescriptorSetManager::Handle fUniformDSHandle; 248 GrVkDescriptorSetManager::Handle fUniformDSHandle;
250
251 // Current pool to allocate uniform descriptor sets from
252 VkDescriptorSetLayout fUniformDescLayout;
253 //Curent number of uniform descriptors allocated from the pool
254 int fCurrentUniformDescCount;
255 int fCurrMaxUniDescriptors;
256
257 enum {
258 kMaxUniformDescriptors = 1024,
259 kNumUniformDescPerSet = 2,
260 kStartNumUniformDescriptors = 16, // must be less than kMaxUniformDescri ptors
261 };
262 }; 249 };
263 250
264 #endif 251 #endif
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkPipelineStateBuilder.cpp ('k') | src/gpu/vk/GrVkResourceProvider.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698