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 "GrVkDescriptorPool.h" | 12 #include "GrVkDescriptorPool.h" |
13 #include "GrVkPipelineState.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 Loading... | |
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 GrVkPipelineState* findOrCreateCompatiblePipelineState(const GrPipeline&, | |
67 const GrPrimitiveProc essor&, | |
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 PipelineStateCache : public ::SkNoncopyable { | |
84 public: | |
85 PipelineStateCache(GrVkGpu* gpu); | |
86 ~PipelineStateCache(); | |
87 | |
88 void abandon(); | |
89 void release(); | |
90 GrVkPipelineState* refPipelineState(const GrPipeline&, | |
91 const GrPrimitiveProcessor&, | |
92 GrPrimitiveType, | |
93 const GrVkRenderPass& renderPass); | |
94 | |
95 private: | |
96 enum { | |
97 // We may actually have kMaxEntries+1 PipelineStates in context beca use we create a new | |
98 // PipelineState before evicting from the cache. | |
99 kMaxEntries = 128, | |
100 kHashBits = 6, | |
101 }; | |
102 | |
103 struct Entry; | |
104 | |
105 struct PipelineDescLess; | |
106 | |
107 void reset(); | |
108 | |
109 // binary search for entry matching desc. returns index into fEntries th at matches desc or ~ | |
110 // of the index of where it should be inserted. | |
111 int search(const GrVkPipelineState::Desc& desc) const; | |
112 | |
113 // sorted array of all the entries | |
114 Entry* fEntries[kMaxEntries]; | |
115 // hash table based on lowest kHashBits bits of the pipeline state key. Used to avoid binary | |
116 // searching fEntries. | |
117 Entry* fHashTable[1 << kHashBits]; | |
118 | |
119 int fCount; | |
120 unsigned int fCurrLRUStamp; | |
121 GrVkGpu* fGpu; | |
122 #ifdef PIPELINE_STATE__CACHE_STATS | |
123 int fTotalRequests; | |
124 int fCacheMisses; | |
125 int fHashMisses; // cache hit but hash table mis sed | |
126 #endif | |
127 }; | |
128 | |
76 GrVkGpu* fGpu; | 129 GrVkGpu* fGpu; |
77 | 130 |
78 // Central cache for creating pipelines | 131 // Central cache for creating pipelines |
79 VkPipelineCache fPipelineCache; | 132 VkPipelineCache fPipelineCache; |
80 | 133 |
81 // Array of RenderPasses that only have a single color attachment, optional stencil attachment, | 134 // Array of RenderPasses that only have a single color attachment, optional stencil attachment, |
82 // optional resolve attachment, and only one subpass | 135 // optional resolve attachment, and only one subpass |
83 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses; | 136 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses; |
bsalomon
2016/03/23 15:04:37
Can you either leave all the members staggered or
egdaniel
2016/03/23 19:12:07
Done.
| |
84 | 137 |
85 // Array of CommandBuffers that are currently in flight | 138 // Array of CommandBuffers that are currently in flight |
86 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; | 139 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; |
87 | 140 |
88 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple | 141 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple |
89 // programs | 142 // GrVkPipelineStates |
90 SkTDynamicHash<GrVkSampler, uint8_t> fSamplers; | 143 SkTDynamicHash<GrVkSampler, uint8_t> fSamplers; |
144 | |
145 // Cache of GrVkPipelineStates | |
146 PipelineStateCache* fPipelineStateCache; | |
91 }; | 147 }; |
92 | 148 |
93 #endif | 149 #endif |
OLD | NEW |