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

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

Issue 1836863002: Change VkPipelineStateCahce to use Hash and LRU LList. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update macro name Created 4 years, 8 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/GrVkPipelineStateCache.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
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrVkDescriptorPool.h" 12 #include "GrVkDescriptorPool.h"
13 #include "GrVkPipelineState.h" 13 #include "GrVkPipelineState.h"
14 #include "GrVkResource.h" 14 #include "GrVkResource.h"
15 #include "GrVkUtil.h" 15 #include "GrVkUtil.h"
16 #include "SkTArray.h" 16 #include "SkTArray.h"
17 #include "SkTDynamicHash.h" 17 #include "SkTDynamicHash.h"
18 #include "SkTHash.h"
19 #include "SkTInternalLList.h"
18 20
19 #include "vulkan/vulkan.h" 21 #include "vulkan/vulkan.h"
20 22
21 class GrPipeline; 23 class GrPipeline;
22 class GrPrimitiveProcessor; 24 class GrPrimitiveProcessor;
23 class GrTextureParams; 25 class GrTextureParams;
24 class GrVkCommandBuffer; 26 class GrVkCommandBuffer;
25 class GrVkGpu; 27 class GrVkGpu;
26 class GrVkPipeline; 28 class GrVkPipeline;
27 class GrVkRenderPass; 29 class GrVkRenderPass;
(...skipping 28 matching lines...) Expand all
56 // TODO: Currently this will just create a descriptor pool without holding o nto a ref itself 58 // TODO: Currently this will just create a descriptor pool without holding o nto a ref itself
57 // so we currently do not reuse them. Rquires knowing if another draw is currently using 59 // so we currently do not reuse them. Rquires knowing if another draw is currently using
58 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out 60 // the GrVkDescriptorPool, the ability to reset pools, and the ability to purge pools out
59 // of our cache of GrVkDescriptorPools. 61 // of our cache of GrVkDescriptorPools.
60 GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool(VkDescriptorType ty pe, uint32_t count); 62 GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool(VkDescriptorType ty pe, uint32_t count);
61 63
62 // Finds or creates a compatible GrVkSampler based on the GrTextureParams. 64 // Finds or creates a compatible GrVkSampler based on the GrTextureParams.
63 // The refcount is incremented and a pointer returned. 65 // The refcount is incremented and a pointer returned.
64 GrVkSampler* findOrCreateCompatibleSampler(const GrTextureParams&); 66 GrVkSampler* findOrCreateCompatibleSampler(const GrTextureParams&);
65 67
66 GrVkPipelineState* findOrCreateCompatiblePipelineState(const GrPipeline&, 68 sk_sp<GrVkPipelineState> findOrCreateCompatiblePipelineState(const GrPipelin e&,
67 const GrPrimitiveProc essor&, 69 const GrPrimiti veProcessor&,
68 GrPrimitiveType, 70 GrPrimitiveType ,
69 const GrVkRenderPass& renderPass); 71 const GrVkRende rPass& renderPass);
70 72
71 // Destroy any cached resources. To be called before destroying the VkDevice . 73 // Destroy any cached resources. To be called before destroying the VkDevice .
72 // The assumption is that all queues are idle and all command buffers are fi nished. 74 // The assumption is that all queues are idle and all command buffers are fi nished.
73 // For resource tracing to work properly, this should be called after unrefi ng all other 75 // For resource tracing to work properly, this should be called after unrefi ng all other
74 // resource usages. 76 // resource usages.
75 void destroyResources(); 77 void destroyResources();
76 78
77 // Abandon any cached resources. To be used when the context/VkDevice is los t. 79 // Abandon any cached resources. To be used when the context/VkDevice is los t.
78 // For resource tracing to work properly, this should be called after unrefi ng all other 80 // For resource tracing to work properly, this should be called after unrefi ng all other
79 // resource usages. 81 // resource usages.
80 void abandonResources(); 82 void abandonResources();
81 83
82 private: 84 private:
85
86 #ifdef SK_DEVELOPER
87 #define GR_PIPELINE_STATE_CACHE_STATS
88 #endif
89
83 class PipelineStateCache : public ::SkNoncopyable { 90 class PipelineStateCache : public ::SkNoncopyable {
84 public: 91 public:
85 PipelineStateCache(GrVkGpu* gpu); 92 PipelineStateCache(GrVkGpu* gpu);
86 ~PipelineStateCache(); 93 ~PipelineStateCache();
87 94
88 void abandon(); 95 void abandon();
89 void release(); 96 void release();
90 GrVkPipelineState* refPipelineState(const GrPipeline&, 97 sk_sp<GrVkPipelineState> refPipelineState(const GrPipeline&,
91 const GrPrimitiveProcessor&, 98 const GrPrimitiveProcessor&,
92 GrPrimitiveType, 99 GrPrimitiveType,
93 const GrVkRenderPass& renderPass); 100 const GrVkRenderPass& renderPa ss);
94 101
95 private: 102 private:
96 enum { 103 enum {
97 // We may actually have kMaxEntries+1 PipelineStates in context beca use we create a new 104 // We may actually have kMaxEntries+1 PipelineStates in context beca use we create a new
98 // PipelineState before evicting from the cache. 105 // PipelineState before evicting from the cache.
99 kMaxEntries = 128, 106 kMaxEntries = 128,
100 kHashBits = 6,
101 }; 107 };
102 108
103 struct Entry; 109 struct Entry;
104 110
105 struct PipelineDescLess;
106
107 void reset(); 111 void reset();
108 112
109 // binary search for entry matching desc. returns index into fEntries th at matches desc or ~ 113 int fCount;
110 // of the index of where it should be inserted. 114 SkTHashTable<Entry*, const GrVkPipelineState::Desc&, Entry> fHashTable;
111 int search(const GrVkPipelineState::Desc& desc) const; 115 SkTInternalLList<Entry> fLRUList;
112 116
113 // sorted array of all the entries 117 GrVkGpu* fGpu;
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 118
119 int fCount; 119 #ifdef GR_PIPELINE_STATE_CACHE_STATS
120 unsigned int fCurrLRUStamp;
121 GrVkGpu* fGpu;
122 #ifdef PIPELINE_STATE_CACHE_STATS
123 int fTotalRequests; 120 int fTotalRequests;
124 int fCacheMisses; 121 int fCacheMisses;
125 int fHashMisses; // cache hit but hash table mis sed
126 #endif 122 #endif
127 }; 123 };
128 124
129 GrVkGpu* fGpu; 125 GrVkGpu* fGpu;
130 126
131 // Central cache for creating pipelines 127 // Central cache for creating pipelines
132 VkPipelineCache fPipelineCache; 128 VkPipelineCache fPipelineCache;
133 129
134 // Array of RenderPasses that only have a single color attachment, optional stencil attachment, 130 // Array of RenderPasses that only have a single color attachment, optional stencil attachment,
135 // optional resolve attachment, and only one subpass 131 // optional resolve attachment, and only one subpass
136 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses; 132 SkSTArray<4, GrVkRenderPass*> fSimpleRenderPasses;
137 133
138 // Array of CommandBuffers that are currently in flight 134 // Array of CommandBuffers that are currently in flight
139 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers; 135 SkSTArray<4, GrVkCommandBuffer*> fActiveCommandBuffers;
140 136
141 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple 137 // Stores GrVkSampler objects that we've already created so we can reuse the m across multiple
142 // GrVkPipelineStates 138 // GrVkPipelineStates
143 SkTDynamicHash<GrVkSampler, uint8_t> fSamplers; 139 SkTDynamicHash<GrVkSampler, uint8_t> fSamplers;
144 140
145 // Cache of GrVkPipelineStates 141 // Cache of GrVkPipelineStates
146 PipelineStateCache* fPipelineStateCache; 142 PipelineStateCache* fPipelineStateCache;
147 }; 143 };
148 144
149 #endif 145 #endif
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkPipelineStateCache.cpp ('k') | src/gpu/vk/GrVkResourceProvider.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698