1 /*-------------------------------------------------------------------------
2 * Vulkan CTS Framework
3 * --------------------
4 *
5 * Copyright (c) 2021 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *-------------------------------------------------------------------------*/
20
21 #include "vksJson.hpp"
22
23 #define VULKAN_JSON_CTS
24 #ifdef __GNUC__
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wunused-parameter"
27 #pragma GCC diagnostic ignored "-Wunused-function"
28 #pragma GCC diagnostic ignored "-Wunused-variable"
29 #endif // __GNUC__
30 #ifdef __clang__
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wpointer-bool-conversion"
33 #endif
34
35 #include "vulkan_json_parser.hpp"
36 #include "vulkan_json_data.hpp"
37
38 #ifdef __GNUC__
39 #pragma GCC diagnostic pop
40 #endif // __GNUC__
41 #ifdef __clang__
42 #pragma clang diagnostic pop
43 #endif
44
45 #include "vksStructsVKSC.hpp"
46
47 namespace vksc_server
48 {
49
50 namespace json
51 {
52
Context()53 Context::Context()
54 {
55 Json::CharReaderBuilder builder;
56 builder.settings_["allowSpecialFloats"] = 1;
57 reader.reset( builder.newCharReader() );
58 }
59
~Context()60 Context::~Context()
61 {
62 }
63
runGarbageCollection()64 void runGarbageCollection()
65 {
66 vk_json_parser::s_globalMem.clear();
67 }
68
VkObjectToString(const vk::VkDeviceObjectReservationCreateInfo & in,string & out)69 void VkObjectToString(const vk::VkDeviceObjectReservationCreateInfo& in, string& out)
70 {
71 vk_json::_string_stream.str({});
72 vk_json::_string_stream.clear();
73 vk_json::print_VkDeviceObjectReservationCreateInfo(&in, "", false);
74 out = vk_json::_string_stream.str();
75 }
76
StringToVkObject(const string & in,vk::VkDeviceObjectReservationCreateInfo & out)77 void StringToVkObject(const string& in, vk::VkDeviceObjectReservationCreateInfo& out)
78 {
79 Json::CharReaderBuilder builder;
80 builder.settings_["allowSpecialFloats"] = 1;
81 std::unique_ptr<Json::CharReader> jsonReader(builder.newCharReader());
82
83 Json::Value jsonRoot;
84 string errors;
85 if (!jsonReader->parse(in.data(), in.data() + in.size(), &jsonRoot, &errors))
86 {
87 throw std::runtime_error("json parse error");
88 }
89 vk_json_parser::parse_VkDeviceObjectReservationCreateInfo("", jsonRoot, out);
90 }
91
writeJSON_VkGraphicsPipelineCreateInfo(const VkGraphicsPipelineCreateInfo & pCreateInfo)92 string writeJSON_VkGraphicsPipelineCreateInfo(const VkGraphicsPipelineCreateInfo& pCreateInfo)
93 {
94 vk_json::_string_stream.str({});
95 vk_json::_string_stream.clear();
96 vk_json::print_VkGraphicsPipelineCreateInfo(pCreateInfo, "", 0);
97 return vk_json::_string_stream.str();
98 }
99
writeJSON_VkComputePipelineCreateInfo(const VkComputePipelineCreateInfo & pCreateInfo)100 string writeJSON_VkComputePipelineCreateInfo(const VkComputePipelineCreateInfo& pCreateInfo)
101 {
102 vk_json::_string_stream.str({});
103 vk_json::_string_stream.clear();
104 vk_json::print_VkComputePipelineCreateInfo(pCreateInfo, "", 0);
105 return vk_json::_string_stream.str();
106 }
107
writeJSON_VkRenderPassCreateInfo(const VkRenderPassCreateInfo & pCreateInfo)108 string writeJSON_VkRenderPassCreateInfo (const VkRenderPassCreateInfo& pCreateInfo)
109 {
110
111 vk_json::_string_stream.str({});
112 vk_json::_string_stream.clear();
113 vk_json::print_VkRenderPassCreateInfo(&pCreateInfo, "", false);
114 return vk_json::_string_stream.str();
115 }
116
writeJSON_VkRenderPassCreateInfo2(const VkRenderPassCreateInfo2 & pCreateInfo)117 string writeJSON_VkRenderPassCreateInfo2 (const VkRenderPassCreateInfo2& pCreateInfo)
118 {
119 vk_json::_string_stream.str({});
120 vk_json::_string_stream.clear();
121 vk_json::print_VkRenderPassCreateInfo2(&pCreateInfo, "", false);
122 return vk_json::_string_stream.str();
123 }
124
writeJSON_VkPipelineLayoutCreateInfo(const VkPipelineLayoutCreateInfo & pCreateInfo)125 string writeJSON_VkPipelineLayoutCreateInfo (const VkPipelineLayoutCreateInfo& pCreateInfo)
126 {
127 vk_json::_string_stream.str({});
128 vk_json::_string_stream.clear();
129 vk_json::print_VkPipelineLayoutCreateInfo(&pCreateInfo, "", false);
130 return vk_json::_string_stream.str();
131 }
132
writeJSON_VkDescriptorSetLayoutCreateInfo(const VkDescriptorSetLayoutCreateInfo & pCreateInfo)133 string writeJSON_VkDescriptorSetLayoutCreateInfo (const VkDescriptorSetLayoutCreateInfo& pCreateInfo)
134 {
135 vk_json::_string_stream.str({});
136 vk_json::_string_stream.clear();
137 vk_json::print_VkDescriptorSetLayoutCreateInfo(&pCreateInfo, "", false);
138 return vk_json::_string_stream.str();
139 }
140
writeJSON_VkSamplerCreateInfo(const VkSamplerCreateInfo & pCreateInfo)141 string writeJSON_VkSamplerCreateInfo(const VkSamplerCreateInfo& pCreateInfo)
142 {
143 vk_json::_string_stream.str({});
144 vk_json::_string_stream.clear();
145 vk_json::print_VkSamplerCreateInfo(&pCreateInfo, "", false);
146 return vk_json::_string_stream.str();
147 }
148
writeJSON_VkDeviceObjectReservationCreateInfo(const VkDeviceObjectReservationCreateInfo & dmrCI)149 string writeJSON_VkDeviceObjectReservationCreateInfo (const VkDeviceObjectReservationCreateInfo& dmrCI)
150 {
151 vk_json::_string_stream.str({});
152 vk_json::_string_stream.clear();
153 vk_json::print_VkDeviceObjectReservationCreateInfo(&dmrCI, "", false);
154 return vk_json::_string_stream.str();
155 }
156
writeJSON_VkPipelineOfflineCreateInfo(const vk::VkPipelineOfflineCreateInfo & piInfo)157 string writeJSON_VkPipelineOfflineCreateInfo(const vk::VkPipelineOfflineCreateInfo& piInfo)
158 {
159 vk_json::_string_stream.str({});
160 vk_json::_string_stream.clear();
161 vk_json::print_VkPipelineOfflineCreateInfo(&piInfo, "", false);
162 return vk_json::_string_stream.str();
163 }
164
writeJSON_GraphicsPipeline_vkpccjson(const std::string & filePrefix,deUint32 pipelineIndex,const vk::VkPipelineOfflineCreateInfo id,const VkGraphicsPipelineCreateInfo & gpCI,const vk::VkPhysicalDeviceFeatures2 & deviceFeatures2,const std::vector<std::string> & deviceExtensions,const std::map<VkSamplerYcbcrConversion,VkSamplerYcbcrConversionCreateInfo> & samplerYcbcrConversions,const std::map<VkSampler,VkSamplerCreateInfo> & samplers,const std::map<VkDescriptorSetLayout,VkDescriptorSetLayoutCreateInfo> & descriptorSetLayouts,const std::map<VkRenderPass,VkRenderPassCreateInfo> & renderPasses,const std::map<VkRenderPass,VkRenderPassCreateInfo2> & renderPasses2,const std::map<VkPipelineLayout,VkPipelineLayoutCreateInfo> & pipelineLayouts)165 string writeJSON_GraphicsPipeline_vkpccjson (const std::string& filePrefix,
166 deUint32 pipelineIndex,
167 const vk::VkPipelineOfflineCreateInfo id,
168 const VkGraphicsPipelineCreateInfo& gpCI,
169 const vk::VkPhysicalDeviceFeatures2& deviceFeatures2,
170 const std::vector<std::string>& deviceExtensions,
171 const std::map<VkSamplerYcbcrConversion, VkSamplerYcbcrConversionCreateInfo>& samplerYcbcrConversions,
172 const std::map<VkSampler, VkSamplerCreateInfo>& samplers,
173 const std::map<VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>& descriptorSetLayouts,
174 const std::map<VkRenderPass, VkRenderPassCreateInfo>& renderPasses,
175 const std::map<VkRenderPass, VkRenderPassCreateInfo2>& renderPasses2,
176 const std::map<VkPipelineLayout, VkPipelineLayoutCreateInfo>& pipelineLayouts)
177 {
178 vk_json::_string_stream.str({});
179 vk_json::_string_stream.clear();
180
181 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
182 vk_json::_string_stream << "{" << std::endl;
183 vk_json::s_num_spaces += 4;
184
185 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
186 vk_json::_string_stream << "\"GraphicsPipelineState\" :" << std::endl;
187 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
188 vk_json::_string_stream << "{" << std::endl;
189 vk_json::s_num_spaces += 4;
190
191 if (!renderPasses.empty())
192 {
193 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
194 vk_json::_string_stream << "\"Renderpass\" : " << std::endl;
195 vk_json::print_VkRenderPassCreateInfo(begin(renderPasses)->second, "", true);
196 }
197 if (!renderPasses2.empty())
198 {
199 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
200 vk_json::_string_stream << "\"Renderpass2\" : " << std::endl;
201 vk_json::print_VkRenderPassCreateInfo2(begin(renderPasses2)->second, "", true);
202 }
203 if (!samplerYcbcrConversions.empty())
204 {
205 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
206 vk_json::_string_stream << "\"YcbcrSamplers\" :" << std::endl;
207 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
208 vk_json::_string_stream << "[" << std::endl;
209 vk_json::s_num_spaces += 4;
210
211 size_t j = 0u;
212 for (auto it = begin(samplerYcbcrConversions); it != end(samplerYcbcrConversions); ++it, ++j)
213 {
214 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
215 vk_json::_string_stream << "{" << std::endl;
216 vk_json::s_num_spaces += 4;
217
218 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
219 vk_json::_string_stream << "\""<< it->first.getInternal() << "\":" << std::endl;
220
221 vk_json::print_VkSamplerYcbcrConversionCreateInfo(it->second, "", false);
222
223 vk_json::s_num_spaces -= 4;
224 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
225 if((j + 1) < samplerYcbcrConversions.size())
226 vk_json::_string_stream << "}," << std::endl;
227 else
228 vk_json::_string_stream << "}" << std::endl;
229 }
230
231 vk_json::s_num_spaces -= 4;
232 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
233 vk_json::_string_stream << "]," << std::endl;
234 }
235
236 if (!samplers.empty())
237 {
238 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
239 vk_json::_string_stream << "\"ImmutableSamplers\" :" << std::endl;
240 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
241 vk_json::_string_stream << "[" << std::endl;
242 vk_json::s_num_spaces += 4;
243
244 size_t j = 0u;
245 for (auto it = begin(samplers); it != end(samplers); ++it, ++j)
246 {
247 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
248 vk_json::_string_stream << "{" << std::endl;
249 vk_json::s_num_spaces += 4;
250
251 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
252 vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
253
254 vk_json::print_VkSamplerCreateInfo(it->second, "", false);
255
256 vk_json::s_num_spaces -= 4;
257 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
258
259 if ((j + 1) < samplers.size())
260 vk_json::_string_stream << "}," << std::endl;
261 else
262 vk_json::_string_stream << "}" << std::endl;
263 }
264
265 vk_json::s_num_spaces -= 4;
266 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
267 vk_json::_string_stream << "]," << std::endl;
268 }
269
270 if (!descriptorSetLayouts.empty())
271 {
272 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
273 vk_json::_string_stream << "\"DescriptorSetLayouts\" :" << std::endl;
274 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
275 vk_json::_string_stream << "[" << std::endl;
276 vk_json::s_num_spaces += 4;
277
278 size_t j = 0u;
279 for (auto it = begin(descriptorSetLayouts); it != end(descriptorSetLayouts); ++it, ++j)
280 {
281 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
282 vk_json::_string_stream << "{" << std::endl;
283 vk_json::s_num_spaces += 4;
284
285 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
286 vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
287
288 vk_json::print_VkDescriptorSetLayoutCreateInfo(it->second, "", false);
289
290 vk_json::s_num_spaces -= 4;
291 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
292
293 if ((j + 1) < descriptorSetLayouts.size())
294 vk_json::_string_stream << "}," << std::endl;
295 else
296 vk_json::_string_stream << "}" << std::endl;
297 }
298
299 vk_json::s_num_spaces -= 4;
300 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
301 vk_json::_string_stream << "]," << std::endl;
302 }
303
304 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
305 vk_json::_string_stream << "\"PipelineLayout\" : " << std::endl;
306 vk_json::print_VkPipelineLayoutCreateInfo(begin(pipelineLayouts)->second, "", true);
307
308 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
309 vk_json::_string_stream << "\"GraphicsPipeline\" : " << std::endl;
310 vk_json::print_VkGraphicsPipelineCreateInfo(gpCI, "", true);
311
312 // shaders
313 {
314 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
315 vk_json::_string_stream << "\"ShaderFileNames\" :" << std::endl;
316 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
317 vk_json::_string_stream << "[" << std::endl;
318 vk_json::s_num_spaces += 4;
319
320 for( deUint32 j=0; j<gpCI.stageCount; ++j)
321 {
322 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
323 vk_json::_string_stream << "{" << std::endl;
324 vk_json::s_num_spaces += 4;
325
326 vk_json::print_VkShaderStageFlagBits(gpCI.pStages[j].stage, "stage", 1);
327
328 std::stringstream shaderName;
329 shaderName << filePrefix << "shader_" << pipelineIndex << "_" << gpCI.pStages[j].module.getInternal() << ".";
330
331 switch (gpCI.pStages[j].stage)
332 {
333 case VK_SHADER_STAGE_VERTEX_BIT: shaderName << "vert"; break;
334 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: shaderName << "tesc"; break;
335 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: shaderName << "tese"; break;
336 case VK_SHADER_STAGE_GEOMETRY_BIT: shaderName << "geom"; break;
337 case VK_SHADER_STAGE_FRAGMENT_BIT: shaderName << "frag"; break;
338 default:
339 TCU_THROW(InternalError, "Unrecognized shader stage");
340 }
341 shaderName << ".spv";
342
343 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
344 vk_json::_string_stream << "\"filename\" : \"" << shaderName.str() << "\"" << std::endl;
345 vk_json::s_num_spaces -= 4;
346 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
347
348 if ((j+1) >= gpCI.stageCount)
349 vk_json::_string_stream << "}" << std::endl;
350 else
351 vk_json::_string_stream << "}," << std::endl;
352 }
353
354 vk_json::s_num_spaces -= 4;
355 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
356 vk_json::_string_stream << "]," << std::endl;
357 }
358
359 // device features
360 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
361 vk_json::_string_stream << "\"PhysicalDeviceFeatures\" : " << std::endl;
362 vk_json::print_VkPhysicalDeviceFeatures2(deviceFeatures2, "", false);
363
364 // close GraphicsPipelineState
365 vk_json::s_num_spaces -= 4;
366 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
367 vk_json::_string_stream << "}," << std::endl;
368
369 // device extensions
370 {
371 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
372 vk_json::_string_stream << "\"EnabledExtensions\" : " << std::endl;
373 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
374 vk_json::_string_stream << "[" << std::endl;
375 vk_json::s_num_spaces += 4;
376
377 for (unsigned int j = 0; j < deviceExtensions.size(); j++)
378 vk_json::print_char(deviceExtensions[j].data(), "", (j + 1) != deviceExtensions.size());
379
380 vk_json::s_num_spaces -= 4;
381 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
382 vk_json::_string_stream << "]," << std::endl;
383 }
384
385 // pipeline identifier
386 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
387 vk_json::_string_stream << "\"PipelineUUID\" : " << std::endl;
388 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
389 vk_json::_string_stream << "[" << std::endl;
390 vk_json::s_num_spaces += 4;
391 for (unsigned int j = 0; j < VK_UUID_SIZE; j++)
392 vk_json::print_uint32_t((deUint32)id.pipelineIdentifier[j], "", (j + 1) != VK_UUID_SIZE);
393 vk_json::s_num_spaces -= 4;
394 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
395 vk_json::_string_stream << "]" << std::endl;
396
397 vk_json::s_num_spaces -= 4;
398 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
399 vk_json::_string_stream << "}" << std::endl;
400
401 return vk_json::_string_stream.str();
402 }
403
writeJSON_ComputePipeline_vkpccjson(const std::string & filePrefix,deUint32 pipelineIndex,const vk::VkPipelineOfflineCreateInfo id,const VkComputePipelineCreateInfo & cpCI,const vk::VkPhysicalDeviceFeatures2 & deviceFeatures2,const std::vector<std::string> & deviceExtensions,const std::map<VkSamplerYcbcrConversion,VkSamplerYcbcrConversionCreateInfo> & samplerYcbcrConversions,const std::map<VkSampler,VkSamplerCreateInfo> & samplers,const std::map<VkDescriptorSetLayout,VkDescriptorSetLayoutCreateInfo> & descriptorSetLayouts,const std::map<VkPipelineLayout,VkPipelineLayoutCreateInfo> & pipelineLayouts)404 string writeJSON_ComputePipeline_vkpccjson (const std::string& filePrefix,
405 deUint32 pipelineIndex,
406 const vk::VkPipelineOfflineCreateInfo id,
407 const VkComputePipelineCreateInfo& cpCI,
408 const vk::VkPhysicalDeviceFeatures2& deviceFeatures2,
409 const std::vector<std::string>& deviceExtensions,
410 const std::map<VkSamplerYcbcrConversion, VkSamplerYcbcrConversionCreateInfo>& samplerYcbcrConversions,
411 const std::map<VkSampler, VkSamplerCreateInfo>& samplers,
412 const std::map<VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>& descriptorSetLayouts,
413 const std::map<VkPipelineLayout, VkPipelineLayoutCreateInfo>& pipelineLayouts)
414 {
415 vk_json::_string_stream.str({});
416 vk_json::_string_stream.clear();
417
418 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
419 vk_json::_string_stream << "{" << std::endl;
420 vk_json::s_num_spaces += 4;
421
422 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
423 vk_json::_string_stream << "\"ComputePipelineState\" :" << std::endl;
424 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
425 vk_json::_string_stream << "{" << std::endl;
426 vk_json::s_num_spaces += 4;
427
428 if (!samplerYcbcrConversions.empty())
429 {
430 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
431 vk_json::_string_stream << "\"YcbcrSamplers\" :" << std::endl;
432 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
433 vk_json::_string_stream << "[" << std::endl;
434 vk_json::s_num_spaces += 4;
435
436 size_t j = 0u;
437 for (auto it = begin(samplerYcbcrConversions); it != end(samplerYcbcrConversions); ++it, ++j)
438 {
439 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
440 vk_json::_string_stream << "{" << std::endl;
441 vk_json::s_num_spaces += 4;
442
443 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
444 vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
445
446 vk_json::print_VkSamplerYcbcrConversionCreateInfo(it->second, "", false);
447
448 vk_json::s_num_spaces -= 4;
449 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
450 if ((j + 1) < samplerYcbcrConversions.size())
451 vk_json::_string_stream << "}," << std::endl;
452 else
453 vk_json::_string_stream << "}" << std::endl;
454 }
455
456 vk_json::s_num_spaces -= 4;
457 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
458 vk_json::_string_stream << "]," << std::endl;
459 }
460
461 if (!samplers.empty())
462 {
463 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
464 vk_json::_string_stream << "\"ImmutableSamplers\" :" << std::endl;
465 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
466 vk_json::_string_stream << "[" << std::endl;
467 vk_json::s_num_spaces += 4;
468
469 size_t j = 0u;
470 for (auto it = begin(samplers); it != end(samplers); ++it, ++j)
471 {
472 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
473 vk_json::_string_stream << "{" << std::endl;
474 vk_json::s_num_spaces += 4;
475
476 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
477 vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
478
479 vk_json::print_VkSamplerCreateInfo(it->second, "", false);
480
481 vk_json::s_num_spaces -= 4;
482 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
483
484 if ((j + 1) < samplers.size())
485 vk_json::_string_stream << "}," << std::endl;
486 else
487 vk_json::_string_stream << "}" << std::endl;
488 }
489
490 vk_json::s_num_spaces -= 4;
491 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
492 vk_json::_string_stream << "]," << std::endl;
493 }
494
495 if (!descriptorSetLayouts.empty())
496 {
497 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
498 vk_json::_string_stream << "\"DescriptorSetLayouts\" :" << std::endl;
499 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
500 vk_json::_string_stream << "[" << std::endl;
501 vk_json::s_num_spaces += 4;
502
503 size_t j = 0u;
504 for (auto it = begin(descriptorSetLayouts); it != end(descriptorSetLayouts); ++it, ++j)
505 {
506 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
507 vk_json::_string_stream << "{" << std::endl;
508 vk_json::s_num_spaces += 4;
509
510 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
511 vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
512
513 vk_json::print_VkDescriptorSetLayoutCreateInfo(it->second, "", false);
514
515 vk_json::s_num_spaces -= 4;
516 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
517
518 if ((j + 1) < descriptorSetLayouts.size())
519 vk_json::_string_stream << "}," << std::endl;
520 else
521 vk_json::_string_stream << "}" << std::endl;
522 }
523
524 vk_json::s_num_spaces -= 4;
525 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
526 vk_json::_string_stream << "]," << std::endl;
527 }
528
529 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
530 vk_json::_string_stream << "\"PipelineLayout\" : " << std::endl;
531 vk_json::print_VkPipelineLayoutCreateInfo(begin(pipelineLayouts)->second, "", true);
532
533 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
534 vk_json::_string_stream << "\"ComputePipeline\" : " << std::endl;
535 vk_json::print_VkComputePipelineCreateInfo(cpCI, "", true);
536
537 // shaders
538 {
539 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
540 vk_json::_string_stream << "\"ShaderFileNames\" :" << std::endl;
541 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
542 vk_json::_string_stream << "[" << std::endl;
543 vk_json::s_num_spaces += 4;
544
545 {
546 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
547 vk_json::_string_stream << "{" << std::endl;
548 vk_json::s_num_spaces += 4;
549
550 vk_json::print_VkShaderStageFlagBits(cpCI.stage.stage, "stage", 1);
551
552 std::stringstream shaderName;
553 shaderName << filePrefix << "shader_" << pipelineIndex << "_" << cpCI.stage.module.getInternal() << ".";
554
555 switch (cpCI.stage.stage)
556 {
557 case VK_SHADER_STAGE_COMPUTE_BIT: shaderName << "comp"; break;
558 default:
559 TCU_THROW(InternalError, "Unrecognized shader stage");
560 }
561 shaderName << ".spv";
562
563 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
564 vk_json::_string_stream << "\"filename\" : \"" << shaderName.str() << "\"" << std::endl;
565 vk_json::s_num_spaces -= 4;
566 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
567
568 vk_json::_string_stream << "}" << std::endl;
569 }
570
571 vk_json::s_num_spaces -= 4;
572 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
573 vk_json::_string_stream << "]," << std::endl;
574 }
575
576 // device features
577 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
578 vk_json::_string_stream << "\"PhysicalDeviceFeatures\" : " << std::endl;
579 vk_json::print_VkPhysicalDeviceFeatures2(deviceFeatures2, "", false);
580
581 // close ComputePipelineState
582 vk_json::s_num_spaces -= 4;
583 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
584 vk_json::_string_stream << "}," << std::endl;
585
586 // device extensions
587 {
588 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
589 vk_json::_string_stream << "\"EnabledExtensions\" : " << std::endl;
590 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
591 vk_json::_string_stream << "[" << std::endl;
592 vk_json::s_num_spaces += 4;
593
594 for (unsigned int j = 0; j < deviceExtensions.size(); j++)
595 vk_json::print_char(deviceExtensions[j].data(), "", (j + 1) != deviceExtensions.size());
596
597 vk_json::s_num_spaces -= 4;
598 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
599 vk_json::_string_stream << "]," << std::endl;
600 }
601
602 // pipeline identifier
603 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
604 vk_json::_string_stream << "\"PipelineUUID\" : " << std::endl;
605 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
606 vk_json::_string_stream << "[" << std::endl;
607 vk_json::s_num_spaces += 4;
608 for (unsigned int j = 0; j < VK_UUID_SIZE; j++)
609 vk_json::print_uint32_t((deUint32)id.pipelineIdentifier[j], "", (j + 1) != VK_UUID_SIZE);
610 vk_json::s_num_spaces -= 4;
611 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
612 vk_json::_string_stream << "]" << std::endl;
613
614 vk_json::s_num_spaces -= 4;
615 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
616 vk_json::_string_stream << "}" << std::endl;
617
618 return vk_json::_string_stream.str();
619 }
620
writeJSON_VkPhysicalDeviceFeatures2(const vk::VkPhysicalDeviceFeatures2 & features)621 string writeJSON_VkPhysicalDeviceFeatures2 (const vk::VkPhysicalDeviceFeatures2& features)
622 {
623 vk_json::_string_stream.str({});
624 vk_json::_string_stream.clear();
625 vk_json::print_VkPhysicalDeviceFeatures2(&features, "", false);
626 return vk_json::_string_stream.str();
627 }
628
writeJSON_pNextChain(const void * pNext)629 string writeJSON_pNextChain (const void* pNext)
630 {
631 vk_json::_string_stream.str({});
632 vk_json::_string_stream.clear();
633 vk_json::dumpPNextChain(pNext);
634 std::string result = vk_json::_string_stream.str();
635 // remove "pNext" at the beggining of result and trailing comma
636 return std::string(begin(result) + result.find_first_of('{'), begin(result) + result.find_last_of('}') + 1u);
637 }
638
writeJSON_VkSamplerYcbcrConversionCreateInfo(const VkSamplerYcbcrConversionCreateInfo & pCreateInfo)639 string writeJSON_VkSamplerYcbcrConversionCreateInfo (const VkSamplerYcbcrConversionCreateInfo& pCreateInfo)
640 {
641 vk_json::_string_stream.str({});
642 vk_json::_string_stream.clear();
643 vk_json::print_VkSamplerYcbcrConversionCreateInfo(&pCreateInfo, "", false);
644 return vk_json::_string_stream.str();
645 }
646
print_VkShaderModuleCreateInfo(const VkShaderModuleCreateInfo * obj,const string & s,bool commaNeeded)647 static void print_VkShaderModuleCreateInfo (const VkShaderModuleCreateInfo* obj, const string& s, bool commaNeeded)
648 {
649 DE_UNREF(s);
650
651 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
652 vk_json::_string_stream << "{" << std::endl;
653 vk_json::s_num_spaces += 4;
654
655 vk_json::print_VkStructureType(obj->sType, "sType", 1);
656
657 if (obj->pNext) {
658 vk_json::dumpPNextChain(obj->pNext);
659 }
660 else {
661 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
662 vk_json::_string_stream << "\"pNext\":" << "\"NULL\"" << "," << std::endl;
663 }
664
665 // VkShaderModuleCreateFlags is reserved for future use and must be 0.
666 vk_json::print_uint32_t((deUint32)obj->flags, "flags", 1);
667 vk_json::print_uint64_t((deUint64)obj->codeSize, "codeSize", 1);
668
669 // pCode must be translated into base64, because JSON
670 vk_json::print_void_data(obj->pCode, static_cast<int>(obj->codeSize), "pCode", 0);
671
672 vk_json::s_num_spaces -= 4;
673 for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
674 if (commaNeeded)
675 vk_json::_string_stream << "}," << std::endl;
676 else
677 vk_json::_string_stream << "}" << std::endl;
678 }
679
writeJSON_VkShaderModuleCreateInfo(const VkShaderModuleCreateInfo & smCI)680 string writeJSON_VkShaderModuleCreateInfo (const VkShaderModuleCreateInfo& smCI)
681 {
682 vk_json::_string_stream.str({});
683 vk_json::_string_stream.clear();
684 print_VkShaderModuleCreateInfo(&smCI, "", false);
685 return vk_json::_string_stream.str();
686 }
687
readJSON_VkGraphicsPipelineCreateInfo(Context & context,const string & graphicsPipelineCreateInfo,VkGraphicsPipelineCreateInfo & gpCI)688 void readJSON_VkGraphicsPipelineCreateInfo (Context& context,
689 const string& graphicsPipelineCreateInfo,
690 VkGraphicsPipelineCreateInfo& gpCI)
691 {
692 Json::Value jsonRoot;
693 string errors;
694 bool parsingSuccessful = context.reader->parse(graphicsPipelineCreateInfo.c_str(), graphicsPipelineCreateInfo.c_str() + graphicsPipelineCreateInfo.size(), &jsonRoot, &errors);
695 if (!parsingSuccessful)
696 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
697 vk_json_parser::parse_VkGraphicsPipelineCreateInfo("", jsonRoot, gpCI);
698 }
699
readJSON_VkComputePipelineCreateInfo(Context & context,const string & computePipelineCreateInfo,VkComputePipelineCreateInfo & cpCI)700 void readJSON_VkComputePipelineCreateInfo (Context& context,
701 const string& computePipelineCreateInfo,
702 VkComputePipelineCreateInfo& cpCI)
703 {
704 Json::Value jsonRoot;
705 string errors;
706 bool parsingSuccessful = context.reader->parse(computePipelineCreateInfo.c_str(), computePipelineCreateInfo.c_str() + computePipelineCreateInfo.size(), &jsonRoot, &errors);
707 if (!parsingSuccessful)
708 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
709 vk_json_parser::parse_VkComputePipelineCreateInfo("", jsonRoot, cpCI);
710 }
711
readJSON_VkRenderPassCreateInfo(Context & context,const string & renderPassCreateInfo,VkRenderPassCreateInfo & rpCI)712 void readJSON_VkRenderPassCreateInfo (Context& context,
713 const string& renderPassCreateInfo,
714 VkRenderPassCreateInfo& rpCI)
715 {
716 Json::Value jsonRoot;
717 string errors;
718 bool parsingSuccessful = context.reader->parse(renderPassCreateInfo.c_str(), renderPassCreateInfo.c_str() + renderPassCreateInfo.size(), &jsonRoot, &errors);
719 if (!parsingSuccessful)
720 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
721 vk_json_parser::parse_VkRenderPassCreateInfo("", jsonRoot, rpCI);
722 }
723
readJSON_VkRenderPassCreateInfo2(Context & context,const string & renderPassCreateInfo,VkRenderPassCreateInfo2 & rpCI)724 void readJSON_VkRenderPassCreateInfo2 (Context& context,
725 const string& renderPassCreateInfo,
726 VkRenderPassCreateInfo2& rpCI)
727 {
728 Json::Value jsonRoot;
729 string errors;
730 bool parsingSuccessful = context.reader->parse(renderPassCreateInfo.c_str(), renderPassCreateInfo.c_str() + renderPassCreateInfo.size(), &jsonRoot, &errors);
731 if (!parsingSuccessful)
732 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
733 vk_json_parser::parse_VkRenderPassCreateInfo2("", jsonRoot, rpCI);
734 }
735
readJSON_VkDescriptorSetLayoutCreateInfo(Context & context,const string & descriptorSetLayoutCreateInfo,VkDescriptorSetLayoutCreateInfo & dsCI)736 void readJSON_VkDescriptorSetLayoutCreateInfo (Context& context,
737 const string& descriptorSetLayoutCreateInfo,
738 VkDescriptorSetLayoutCreateInfo& dsCI)
739 {
740 Json::Value jsonRoot;
741 string errors;
742 bool parsingSuccessful = context.reader->parse(descriptorSetLayoutCreateInfo.c_str(), descriptorSetLayoutCreateInfo.c_str() + descriptorSetLayoutCreateInfo.size(), &jsonRoot, &errors);
743 if (!parsingSuccessful)
744 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
745 vk_json_parser::parse_VkDescriptorSetLayoutCreateInfo("", jsonRoot, dsCI);
746 }
747
readJSON_VkPipelineLayoutCreateInfo(Context & context,const string & pipelineLayoutCreateInfo,VkPipelineLayoutCreateInfo & plCI)748 void readJSON_VkPipelineLayoutCreateInfo (Context& context,
749 const string& pipelineLayoutCreateInfo,
750 VkPipelineLayoutCreateInfo& plCI)
751 {
752 Json::Value jsonRoot;
753 string errors;
754 bool parsingSuccessful = context.reader->parse(pipelineLayoutCreateInfo.c_str(), pipelineLayoutCreateInfo.c_str() + pipelineLayoutCreateInfo.size(), &jsonRoot, &errors);
755 if (!parsingSuccessful)
756 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
757 vk_json_parser::parse_VkPipelineLayoutCreateInfo("", jsonRoot, plCI);
758 }
759
readJSON_VkDeviceObjectReservationCreateInfo(Context & context,const string & deviceMemoryReservation,VkDeviceObjectReservationCreateInfo & dmrCI)760 void readJSON_VkDeviceObjectReservationCreateInfo (Context& context,
761 const string& deviceMemoryReservation,
762 VkDeviceObjectReservationCreateInfo& dmrCI)
763 {
764 Json::Value jsonRoot;
765 string errors;
766 bool parsingSuccessful = context.reader->parse(deviceMemoryReservation.c_str(), deviceMemoryReservation.c_str() + deviceMemoryReservation.size(), &jsonRoot, &errors);
767 if (!parsingSuccessful)
768 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
769 vk_json_parser::parse_VkDeviceObjectReservationCreateInfo("", jsonRoot, dmrCI);
770 }
771
readJSON_VkPipelineOfflineCreateInfo(Context & context,const string & pipelineIdentifierInfo,vk::VkPipelineOfflineCreateInfo & piInfo)772 void readJSON_VkPipelineOfflineCreateInfo (Context& context,
773 const string& pipelineIdentifierInfo,
774 vk::VkPipelineOfflineCreateInfo& piInfo)
775 {
776 Json::Value jsonRoot;
777 string errors;
778 bool parsingSuccessful = context.reader->parse(pipelineIdentifierInfo.c_str(), pipelineIdentifierInfo.c_str() + pipelineIdentifierInfo.size(), &jsonRoot, &errors);
779 if (!parsingSuccessful)
780 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
781 vk_json_parser::parse_VkPipelineOfflineCreateInfo("", jsonRoot, piInfo);
782 }
783
readJSON_VkSamplerCreateInfo(Context & context,const string & samplerCreateInfo,VkSamplerCreateInfo & sCI)784 void readJSON_VkSamplerCreateInfo (Context& context,
785 const string& samplerCreateInfo,
786 VkSamplerCreateInfo& sCI)
787 {
788 Json::Value jsonRoot;
789 string errors;
790 bool parsingSuccessful = context.reader->parse(samplerCreateInfo.c_str(), samplerCreateInfo.c_str() + samplerCreateInfo.size(), &jsonRoot, &errors);
791 if (!parsingSuccessful)
792 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
793 vk_json_parser::parse_VkSamplerCreateInfo("", jsonRoot, sCI);
794 }
795
readJSON_VkSamplerYcbcrConversionCreateInfo(Context & context,const std::string & samplerYcbcrConversionCreateInfo,VkSamplerYcbcrConversionCreateInfo & sycCI)796 void readJSON_VkSamplerYcbcrConversionCreateInfo (Context& context,
797 const std::string& samplerYcbcrConversionCreateInfo,
798 VkSamplerYcbcrConversionCreateInfo& sycCI)
799 {
800 Json::Value jsonRoot;
801 std::string errors;
802 bool parsingSuccessful = context.reader->parse(samplerYcbcrConversionCreateInfo.c_str(), samplerYcbcrConversionCreateInfo.c_str() + samplerYcbcrConversionCreateInfo.size(), &jsonRoot, &errors);
803 if (!parsingSuccessful)
804 TCU_THROW(InternalError, (std::string("JSON parsing error: ") + errors).c_str());
805 vk_json_parser::parse_VkSamplerYcbcrConversionCreateInfo("", jsonRoot, sycCI);
806 }
807
readJSON_VkPhysicalDeviceFeatures2(Context & context,const std::string & featuresJson,vk::VkPhysicalDeviceFeatures2 & features)808 void readJSON_VkPhysicalDeviceFeatures2 (Context& context,
809 const std::string& featuresJson,
810 vk::VkPhysicalDeviceFeatures2& features)
811 {
812 Json::Value jsonRoot;
813 std::string errors;
814 bool parsingSuccessful = context.reader->parse(featuresJson.c_str(), featuresJson.c_str() + featuresJson.size(), &jsonRoot, &errors);
815 if (!parsingSuccessful)
816 TCU_THROW(InternalError, (std::string("JSON parsing error: ") + errors).c_str());
817 vk_json_parser::parse_VkPhysicalDeviceFeatures2("", jsonRoot, features);
818 }
819
readJSON_pNextChain(Context & context,const std::string & chainJson)820 void* readJSON_pNextChain (Context& context,
821 const std::string& chainJson)
822 {
823 Json::Value jsonRoot;
824 std::string errors;
825 bool parsingSuccessful = context.reader->parse(chainJson.c_str(), chainJson.c_str() + chainJson.size(), &jsonRoot, &errors);
826 if (!parsingSuccessful)
827 TCU_THROW(InternalError, (std::string("JSON parsing error: ") + errors).c_str());
828 return vk_json_parser::parsePNextChain(jsonRoot);
829 }
830
parse_VkShaderModuleCreateInfo(const char * s,Json::Value & obj,VkShaderModuleCreateInfo & o,std::vector<deUint8> & spirvShader)831 static void parse_VkShaderModuleCreateInfo (const char* s,
832 Json::Value& obj,
833 VkShaderModuleCreateInfo& o,
834 std::vector<deUint8>& spirvShader)
835 {
836 DE_UNREF(s);
837
838 vk_json_parser::parse_VkStructureType("sType", obj["sType"], (o.sType));
839
840 o.pNext = (VkDeviceObjectReservationCreateInfo*)vk_json_parser::parsePNextChain(obj);
841
842 vk_json_parser::parse_uint32_t("flags", obj["flags"], (o.flags));
843 deUint64 codeSizeValue;
844 vk_json_parser::parse_uint64_t("codeSize", obj["codeSize"], (codeSizeValue));
845 o.codeSize = (deUintptr)codeSizeValue;
846
847 // pCode is encoded using Base64.
848 spirvShader = vk_json_parser::base64decode(obj["pCode"].asString());
849 // Base64 always decodes a multiple of 3 bytes, so the size could mismatch the module
850 // size by one or two bytes. resize spirvShader to match.
851 spirvShader.resize(o.codeSize);
852 o.pCode = (deUint32*)spirvShader.data();
853 }
854
readJSON_VkShaderModuleCreateInfo(Context & context,const string & shaderModuleCreate,VkShaderModuleCreateInfo & smCI,std::vector<deUint8> & spirvShader)855 void readJSON_VkShaderModuleCreateInfo (Context& context,
856 const string& shaderModuleCreate,
857 VkShaderModuleCreateInfo& smCI,
858 std::vector<deUint8>& spirvShader)
859 {
860 Json::Value jsonRoot;
861 string errors;
862 bool parsingSuccessful = context.reader->parse(shaderModuleCreate.c_str(), shaderModuleCreate.c_str() + shaderModuleCreate.size(), &jsonRoot, &errors);
863 if (!parsingSuccessful)
864 TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
865 parse_VkShaderModuleCreateInfo("", jsonRoot, smCI, spirvShader);
866 }
867
868 } // namespace json
869
870 } // namespace vksc_server
871