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 #include "GrVkResourceProvider.h" | 8 #include "GrVkResourceProvider.h" |
9 | 9 |
10 #include "GrTextureParams.h" | 10 #include "GrTextureParams.h" |
11 #include "GrVkCommandBuffer.h" | 11 #include "GrVkCommandBuffer.h" |
12 #include "GrVkPipeline.h" | 12 #include "GrVkPipeline.h" |
13 #include "GrVkRenderPass.h" | 13 #include "GrVkRenderPass.h" |
14 #include "GrVkSampler.h" | 14 #include "GrVkSampler.h" |
15 #include "GrVkUtil.h" | 15 #include "GrVkUtil.h" |
16 | 16 |
17 #ifdef SK_TRACE_VK_RESOURCES | 17 #ifdef SK_TRACE_VK_RESOURCES |
18 SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace; | 18 SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace; |
19 SkRandom GrVkResource::fRandom; | 19 SkRandom GrVkResource::fRandom; |
20 #endif | 20 #endif |
21 | 21 |
22 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) : fGpu(gpu) | 22 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) : fGpu(gpu) |
23 , fPipelineCache(VK_NUL
L_HANDLE) { | 23 , fPipelineCache(VK_NUL
L_HANDLE) { |
| 24 fPipelineStateCache = new PipelineStateCache(gpu); |
24 } | 25 } |
25 | 26 |
26 GrVkResourceProvider::~GrVkResourceProvider() { | 27 GrVkResourceProvider::~GrVkResourceProvider() { |
27 SkASSERT(0 == fSimpleRenderPasses.count()); | 28 SkASSERT(0 == fSimpleRenderPasses.count()); |
28 SkASSERT(VK_NULL_HANDLE == fPipelineCache); | 29 SkASSERT(VK_NULL_HANDLE == fPipelineCache); |
| 30 delete fPipelineStateCache; |
29 } | 31 } |
30 | 32 |
31 void GrVkResourceProvider::init() { | 33 void GrVkResourceProvider::init() { |
32 VkPipelineCacheCreateInfo createInfo; | 34 VkPipelineCacheCreateInfo createInfo; |
33 memset(&createInfo, 0, sizeof(VkPipelineCacheCreateInfo)); | 35 memset(&createInfo, 0, sizeof(VkPipelineCacheCreateInfo)); |
34 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; | 36 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
35 createInfo.pNext = nullptr; | 37 createInfo.pNext = nullptr; |
36 createInfo.flags = 0; | 38 createInfo.flags = 0; |
37 createInfo.initialDataSize = 0; | 39 createInfo.initialDataSize = 0; |
38 createInfo.pInitialData = nullptr; | 40 createInfo.pInitialData = nullptr; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params)); | 89 GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params)); |
88 if (!sampler) { | 90 if (!sampler) { |
89 sampler = GrVkSampler::Create(fGpu, params); | 91 sampler = GrVkSampler::Create(fGpu, params); |
90 fSamplers.add(sampler); | 92 fSamplers.add(sampler); |
91 } | 93 } |
92 SkASSERT(sampler); | 94 SkASSERT(sampler); |
93 sampler->ref(); | 95 sampler->ref(); |
94 return sampler; | 96 return sampler; |
95 } | 97 } |
96 | 98 |
| 99 GrVkPipelineState* GrVkResourceProvider::findOrCreateCompatiblePipelineState( |
| 100 const GrPipelin
e& pipeline, |
| 101 const GrPrimiti
veProcessor& proc, |
| 102 GrPrimitiveType
primitiveType, |
| 103 const GrVkRende
rPass& renderPass) { |
| 104 return fPipelineStateCache->refPipelineState(pipeline, proc, primitiveType,
renderPass); |
| 105 } |
| 106 |
97 GrVkCommandBuffer* GrVkResourceProvider::createCommandBuffer() { | 107 GrVkCommandBuffer* GrVkResourceProvider::createCommandBuffer() { |
98 GrVkCommandBuffer* cmdBuffer = GrVkCommandBuffer::Create(fGpu, fGpu->cmdPool
()); | 108 GrVkCommandBuffer* cmdBuffer = GrVkCommandBuffer::Create(fGpu, fGpu->cmdPool
()); |
99 fActiveCommandBuffers.push_back(cmdBuffer); | 109 fActiveCommandBuffers.push_back(cmdBuffer); |
100 cmdBuffer->ref(); | 110 cmdBuffer->ref(); |
101 return cmdBuffer; | 111 return cmdBuffer; |
102 } | 112 } |
103 | 113 |
104 void GrVkResourceProvider::checkCommandBuffers() { | 114 void GrVkResourceProvider::checkCommandBuffers() { |
105 for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) { | 115 for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) { |
106 if (fActiveCommandBuffers[i]->finished(fGpu)) { | 116 if (fActiveCommandBuffers[i]->finished(fGpu)) { |
(...skipping 18 matching lines...) Expand all Loading... |
125 } | 135 } |
126 fSimpleRenderPasses.reset(); | 136 fSimpleRenderPasses.reset(); |
127 | 137 |
128 // Iterate through all store GrVkSamplers and unref them before resetting th
e hash. | 138 // Iterate through all store GrVkSamplers and unref them before resetting th
e hash. |
129 SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers); | 139 SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers); |
130 for (; !iter.done(); ++iter) { | 140 for (; !iter.done(); ++iter) { |
131 (*iter).unref(fGpu); | 141 (*iter).unref(fGpu); |
132 } | 142 } |
133 fSamplers.reset(); | 143 fSamplers.reset(); |
134 | 144 |
| 145 fPipelineStateCache->release(); |
| 146 |
135 #ifdef SK_TRACE_VK_RESOURCES | 147 #ifdef SK_TRACE_VK_RESOURCES |
136 SkASSERT(0 == GrVkResource::fTrace.count()); | 148 SkASSERT(0 == GrVkResource::fTrace.count()); |
137 #endif | 149 #endif |
138 | 150 |
139 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli
neCache, nullptr)); | 151 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli
neCache, nullptr)); |
140 fPipelineCache = VK_NULL_HANDLE; | 152 fPipelineCache = VK_NULL_HANDLE; |
141 } | 153 } |
142 | 154 |
143 void GrVkResourceProvider::abandonResources() { | 155 void GrVkResourceProvider::abandonResources() { |
144 // release our current command buffers | 156 // release our current command buffers |
145 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 157 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
146 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 158 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
147 fActiveCommandBuffers[i]->unrefAndAbandon(); | 159 fActiveCommandBuffers[i]->unrefAndAbandon(); |
148 } | 160 } |
149 fActiveCommandBuffers.reset(); | 161 fActiveCommandBuffers.reset(); |
150 | 162 |
151 for (int i = 0; i < fSimpleRenderPasses.count(); ++i) { | 163 for (int i = 0; i < fSimpleRenderPasses.count(); ++i) { |
152 fSimpleRenderPasses[i]->unrefAndAbandon(); | 164 fSimpleRenderPasses[i]->unrefAndAbandon(); |
153 } | 165 } |
154 fSimpleRenderPasses.reset(); | 166 fSimpleRenderPasses.reset(); |
155 | 167 |
156 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re
setting the hash. | 168 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re
setting the hash. |
157 SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers); | 169 SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers); |
158 for (; !iter.done(); ++iter) { | 170 for (; !iter.done(); ++iter) { |
159 (*iter).unrefAndAbandon(); | 171 (*iter).unrefAndAbandon(); |
160 } | 172 } |
161 fSamplers.reset(); | 173 fSamplers.reset(); |
162 | 174 |
| 175 fPipelineStateCache->abandon(); |
| 176 |
163 #ifdef SK_TRACE_VK_RESOURCES | 177 #ifdef SK_TRACE_VK_RESOURCES |
164 SkASSERT(0 == GrVkResource::fTrace.count()); | 178 SkASSERT(0 == GrVkResource::fTrace.count()); |
165 #endif | 179 #endif |
166 fPipelineCache = VK_NULL_HANDLE; | 180 fPipelineCache = VK_NULL_HANDLE; |
167 } | 181 } |
OLD | NEW |