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