| 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" | |
| 14 #include "GrVkSampler.h" | 13 #include "GrVkSampler.h" |
| 15 #include "GrVkUtil.h" | 14 #include "GrVkUtil.h" |
| 16 | 15 |
| 17 #ifdef SK_TRACE_VK_RESOURCES | 16 #ifdef SK_TRACE_VK_RESOURCES |
| 18 SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace; | 17 SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace; |
| 19 SkRandom GrVkResource::fRandom; | 18 SkRandom GrVkResource::fRandom; |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) | 21 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) |
| 23 : fGpu(gpu) | 22 : fGpu(gpu) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 126 |
| 128 const GrVkRenderPass* | 127 const GrVkRenderPass* |
| 129 GrVkResourceProvider::findCompatibleRenderPass(const CompatibleRPHandle& compati
bleHandle) { | 128 GrVkResourceProvider::findCompatibleRenderPass(const CompatibleRPHandle& compati
bleHandle) { |
| 130 SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderP
assArray.count()); | 129 SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderP
assArray.count()); |
| 131 int index = compatibleHandle.toIndex(); | 130 int index = compatibleHandle.toIndex(); |
| 132 const GrVkRenderPass* renderPass = fRenderPassArray[index].getCompatibleRend
erPass(); | 131 const GrVkRenderPass* renderPass = fRenderPassArray[index].getCompatibleRend
erPass(); |
| 133 renderPass->ref(); | 132 renderPass->ref(); |
| 134 return renderPass; | 133 return renderPass; |
| 135 } | 134 } |
| 136 | 135 |
| 136 const GrVkRenderPass* GrVkResourceProvider::findRenderPass( |
| 137 const GrVkRenderTarget& tar
get, |
| 138 const GrVkRenderPass::LoadS
toreOps& colorOps, |
| 139 const GrVkRenderPass::LoadS
toreOps& resolveOps, |
| 140 const GrVkRenderPass::LoadS
toreOps& stencilOps, |
| 141 CompatibleRPHandle* compati
bleHandle) { |
| 142 // This will get us the handle to (and possible create) the compatible set f
or the specific |
| 143 // GrVkRenderPass we are looking for. |
| 144 this->findCompatibleRenderPass(target, compatibleHandle); |
| 145 return this->findRenderPass(*compatibleHandle, colorOps, resolveOps, stencil
Ops); |
| 146 } |
| 147 |
| 148 const GrVkRenderPass* |
| 149 GrVkResourceProvider::findRenderPass(const CompatibleRPHandle& compatibleHandle, |
| 150 const GrVkRenderPass::LoadStoreOps& colorOp
s, |
| 151 const GrVkRenderPass::LoadStoreOps& resolve
Ops, |
| 152 const GrVkRenderPass::LoadStoreOps& stencil
Ops) { |
| 153 SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderP
assArray.count()); |
| 154 CompatibleRenderPassSet& compatibleSet = fRenderPassArray[compatibleHandle.t
oIndex()]; |
| 155 const GrVkRenderPass* renderPass = compatibleSet.getRenderPass(fGpu, |
| 156 colorOps, |
| 157 resolveOps, |
| 158 stencilOps); |
| 159 renderPass->ref(); |
| 160 return renderPass; |
| 161 } |
| 162 |
| 137 GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool( | 163 GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool( |
| 138 VkDescriptorType typ
e, uint32_t count) { | 164 VkDescriptorType typ
e, uint32_t count) { |
| 139 return new GrVkDescriptorPool(fGpu, type, count); | 165 return new GrVkDescriptorPool(fGpu, type, count); |
| 140 } | 166 } |
| 141 | 167 |
| 142 GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrTexture
Params& params, | 168 GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrTexture
Params& params, |
| 143 uint32_t mipLev
els) { | 169 uint32_t mipLev
els) { |
| 144 GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params, mipLe
vels)); | 170 GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params, mipLe
vels)); |
| 145 if (!sampler) { | 171 if (!sampler) { |
| 146 sampler = GrVkSampler::Create(fGpu, params, mipLevels); | 172 sampler = GrVkSampler::Create(fGpu, params, mipLevels); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 314 } |
| 289 | 315 |
| 290 bool GrVkResourceProvider::CompatibleRenderPassSet::isCompatible( | 316 bool GrVkResourceProvider::CompatibleRenderPassSet::isCompatible( |
| 291 const GrVkRenderTar
get& target) const { | 317 const GrVkRenderTar
get& target) const { |
| 292 // The first GrVkRenderpass should always exists since we create the basic l
oad store | 318 // The first GrVkRenderpass should always exists since we create the basic l
oad store |
| 293 // render pass on create | 319 // render pass on create |
| 294 SkASSERT(fRenderPasses[0]); | 320 SkASSERT(fRenderPasses[0]); |
| 295 return fRenderPasses[0]->isCompatible(target); | 321 return fRenderPasses[0]->isCompatible(target); |
| 296 } | 322 } |
| 297 | 323 |
| 324 GrVkRenderPass* GrVkResourceProvider::CompatibleRenderPassSet::getRenderPass( |
| 325 const GrVkGpu* gpu, |
| 326 const GrVkRenderPass::LoadSto
reOps& colorOps, |
| 327 const GrVkRenderPass::LoadSto
reOps& resolveOps, |
| 328 const GrVkRenderPass::LoadSto
reOps& stencilOps) { |
| 329 for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 330 int idx = (i + fLastReturnedIndex) % fRenderPasses.count(); |
| 331 if (fRenderPasses[idx]->equalLoadStoreOps(colorOps, resolveOps, stencilO
ps)) { |
| 332 fLastReturnedIndex = idx; |
| 333 return fRenderPasses[idx]; |
| 334 } |
| 335 } |
| 336 GrVkRenderPass* renderPass = fRenderPasses.push_back(); |
| 337 renderPass->init(gpu, *this->getCompatibleRenderPass(), colorOps, resolveOps
, stencilOps); |
| 338 fLastReturnedIndex = fRenderPasses.count() - 1; |
| 339 return renderPass; |
| 340 } |
| 341 |
| 298 void GrVkResourceProvider::CompatibleRenderPassSet::releaseResources(const GrVkG
pu* gpu) { | 342 void GrVkResourceProvider::CompatibleRenderPassSet::releaseResources(const GrVkG
pu* gpu) { |
| 299 for (int i = 0; i < fRenderPasses.count(); ++i) { | 343 for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 300 if (fRenderPasses[i]) { | 344 if (fRenderPasses[i]) { |
| 301 fRenderPasses[i]->unref(gpu); | 345 fRenderPasses[i]->unref(gpu); |
| 302 fRenderPasses[i] = nullptr; | 346 fRenderPasses[i] = nullptr; |
| 303 } | 347 } |
| 304 } | 348 } |
| 305 } | 349 } |
| 306 | 350 |
| 307 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { | 351 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
| 308 for (int i = 0; i < fRenderPasses.count(); ++i) { | 352 for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 309 if (fRenderPasses[i]) { | 353 if (fRenderPasses[i]) { |
| 310 fRenderPasses[i]->unrefAndAbandon(); | 354 fRenderPasses[i]->unrefAndAbandon(); |
| 311 fRenderPasses[i] = nullptr; | 355 fRenderPasses[i] = nullptr; |
| 312 } | 356 } |
| 313 } | 357 } |
| 314 } | 358 } |
| OLD | NEW |