OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 (all atta
chments load and |
| 165 // store their data) so that there is at least one compatible VkRenderPa
ss that can be used |
| 166 // with this set. |
| 167 CompatibleRenderPassSet(const GrVkGpu* gpu, const GrVkRenderTarget& targ
et); |
| 168 |
| 169 bool isCompatible(const GrVkRenderTarget& target) const; |
| 170 |
| 171 GrVkRenderPass* getCompatibleRenderPass() const { |
| 172 // The first GrVkRenderpass should always exist since we create the
basic load store |
| 173 // render pass on create |
| 174 SkASSERT(fRenderPasses[0]); |
| 175 return fRenderPasses[0]; |
| 176 } |
| 177 |
| 178 void releaseResources(const GrVkGpu* gpu); |
| 179 void abandonResources(); |
| 180 |
| 181 private: |
| 182 SkSTArray<4, GrVkRenderPass*> fRenderPasses; |
| 183 int fLastReturnedIndex; |
| 184 }; |
| 185 |
137 // Initialiaze the vkDescriptorSetLayout used for allocating new uniform buf
fer descritpor sets. | 186 // Initialiaze the vkDescriptorSetLayout used for allocating new uniform buf
fer descritpor sets. |
138 void initUniformDescObjects(); | 187 void initUniformDescObjects(); |
139 | 188 |
140 GrVkGpu* fGpu; | 189 GrVkGpu* fGpu; |
141 | 190 |
142 // Central cache for creating pipelines | 191 // Central cache for creating pipelines |
143 VkPipelineCache fPipelineCache; | 192 VkPipelineCache fPipelineCache; |
144 | 193 |
145 // Array of RenderPasses that only have a single color attachment, optional
stencil attachment, | 194 SkSTArray<4, CompatibleRenderPassSet> fRenderPassArray; |
146 // optional resolve attachment, and only one subpass | |
147 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses; | |
148 | 195 |
149 // Array of CommandBuffers that are currently in flight | 196 // Array of CommandBuffers that are currently in flight |
150 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; | 197 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; |
151 | 198 |
152 // Stores GrVkSampler objects that we've already created so we can reuse the
m across multiple | 199 // Stores GrVkSampler objects that we've already created so we can reuse the
m across multiple |
153 // GrVkPipelineStates | 200 // GrVkPipelineStates |
154 SkTDynamicHash<GrVkSampler, uint16_t> fSamplers; | 201 SkTDynamicHash<GrVkSampler, uint16_t> fSamplers; |
155 | 202 |
156 // Cache of GrVkPipelineStates | 203 // Cache of GrVkPipelineStates |
157 PipelineStateCache* fPipelineStateCache; | 204 PipelineStateCache* fPipelineStateCache; |
158 | 205 |
159 // Current pool to allocate uniform descriptor sets from | 206 // Current pool to allocate uniform descriptor sets from |
160 const GrVkDescriptorPool* fUniformDescPool; | 207 const GrVkDescriptorPool* fUniformDescPool; |
161 VkDescriptorSetLayout fUniformDescLayout; | 208 VkDescriptorSetLayout fUniformDescLayout; |
162 //Curent number of uniform descriptors allocated from the pool | 209 //Curent number of uniform descriptors allocated from the pool |
163 int fCurrentUniformDescCount; | 210 int fCurrentUniformDescCount; |
164 int fCurrMaxUniDescriptors; | 211 int fCurrMaxUniDescriptors; |
165 | 212 |
166 enum { | 213 enum { |
167 kMaxUniformDescriptors = 1024, | 214 kMaxUniformDescriptors = 1024, |
168 kNumUniformDescPerSet = 2, | 215 kNumUniformDescPerSet = 2, |
169 kStartNumUniformDescriptors = 16, // must be less than kMaxUniformDescri
ptors | 216 kStartNumUniformDescriptors = 16, // must be less than kMaxUniformDescri
ptors |
170 }; | 217 }; |
171 }; | 218 }; |
172 | 219 |
173 #endif | 220 #endif |
OLD | NEW |