| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | #ifndef NCNN_PIPELINECACHE_H |
| 16 | #define NCNN_PIPELINECACHE_H |
| 17 | |
| 18 | #include "platform.h" |
| 19 | |
| 20 | #include "mat.h" |
| 21 | #include "gpu.h" |
| 22 | |
| 23 | namespace ncnn { |
| 24 | |
| 25 | #if NCNN_VULKAN |
| 26 | |
| 27 | class VulkanDevice; |
| 28 | class PipelineCachePrivate; |
| 29 | class NCNN_EXPORT PipelineCache |
| 30 | { |
| 31 | public: |
| 32 | explicit PipelineCache(const VulkanDevice* _vkdev); |
| 33 | |
| 34 | virtual ~PipelineCache(); |
| 35 | |
| 36 | void clear(); |
| 37 | |
| 38 | int get_pipeline(const uint32_t* spv_data, size_t spv_data_size, const std::vector<vk_specialization_type>& specializations, |
| 39 | uint32_t local_size_x, uint32_t local_size_y, uint32_t local_size_z, |
| 40 | VkShaderModule* shader_module, |
| 41 | VkDescriptorSetLayout* descriptorset_layout, |
| 42 | VkPipelineLayout* pipeline_layout, |
| 43 | VkPipeline* pipeline, |
| 44 | VkDescriptorUpdateTemplateKHR* descriptor_update_template, |
| 45 | ShaderInfo& shader_info) const; |
| 46 | |
| 47 | int get_pipeline(int shader_type_index, const Option& opt, const std::vector<vk_specialization_type>& specializations, |
| 48 | uint32_t local_size_x, uint32_t local_size_y, uint32_t local_size_z, |
| 49 | VkShaderModule* shader_module, |
| 50 | VkDescriptorSetLayout* descriptorset_layout, |
| 51 | VkPipelineLayout* pipeline_layout, |
| 52 | VkPipeline* pipeline, |
| 53 | VkDescriptorUpdateTemplateKHR* descriptor_update_template, |
| 54 | ShaderInfo& shader_info) const; |
| 55 | |
| 56 | protected: |
| 57 | int create_shader_module(int shader_type_index, const Option& opt, uint32_t local_size_x, uint32_t local_size_y, uint32_t local_size_z, |
| 58 | VkShaderModule* _shader_module, ShaderInfo& si) const; |
| 59 | |
| 60 | int new_pipeline(VkShaderModule shader_module, const ShaderInfo& shader_info, const std::vector<vk_specialization_type>& specializations, |
| 61 | VkDescriptorSetLayout* descriptorset_layout, |
| 62 | VkPipelineLayout* pipeline_layout, |
| 63 | VkPipeline* pipeline, |
| 64 | VkDescriptorUpdateTemplateKHR* descriptor_update_template) const; |
| 65 | |
| 66 | protected: |
| 67 | const VulkanDevice* vkdev; |
| 68 | |
| 69 | private: |
| 70 | PipelineCache(const PipelineCache&); |
| 71 | PipelineCache& operator=(const PipelineCache&); |
| 72 | |
| 73 | private: |
| 74 | PipelineCachePrivate* const d; |
| 75 | }; |
| 76 | |
| 77 | #endif // NCNN_VULKAN |
| 78 | |
| 79 | } // namespace ncnn |
| 80 | |
| 81 | #endif // NCNN_PIPELINECACHE_H |