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

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

Issue 1977403002: Refactor creation of GrVkRenderPasses to make them move general (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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 "GrGpu.h"
12 #include "GrResourceHandle.h"
12 #include "GrVkDescriptorPool.h" 13 #include "GrVkDescriptorPool.h"
13 #include "GrVkPipelineState.h" 14 #include "GrVkPipelineState.h"
14 #include "GrVkResource.h" 15 #include "GrVkResource.h"
15 #include "GrVkUtil.h" 16 #include "GrVkUtil.h"
16 #include "SkTArray.h" 17 #include "SkTArray.h"
17 #include "SkTDynamicHash.h" 18 #include "SkTDynamicHash.h"
18 #include "SkTHash.h" 19 #include "SkTHash.h"
19 #include "SkTInternalLList.h" 20 #include "SkTInternalLList.h"
20 21
21 #include "vk/GrVkDefines.h" 22 #include "vk/GrVkDefines.h"
(...skipping 17 matching lines...) Expand all
39 void init(); 40 void init();
40 41
41 GrVkPipeline* createPipeline(const GrPipeline& pipeline, 42 GrVkPipeline* createPipeline(const GrPipeline& pipeline,
42 const GrPrimitiveProcessor& primProc, 43 const GrPrimitiveProcessor& primProc,
43 VkPipelineShaderStageCreateInfo* shaderStageInf o, 44 VkPipelineShaderStageCreateInfo* shaderStageInf o,
44 int shaderStageCount, 45 int shaderStageCount,
45 GrPrimitiveType primitiveType, 46 GrPrimitiveType primitiveType,
46 const GrVkRenderPass& renderPass, 47 const GrVkRenderPass& renderPass,
47 VkPipelineLayout layout); 48 VkPipelineLayout layout);
48 49
50 GR_DEFINE_RESOURCE_HANDLE_CLASS(CompatibleRPHandle);
51
49 // Finds or creates a simple render pass that matches the target, increments the refcount, 52 // Finds or creates a simple render pass that matches the target, increments the refcount,
50 // and returns. 53 // and returns. The caller can optionally pass in a pointer to a CompatibleR PHandle. If this is
51 const GrVkRenderPass* findOrCreateCompatibleRenderPass(const GrVkRenderTarge t& target); 54 // non null it will be set to a handle that can be used in the furutre to qu ickly return a
55 // compatible GrVkRenderPasses without the need inspecting a GrVkRenderTarge t.
56 const GrVkRenderPass* findCompatibleRenderPass(const GrVkRenderTarget& targe t,
57 CompatibleRPHandle* compatibl eHandle = nullptr);
58 // The CompatibleRPHandle must be a valid handle previously set by a call to
59 // findCompatibleRenderPass(GrVkRenderTarget&, CompatibleRPHandle*).
60 const GrVkRenderPass* findCompatibleRenderPass(const CompatibleRPHandle& com patibleHandle);
61
62 #if 0
63 // TODO:
64 const GrVkRenderPass* findRenderPass(const GrVkRenderTarget& target,
65 VkAttachmentLoadOp colorLoad,
66 VkAttachmentStoreOp colorStore,
67 VkAttachmentLoadOp stencilLoad,
68 VkAttachmentStoreOp stencilStore,
69 CompatibleRPHandle* compatibleHandle = nullptr);
70
71 const GrVkRenderPass* findRenderPass(const CompatibleRPHandle& compatibleHan dle,
72 VkAttachmentLoadOp colorLoad,
73 VkAttachmentStoreOp colorStore,
74 VkAttachmentLoadOp stencilLoad,
75 VkAttachmentStoreOp stencilStore);
76 #endif
52 77
53 GrVkCommandBuffer* createCommandBuffer(); 78 GrVkCommandBuffer* createCommandBuffer();
54 void checkCommandBuffers(); 79 void checkCommandBuffers();
55 80
56 // Finds or creates a compatible GrVkDescriptorPool for the requested type a nd count. 81 // Finds or creates a compatible GrVkDescriptorPool for the requested type a nd count.
57 // The refcount is incremented and a pointer returned. 82 // The refcount is incremented and a pointer returned.
58 // TODO: Currently this will just create a descriptor pool without holding o nto a ref itself 83 // TODO: Currently this will just create a descriptor pool without holding o nto a ref itself
59 // so we currently do not reuse them. Rquires knowing if another draw is currently using 84 // so we currently do not reuse them. Rquires knowing if another draw is currently using
60 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out 85 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out
61 // of our cache of GrVkDescriptorPools. 86 // of our cache of GrVkDescriptorPools.
(...skipping 25 matching lines...) Expand all
87 // For resource tracing to work properly, this should be called after unrefi ng all other 112 // For resource tracing to work properly, this should be called after unrefi ng all other
88 // resource usages. 113 // resource usages.
89 void destroyResources(); 114 void destroyResources();
90 115
91 // Abandon any cached resources. To be used when the context/VkDevice is los t. 116 // Abandon any cached resources. To be used when the context/VkDevice is los t.
92 // For resource tracing to work properly, this should be called after unrefi ng all other 117 // For resource tracing to work properly, this should be called after unrefi ng all other
93 // resource usages. 118 // resource usages.
94 void abandonResources(); 119 void abandonResources();
95 120
96 private: 121 private:
97
98 #ifdef SK_DEBUG 122 #ifdef SK_DEBUG
99 #define GR_PIPELINE_STATE_CACHE_STATS 123 #define GR_PIPELINE_STATE_CACHE_STATS
100 #endif 124 #endif
101 125
102 class PipelineStateCache : public ::SkNoncopyable { 126 class PipelineStateCache : public ::SkNoncopyable {
103 public: 127 public:
104 PipelineStateCache(GrVkGpu* gpu); 128 PipelineStateCache(GrVkGpu* gpu);
105 ~PipelineStateCache(); 129 ~PipelineStateCache();
106 130
107 void abandon(); 131 void abandon();
(...skipping 19 matching lines...) Expand all
127 SkTInternalLList<Entry> fLRUList; 151 SkTInternalLList<Entry> fLRUList;
128 152
129 GrVkGpu* fGpu; 153 GrVkGpu* fGpu;
130 154
131 #ifdef GR_PIPELINE_STATE_CACHE_STATS 155 #ifdef GR_PIPELINE_STATE_CACHE_STATS
132 int fTotalRequests; 156 int fTotalRequests;
133 int fCacheMisses; 157 int fCacheMisses;
134 #endif 158 #endif
135 }; 159 };
136 160
161
162 class CompatibleRenderPassSet {
163 public:
164 // This will always construct the basic load store render pass so that t here is at least
165 // one compatible VkRenderPass that can be used with this set.
166 CompatibleRenderPassSet(const GrVkGpu* gpu, const GrVkRenderTarget& targ et);
167
168 bool isCompatible(const GrVkRenderTarget& target) const;
169
170 GrVkRenderPass* getCompatibleRenderPass() const {
171 SkASSERT(fRenderPasses[kLoadStore_LoadStoreOp])
172 return fRenderPasses[kLoadStore_LoadStoreOp];
173 }
174
175 void releaseResources(const GrVkGpu* gpu);
176 void abandonResources();
177
178 private:
179 enum LoadStoreOp {
180 kLoadStore_LoadStoreOp,
181 kDCStore_LoadStoreOp,
jvanverth1 2016/05/18 20:42:21 It would be clearer to write out DontCare or Disca
egdaniel 2016/06/02 17:26:25 Removed enum.
182 kClearStore_LoadStoreOp,
183 kLoadDC_LoadStoreOp,
184 kDCDC_LoadStoreOp,
185 kClearDC_LoadStoreOp,
186
187 kLast_LoadStoreOp = kClearDC_LoadStoreOp
188 };
189 static const int kLoadStoreOpCount = kLast_LoadStoreOp + 1;
190
191 GrVkRenderPass* fRenderPasses[kLoadStoreOpCount];
192 };
193
137 // Initialiaze the vkDescriptorSetLayout used for allocating new uniform buf fer descritpor sets. 194 // Initialiaze the vkDescriptorSetLayout used for allocating new uniform buf fer descritpor sets.
138 void initUniformDescObjects(); 195 void initUniformDescObjects();
139 196
140 GrVkGpu* fGpu; 197 GrVkGpu* fGpu;
141 198
142 // Central cache for creating pipelines 199 // Central cache for creating pipelines
143 VkPipelineCache fPipelineCache; 200 VkPipelineCache fPipelineCache;
144 201
145 // Array of RenderPasses that only have a single color attachment, optional stencil attachment, 202 SkSTArray<4, CompatibleRenderPassSet> fRenderPassArray;
146 // optional resolve attachment, and only one subpass
147 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses;
148 203
149 // Array of CommandBuffers that are currently in flight 204 // Array of CommandBuffers that are currently in flight
150 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; 205 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers;
151 206
152 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple 207 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple
153 // GrVkPipelineStates 208 // GrVkPipelineStates
154 SkTDynamicHash<GrVkSampler, uint16_t> fSamplers; 209 SkTDynamicHash<GrVkSampler, uint16_t> fSamplers;
155 210
156 // Cache of GrVkPipelineStates 211 // Cache of GrVkPipelineStates
157 PipelineStateCache* fPipelineStateCache; 212 PipelineStateCache* fPipelineStateCache;
158 213
159 // Current pool to allocate uniform descriptor sets from 214 // Current pool to allocate uniform descriptor sets from
160 const GrVkDescriptorPool* fUniformDescPool; 215 const GrVkDescriptorPool* fUniformDescPool;
161 VkDescriptorSetLayout fUniformDescLayout; 216 VkDescriptorSetLayout fUniformDescLayout;
162 //Curent number of uniform descriptors allocated from the pool 217 //Curent number of uniform descriptors allocated from the pool
163 int fCurrentUniformDescCount; 218 int fCurrentUniformDescCount;
164 int fCurrMaxUniDescriptors; 219 int fCurrMaxUniDescriptors;
165 220
166 enum { 221 enum {
167 kMaxUniformDescriptors = 1024, 222 kMaxUniformDescriptors = 1024,
168 kNumUniformDescPerSet = 2, 223 kNumUniformDescPerSet = 2,
169 kStartNumUniformDescriptors = 16, // must be less than kMaxUniformDescri ptors 224 kStartNumUniformDescriptors = 16, // must be less than kMaxUniformDescri ptors
170 }; 225 };
171 }; 226 };
172 227
173 #endif 228 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698