pipelinecache.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifndef NCNN_PIPELINECACHE_H
  15. #define NCNN_PIPELINECACHE_H
  16. #include "platform.h"
  17. #if NCNN_VULKAN
  18. #include <vulkan/vulkan.h>
  19. #endif // NCNN_VULKAN
  20. #include "mat.h"
  21. #include "gpu.h"
  22. namespace ncnn {
  23. #if NCNN_VULKAN
  24. class VulkanDevice;
  25. class PipelineCachePrivate;
  26. class NCNN_EXPORT PipelineCache
  27. {
  28. public:
  29. explicit PipelineCache(const VulkanDevice* _vkdev);
  30. virtual ~PipelineCache();
  31. void clear();
  32. int get_pipeline(const uint32_t* spv_data, size_t spv_data_size, const std::vector<vk_specialization_type>& specializations,
  33. uint32_t local_size_x, uint32_t local_size_y, uint32_t local_size_z,
  34. VkShaderModule* shader_module,
  35. VkDescriptorSetLayout* descriptorset_layout,
  36. VkPipelineLayout* pipeline_layout,
  37. VkPipeline* pipeline,
  38. VkDescriptorUpdateTemplateKHR* descriptor_update_template,
  39. ShaderInfo& shader_info) const;
  40. int get_pipeline(int shader_type_index, const Option& opt, const std::vector<vk_specialization_type>& specializations,
  41. uint32_t local_size_x, uint32_t local_size_y, uint32_t local_size_z,
  42. VkShaderModule* shader_module,
  43. VkDescriptorSetLayout* descriptorset_layout,
  44. VkPipelineLayout* pipeline_layout,
  45. VkPipeline* pipeline,
  46. VkDescriptorUpdateTemplateKHR* descriptor_update_template,
  47. ShaderInfo& shader_info) const;
  48. protected:
  49. 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,
  50. VkShaderModule* _shader_module, ShaderInfo& si) const;
  51. int new_pipeline(VkShaderModule shader_module, const ShaderInfo& shader_info, const std::vector<vk_specialization_type>& specializations,
  52. VkDescriptorSetLayout* descriptorset_layout,
  53. VkPipelineLayout* pipeline_layout,
  54. VkPipeline* pipeline,
  55. VkDescriptorUpdateTemplateKHR* descriptor_update_template) const;
  56. protected:
  57. const VulkanDevice* vkdev;
  58. private:
  59. PipelineCache(const PipelineCache&);
  60. PipelineCache& operator=(const PipelineCache&);
  61. private:
  62. PipelineCachePrivate* const d;
  63. };
  64. #endif // NCNN_VULKAN
  65. } // namespace ncnn
  66. #endif // NCNN_PIPELINECACHE_H