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 | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 94 | GrVkPipeline* GrVkResourceProvider::createPipeline(const GrProgramInfo& programInfo, |
Robert Phillips | 6c2aa7a | 2019-10-17 19:06:39 +0000 | [diff] [blame] | 95 | const GrStencilSettings& stencil, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 96 | VkPipelineShaderStageCreateInfo* shaderStageInfo, |
| 97 | int shaderStageCount, |
| 98 | GrPrimitiveType primitiveType, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 99 | VkRenderPass compatibleRenderPass, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 100 | VkPipelineLayout layout) { |
Robert Phillips | 6c2aa7a | 2019-10-17 19:06:39 +0000 | [diff] [blame] | 101 | return GrVkPipeline::Create(fGpu, programInfo, stencil, shaderStageInfo, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 102 | shaderStageCount, primitiveType, compatibleRenderPass, |
| 103 | layout, this->pipelineCache()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 106 | // To create framebuffers, we first need to create a simple RenderPass that is |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 107 | // only used for framebuffer creation. When we actually render we will create |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 108 | // RenderPasses as needed that are compatible with the framebuffer. |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 109 | const GrVkRenderPass* |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 110 | GrVkResourceProvider::findCompatibleRenderPass(const GrVkRenderTarget& target, |
| 111 | CompatibleRPHandle* compatibleHandle) { |
| 112 | for (int i = 0; i < fRenderPassArray.count(); ++i) { |
| 113 | if (fRenderPassArray[i].isCompatible(target)) { |
| 114 | const GrVkRenderPass* renderPass = fRenderPassArray[i].getCompatibleRenderPass(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 115 | renderPass->ref(); |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 116 | if (compatibleHandle) { |
| 117 | *compatibleHandle = CompatibleRPHandle(i); |
| 118 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 119 | return renderPass; |
| 120 | } |
| 121 | } |
| 122 | |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 123 | const GrVkRenderPass* renderPass = |
| 124 | fRenderPassArray.emplace_back(fGpu, target).getCompatibleRenderPass(); |
| 125 | renderPass->ref(); |
| 126 | |
| 127 | if (compatibleHandle) { |
| 128 | *compatibleHandle = CompatibleRPHandle(fRenderPassArray.count() - 1); |
| 129 | } |
| 130 | return renderPass; |
| 131 | } |
| 132 | |
| 133 | const GrVkRenderPass* |
| 134 | GrVkResourceProvider::findCompatibleRenderPass(const CompatibleRPHandle& compatibleHandle) { |
| 135 | SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderPassArray.count()); |
| 136 | int index = compatibleHandle.toIndex(); |
| 137 | const GrVkRenderPass* renderPass = fRenderPassArray[index].getCompatibleRenderPass(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 138 | renderPass->ref(); |
| 139 | return renderPass; |
| 140 | } |
| 141 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 142 | const GrVkRenderPass* GrVkResourceProvider::findCompatibleExternalRenderPass( |
| 143 | VkRenderPass renderPass, uint32_t colorAttachmentIndex) { |
| 144 | for (int i = 0; i < fExternalRenderPasses.count(); ++i) { |
| 145 | if (fExternalRenderPasses[i]->isCompatibleExternalRP(renderPass)) { |
| 146 | fExternalRenderPasses[i]->ref(); |
| 147 | #ifdef SK_DEBUG |
| 148 | uint32_t cachedColorIndex; |
| 149 | SkASSERT(fExternalRenderPasses[i]->colorAttachmentIndex(&cachedColorIndex)); |
| 150 | SkASSERT(cachedColorIndex == colorAttachmentIndex); |
| 151 | #endif |
| 152 | return fExternalRenderPasses[i]; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | const GrVkRenderPass* newRenderPass = new GrVkRenderPass(renderPass, colorAttachmentIndex); |
| 157 | fExternalRenderPasses.push_back(newRenderPass); |
| 158 | newRenderPass->ref(); |
| 159 | return newRenderPass; |
| 160 | } |
| 161 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 162 | const GrVkRenderPass* GrVkResourceProvider::findRenderPass( |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame^] | 163 | GrVkRenderTarget* target, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 164 | const GrVkRenderPass::LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 165 | const GrVkRenderPass::LoadStoreOps& stencilOps, |
| 166 | CompatibleRPHandle* compatibleHandle) { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 167 | GrVkResourceProvider::CompatibleRPHandle tempRPHandle; |
| 168 | GrVkResourceProvider::CompatibleRPHandle* pRPHandle = compatibleHandle ? compatibleHandle |
| 169 | : &tempRPHandle; |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame^] | 170 | *pRPHandle = target->compatibleRenderPassHandle(); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 171 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 172 | // This will get us the handle to (and possible create) the compatible set for the specific |
| 173 | // GrVkRenderPass we are looking for. |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame^] | 174 | this->findCompatibleRenderPass(*target, compatibleHandle); |
Greg Daniel | d368211 | 2016-10-03 15:06:07 -0400 | [diff] [blame] | 175 | return this->findRenderPass(*pRPHandle, colorOps, stencilOps); |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | const GrVkRenderPass* |
| 179 | GrVkResourceProvider::findRenderPass(const CompatibleRPHandle& compatibleHandle, |
| 180 | const GrVkRenderPass::LoadStoreOps& colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 181 | const GrVkRenderPass::LoadStoreOps& stencilOps) { |
| 182 | SkASSERT(compatibleHandle.isValid() && compatibleHandle.toIndex() < fRenderPassArray.count()); |
| 183 | CompatibleRenderPassSet& compatibleSet = fRenderPassArray[compatibleHandle.toIndex()]; |
| 184 | const GrVkRenderPass* renderPass = compatibleSet.getRenderPass(fGpu, |
| 185 | colorOps, |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 186 | stencilOps); |
| 187 | renderPass->ref(); |
| 188 | return renderPass; |
| 189 | } |
| 190 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 191 | GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool( |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 192 | VkDescriptorType type, uint32_t count) { |
Greg Daniel | 9b63dc8 | 2019-11-06 09:21:55 -0500 | [diff] [blame] | 193 | return GrVkDescriptorPool::Create(fGpu, type, count); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 194 | } |
| 195 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 196 | GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler( |
| 197 | const GrSamplerState& params, const GrVkYcbcrConversionInfo& ycbcrInfo) { |
| 198 | GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params, ycbcrInfo)); |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 199 | if (!sampler) { |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 200 | sampler = GrVkSampler::Create(fGpu, params, ycbcrInfo); |
| 201 | if (!sampler) { |
| 202 | return nullptr; |
| 203 | } |
egdaniel | 8b6394c | 2016-03-04 07:35:10 -0800 | [diff] [blame] | 204 | fSamplers.add(sampler); |
| 205 | } |
| 206 | SkASSERT(sampler); |
| 207 | sampler->ref(); |
| 208 | return sampler; |
| 209 | } |
| 210 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 211 | GrVkSamplerYcbcrConversion* GrVkResourceProvider::findOrCreateCompatibleSamplerYcbcrConversion( |
| 212 | const GrVkYcbcrConversionInfo& ycbcrInfo) { |
| 213 | GrVkSamplerYcbcrConversion* ycbcrConversion = |
| 214 | fYcbcrConversions.find(GrVkSamplerYcbcrConversion::GenerateKey(ycbcrInfo)); |
| 215 | if (!ycbcrConversion) { |
| 216 | ycbcrConversion = GrVkSamplerYcbcrConversion::Create(fGpu, ycbcrInfo); |
| 217 | if (!ycbcrConversion) { |
| 218 | return nullptr; |
| 219 | } |
| 220 | fYcbcrConversions.add(ycbcrConversion); |
| 221 | } |
| 222 | SkASSERT(ycbcrConversion); |
| 223 | ycbcrConversion->ref(); |
| 224 | return ycbcrConversion; |
| 225 | } |
| 226 | |
Greg Daniel | 09eeefb | 2017-10-16 15:15:02 -0400 | [diff] [blame] | 227 | GrVkPipelineState* GrVkResourceProvider::findOrCreateCompatiblePipelineState( |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 228 | GrRenderTarget* renderTarget, |
| 229 | const GrProgramInfo& programInfo, |
| 230 | GrPrimitiveType primitiveType, |
Greg Daniel | 99b88e0 | 2018-10-03 15:31:20 -0400 | [diff] [blame] | 231 | VkRenderPass compatibleRenderPass) { |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 232 | return fPipelineStateCache->refPipelineState(renderTarget, programInfo, |
| 233 | primitiveType, compatibleRenderPass); |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 236 | void GrVkResourceProvider::getSamplerDescriptorSetHandle(VkDescriptorType type, |
| 237 | const GrVkUniformHandler& uniformHandler, |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 238 | GrVkDescriptorSetManager::Handle* handle) { |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 239 | SkASSERT(handle); |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 240 | SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type || |
| 241 | VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER == type); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 242 | for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 243 | if (fDescriptorSetManagers[i]->isCompatible(type, &uniformHandler)) { |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 244 | *handle = GrVkDescriptorSetManager::Handle(i); |
| 245 | return; |
| 246 | } |
| 247 | } |
| 248 | |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 249 | GrVkDescriptorSetManager* dsm = GrVkDescriptorSetManager::CreateSamplerManager(fGpu, type, |
| 250 | uniformHandler); |
| 251 | fDescriptorSetManagers.emplace_back(dsm); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 252 | *handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1); |
| 253 | } |
| 254 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 255 | void GrVkResourceProvider::getSamplerDescriptorSetHandle(VkDescriptorType type, |
| 256 | const SkTArray<uint32_t>& visibilities, |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 257 | GrVkDescriptorSetManager::Handle* handle) { |
| 258 | SkASSERT(handle); |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 259 | SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type || |
| 260 | VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER == type); |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 261 | for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 262 | if (fDescriptorSetManagers[i]->isCompatible(type, visibilities)) { |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 263 | *handle = GrVkDescriptorSetManager::Handle(i); |
| 264 | return; |
| 265 | } |
| 266 | } |
| 267 | |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 268 | GrVkDescriptorSetManager* dsm = GrVkDescriptorSetManager::CreateSamplerManager(fGpu, type, |
| 269 | visibilities); |
| 270 | fDescriptorSetManagers.emplace_back(dsm); |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 271 | *handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1); |
| 272 | } |
| 273 | |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 274 | VkDescriptorSetLayout GrVkResourceProvider::getUniformDSLayout() const { |
| 275 | SkASSERT(fUniformDSHandle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 276 | return fDescriptorSetManagers[fUniformDSHandle.toIndex()]->layout(); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | VkDescriptorSetLayout GrVkResourceProvider::getSamplerDSLayout( |
| 280 | const GrVkDescriptorSetManager::Handle& handle) const { |
| 281 | SkASSERT(handle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 282 | return fDescriptorSetManagers[handle.toIndex()]->layout(); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 283 | } |
| 284 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 285 | const GrVkDescriptorSet* GrVkResourceProvider::getUniformDescriptorSet() { |
| 286 | SkASSERT(fUniformDSHandle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 287 | return fDescriptorSetManagers[fUniformDSHandle.toIndex()]->getDescriptorSet(fGpu, |
| 288 | fUniformDSHandle); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 289 | } |
| 290 | |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 291 | const GrVkDescriptorSet* GrVkResourceProvider::getSamplerDescriptorSet( |
| 292 | const GrVkDescriptorSetManager::Handle& handle) { |
| 293 | SkASSERT(handle.isValid()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 294 | return fDescriptorSetManagers[handle.toIndex()]->getDescriptorSet(fGpu, handle); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 295 | } |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 296 | |
| 297 | void GrVkResourceProvider::recycleDescriptorSet(const GrVkDescriptorSet* descSet, |
| 298 | const GrVkDescriptorSetManager::Handle& handle) { |
| 299 | SkASSERT(descSet); |
| 300 | SkASSERT(handle.isValid()); |
| 301 | int managerIdx = handle.toIndex(); |
| 302 | SkASSERT(managerIdx < fDescriptorSetManagers.count()); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 303 | fDescriptorSetManagers[managerIdx]->recycleDescriptorSet(descSet); |
egdaniel | 778555c | 2016-05-02 06:50:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 306 | GrVkCommandPool* GrVkResourceProvider::findOrCreateCommandPool() { |
| 307 | std::unique_lock<std::recursive_mutex> lock(fBackgroundMutex); |
| 308 | GrVkCommandPool* result; |
| 309 | if (fAvailableCommandPools.count()) { |
| 310 | result = fAvailableCommandPools.back(); |
| 311 | fAvailableCommandPools.pop_back(); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 312 | } else { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 313 | result = GrVkCommandPool::Create(fGpu); |
Greg Daniel | 9b63dc8 | 2019-11-06 09:21:55 -0500 | [diff] [blame] | 314 | if (!result) { |
| 315 | return nullptr; |
| 316 | } |
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( |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 540 | GrVkGpu* gpu, const GrVkRenderTarget& target) : fLastReturnedIndex(0) { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 541 | fRenderPasses.emplace_back(new GrVkRenderPass()); |
| 542 | fRenderPasses[0]->initSimple(gpu, target); |
| 543 | } |
| 544 | |
| 545 | bool GrVkResourceProvider::CompatibleRenderPassSet::isCompatible( |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 546 | const GrVkRenderTarget& target) const { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 547 | // The first GrVkRenderpass should always exists since we create the basic load store |
| 548 | // render pass on create |
| 549 | SkASSERT(fRenderPasses[0]); |
| 550 | return fRenderPasses[0]->isCompatible(target); |
| 551 | } |
| 552 | |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 553 | GrVkRenderPass* GrVkResourceProvider::CompatibleRenderPassSet::getRenderPass( |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 554 | GrVkGpu* gpu, |
| 555 | const GrVkRenderPass::LoadStoreOps& colorOps, |
| 556 | const GrVkRenderPass::LoadStoreOps& stencilOps) { |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 557 | for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 558 | int idx = (i + fLastReturnedIndex) % fRenderPasses.count(); |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 559 | if (fRenderPasses[idx]->equalLoadStoreOps(colorOps, stencilOps)) { |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 560 | fLastReturnedIndex = idx; |
| 561 | return fRenderPasses[idx]; |
| 562 | } |
| 563 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 564 | GrVkRenderPass* renderPass = fRenderPasses.emplace_back(new GrVkRenderPass()); |
egdaniel | ce3bfb1 | 2016-08-26 11:05:13 -0700 | [diff] [blame] | 565 | renderPass->init(gpu, *this->getCompatibleRenderPass(), colorOps, stencilOps); |
egdaniel | 2feb093 | 2016-06-08 06:48:09 -0700 | [diff] [blame] | 566 | fLastReturnedIndex = fRenderPasses.count() - 1; |
| 567 | return renderPass; |
| 568 | } |
| 569 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 570 | void GrVkResourceProvider::CompatibleRenderPassSet::releaseResources(GrVkGpu* gpu) { |
egdaniel | d62e28b | 2016-06-07 08:43:30 -0700 | [diff] [blame] | 571 | for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 572 | if (fRenderPasses[i]) { |
| 573 | fRenderPasses[i]->unref(gpu); |
| 574 | fRenderPasses[i] = nullptr; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
| 580 | for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 581 | if (fRenderPasses[i]) { |
| 582 | fRenderPasses[i]->unrefAndAbandon(); |
| 583 | fRenderPasses[i] = nullptr; |
| 584 | } |
| 585 | } |
| 586 | } |