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 #include "rs_vk_pipeline_config.h"
17
18 #include <cstdint>
19 #include <fstream>
20 #include <memory>
21
22 #include "config_policy_utils.h"
23 #include "platform/common/rs_log.h"
24 #include "rs_trace.h"
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace RDC {
29 static const std::streamsize SHADER_MAX_SIZE = 102400; // 100K
30 static constexpr int DECIMAL_BASE = 10;
31
FindChildNodeByPropName(const xmlNodePtr & src,const std::string & index)32 xmlNodePtr XMLReader::FindChildNodeByPropName(const xmlNodePtr& src, const std::string& index)
33 {
34 if (src == nullptr) {
35 RS_LOGE(
36 "RDC [%{public}s] can not found node by prop name %{public}s, src is null! \n", __func__, index.c_str());
37 return nullptr;
38 }
39 xmlNodePtr startPtr = src->children;
40 while (startPtr != nullptr) {
41 if (XMLReader::ReadAttrStr(startPtr, std::string("name")) == index) {
42 return startPtr;
43 }
44 startPtr = startPtr->next;
45 }
46 RS_LOGE("RDC [%{public}s] can not found node by prop name %{public}s! \n", __func__, index.c_str());
47 return nullptr;
48 }
49
ReadNodeValue(const xmlNodePtr & node)50 std::string XMLReader::ReadNodeValue(const xmlNodePtr& node)
51 {
52 if (node == nullptr) {
53 RS_LOGE("RDC read xml node error, node is null");
54 return "";
55 }
56 xmlChar* content = xmlNodeGetContent(node);
57 if (content == nullptr) {
58 RS_LOGE("RDC read xml node error, content is null");
59 return "";
60 }
61
62 std::string contentStr = reinterpret_cast<const char*>(content);
63 xmlFree(content);
64
65 return contentStr;
66 }
67
ReadNodeValueInt(const xmlNodePtr & node)68 uint32_t XMLReader::ReadNodeValueInt(const xmlNodePtr& node)
69 {
70 std::string nodeValueStr = ReadNodeValue(node);
71 if (nodeValueStr.empty()) {
72 RS_LOGE("RDC read xml node error, read node value is empty");
73 return 0;
74 }
75 char* end;
76 unsigned long long value = std::strtoull(nodeValueStr.c_str(), &end, DECIMAL_BASE);
77 if (*end != '\0') {
78 RS_LOGE("RDC read xml node error, read node value is not end");
79 return 0;
80 }
81 if (value > UINT32_MAX) {
82 RS_LOGE("RDC read xml node error, read node value is overflow");
83 return 0;
84 }
85 return static_cast<uint32_t>(value);
86 }
87
ReadAttrStr(const xmlNodePtr & src,const std::string & attr)88 std::string XMLReader::ReadAttrStr(const xmlNodePtr& src, const std::string& attr)
89 {
90 auto result = reinterpret_cast<char*>((xmlGetProp(src, BAD_CAST(attr.c_str()))));
91 if (result == nullptr) {
92 RS_LOGE("RDC [%{public}s] can not found attribute %{public}s! \n", __func__, attr.c_str());
93 return std::string("");
94 }
95 std::string str(result);
96 xmlFree(result);
97 return str;
98 }
99
GetConfigPath(const std::string & configFileName)100 std::string XMLReader::GetConfigPath(const std::string& configFileName)
101 {
102 char buf[PATH_MAX];
103 char* configPath = GetOneCfgFile(configFileName.c_str(), buf, PATH_MAX);
104 char tmpPath[PATH_MAX] = { 0 };
105 if (!configPath || strlen(configPath) == 0 || strlen(configPath) >= PATH_MAX || !realpath(configPath, tmpPath)) {
106 RS_LOGI("RDC can not get customization config file");
107 return "/system/" + configFileName;
108 }
109 return std::string(tmpPath);
110 }
111
GetRenderPassModelByResourceId(uint32_t resourceId)112 std::shared_ptr<VkRenderPassCreateInfoModel> RDCConfig::GetRenderPassModelByResourceId(uint32_t resourceId)
113 {
114 auto iter = std::find_if(renderPassModels.begin(), renderPassModels.end(),
115 [&resourceId](auto model) { return model != nullptr && model->resourceId == resourceId; });
116 if (iter == renderPassModels.end()) {
117 RS_LOGE("RDC [%{public}s] can not found resourceId:%{public}d! \n", __func__, resourceId);
118 return nullptr;
119 }
120 return *iter;
121 }
122
GetDescriptorSetLayoutModelByResourceId(uint32_t resourceId)123 std::shared_ptr<VkDescriptorSetLayoutCreateInfoModel> RDCConfig::GetDescriptorSetLayoutModelByResourceId(
124 uint32_t resourceId)
125 {
126 auto iter = std::find_if(descriptorSetLayoutModels.begin(), descriptorSetLayoutModels.end(),
127 [&resourceId](auto model) { return model != nullptr && model->resourceId == resourceId; });
128 if (iter == descriptorSetLayoutModels.end()) {
129 RS_LOGE("RDC [%{public}s] can not found resourceId:%{public}d! \n", __func__, resourceId);
130 return nullptr;
131 }
132 return *iter;
133 }
134
GetPipelineLayoutModelByResourceId(uint32_t resourceId)135 std::shared_ptr<VkPipelineLayoutCreateInfoModel> RDCConfig::GetPipelineLayoutModelByResourceId(uint32_t resourceId)
136 {
137 auto iter = std::find_if(pipelineLayoutModels.begin(), pipelineLayoutModels.end(),
138 [&resourceId](auto model) { return model != nullptr && model->resourceId == resourceId; });
139 if (iter == pipelineLayoutModels.end()) {
140 RS_LOGE("RDC [%{public}s] can not found resourceId:%{public}d! \n", __func__, resourceId);
141 return nullptr;
142 }
143 return *iter;
144 }
145
LoadRenderPassModels(const xmlNodePtr & chunkPtr)146 void RDCConfig::LoadRenderPassModels(const xmlNodePtr& chunkPtr)
147 {
148 auto chunIndexStr = XMLReader::ReadAttrStr(chunkPtr, std::string("index"));
149 RS_LOGI("RDC Begin read one vkCreateRenderPass, index!:[%{public}s]} \n", chunIndexStr.c_str());
150
151 auto createInfo = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("CreateInfo"));
152 if (!createInfo) {
153 RS_LOGE("RDC read createInfo fail, createInfo is null! \n");
154 return;
155 }
156 std::shared_ptr<VkRenderPassCreateInfoModel> createInfoModel = std::make_shared<VkRenderPassCreateInfoModel>();
157 if (createInfoModel->ReadXmlNode(createInfo)) {
158 renderPassModels.push_back(createInfoModel);
159 auto renderPassPtr = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("RenderPass"));
160 if (renderPassPtr == nullptr) {
161 RS_LOGE("RDC [%{public}s] input renderPassPtr node is null! \n", __func__);
162 } else {
163 createInfoModel->resourceId = XMLReader::ReadNodeValueInt(renderPassPtr);
164 }
165 } else {
166 RS_LOGE("RDC read createInfoModel fail! \n");
167 }
168 }
169
LoadDescriptorSetLayoutModels(const xmlNodePtr & chunkPtr)170 void RDCConfig::LoadDescriptorSetLayoutModels(const xmlNodePtr& chunkPtr)
171 {
172 auto chunIndexStr = XMLReader::ReadAttrStr(chunkPtr, std::string("index"));
173 RS_LOGI("RDC Begin read one vkCreateDescriptorSetLayout, index!:[%{public}s]} \n", chunIndexStr.c_str());
174
175 auto createInfo = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("CreateInfo"));
176 if (!createInfo) {
177 RS_LOGE("RDC read createInfo fail, createInfo is null! \n");
178 return;
179 }
180 std::shared_ptr<VkDescriptorSetLayoutCreateInfoModel> createInfoModel =
181 std::make_shared<VkDescriptorSetLayoutCreateInfoModel>();
182 if (createInfoModel->ReadXmlNode(createInfo)) {
183 descriptorSetLayoutModels.push_back(createInfoModel);
184 auto setLayoutPtr = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("SetLayout"));
185 if (setLayoutPtr == nullptr) {
186 RS_LOGE("RDC [%{public}s] input setLayoutPtr node is null! \n", __func__);
187 } else {
188 createInfoModel->resourceId = XMLReader::ReadNodeValueInt(setLayoutPtr);
189 }
190 } else {
191 RS_LOGE("RDC read createInfoModel fail! \n");
192 }
193 }
194
LoadPipelineLayoutModels(const xmlNodePtr & chunkPtr)195 void RDCConfig::LoadPipelineLayoutModels(const xmlNodePtr& chunkPtr)
196 {
197 auto chunIndexStr = XMLReader::ReadAttrStr(chunkPtr, std::string("index"));
198 RS_LOGI("RDC Begin read one vkCreatePipelineLayout, index!:[%{public}s]} \n", chunIndexStr.c_str());
199
200 auto createInfo = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("CreateInfo"));
201 if (!createInfo) {
202 RS_LOGE("RDC read createInfo fail, createInfo is null! \n");
203 return;
204 }
205 std::shared_ptr<VkPipelineLayoutCreateInfoModel> createInfoModel =
206 std::make_shared<VkPipelineLayoutCreateInfoModel>();
207 if (createInfoModel->ReadXmlNode(createInfo)) {
208 pipelineLayoutModels.push_back(createInfoModel);
209 auto pipelineLayoutPtr = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("PipelineLayout"));
210 if (pipelineLayoutPtr == nullptr) {
211 RS_LOGE("RDC [%{public}s] input pipelineLayoutPtr node is null! \n", __func__);
212 } else {
213 createInfoModel->resourceId = XMLReader::ReadNodeValueInt(pipelineLayoutPtr);
214 }
215 } else {
216 RS_LOGE("RDC read createInfoModel fail! \n");
217 }
218 }
219
LoadGraphicsPipelineModels(const xmlNodePtr & chunkPtr)220 void RDCConfig::LoadGraphicsPipelineModels(const xmlNodePtr& chunkPtr)
221 {
222 auto chunIndexStr = XMLReader::ReadAttrStr(chunkPtr, std::string("index"));
223 RS_LOGI("RDC Begin read one vkCreateGraphicsPipelines, index!:[%{public}s]} \n", chunIndexStr.c_str());
224
225 auto createInfo = XMLReader::FindChildNodeByPropName(chunkPtr, std::string("CreateInfo"));
226 if (!createInfo) {
227 RS_LOGE("RDC read createInfo fail, createInfo is null! \n");
228 return;
229 }
230 std::shared_ptr<VkGraphicsPipelineCreateInfoModel> createInfoModel =
231 std::make_shared<VkGraphicsPipelineCreateInfoModel>();
232 if (createInfoModel->ReadXmlNode(createInfo)) {
233 createInfoModel->chunkIndex = chunIndexStr;
234 graphicsPipelineModels.push_back(createInfoModel);
235 } else {
236 RS_LOGE("RDC read createInfoModel fail! \n");
237 }
238 }
239
LoadAndAnalyze(const std::string & configFile)240 bool RDCConfig::LoadAndAnalyze(const std::string& configFile)
241 {
242 RS_TRACE_FUNC();
243 if (OHOS::Rosen::RsVulkanContext::GetSingleton().GetRsVulkanInterface().GetDevice() == VK_NULL_HANDLE) {
244 RS_LOGE("RDC LoadAndAnalyze failed device is null. \n");
245 return false;
246 }
247 auto configFilePath = XMLReader::GetConfigPath(configFile);
248 std::lock_guard<std::mutex> lock(xmlMut);
249 xmlKeepBlanksDefault(0);
250 pDoc = xmlReadFile(configFilePath.c_str(), "", XML_PARSE_RECOVER);
251 if (pDoc == nullptr) {
252 RS_LOGE("RDC read xml failed \n");
253 CloseXML();
254 return false;
255 }
256 pRoot = xmlDocGetRootElement(pDoc);
257 if (pRoot == nullptr) {
258 RS_LOGE("RDC get xml root failed \n");
259 CloseXML();
260 return false;
261 }
262 xmlNodePtr chunksPtr = pRoot->children;
263 while (chunksPtr != nullptr) {
264 auto name = chunksPtr->name;
265 if (xmlStrEqual(name, BAD_CAST(NODE_CHUNKS)) == 1) {
266 break;
267 }
268 chunksPtr = chunksPtr->next;
269 }
270 if (chunksPtr == nullptr) {
271 RS_LOGE("RDC get xml chunksPtr failed \n");
272 CloseXML();
273 return false;
274 }
275 LoadChunks(chunksPtr->children);
276 CreatePipelines();
277 CloseXML();
278 RS_LOGI("RDC read xml finish");
279 return true;
280 }
281
LoadChunks(xmlNodePtr & chunkPtr)282 void RDCConfig::LoadChunks(xmlNodePtr& chunkPtr)
283 {
284 while (chunkPtr != nullptr) {
285 if (XMLReader::ReadAttrStr(chunkPtr, std::string("name")) == "vkCreateRenderPass") {
286 LoadRenderPassModels(chunkPtr);
287 } else if (XMLReader::ReadAttrStr(chunkPtr, std::string("name")) == "vkCreateDescriptorSetLayout") {
288 LoadDescriptorSetLayoutModels(chunkPtr);
289 } else if (XMLReader::ReadAttrStr(chunkPtr, std::string("name")) == "vkCreatePipelineLayout") {
290 LoadPipelineLayoutModels(chunkPtr);
291 } else if (XMLReader::ReadAttrStr(chunkPtr, std::string("name")) == "vkCreateGraphicsPipelines") {
292 LoadGraphicsPipelineModels(chunkPtr);
293 }
294 chunkPtr = chunkPtr->next;
295 }
296 }
297
CreatePipelines()298 void RDCConfig::CreatePipelines()
299 {
300 RS_TRACE_FUNC();
301 for (auto pipelineModel : graphicsPipelineModels) {
302 auto renderPassModel = GetRenderPassModelByResourceId(pipelineModel->renderPassResourceId);
303 if (renderPassModel == nullptr) {
304 continue;
305 }
306 pipelineModel->createInfo.renderPass = renderPassModel->renderPass;
307 auto layoutModel = GetPipelineLayoutModelByResourceId(pipelineModel->layoutResourceId);
308 if (layoutModel == nullptr) {
309 continue;
310 }
311 std::vector<VkDescriptorSetLayout> descriptorSetLayout(layoutModel->setLayoutResourceIds.size());
312 for (size_t i = 0; i < layoutModel->setLayoutResourceIds.size(); ++i) {
313 auto model = GetDescriptorSetLayoutModelByResourceId(layoutModel->setLayoutResourceIds[i]);
314 if (model == nullptr) {
315 RS_LOGE("RDC [%{public}s] input model is null! \n", __func__);
316 continue;
317 }
318 descriptorSetLayout[i] = model->descriptorSetLayout;
319 }
320 layoutModel->createInfo.pSetLayouts = descriptorSetLayout.data();
321 auto& vkContext = OHOS::Rosen::RsVulkanContext::GetSingleton().GetRsVulkanInterface();
322 VkDevice device = vkContext.GetDevice();
323 auto result = vkCreatePipelineLayout(device, &(layoutModel->createInfo), nullptr, &pipelineLayout);
324 if (result != VK_SUCCESS) {
325 RS_LOGE("RDC [%{public}s] vkCreatePipelineLayout fail, result: %{public}d", __func__, result);
326 continue;
327 }
328 pipelineModel->createInfo.layout = pipelineLayout;
329 std::vector<VkPipelineShaderStageCreateInfo> shaderStages(pipelineModel->createInfo.stageCount);
330 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
331 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
332 shaderStages[0].module = LoadSpirvShader(pipelineModel->vertexShaderFilePath);
333 shaderStages[0].pName = "main";
334 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
335 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
336 shaderStages[1].module = LoadSpirvShader(pipelineModel->fragShaderFilePath);
337 shaderStages[1].pName = "main";
338 pipelineModel->createInfo.pStages = shaderStages.data();
339 result = vkCreateGraphicsPipelines(device, nullptr, 1, &(pipelineModel->createInfo), nullptr, &pipeline);
340
341 vkDestroyShaderModule(device, shaderStages[0].module, nullptr);
342 vkDestroyShaderModule(device, shaderStages[1].module, nullptr);
343 vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
344 vkDestroyPipeline(device, pipeline, nullptr);
345 if (result != VK_SUCCESS) {
346 RS_LOGE("RDC CreatePipelines fail, result: %{public}d", result);
347 }
348 }
349 }
350
ReadAttachments(const xmlNodePtr & node,std::vector<VkAttachmentDescription> & vec)351 void VkRenderPassCreateInfoModel::ReadAttachments(const xmlNodePtr& node, std::vector<VkAttachmentDescription>& vec)
352 {
353 auto pAttachmentsPtr = XMLReader::FindChildNodeByPropName(node, std::string("pAttachments"));
354 if (pAttachmentsPtr == nullptr) {
355 RS_LOGE("RDC [%{public}s] pAttachmentsPtr is nullptr.", __func__);
356 return;
357 }
358 auto VkAttachmentDescriptionPtr = pAttachmentsPtr->children;
359 for (size_t i = 0; i < vec.size(); i++) {
360 if (VkAttachmentDescriptionPtr == nullptr) {
361 RS_LOGE("RDC [%{public}s] VkAttachmentDescriptionPtr is nullptr.", __func__);
362 return;
363 }
364 auto flagsPtr = XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("flags"));
365 vec[i].flags = static_cast<VkAttachmentDescriptionFlags>(XMLReader::ReadNodeValueInt(flagsPtr));
366
367 auto formatPtr = XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("format"));
368 vec[i].format = static_cast<VkFormat>(XMLReader::ReadNodeValueInt(formatPtr));
369
370 auto samplesPtr = XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("samples"));
371 vec[i].samples = static_cast<VkSampleCountFlagBits>(XMLReader::ReadNodeValueInt(samplesPtr));
372
373 auto loadOpPtr = XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("loadOp"));
374 vec[i].loadOp = static_cast<VkAttachmentLoadOp>(XMLReader::ReadNodeValueInt(loadOpPtr));
375
376 auto storeOpPtr = XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("storeOp"));
377 vec[i].storeOp = static_cast<VkAttachmentStoreOp>(XMLReader::ReadNodeValueInt(storeOpPtr));
378
379 auto stencilLoadOpPtr =
380 XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("stencilLoadOp"));
381 vec[i].stencilLoadOp = static_cast<VkAttachmentLoadOp>(XMLReader::ReadNodeValueInt(stencilLoadOpPtr));
382
383 auto stencilStoreOpPtr =
384 XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("stencilStoreOp"));
385 vec[i].stencilStoreOp = static_cast<VkAttachmentStoreOp>(XMLReader::ReadNodeValueInt(stencilStoreOpPtr));
386
387 auto initialLayoutPtr =
388 XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("initialLayout"));
389 vec[i].initialLayout = static_cast<VkImageLayout>(XMLReader::ReadNodeValueInt(initialLayoutPtr));
390
391 auto finalLayoutPtr =
392 XMLReader::FindChildNodeByPropName(VkAttachmentDescriptionPtr, std::string("finalLayout"));
393 vec[i].finalLayout = static_cast<VkImageLayout>(XMLReader::ReadNodeValueInt(finalLayoutPtr));
394
395 VkAttachmentDescriptionPtr = VkAttachmentDescriptionPtr->next;
396 }
397 }
398
ReadColorReference(const xmlNodePtr & node)399 VkAttachmentReference* VkRenderPassCreateInfoModel::ReadColorReference(const xmlNodePtr& node)
400 {
401 VkAttachmentReference* colorReference = new VkAttachmentReference();
402 auto pColorAttachmentsPtr = XMLReader::FindChildNodeByPropName(node, std::string("pColorAttachments"));
403 if (pColorAttachmentsPtr == nullptr) {
404 delete colorReference;
405 colorReference = nullptr;
406 return nullptr;
407 }
408 auto colorAttachmentPtr =
409 XMLReader::FindChildNodeByPropName(pColorAttachmentsPtr->children, std::string("attachment"));
410 if (colorAttachmentPtr == nullptr) {
411 delete colorReference;
412 colorReference = nullptr;
413 return nullptr;
414 }
415 colorReference->attachment = XMLReader::ReadNodeValueInt(colorAttachmentPtr);
416 auto colorLayoutPtr = XMLReader::FindChildNodeByPropName(pColorAttachmentsPtr->children, std::string("layout"));
417 if (colorLayoutPtr == nullptr) {
418 delete colorReference;
419 colorReference = nullptr;
420 return nullptr;
421 }
422 colorReference->layout = static_cast<VkImageLayout>(XMLReader::ReadNodeValueInt(colorLayoutPtr));
423 return colorReference;
424 }
425
ReadDepthReference(const xmlNodePtr & node)426 VkAttachmentReference* VkRenderPassCreateInfoModel::ReadDepthReference(const xmlNodePtr& node)
427 {
428 VkAttachmentReference* depthReference = new VkAttachmentReference();
429 auto pDepthStencilAttachmentsPtr = XMLReader::FindChildNodeByPropName(node, std::string("pDepthStencilAttachment"));
430 if (pDepthStencilAttachmentsPtr == nullptr) {
431 delete depthReference;
432 depthReference = nullptr;
433 return nullptr;
434 }
435 auto attachmentPtr = XMLReader::FindChildNodeByPropName(pDepthStencilAttachmentsPtr, std::string("attachment"));
436 if (attachmentPtr == nullptr) {
437 delete depthReference;
438 depthReference = nullptr;
439 return nullptr;
440 }
441 depthReference->attachment = XMLReader::ReadNodeValueInt(attachmentPtr);
442
443 auto layoutPtr = XMLReader::FindChildNodeByPropName(pDepthStencilAttachmentsPtr, std::string("layout"));
444 if (layoutPtr == nullptr) {
445 delete depthReference;
446 depthReference = nullptr;
447 return nullptr;
448 }
449 depthReference->layout = static_cast<VkImageLayout>(XMLReader::ReadNodeValueInt(layoutPtr));
450 return depthReference;
451 }
452
ReadSubPass(const xmlNodePtr & node,std::vector<VkSubpassDescription> & vec)453 void VkRenderPassCreateInfoModel::ReadSubPass(const xmlNodePtr& node, std::vector<VkSubpassDescription>& vec)
454 {
455 auto pSubpassesPtr = XMLReader::FindChildNodeByPropName(node, std::string("pSubpasses"));
456 if (pSubpassesPtr == nullptr) {
457 RS_LOGE("RDC [%{public}s] pSubpassesPtr is nullptr.", __func__);
458 return;
459 }
460 auto VkSubpassDescriptionPtr = pSubpassesPtr->children;
461 for (size_t i = 0; i < vec.size(); i++) {
462 if (VkSubpassDescriptionPtr == nullptr) {
463 RS_LOGE("RDC [%{public}s] VkSubpassDescriptionPtr is nullptr.", __func__);
464 return;
465 }
466 auto flagsPtr = XMLReader::FindChildNodeByPropName(VkSubpassDescriptionPtr, std::string("flags"));
467 vec[i].flags = static_cast<VkSubpassDescriptionFlags>(XMLReader::ReadNodeValueInt(flagsPtr));
468
469 auto pipelineBindPointPtr =
470 XMLReader::FindChildNodeByPropName(VkSubpassDescriptionPtr, std::string("pipelineBindPoint"));
471 vec[i].pipelineBindPoint = static_cast<VkPipelineBindPoint>(XMLReader::ReadNodeValueInt(pipelineBindPointPtr));
472
473 auto inputAttachmentCountPtr =
474 XMLReader::FindChildNodeByPropName(VkSubpassDescriptionPtr, std::string("inputAttachmentCount"));
475 vec[i].inputAttachmentCount =
476 static_cast<VkPipelineBindPoint>(XMLReader::ReadNodeValueInt(inputAttachmentCountPtr));
477
478 auto colorAttachmentCountPtr =
479 XMLReader::FindChildNodeByPropName(VkSubpassDescriptionPtr, std::string("colorAttachmentCount"));
480 vec[i].colorAttachmentCount =
481 static_cast<VkPipelineBindPoint>(XMLReader::ReadNodeValueInt(colorAttachmentCountPtr));
482
483 vec[i].pColorAttachments = ReadColorReference(VkSubpassDescriptionPtr);
484 vec[i].pDepthStencilAttachment = ReadDepthReference(VkSubpassDescriptionPtr);
485
486 auto preserveAttachmentCountPtr =
487 XMLReader::FindChildNodeByPropName(VkSubpassDescriptionPtr, std::string("preserveAttachmentCount"));
488 if (preserveAttachmentCountPtr == nullptr) {
489 continue;
490 }
491 vec[i].preserveAttachmentCount =
492 static_cast<VkImageLayout>(XMLReader::ReadNodeValueInt(preserveAttachmentCountPtr));
493
494 VkSubpassDescriptionPtr = VkSubpassDescriptionPtr->next;
495 }
496 }
497
ReadXmlNode(const xmlNodePtr & createInfoNodePtr)498 bool VkRenderPassCreateInfoModel::ReadXmlNode(const xmlNodePtr& createInfoNodePtr)
499 {
500 VkRenderPassCreateInfo renderPassCI {};
501 renderPassCI.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
502 auto attachmentCountPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("attachmentCount"));
503 if (attachmentCountPtr == nullptr) {
504 return false;
505 }
506 renderPassCI.attachmentCount = XMLReader::ReadNodeValueInt(attachmentCountPtr);
507 std::vector<VkAttachmentDescription> attachments(renderPassCI.attachmentCount);
508 ReadAttachments(createInfoNodePtr, attachments);
509 renderPassCI.pAttachments = attachments.data();
510
511 auto subpassCountPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("subpassCount"));
512 if (subpassCountPtr == nullptr) {
513 return false;
514 }
515 renderPassCI.subpassCount = XMLReader::ReadNodeValueInt(subpassCountPtr);
516 std::vector<VkSubpassDescription> subpassDescription(renderPassCI.subpassCount);
517 ReadSubPass(createInfoNodePtr, subpassDescription);
518 renderPassCI.pSubpasses = subpassDescription.data();
519
520 renderPassCI.dependencyCount = 0;
521
522 auto& vkContext = OHOS::Rosen::RsVulkanContext::GetSingleton().GetRsVulkanInterface();
523 VkDevice device = vkContext.GetDevice();
524 auto result = vkCreateRenderPass(device, &renderPassCI, nullptr, &renderPass);
525 for (auto subPass : subpassDescription) {
526 if (subPass.pColorAttachments) {
527 delete subPass.pColorAttachments;
528 subPass.pColorAttachments = nullptr;
529 }
530 if (subPass.pDepthStencilAttachment) {
531 delete subPass.pDepthStencilAttachment;
532 subPass.pDepthStencilAttachment = nullptr;
533 }
534 }
535 if (result != VK_SUCCESS) {
536 RS_LOGE("RDC [%{public}s] vkCreateRenderPass fail, result: %{public}d! \n", __func__, result);
537 return false;
538 }
539 return true;
540 }
541
ReadXmlNode(const xmlNodePtr & createInfoNodePtr)542 bool VkDescriptorSetLayoutCreateInfoModel::ReadXmlNode(const xmlNodePtr& createInfoNodePtr)
543 {
544 VkDescriptorSetLayoutCreateInfo descriptorLayoutCI {};
545 descriptorLayoutCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
546 descriptorLayoutCI.pNext = nullptr;
547 descriptorLayoutCI.flags = 0;
548
549 auto bindingCountPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("bindingCount"));
550 if (bindingCountPtr == nullptr) {
551 return false;
552 }
553 descriptorLayoutCI.bindingCount = XMLReader::ReadNodeValueInt(bindingCountPtr);
554 std::vector<VkDescriptorSetLayoutBinding> layoutBinding(descriptorLayoutCI.bindingCount);
555
556 auto pBindingsPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("pBindings"));
557 if (pBindingsPtr == nullptr) {
558 RS_LOGE("RDC [%{public}s] pBindingsPtr is nullptr.", __func__);
559 return false;
560 }
561 auto VkDescriptorSetLayoutBindingPtr = pBindingsPtr->children;
562 for (size_t i = 0; i < descriptorLayoutCI.bindingCount; i++) {
563 if (VkDescriptorSetLayoutBindingPtr == nullptr) {
564 RS_LOGE("RDC [%{public}s] VkDescriptorSetLayoutBindingPtr is nullptr.", __func__);
565 return false;
566 }
567 auto bindingPtr = XMLReader::FindChildNodeByPropName(VkDescriptorSetLayoutBindingPtr, std::string("binding"));
568 layoutBinding[i].binding = XMLReader::ReadNodeValueInt(bindingPtr);
569
570 auto descriptorTypePtr =
571 XMLReader::FindChildNodeByPropName(VkDescriptorSetLayoutBindingPtr, std::string("descriptorType"));
572 layoutBinding[i].descriptorType = static_cast<VkDescriptorType>(XMLReader::ReadNodeValueInt(descriptorTypePtr));
573
574 auto descriptorCountPtr =
575 XMLReader::FindChildNodeByPropName(VkDescriptorSetLayoutBindingPtr, std::string("descriptorCount"));
576 layoutBinding[i].descriptorCount =
577 static_cast<VkDescriptorType>(XMLReader::ReadNodeValueInt(descriptorTypePtr));
578
579 auto stageFlagsPtr =
580 XMLReader::FindChildNodeByPropName(VkDescriptorSetLayoutBindingPtr, std::string("stageFlags"));
581 layoutBinding[i].stageFlags = static_cast<VkShaderStageFlags>(XMLReader::ReadNodeValueInt(stageFlagsPtr));
582
583 layoutBinding[i].pImmutableSamplers = nullptr;
584 VkDescriptorSetLayoutBindingPtr = VkDescriptorSetLayoutBindingPtr->next;
585 }
586 descriptorLayoutCI.pBindings = layoutBinding.data();
587
588 auto& vkContext = OHOS::Rosen::RsVulkanContext::GetSingleton().GetRsVulkanInterface();
589 VkDevice device = vkContext.GetDevice();
590 auto result = vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayout);
591 if (result != VK_SUCCESS) {
592 RS_LOGE("RDC [%{public}s] vkCreateDescriptorSetLayout fail, result: %{public}d! \n", __func__, result);
593 return false;
594 }
595 return true;
596 }
597
ReadXmlNode(const xmlNodePtr & createInfoNodePtr)598 bool VkPipelineLayoutCreateInfoModel::ReadXmlNode(const xmlNodePtr& createInfoNodePtr)
599 {
600 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
601 createInfo.pNext = nullptr;
602 createInfo.flags = 0;
603 createInfo.pushConstantRangeCount = 0;
604 createInfo.pPushConstantRanges = nullptr;
605
606 auto setLayoutCountPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("setLayoutCount"));
607 if (setLayoutCountPtr == nullptr) {
608 RS_LOGE("RDC [%{public}s] input setLayoutCountPtr node is null! \n", __func__);
609 return false;
610 }
611 createInfo.setLayoutCount = XMLReader::ReadNodeValueInt(setLayoutCountPtr);
612 RS_LOGI("RDC [%{public}s] read setLayoutCount succ: %{public}d! \n", __func__, createInfo.setLayoutCount);
613
614 auto pSetLayoutsPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("pSetLayouts"));
615 if (pSetLayoutsPtr == nullptr) {
616 RS_LOGE("RDC [%{public}s] input pSetLayoutsPtr node is null! \n", __func__);
617 return false;
618 }
619 auto layoutResourceIdPtr = pSetLayoutsPtr->children;
620 for (size_t i = 0; i < createInfo.setLayoutCount; i++) {
621 if (layoutResourceIdPtr == nullptr) {
622 RS_LOGE("RDC [%{public}s] input layoutResourceIdPtr node is null! \n", __func__);
623 return false;
624 }
625 setLayoutResourceIds.push_back(XMLReader::ReadNodeValueInt(layoutResourceIdPtr));
626 layoutResourceIdPtr = layoutResourceIdPtr->next;
627 }
628 return true;
629 }
630
LoadSpirvShader(std::string fileName)631 VkShaderModule RDCConfig::LoadSpirvShader(std::string fileName)
632 {
633 auto& vkContext = OHOS::Rosen::RsVulkanContext::GetSingleton().GetRsVulkanInterface();
634 VkDevice device = vkContext.GetDevice();
635 std::streamsize shaderSize;
636 char* shaderCode { nullptr };
637
638 char realPath[PATH_MAX] = { 0 };
639 if (fileName.length() == 0 || fileName.length() >= PATH_MAX || !realpath(fileName.c_str(), realPath)) {
640 RS_LOGE("RDC can not get spirv shader file.");
641 return VK_NULL_HANDLE;
642 }
643 std::ifstream is(realPath, std::ios::binary | std::ios::in | std::ios::ate);
644
645 if (is.is_open()) {
646 shaderSize = is.tellg();
647 if (shaderSize <= 0 || shaderSize >= SHADER_MAX_SIZE) {
648 RS_LOGE("RDC [%{public}s] fail,shaderSize is unvalid size: %{public}zu \n", __func__, shaderSize);
649 is.close();
650 return VK_NULL_HANDLE;
651 }
652 is.seekg(0, std::ios::beg);
653 // Copy file contents into a buffer
654 shaderCode = new char[shaderSize];
655 is.read(shaderCode, shaderSize);
656 is.close();
657 }
658
659 if (shaderCode) {
660 // Create a new shader module that will be used for pipeline creation
661 VkShaderModuleCreateInfo shaderModuleCI {};
662 shaderModuleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
663 shaderModuleCI.codeSize = static_cast<size_t>(shaderSize);
664 shaderModuleCI.pCode = (uint32_t*)shaderCode;
665
666 VkShaderModule shaderModule;
667 auto result = vkCreateShaderModule(device, &shaderModuleCI, nullptr, &shaderModule);
668 if (result != VK_SUCCESS) {
669 RS_LOGE("RDC [%{public}s] vkCreateShaderModule fail, result: %{public}d! \n", __func__, result);
670 }
671
672 delete[] shaderCode;
673 return shaderModule;
674 } else {
675 RS_LOGE("RDC [%{public}s] LoadSpirvShader fail, file: %{public}s. \n", __func__, realPath);
676 return VK_NULL_HANDLE;
677 }
678 }
679
ReadVertexInputBinding(const xmlNodePtr & node)680 void VkGraphicsPipelineCreateInfoModel::ReadVertexInputBinding(const xmlNodePtr& node)
681 {
682 auto vertexBindingDescriptionCountPtr =
683 XMLReader::FindChildNodeByPropName(node, std::string("vertexBindingDescriptionCount"));
684 if (vertexBindingDescriptionCountPtr == nullptr) {
685 return;
686 }
687 vertexInputStateCI.vertexBindingDescriptionCount = XMLReader::ReadNodeValueInt(vertexBindingDescriptionCountPtr);
688 vertexInputBinding.resize(vertexInputStateCI.vertexBindingDescriptionCount);
689 auto pVertexBindingDescriptionsPtr =
690 XMLReader::FindChildNodeByPropName(node, std::string("pVertexBindingDescriptions"));
691 if (pVertexBindingDescriptionsPtr == nullptr) {
692 RS_LOGE("RDC [%{public}s] pVertexBindingDescriptionsPtr is nullptr! \n", __func__);
693 return;
694 }
695 auto VkVertexInputBindingDescriptionPtr = pVertexBindingDescriptionsPtr->children;
696 for (size_t i = 0; i < vertexInputStateCI.vertexBindingDescriptionCount; i++) {
697 if (VkVertexInputBindingDescriptionPtr == nullptr) {
698 RS_LOGE("RDC [%{public}s] VkVertexInputBindingDescriptionPtr is nullptr.", __func__);
699 return;
700 }
701 auto bindingPtr =
702 XMLReader::FindChildNodeByPropName(VkVertexInputBindingDescriptionPtr, std::string("binding"));
703 vertexInputBinding[i].binding = XMLReader::ReadNodeValueInt(bindingPtr);
704
705 auto stridePtr = XMLReader::FindChildNodeByPropName(VkVertexInputBindingDescriptionPtr, std::string("stride"));
706 vertexInputBinding[i].stride = XMLReader::ReadNodeValueInt(stridePtr);
707
708 auto inputRatePtr =
709 XMLReader::FindChildNodeByPropName(VkVertexInputBindingDescriptionPtr, std::string("inputRate"));
710 vertexInputBinding[i].inputRate = static_cast<VkVertexInputRate>(XMLReader::ReadNodeValueInt(inputRatePtr));
711
712 VkVertexInputBindingDescriptionPtr = VkVertexInputBindingDescriptionPtr->next;
713 }
714 vertexInputStateCI.pVertexBindingDescriptions = vertexInputBinding.data();
715 }
716
ReadVertexInputAttributs(const xmlNodePtr & node)717 void VkGraphicsPipelineCreateInfoModel::ReadVertexInputAttributs(const xmlNodePtr& node)
718 {
719 auto vertexAttributeDescriptionCountPtr =
720 XMLReader::FindChildNodeByPropName(node, std::string("vertexAttributeDescriptionCount"));
721 if (vertexAttributeDescriptionCountPtr == nullptr) {
722 return;
723 }
724 vertexInputStateCI.vertexAttributeDescriptionCount =
725 XMLReader::ReadNodeValueInt(vertexAttributeDescriptionCountPtr);
726 vertexInputAttributs.resize(vertexInputStateCI.vertexAttributeDescriptionCount);
727 auto pVertexAttributeDescriptionsPtr =
728 XMLReader::FindChildNodeByPropName(node, std::string("pVertexAttributeDescriptions"));
729 if (pVertexAttributeDescriptionsPtr == nullptr) {
730 RS_LOGE("RDC [%{public}s] pVertexAttributeDescriptionsPtr is nullptr! \n", __func__);
731 return;
732 }
733 auto VkVertexInputAttributeDescriptionPtr = pVertexAttributeDescriptionsPtr->children;
734 for (size_t i = 0; i < vertexInputStateCI.vertexAttributeDescriptionCount; i++) {
735 if (VkVertexInputAttributeDescriptionPtr == nullptr) {
736 RS_LOGE("RDC [%{public}s] VkVertexInputAttributeDescriptionPtr is nullptr.", __func__);
737 return;
738 }
739 auto locationPtr =
740 XMLReader::FindChildNodeByPropName(VkVertexInputAttributeDescriptionPtr, std::string("location"));
741 vertexInputAttributs[i].location = XMLReader::ReadNodeValueInt(locationPtr);
742
743 auto bindingPtr =
744 XMLReader::FindChildNodeByPropName(VkVertexInputAttributeDescriptionPtr, std::string("binding"));
745 vertexInputAttributs[i].binding = XMLReader::ReadNodeValueInt(bindingPtr);
746
747 auto formatPtr =
748 XMLReader::FindChildNodeByPropName(VkVertexInputAttributeDescriptionPtr, std::string("format"));
749 vertexInputAttributs[i].format = static_cast<VkFormat>(XMLReader::ReadNodeValueInt(formatPtr));
750
751 auto offsetPtr =
752 XMLReader::FindChildNodeByPropName(VkVertexInputAttributeDescriptionPtr, std::string("offset"));
753 vertexInputAttributs[i].offset = XMLReader::ReadNodeValueInt(offsetPtr);
754
755 VkVertexInputAttributeDescriptionPtr = VkVertexInputAttributeDescriptionPtr->next;
756 }
757 vertexInputStateCI.pVertexAttributeDescriptions = vertexInputAttributs.data();
758 }
759
ReadVertexInputState(const xmlNodePtr & node)760 void VkGraphicsPipelineCreateInfoModel::ReadVertexInputState(const xmlNodePtr& node)
761 {
762 vertexInputStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
763 auto pVertexInputStatePtr = XMLReader::FindChildNodeByPropName(node, std::string("pVertexInputState"));
764 if (pVertexInputStatePtr == nullptr) {
765 return;
766 }
767 ReadVertexInputBinding(pVertexInputStatePtr);
768 ReadVertexInputAttributs(pVertexInputStatePtr);
769 createInfo.pVertexInputState = &vertexInputStateCI;
770 }
771
ReadColorBlendState(const xmlNodePtr & node)772 void VkGraphicsPipelineCreateInfoModel::ReadColorBlendState(const xmlNodePtr& node)
773 {
774 colorBlendStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
775 auto pColorBlendStatePtr = XMLReader::FindChildNodeByPropName(node, std::string("pColorBlendState"));
776 auto attachmentCountPtr = XMLReader::FindChildNodeByPropName(pColorBlendStatePtr, std::string("attachmentCount"));
777 colorBlendStateCI.attachmentCount = XMLReader::ReadNodeValueInt(attachmentCountPtr);
778 if (attachmentCountPtr == nullptr || colorBlendStateCI.attachmentCount == 0) {
779 return;
780 }
781 auto pAttachmentsPtr = XMLReader::FindChildNodeByPropName(pColorBlendStatePtr, std::string("pAttachments"));
782 if (pAttachmentsPtr == nullptr) {
783 return;
784 }
785 auto pAttachmentsStatePtr = pAttachmentsPtr->children;
786 blendAttachmentState.resize(colorBlendStateCI.attachmentCount);
787 for (size_t i = 0; i < colorBlendStateCI.attachmentCount; i++) {
788 if (pAttachmentsStatePtr == nullptr) {
789 RS_LOGE("RDC [%{public}s] input pAttachmentsStatePtr is null! \n", __func__);
790 return;
791 }
792 auto blendEnablePtr = XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("blendEnable"));
793 blendAttachmentState[i].blendEnable = static_cast<VkBool32>(XMLReader::ReadNodeValueInt(blendEnablePtr));
794
795 auto srcColorBlendFactorPtr =
796 XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("srcColorBlendFactor"));
797 blendAttachmentState[i].srcColorBlendFactor =
798 static_cast<VkBlendFactor>(XMLReader::ReadNodeValueInt(srcColorBlendFactorPtr));
799
800 auto dstColorBlendFactorPtr =
801 XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("dstColorBlendFactor"));
802 blendAttachmentState[i].dstColorBlendFactor =
803 static_cast<VkBlendFactor>(XMLReader::ReadNodeValueInt(dstColorBlendFactorPtr));
804
805 auto colorBlendOpPtr = XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("colorBlendOp"));
806 blendAttachmentState[i].colorBlendOp = static_cast<VkBlendOp>(XMLReader::ReadNodeValueInt(colorBlendOpPtr));
807
808 auto srcAlphaBlendFactorPtr =
809 XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("srcAlphaBlendFactor"));
810 blendAttachmentState[i].srcAlphaBlendFactor =
811 static_cast<VkBlendFactor>(XMLReader::ReadNodeValueInt(srcAlphaBlendFactorPtr));
812
813 auto dstAlphaBlendFactorPtr =
814 XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("dstAlphaBlendFactor"));
815 blendAttachmentState[i].dstAlphaBlendFactor =
816 static_cast<VkBlendFactor>(XMLReader::ReadNodeValueInt(dstAlphaBlendFactorPtr));
817
818 auto alphaBlendOpPtr = XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("alphaBlendOp"));
819 blendAttachmentState[i].alphaBlendOp = static_cast<VkBlendOp>(XMLReader::ReadNodeValueInt(alphaBlendOpPtr));
820
821 auto colorWriteMaskPtr =
822 XMLReader::FindChildNodeByPropName(pAttachmentsStatePtr, std::string("colorWriteMask"));
823 blendAttachmentState[i].colorWriteMask =
824 static_cast<VkColorComponentFlags>(XMLReader::ReadNodeValueInt(colorWriteMaskPtr));
825
826 pAttachmentsStatePtr = pAttachmentsStatePtr->next;
827 }
828 colorBlendStateCI.pAttachments = blendAttachmentState.data();
829 createInfo.pColorBlendState = &colorBlendStateCI;
830 }
831
ReadRasterizationState(const xmlNodePtr & node)832 void VkGraphicsPipelineCreateInfoModel::ReadRasterizationState(const xmlNodePtr& node)
833 {
834 rasterizationStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
835 rasterizationStateCI.polygonMode = VK_POLYGON_MODE_FILL;
836 rasterizationStateCI.cullMode = VK_CULL_MODE_NONE;
837 rasterizationStateCI.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
838 rasterizationStateCI.depthClampEnable = VK_FALSE;
839 rasterizationStateCI.rasterizerDiscardEnable = VK_FALSE;
840 rasterizationStateCI.depthBiasEnable = VK_FALSE;
841 rasterizationStateCI.lineWidth = 1.0f;
842 createInfo.pRasterizationState = &rasterizationStateCI;
843 }
844
ReadMultiSampleState(const xmlNodePtr & node)845 void VkGraphicsPipelineCreateInfoModel::ReadMultiSampleState(const xmlNodePtr& node)
846 {
847 multisampleStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
848 multisampleStateCI.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
849 multisampleStateCI.pSampleMask = nullptr;
850 createInfo.pMultisampleState = &multisampleStateCI;
851 }
852
ReadXmlNode(const xmlNodePtr & createInfoNodePtr)853 bool VkGraphicsPipelineCreateInfoModel::ReadXmlNode(const xmlNodePtr& createInfoNodePtr)
854 {
855 if (createInfoNodePtr == nullptr) {
856 RS_LOGE("RDC [%{public}s] input createInfoNodePtr is null! \n", __func__);
857 return false;
858 }
859 auto stageCountPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("stageCount"));
860 if (stageCountPtr == nullptr) {
861 RS_LOGE("RDC [%{public}s] stageCountPtr is null! \n", __func__);
862 return false;
863 }
864 createInfo.stageCount = XMLReader::ReadNodeValueInt(stageCountPtr);
865 auto pStagesPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("pStages"));
866 if (pStagesPtr == nullptr) {
867 RS_LOGE("RDC [%{public}s] pStagesPtr is null! \n", __func__);
868 return false;
869 }
870 auto vertexShaderPtr = pStagesPtr->children;
871 if (vertexShaderPtr == nullptr) {
872 RS_LOGE("RDC [%{public}s] vertexShaderPtr is null! \n", __func__);
873 return false;
874 }
875 auto vsModulePtr = XMLReader::FindChildNodeByPropName(vertexShaderPtr, std::string("module"));
876 auto vsResourceIdStr = XMLReader::ReadNodeValue(vsModulePtr);
877 vertexShaderFilePath = XMLReader::GetConfigPath(std::string(PATH_CONFIG_DIR) + vsResourceIdStr + "vs.spv");
878 auto fragShaderPtr = vertexShaderPtr->next;
879 auto fsModulePtr = XMLReader::FindChildNodeByPropName(fragShaderPtr, std::string("module"));
880 auto fsResourceIdStr = XMLReader::ReadNodeValue(fsModulePtr);
881 fragShaderFilePath = XMLReader::GetConfigPath(std::string(PATH_CONFIG_DIR) + fsResourceIdStr + "fs.spv");
882
883 auto layoutPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("layout"));
884 if (layoutPtr == nullptr) {
885 RS_LOGE("RDC [%{public}s] layoutPtr is null! \n", __func__);
886 return false;
887 }
888 layoutResourceId = XMLReader::ReadNodeValueInt(layoutPtr);
889
890 auto renderPassPtr = XMLReader::FindChildNodeByPropName(createInfoNodePtr, std::string("renderPass"));
891 if (renderPassPtr == nullptr) {
892 RS_LOGE("RDC [%{public}s] renderPassPtr is null! \n", __func__);
893 return false;
894 }
895 renderPassResourceId = XMLReader::ReadNodeValueInt(renderPassPtr);
896
897 createInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
898 ReadVertexInputState(createInfoNodePtr);
899 ReadRasterizationState(createInfoNodePtr);
900 ReadMultiSampleState(createInfoNodePtr);
901 ReadColorBlendState(createInfoNodePtr);
902
903 return true;
904 }
905
CloseXML()906 void RDCConfig::CloseXML()
907 {
908 if (pDoc != nullptr) {
909 xmlFreeDoc(pDoc);
910 pDoc = nullptr;
911 }
912 }
913
914 } // namespace RDC
915 } // namespace Rosen
916 } // namespace OHOS
917