• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef RENDER_SERVICE_CORE_PIPELINE_RS_RDC_CONFIG_H
17 #define RENDER_SERVICE_CORE_PIPELINE_RS_RDC_CONFIG_H
18 
19 #include <cstring>
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
22 #include <mutex>
23 #include <vector>
24 
25 #include "platform/ohos/backend/rs_vulkan_context.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace RDC {
30 
31 const char NODE_CHUNKS[] = "chunks";
32 const char CONFIG_XML_FILE[] = "/etc/vkpipeline/config.xml";
33 const char PATH_CONFIG_DIR[] = "etc/vkpipeline/";
34 
35 struct XMLReader {
36     static std::string ReadAttrStr(const xmlNodePtr& src, const std::string& attr);
37     static xmlNodePtr FindChildNodeByPropName(const xmlNodePtr& src, const std::string& index);
38     static std::string ReadNodeValue(const xmlNodePtr& node);
39     static uint32_t ReadNodeValueInt(const xmlNodePtr& node);
40     static std::string GetConfigPath(const std::string& configFileName);
41 };
42 
43 struct VkRenderPassCreateInfoModel {
44     bool ReadXmlNode(const xmlNodePtr& createInfoNodePtr);
45     uint32_t resourceId;
46     VkRenderPass renderPass;
47 
48 private:
49     void ReadAttachments(const xmlNodePtr& node, std::vector<VkAttachmentDescription>& vec);
50     void ReadSubPass(const xmlNodePtr& node, std::vector<VkSubpassDescription>& vec);
51     VkAttachmentReference* ReadColorReference(const xmlNodePtr& node);
52     VkAttachmentReference* ReadDepthReference(const xmlNodePtr& node);
53 };
54 
55 struct VkDescriptorSetLayoutCreateInfoModel {
56     bool ReadXmlNode(const xmlNodePtr& createInfoNodePtr);
57     VkDescriptorSetLayout descriptorSetLayout;
58     uint32_t resourceId;
59 };
60 
61 struct VkPipelineLayoutCreateInfoModel {
62     bool ReadXmlNode(const xmlNodePtr& createInfoNodePtr);
63     VkPipelineLayoutCreateInfo createInfo;
64     uint32_t resourceId;
65     std::vector<uint32_t> setLayoutResourceIds;
66 };
67 
68 struct VkGraphicsPipelineCreateInfoModel {
69     bool ReadXmlNode(const xmlNodePtr& createInfoNodePtr);
70     VkGraphicsPipelineCreateInfo createInfo;
71     uint32_t renderPassResourceId;
72     uint32_t layoutResourceId;
73     std::string chunkIndex;
74     std::string vertexShaderFilePath;
75     std::string fragShaderFilePath;
76 
77 private:
78     void ReadVertexInputAttributs(const xmlNodePtr& node);
79     void ReadVertexInputBinding(const xmlNodePtr& node);
80     void ReadVertexInputState(const xmlNodePtr& node);
81     void ReadRasterizationState(const xmlNodePtr& node);
82     void ReadMultiSampleState(const xmlNodePtr& node);
83     void ReadColorBlendState(const xmlNodePtr& node);
84 
85     VkPipelineVertexInputStateCreateInfo vertexInputStateCI;
86     VkPipelineRasterizationStateCreateInfo rasterizationStateCI;
87     VkPipelineColorBlendStateCreateInfo colorBlendStateCI;
88     VkPipelineMultisampleStateCreateInfo multisampleStateCI;
89     std::vector<VkVertexInputBindingDescription> vertexInputBinding;
90     std::vector<VkVertexInputAttributeDescription> vertexInputAttributs;
91     std::vector<VkPipelineColorBlendAttachmentState> blendAttachmentState;
92 };
93 
94 struct RDCConfig {
RDCConfigRDCConfig95     RDCConfig() {}
96     virtual ~RDCConfig() = default;
97     bool LoadAndAnalyze(const std::string& configFile);
98 
99 private:
100     void LoadChunks(xmlNodePtr& chunkPtr);
101     void LoadRenderPassModels(const xmlNodePtr& chunksPtr);
102     void LoadDescriptorSetLayoutModels(const xmlNodePtr& chunksPtr);
103     void LoadPipelineLayoutModels(const xmlNodePtr& chunksPtr);
104     void LoadGraphicsPipelineModels(const xmlNodePtr& chunksPtr);
105     void CreatePipelines();
106     VkShaderModule LoadSpirvShader(std::string fileName);
107     std::shared_ptr<VkRenderPassCreateInfoModel> GetRenderPassModelByResourceId(uint32_t resourceId);
108     std::shared_ptr<VkDescriptorSetLayoutCreateInfoModel> GetDescriptorSetLayoutModelByResourceId(uint32_t resourceId);
109     std::shared_ptr<VkPipelineLayoutCreateInfoModel> GetPipelineLayoutModelByResourceId(uint32_t resourceId);
110     std::vector<std::shared_ptr<VkRenderPassCreateInfoModel>> renderPassModels;
111     std::vector<std::shared_ptr<VkDescriptorSetLayoutCreateInfoModel>> descriptorSetLayoutModels;
112     std::vector<std::shared_ptr<VkPipelineLayoutCreateInfoModel>> pipelineLayoutModels;
113     std::vector<std::shared_ptr<VkGraphicsPipelineCreateInfoModel>> graphicsPipelineModels;
114     void CloseXML();
115     xmlDocPtr pDoc = nullptr;
116     xmlNodePtr pRoot = nullptr;
117     std::mutex xmlMut;
118     VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
119     VkPipeline pipeline = VK_NULL_HANDLE;
120 };
121 } // namespace RDC
122 } // namespace Rosen
123 } // namespace OHOS
124 
125 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_RDC_CONFIG_H
126