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