Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrVkResourceProvider.h" |
| 9 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 10 | #include "GrContextPriv.h" |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 11 | #include "GrSamplerState.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 12 | #include "GrVkCommandBuffer.h" |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 13 | #include "GrVkCommandPool.h" |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 14 | #include "GrVkCopyPipeline.h" |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 15 | #include "GrVkGpu.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 16 | #include "GrVkPipeline.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 17 | #include "GrVkRenderTarget.h" |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 18 | #include "GrVkUniformBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 19 | #include "GrVkUtil.h" |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 20 | #include "SkTaskGroup.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 21 | |
| 22 | #ifdef SK_TRACE_VK_RESOURCES |
Mike Klein | 820e79b | 2018-12-04 09:31:31 -0500 | [diff] [blame] | 23 | std::atomic<uint32_t> GrVkResource::fKeyCounter{0}; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 24 | #endif |
| 25 | |
egdaniel | 778555c | 2016-05-02 06:50:36 -0700 | [diff] [blame] | 26 | GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) |
| 27 | : fGpu(gpu) |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 28 | , fPipelineCache(VK_NULL_HANDLE) { |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 29 | fPipelineStateCache = new PipelineStateCache(gpu); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | GrVkResourceProvider::~GrVkResourceProvider() { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 33 | SkASSERT(0 == fRenderPassArray.count()); |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 34 | SkASSERT(0 == fExternalRenderPasses.count()); |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 35 | SkASSERT(VK_NULL_HANDLE == fPipelineCache); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 36 | delete fPipelineStateCache; |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 39 | VkPipelineCache GrVkResourceProvider::pipelineCache() { |
| 40 | if (fPipelineCache == VK_NULL_HANDLE) { |
| 41 | VkPipelineCacheCreateInfo createInfo; |
| 42 | memset(&createInfo, 0, sizeof(VkPipelineCacheCreateInfo)); |
| 43 | createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 44 | createInfo.pNext = nullptr; |
| 45 | createInfo.flags = 0; |
egdaniel | 778555c | 2016-05-02 06:50:36 -0700 | [diff] [blame] | 46 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 47 | auto persistentCache = fGpu->getContext()->priv().getPersistentCache(); |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 48 | sk_sp<SkData> cached; |
| 49 | if (persistentCache) { |
| 50 | uint32_t key = GrVkGpu::kPipelineCache_PersistentCacheKeyType; |
| 51 | sk_sp<SkData> keyData = SkData::MakeWithoutCopy(&key, sizeof(uint32_t)); |
| 52 | cached = persistentCache->load(*keyData); |
| 53 | } |
| 54 | bool usedCached = false; |
| 55 | if (cached) { |
| 56 | uint32_t* cacheHeader = (uint32_t*)cached->data(); |
| 57 | if (cacheHeader[1] == VK_PIPELINE_CACHE_HEADER_VERSION_ONE) { |
| 58 | // For version one of the header, the total header size is 16 bytes plus |
| 59 | // VK_UUID_SIZE bytes. See Section 9.6 (Pipeline Cache) in the vulkan spec to see |
| 60 | // the breakdown of these bytes. |
| 61 | SkASSERT(cacheHeader[0] == 16 + VK_UUID_SIZE); |
| 62 | const VkPhysicalDeviceProperties& devProps = fGpu->physicalDeviceProperties(); |
| 63 | const uint8_t* supportedPipelineCacheUUID = devProps.pipelineCacheUUID; |
| 64 | if (cacheHeader[2] == devProps.vendorID && cacheHeader[3] == devProps.deviceID && |
| 65 | !memcmp(&cacheHeader[4], supportedPipelineCacheUUID, VK_UUID_SIZE)) { |
| 66 | createInfo.initialDataSize = cached->size(); |
| 67 | createInfo.pInitialData = cached->data(); |
| 68 | usedCached = true; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | if (!usedCached) { |
| 73 | createInfo.initialDataSize = 0; |
| 74 | createInfo.pInitialData = nullptr; |
| 75 | } |
| 76 | VkResult result = GR_VK_CALL(fGpu->vkInterface(), |
| 77 | CreatePipelineCache(fGpu->device(), &createInfo, nullptr, |
| 78 | &fPipelineCache)); |
| 79 | SkASSERT(VK_SUCCESS == result); |
| 80 | if (VK_SUCCESS != result) { |
| 81 | fPipelineCache = VK_NULL_HANDLE; |
| 82 | } |
| 83 | } |
| 84 | return fPipelineCache; |
| 85 | } |
| 86 | |
| 87 | void GrVkResourceProvider::init() { |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 88 | // Init uniform descriptor objects |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 89 | GrVkDescriptorSetManager* dsm = GrVkDescriptorSetManager::CreateUniformManager(fGpu); |
| 90 | fDescriptorSetManagers.emplace_back(dsm); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 91 | SkASSERT(1 == fDescriptorSetManagers.count()); |
| 92 | fUniformDSHandle = GrVkDescriptorSetManager::Handle(0); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 95 | GrVkPipeline* GrVkResourceProvider::createPipeline(int numColorSamples, |
| 96 | const GrPrimitiveProcessor& primProc, |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 97 | const GrPipeline& pipeline, |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 98 | const GrStencilSettings& stencil, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 99 | VkPipelineShaderStageCreateInfo* shaderStageInfo, |
| 100 | int shaderStageCount, |
| 101 | GrPrimitiveType primitiveType, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 102 | VkRenderPass compatibleRenderPass, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 103 | VkPipelineLayout layout) { |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 104 | return GrVkPipeline::Create(fGpu, numColorSamples, primProc, pipeline, stencil, shaderStageInfo, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 105 | shaderStageCount, primitiveType, compatibleRenderPass, layout, |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 106 | this->pipelineCache()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 107 | } |
| 108 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 109 | GrVkCopyPipeline* GrVkResourceProvider::findOrCreateCopyPipeline( |
| 110 | const GrVkRenderTarget* dst, |
| 111 | VkPipelineShaderStageCreateInfo* shaderStageInfo, |
| 112 | VkPipelineLayout pipelineLayout) { |
| 113 | // Find or Create a compatible pipeline |
| 114 | GrVkCopyPipeline* pipeline = nullptr; |
| 115 | for (int i = 0; i < fCopyPipelines.count() && !pipeline; ++i) { |
| 116 | if (fCopyPipelines[i]->isCompatible(*dst->simpleRenderPass())) { |
| 117 | pipeline = fCopyPipelines[i]; |
| 118 | } |
| 119 | } |
| 120 | if (!pipeline) { |
| 121 | pipeline = GrVkCopyPipeline::Create(fGpu, shaderStageInfo, |
| 122 | pipelineLayout, |
| 123 | dst->numColorSamples(), |
| 124 | *dst->simpleRenderPass(), |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 125 | this->pipelineCache()); |
Greg Daniel | f3a4ef9 | 2018-03-01 11:34:59 -0500 | [diff] [blame] | 126 | if (!pipeline) { |
| 127 | return nullptr; |
| 128 | } |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 129 | fCopyPipelines.push_back(pipeline); |
| 130 | } |
| 131 | SkASSERT(pipeline); |
| 132 | pipeline->ref(); |
| 133 | return pipeline; |
| 134 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 135 | |
| 136 | // To create framebuffers, we first need to create a simple RenderPass that is |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 137 | // only used for framebuffer creation. When we actually render we will create |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 138 | // RenderPasses as needed that are compatible with the framebuffer. |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 139 | const GrVkRenderPass* |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 140 | GrVkResourceProvider::findCompatibleRenderPass(const GrVkRenderTarget& target, |
| 141 | CompatibleRPHandle* compatibleHandle) { |
| 142 | for (int i = 0; i < fRenderPassArray.count(); ++i) { |
| 143 | if (fRenderPassArray[i].isCompatible(target)) { |
| 144 | const GrVkRenderPass* renderPass = fRenderPassArray[i].getCompatibleRenderPass(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 145 | renderPass->ref(); |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 146 | if (compatibleHandle) { |
| 147 | *compatibleHandle = CompatibleRPHandle(i); |
| 148 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 149 | return renderPass; |
| 150 | } |
| 151 | } |
| 152 | |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 153 | const GrVkRenderPass* renderPass = |
| 154 | fRenderPassArray.emplace_back(fGpu, target).getCompatibleRenderPass(); |
| 155 | renderPass->ref(); |
| 156 | |
| 157 | if (compatibleHandle) { |
| 158 | *compatibleHandle = CompatibleRPHandle(fRenderPassArray.count() - 1); |
| 159 | } |
| 160 | return renderPass; |
| 161 | } |
| 162 | |
| 163 | const GrVkRenderPass* |
| 164 | GrVkResourceProvider::findCompatibleRenderPass(const CompatibleRPHandle& compatibleHandle) { |
| 165 | SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderPassArray.count()); |
| 166 | int index = compatibleHandle.toIndex(); |
| 167 | const GrVkRenderPass* renderPass = fRenderPassArray[index].getCompatibleRenderPass(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 168 | renderPass->ref(); |
| 169 | return renderPass; |
| 170 | } |
| 171 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 172 | const GrVkRenderPass* GrVkResourceProvider::findCompatibleExternalRenderPass( |
| 173 | VkRenderPass renderPass, uint32_t colorAttachmentIndex) { |
| 174 | for (int i = 0; i < fExternalRenderPasses.count(); ++i) { |
| 175 | if (fExternalRenderPasses[i]->isCompatibleExternalRP(renderPass)) { |
| 176 | fExternalRenderPasses[i]->ref(); |
| 177 | #ifdef SK_DEBUG |
| 178 | uint32_t cachedColorIndex; |
| 179 | SkASSERT(fExternalRenderPasses[i]->colorAttachmentIndex(&cachedColorIndex)); |
| 180 | SkASSERT(cachedColorIndex == colorAttachmentIndex); |
| 181 | #endif |
| 182 | return fExternalRenderPasses[i]; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | const GrVkRenderPass* newRenderPass = new GrVkRenderPass(renderPass, colorAttachmentIndex); |
| 187 | fExternalRenderPasses.push_back(newRenderPass); |
| 188 | newRenderPass->ref(); |
| 189 | return newRenderPass; |
| 190 | } |
| 191 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 192 | const GrVkRenderPass* GrVkResourceProvider::findRenderPass( |
| 193 | const GrVkRenderTarget& target, |
| 194 | const GrVkRenderPass::LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 195 | const GrVkRenderPass::LoadStoreOps& stencilOps, |
| 196 | CompatibleRPHandle* compatibleHandle) { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 197 | GrVkResourceProvider::CompatibleRPHandle tempRPHandle; |
| 198 | GrVkResourceProvider::CompatibleRPHandle* pRPHandle = compatibleHandle ? compatibleHandle |
| 199 | : &tempRPHandle; |
| 200 | *pRPHandle = target.compatibleRenderPassHandle(); |
| 201 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 202 | // This will get us the handle to (and possible create) the compatible set for the specific |
| 203 | // GrVkRenderPass we are looking for. |
| 204 | this->findCompatibleRenderPass(target, compatibleHandle); |
Greg Daniel | d368211 | 2016-10-03 15:06:07 -0400 | [diff] [blame] | 205 | return this->findRenderPass(*pRPHandle, colorOps, stencilOps); |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | const GrVkRenderPass* |
| 209 | GrVkResourceProvider::findRenderPass(const CompatibleRPHandle& compatibleHandle, |
| 210 | const GrVkRenderPass::LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 211 | const GrVkRenderPass::LoadStoreOps& stencilOps) { |
| 212 | SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderPassArray.count()); |
| 213 | CompatibleRenderPassSet& compatibleSet = fRenderPassArray[compatibleHandle.toIndex()]; |
| 214 | const GrVkRenderPass* renderPass = compatibleSet.getRenderPass(fGpu, |
| 215 | colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 216 | stencilOps); |
| 217 | renderPass->ref(); |
| 218 | return renderPass; |
| 219 | } |
| 220 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 221 | GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool( |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 222 | VkDescriptorType type, uint32_t count) { |
| 223 | return new GrVkDescriptorPool(fGpu, type, count); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 224 | } |
| 225 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 226 | GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler( |
| 227 | const GrSamplerState& params, const GrVkYcbcrConversionInfo& ycbcrInfo) { |
| 228 | GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params, ycbcrInfo)); |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 229 | if (!sampler) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 230 | sampler = GrVkSampler::Create(fGpu, params, ycbcrInfo); |
| 231 | if (!sampler) { |
| 232 | return nullptr; |
| 233 | } |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 234 | fSamplers.add(sampler); |
| 235 | } |
| 236 | SkASSERT(sampler); |
| 237 | sampler->ref(); |
| 238 | return sampler; |
| 239 | } |
| 240 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 241 | GrVkSamplerYcbcrConversion* GrVkResourceProvider::findOrCreateCompatibleSamplerYcbcrConversion( |
| 242 | const GrVkYcbcrConversionInfo& ycbcrInfo) { |
| 243 | GrVkSamplerYcbcrConversion* ycbcrConversion = |
| 244 | fYcbcrConversions.find(GrVkSamplerYcbcrConversion::GenerateKey(ycbcrInfo)); |
| 245 | if (!ycbcrConversion) { |
| 246 | ycbcrConversion = GrVkSamplerYcbcrConversion::Create(fGpu, ycbcrInfo); |
| 247 | if (!ycbcrConversion) { |
| 248 | return nullptr; |
| 249 | } |
| 250 | fYcbcrConversions.add(ycbcrConversion); |
| 251 | } |
| 252 | SkASSERT(ycbcrConversion); |
| 253 | ycbcrConversion->ref(); |
| 254 | return ycbcrConversion; |
| 255 | } |
| 256 | |
Greg Daniel | 09eeefb | 2017-10-16 15:15:02 -0400 | [diff] [blame] | 257 | GrVkPipelineState* GrVkResourceProvider::findOrCreateCompatiblePipelineState( |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 258 | GrRenderTarget* renderTarget, GrSurfaceOrigin origin, |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 259 | const GrPipeline& pipeline, const GrPrimitiveProcessor& proc, |
| 260 | const GrTextureProxy* const primProcProxies[], GrPrimitiveType primitiveType, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 261 | VkRenderPass compatibleRenderPass) { |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 262 | return fPipelineStateCache->refPipelineState(renderTarget, origin, proc, primProcProxies, |
| 263 | pipeline, primitiveType, compatibleRenderPass); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 266 | void GrVkResourceProvider::getSamplerDescriptorSetHandle(VkDescriptorType type, |
| 267 | const GrVkUniformHandler& uniformHandler, |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 268 | GrVkDescriptorSetManager::Handle* handle) { |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 269 | SkASSERT(handle); |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 270 | SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type || |
| 271 | VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER == type); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 272 | for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 273 | if (fDescriptorSetManagers[i]->isCompatible(type, &uniformHandler)) { |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 274 | *handle = GrVkDescriptorSetManager::Handle(i); |
| 275 | return; |
| 276 | } |
| 277 | } |
| 278 | |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 279 | GrVkDescriptorSetManager* dsm = GrVkDescriptorSetManager::CreateSamplerManager(fGpu, type, |
| 280 | uniformHandler); |
| 281 | fDescriptorSetManagers.emplace_back(dsm); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 282 | *handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1); |
| 283 | } |
| 284 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 285 | void GrVkResourceProvider::getSamplerDescriptorSetHandle(VkDescriptorType type, |
| 286 | const SkTArray<uint32_t>& visibilities, |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 287 | GrVkDescriptorSetManager::Handle* handle) { |
| 288 | SkASSERT(handle); |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 289 | SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type || |
| 290 | VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER == type); |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 291 | for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 292 | if (fDescriptorSetManagers[i]->isCompatible(type, visibilities)) { |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 293 | *handle = GrVkDescriptorSetManager::Handle(i); |
| 294 | return; |
| 295 | } |
| 296 | } |
| 297 | |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 298 | GrVkDescriptorSetManager* dsm = GrVkDescriptorSetManager::CreateSamplerManager(fGpu, type, |
| 299 | visibilities); |
| 300 | fDescriptorSetManagers.emplace_back(dsm); |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 301 | *handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1); |
| 302 | } |
| 303 | |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 304 | VkDescriptorSetLayout GrVkResourceProvider::getUniformDSLayout() const { |
| 305 | SkASSERT(fUniformDSHandle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 306 | return fDescriptorSetManagers[fUniformDSHandle.toIndex()]->layout(); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | VkDescriptorSetLayout GrVkResourceProvider::getSamplerDSLayout( |
| 310 | const GrVkDescriptorSetManager::Handle& handle) const { |
| 311 | SkASSERT(handle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 312 | return fDescriptorSetManagers[handle.toIndex()]->layout(); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 313 | } |
| 314 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 315 | const GrVkDescriptorSet* GrVkResourceProvider::getUniformDescriptorSet() { |
| 316 | SkASSERT(fUniformDSHandle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 317 | return fDescriptorSetManagers[fUniformDSHandle.toIndex()]->getDescriptorSet(fGpu, |
| 318 | fUniformDSHandle); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 319 | } |
| 320 | |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 321 | const GrVkDescriptorSet* GrVkResourceProvider::getSamplerDescriptorSet( |
| 322 | const GrVkDescriptorSetManager::Handle& handle) { |
| 323 | SkASSERT(handle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 324 | return fDescriptorSetManagers[handle.toIndex()]->getDescriptorSet(fGpu, handle); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 325 | } |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 326 | |
| 327 | void GrVkResourceProvider::recycleDescriptorSet(const GrVkDescriptorSet* descSet, |
| 328 | const GrVkDescriptorSetManager::Handle& handle) { |
| 329 | SkASSERT(descSet); |
| 330 | SkASSERT(handle.isValid()); |
| 331 | int managerIdx = handle.toIndex(); |
| 332 | SkASSERT(managerIdx < fDescriptorSetManagers.count()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 333 | fDescriptorSetManagers[managerIdx]->recycleDescriptorSet(descSet); |
egdaniel | 778555c | 2016-05-02 06:50:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 336 | GrVkCommandPool* GrVkResourceProvider::findOrCreateCommandPool() { |
| 337 | std::unique_lock<std::recursive_mutex> lock(fBackgroundMutex); |
| 338 | GrVkCommandPool* result; |
| 339 | if (fAvailableCommandPools.count()) { |
| 340 | result = fAvailableCommandPools.back(); |
| 341 | fAvailableCommandPools.pop_back(); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 342 | } else { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 343 | result = GrVkCommandPool::Create(fGpu); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 344 | } |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 345 | SkASSERT(result->unique()); |
| 346 | SkDEBUGCODE( |
| 347 | for (const GrVkCommandPool* pool : fActiveCommandPools) { |
| 348 | SkASSERT(pool != result); |
| 349 | } |
| 350 | for (const GrVkCommandPool* pool : fAvailableCommandPools) { |
| 351 | SkASSERT(pool != result); |
| 352 | } |
Ben Wagner | 1c0cacf | 2019-01-14 12:57:36 -0500 | [diff] [blame] | 353 | ) |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 354 | fActiveCommandPools.push_back(result); |
| 355 | result->ref(); |
| 356 | return result; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void GrVkResourceProvider::checkCommandBuffers() { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 360 | for (int i = fActiveCommandPools.count() - 1; i >= 0; --i) { |
| 361 | GrVkCommandPool* pool = fActiveCommandPools[i]; |
| 362 | if (!pool->isOpen()) { |
| 363 | GrVkPrimaryCommandBuffer* buffer = pool->getPrimaryCommandBuffer(); |
| 364 | if (buffer->finished(fGpu)) { |
| 365 | fActiveCommandPools.removeShuffle(i); |
| 366 | this->backgroundReset(pool); |
| 367 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 372 | const GrVkResource* GrVkResourceProvider::findOrCreateStandardUniformBufferResource() { |
| 373 | const GrVkResource* resource = nullptr; |
| 374 | int count = fAvailableUniformBufferResources.count(); |
| 375 | if (count > 0) { |
| 376 | resource = fAvailableUniformBufferResources[count - 1]; |
| 377 | fAvailableUniformBufferResources.removeShuffle(count - 1); |
| 378 | } else { |
| 379 | resource = GrVkUniformBuffer::CreateResource(fGpu, GrVkUniformBuffer::kStandardSize); |
| 380 | } |
| 381 | return resource; |
| 382 | } |
| 383 | |
| 384 | void GrVkResourceProvider::recycleStandardUniformBufferResource(const GrVkResource* resource) { |
| 385 | fAvailableUniformBufferResources.push_back(resource); |
| 386 | } |
| 387 | |
Jim Van Verth | 09557d7 | 2016-11-07 11:10:21 -0500 | [diff] [blame] | 388 | void GrVkResourceProvider::destroyResources(bool deviceLost) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 389 | SkTaskGroup* taskGroup = fGpu->getContext()->priv().getTaskGroup(); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 390 | if (taskGroup) { |
| 391 | taskGroup->wait(); |
Ethan Nicholas | bff4e07 | 2018-12-12 18:17:24 +0000 | [diff] [blame] | 392 | } |
Ethan Nicholas | bff4e07 | 2018-12-12 18:17:24 +0000 | [diff] [blame] | 393 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 394 | // Release all copy pipelines |
| 395 | for (int i = 0; i < fCopyPipelines.count(); ++i) { |
| 396 | fCopyPipelines[i]->unref(fGpu); |
| 397 | } |
| 398 | |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 399 | // loop over all render pass sets to make sure we destroy all the internal VkRenderPasses |
| 400 | for (int i = 0; i < fRenderPassArray.count(); ++i) { |
| 401 | fRenderPassArray[i].releaseResources(fGpu); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 402 | } |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 403 | fRenderPassArray.reset(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 404 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 405 | for (int i = 0; i < fExternalRenderPasses.count(); ++i) { |
| 406 | fExternalRenderPasses[i]->unref(fGpu); |
| 407 | } |
| 408 | fExternalRenderPasses.reset(); |
| 409 | |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 410 | // Iterate through all store GrVkSamplers and unref them before resetting the hash. |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 411 | SkTDynamicHash<GrVkSampler, GrVkSampler::Key>::Iter iter(&fSamplers); |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 412 | for (; !iter.done(); ++iter) { |
| 413 | (*iter).unref(fGpu); |
| 414 | } |
| 415 | fSamplers.reset(); |
| 416 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 417 | fPipelineStateCache->release(); |
| 418 | |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 419 | GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipelineCache, nullptr)); |
| 420 | fPipelineCache = VK_NULL_HANDLE; |
egdaniel | 778555c | 2016-05-02 06:50:36 -0700 | [diff] [blame] | 421 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 422 | for (GrVkCommandPool* pool : fActiveCommandPools) { |
| 423 | SkASSERT(pool->unique()); |
| 424 | pool->unref(fGpu); |
| 425 | } |
| 426 | fActiveCommandPools.reset(); |
| 427 | |
| 428 | for (GrVkCommandPool* pool : fAvailableCommandPools) { |
| 429 | SkASSERT(pool->unique()); |
| 430 | pool->unref(fGpu); |
| 431 | } |
| 432 | fAvailableCommandPools.reset(); |
| 433 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 434 | // We must release/destroy all command buffers and pipeline states before releasing the |
| 435 | // GrVkDescriptorSetManagers |
| 436 | for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 437 | fDescriptorSetManagers[i]->release(fGpu); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 438 | } |
| 439 | fDescriptorSetManagers.reset(); |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 440 | |
| 441 | // release our uniform buffers |
| 442 | for (int i = 0; i < fAvailableUniformBufferResources.count(); ++i) { |
| 443 | SkASSERT(fAvailableUniformBufferResources[i]->unique()); |
| 444 | fAvailableUniformBufferResources[i]->unref(fGpu); |
| 445 | } |
| 446 | fAvailableUniformBufferResources.reset(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void GrVkResourceProvider::abandonResources() { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 450 | SkTaskGroup* taskGroup = fGpu->getContext()->priv().getTaskGroup(); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 451 | if (taskGroup) { |
| 452 | taskGroup->wait(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 453 | } |
Ethan Nicholas | bff4e07 | 2018-12-12 18:17:24 +0000 | [diff] [blame] | 454 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 455 | // Abandon all command pools |
| 456 | for (int i = 0; i < fActiveCommandPools.count(); ++i) { |
| 457 | SkASSERT(fActiveCommandPools[i]->unique()); |
| 458 | fActiveCommandPools[i]->unrefAndAbandon(); |
Ethan Nicholas | bff4e07 | 2018-12-12 18:17:24 +0000 | [diff] [blame] | 459 | } |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 460 | fActiveCommandPools.reset(); |
| 461 | for (int i = 0; i < fAvailableCommandPools.count(); ++i) { |
| 462 | SkASSERT(fAvailableCommandPools[i]->unique()); |
| 463 | fAvailableCommandPools[i]->unrefAndAbandon(); |
| 464 | } |
| 465 | fAvailableCommandPools.reset(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 466 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 467 | // Abandon all copy pipelines |
| 468 | for (int i = 0; i < fCopyPipelines.count(); ++i) { |
| 469 | fCopyPipelines[i]->unrefAndAbandon(); |
| 470 | } |
| 471 | |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 472 | // loop over all render pass sets to make sure we destroy all the internal VkRenderPasses |
| 473 | for (int i = 0; i < fRenderPassArray.count(); ++i) { |
| 474 | fRenderPassArray[i].abandonResources(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 475 | } |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 476 | fRenderPassArray.reset(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 477 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 478 | for (int i = 0; i < fExternalRenderPasses.count(); ++i) { |
| 479 | fExternalRenderPasses[i]->unrefAndAbandon(); |
| 480 | } |
| 481 | fExternalRenderPasses.reset(); |
| 482 | |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 483 | // Iterate through all store GrVkSamplers and unrefAndAbandon them before resetting the hash. |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 484 | SkTDynamicHash<GrVkSampler, GrVkSampler::Key>::Iter iter(&fSamplers); |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 485 | for (; !iter.done(); ++iter) { |
| 486 | (*iter).unrefAndAbandon(); |
| 487 | } |
| 488 | fSamplers.reset(); |
| 489 | |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 490 | fPipelineStateCache->abandon(); |
| 491 | |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 492 | fPipelineCache = VK_NULL_HANDLE; |
egdaniel | 778555c | 2016-05-02 06:50:36 -0700 | [diff] [blame] | 493 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 494 | // We must abandon all command buffers and pipeline states before abandoning the |
| 495 | // GrVkDescriptorSetManagers |
| 496 | for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 497 | fDescriptorSetManagers[i]->abandon(); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 498 | } |
| 499 | fDescriptorSetManagers.reset(); |
| 500 | |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 501 | // release our uniform buffers |
| 502 | for (int i = 0; i < fAvailableUniformBufferResources.count(); ++i) { |
| 503 | SkASSERT(fAvailableUniformBufferResources[i]->unique()); |
| 504 | fAvailableUniformBufferResources[i]->unrefAndAbandon(); |
| 505 | } |
| 506 | fAvailableUniformBufferResources.reset(); |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 507 | } |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 508 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 509 | void GrVkResourceProvider::backgroundReset(GrVkCommandPool* pool) { |
| 510 | SkASSERT(pool->unique()); |
| 511 | pool->releaseResources(fGpu); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 512 | SkTaskGroup* taskGroup = fGpu->getContext()->priv().getTaskGroup(); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 513 | if (taskGroup) { |
| 514 | taskGroup->add([this, pool]() { |
| 515 | this->reset(pool); |
| 516 | }); |
| 517 | } else { |
| 518 | this->reset(pool); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | void GrVkResourceProvider::reset(GrVkCommandPool* pool) { |
| 523 | SkASSERT(pool->unique()); |
| 524 | pool->reset(fGpu); |
| 525 | std::unique_lock<std::recursive_mutex> providerLock(fBackgroundMutex); |
| 526 | fAvailableCommandPools.push_back(pool); |
| 527 | } |
| 528 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 529 | void GrVkResourceProvider::storePipelineCacheData() { |
| 530 | size_t dataSize = 0; |
| 531 | VkResult result = GR_VK_CALL(fGpu->vkInterface(), GetPipelineCacheData(fGpu->device(), |
| 532 | this->pipelineCache(), |
| 533 | &dataSize, nullptr)); |
| 534 | SkASSERT(result == VK_SUCCESS); |
| 535 | |
| 536 | std::unique_ptr<uint8_t[]> data(new uint8_t[dataSize]); |
| 537 | |
| 538 | result = GR_VK_CALL(fGpu->vkInterface(), GetPipelineCacheData(fGpu->device(), |
| 539 | this->pipelineCache(), |
| 540 | &dataSize, |
| 541 | (void*)data.get())); |
| 542 | SkASSERT(result == VK_SUCCESS); |
| 543 | |
| 544 | uint32_t key = GrVkGpu::kPipelineCache_PersistentCacheKeyType; |
| 545 | sk_sp<SkData> keyData = SkData::MakeWithoutCopy(&key, sizeof(uint32_t)); |
| 546 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 547 | fGpu->getContext()->priv().getPersistentCache()->store( |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 548 | *keyData, *SkData::MakeWithoutCopy(data.get(), dataSize)); |
| 549 | } |
| 550 | |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 551 | //////////////////////////////////////////////////////////////////////////////// |
| 552 | |
| 553 | GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet( |
| 554 | const GrVkGpu* gpu, |
| 555 | const GrVkRenderTarget& target) |
| 556 | : fLastReturnedIndex(0) { |
| 557 | fRenderPasses.emplace_back(new GrVkRenderPass()); |
| 558 | fRenderPasses[0]->initSimple(gpu, target); |
| 559 | } |
| 560 | |
| 561 | bool GrVkResourceProvider::CompatibleRenderPassSet::isCompatible( |
| 562 | const GrVkRenderTarget& target) const { |
| 563 | // The first GrVkRenderpass should always exists since we create the basic load store |
| 564 | // render pass on create |
| 565 | SkASSERT(fRenderPasses[0]); |
| 566 | return fRenderPasses[0]->isCompatible(target); |
| 567 | } |
| 568 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 569 | GrVkRenderPass* GrVkResourceProvider::CompatibleRenderPassSet::getRenderPass( |
| 570 | const GrVkGpu* gpu, |
| 571 | const GrVkRenderPass::LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 572 | const GrVkRenderPass::LoadStoreOps& stencilOps) { |
| 573 | for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 574 | int idx = (i + fLastReturnedIndex) % fRenderPasses.count(); |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 575 | if (fRenderPasses[idx]->equalLoadStoreOps(colorOps, stencilOps)) { |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 576 | fLastReturnedIndex = idx; |
| 577 | return fRenderPasses[idx]; |
| 578 | } |
| 579 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 580 | GrVkRenderPass* renderPass = fRenderPasses.emplace_back(new GrVkRenderPass()); |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 581 | renderPass->init(gpu, *this->getCompatibleRenderPass(), colorOps, stencilOps); |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 582 | fLastReturnedIndex = fRenderPasses.count() - 1; |
| 583 | return renderPass; |
| 584 | } |
| 585 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 586 | void GrVkResourceProvider::CompatibleRenderPassSet::releaseResources(GrVkGpu* gpu) { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 587 | for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 588 | if (fRenderPasses[i]) { |
| 589 | fRenderPasses[i]->unref(gpu); |
| 590 | fRenderPasses[i] = nullptr; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
| 596 | for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 597 | if (fRenderPasses[i]) { |
| 598 | fRenderPasses[i]->unrefAndAbandon(); |
| 599 | fRenderPasses[i] = nullptr; |
| 600 | } |
| 601 | } |
| 602 | } |