1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3cb93a386Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cb93a386Sopenharmony_ci * you may not use this file except in compliance with the License. 5cb93a386Sopenharmony_ci * You may obtain a copy of the License at 6cb93a386Sopenharmony_ci * 7cb93a386Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cb93a386Sopenharmony_ci * 9cb93a386Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cb93a386Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cb93a386Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb93a386Sopenharmony_ci * See the License for the specific language governing permissions and 13cb93a386Sopenharmony_ci * limitations under the License. 14cb93a386Sopenharmony_ci */ 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ci#ifndef GrVkMemoryReclaimer_DEFINED 17cb93a386Sopenharmony_ci#define GrVkMemoryReclaimer_DEFINED 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_ci#include "include/gpu/vk/GrVkTypes.h" 20cb93a386Sopenharmony_ci 21cb93a386Sopenharmony_ci#include "include/core/SkExecutor.h" 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkImage.h" 24cb93a386Sopenharmony_ci#include "src/gpu/vk/GrVkBuffer.h" 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_cienum class ItemType { 27cb93a386Sopenharmony_ci BUFFER, 28cb93a386Sopenharmony_ci IMAGE 29cb93a386Sopenharmony_ci}; 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ciclass GrVkMemoryReclaimer { 32cb93a386Sopenharmony_cipublic: 33cb93a386Sopenharmony_ci struct WaitQueueItem { 34cb93a386Sopenharmony_ci const GrVkGpu* fGpu; 35cb93a386Sopenharmony_ci GrVkAlloc fAlloc; 36cb93a386Sopenharmony_ci ItemType fType; 37cb93a386Sopenharmony_ci union { 38cb93a386Sopenharmony_ci VkBuffer fBuffer; 39cb93a386Sopenharmony_ci VkImage fImage; 40cb93a386Sopenharmony_ci }; 41cb93a386Sopenharmony_ci }; 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci SkExecutor& getThreadPool(); 44cb93a386Sopenharmony_ci void setGpuMemoryAsyncReclaimerSwitch(bool enabled); 45cb93a386Sopenharmony_ci bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkBuffer& buffer); 46cb93a386Sopenharmony_ci bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image); 47cb93a386Sopenharmony_ci void flushGpuMemoryInWaitQueue(); 48cb93a386Sopenharmony_ciprivate: 49cb93a386Sopenharmony_ci void invokeParallelReclaiming(); 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci bool fEnabled = false; 52cb93a386Sopenharmony_ci const int fMemoryCountThreshold = 50; 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ci std::vector<WaitQueueItem> fWaitQueues; 55cb93a386Sopenharmony_ci}; 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_ci#endif 58